[b]Problems converting OptiTrack image to OpenCV in C#[
Posted: Fri Nov 05, 2010 6:41 am
Problems converting OptiTrack camera image to OpenCV image �IplImage� in C# language.
I have succeeded to convert it rather easily in C++ but I have difficulties to do it in C#. Following are the sections of the concerned code in C# that I am using.
static System.Drawing.Imaging.PixelFormat ThisPixelFormat = System.Drawing.Imaging.PixelFormat.Format32bppArgb;
private System.Drawing.Bitmap raw = new System.Drawing.Bitmap(840, 480, ThisPixelFormat);
��
(other code)
��
IntPtr OpenCVimage = CvInvoke.cvCreateImage(new System.Drawing.Size(FrameWidth, FrameHeight), Emgu.CV.CvEnum.IPL_DEPTH.IPL_DEPTH_8U, 3);
��
(other code)
��
private void GetOpenCVimage( IntPtr OpenCVimage)
{
BitmapData bmData = raw.LockBits(new System.Drawing.Rectangle(0, 0, raw.Width, raw.Height), ImageLockMode.ReadWrite, ThisPixelFormat);
int widthStep = bmData.Width * 4;
CvInvoke.cvSetData(OpenCVimage, bmData.Scan0, widthStep);
raw.UnlockBits(bmData);
mVideoFrameAvailable = true;
}
��
(other code)
��
CvInvoke.cvShowImage("FFTT show Image", OpenCVimage);
The problem I am trying to solve:
No matter what I try the image appears always in gray scale and looks as if it had for every pixel 2 other pixels one on the top and one on the bottom. Also it looks like if it had a blank pixel after each pixel, which gives the effect that the image had vertical blank stripes and the objects wider than in real.
Could you help ?
Thank you
Brian
I have succeeded to convert it rather easily in C++ but I have difficulties to do it in C#. Following are the sections of the concerned code in C# that I am using.
static System.Drawing.Imaging.PixelFormat ThisPixelFormat = System.Drawing.Imaging.PixelFormat.Format32bppArgb;
private System.Drawing.Bitmap raw = new System.Drawing.Bitmap(840, 480, ThisPixelFormat);
��
(other code)
��
IntPtr OpenCVimage = CvInvoke.cvCreateImage(new System.Drawing.Size(FrameWidth, FrameHeight), Emgu.CV.CvEnum.IPL_DEPTH.IPL_DEPTH_8U, 3);
��
(other code)
��
private void GetOpenCVimage( IntPtr OpenCVimage)
{
BitmapData bmData = raw.LockBits(new System.Drawing.Rectangle(0, 0, raw.Width, raw.Height), ImageLockMode.ReadWrite, ThisPixelFormat);
int widthStep = bmData.Width * 4;
CvInvoke.cvSetData(OpenCVimage, bmData.Scan0, widthStep);
raw.UnlockBits(bmData);
mVideoFrameAvailable = true;
}
��
(other code)
��
CvInvoke.cvShowImage("FFTT show Image", OpenCVimage);
The problem I am trying to solve:
No matter what I try the image appears always in gray scale and looks as if it had for every pixel 2 other pixels one on the top and one on the bottom. Also it looks like if it had a blank pixel after each pixel, which gives the effect that the image had vertical blank stripes and the objects wider than in real.
Could you help ?
Thank you
Brian