[b]Problems converting OptiTrack image to OpenCV in C#[

Post Reply
BrianScherady
Posts: 4
Joined: Thu Apr 01, 2010 1:40 pm

[b]Problems converting OptiTrack image to OpenCV in C#[

Post by BrianScherady »

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
beckdo
Posts: 520
Joined: Tue Jan 02, 2007 2:02 pm

Re: [b]Problems converting OptiTrack image to OpenCV in C#[

Post by beckdo »

If the pixels are spaced with gaps that would suggest that you have a pixel format issue.

I would suggest trying 8 bits per pixel format when calling Rasterize. That will basically mean one pixel per byte, which means no gaps.
BrianScherady
Posts: 4
Joined: Thu Apr 01, 2010 1:40 pm

Re: [b]Problems converting OptiTrack image to OpenCV in C#[

Post by BrianScherady »

I tried:
camera.GetFrameImage(frame, bmData.Width, bmData.Height, bmData.Stride, 8, ref buffer[0])
instead of
camera.GetFrameImage(frame, bmData.Width, bmData.Height, bmData.Stride, 32, ref buffer[0])


and I tried:
System.Drawing.Imaging.PixelFormat.Format8bppIndexed
instead of
System.Drawing.Imaging.PixelFormat.Format32bppArgb

I also tried all other possible combinations but without success.
I am using the code �CameraView.xaml.cs� from �Single_Camera_CSharp_.NET_3.0�

What to do ?
BrianScherady
Posts: 4
Joined: Thu Apr 01, 2010 1:40 pm

Re: [b]Problems converting OptiTrack image to OpenCV in C#[

Post by BrianScherady »

Solved !

I used:

OpenCVimage = CvInvoke.cvCreateImageHeader(new System.Drawing.Size(WIN_WIDTH, WIN_HEIGHT), Emgu.CV.CvEnum.IPL_DEPTH.IPL_DEPTH_8U, 4);

instead of:

OpenCVimage = CvInvoke.cvCreateImageHeader(new System.Drawing.Size(WIN_WIDTH, WIN_HEIGHT), Emgu.CV.CvEnum.IPL_DEPTH.IPL_DEPTH_8U, 3);
Post Reply