EmguCV image depth problem with Code Laboratory Kinect Calibration
I'm using the Emgu wrapper for OpenCV in C#, and I have the following nagging problem.
I'm using the Code Laboratories Kinect API and the code to get an image out of the Kinect looks like this:
//Forms the array to store the image data in.
uint[] imageSource = new uint[640 * 480];
//EmguCV needs everything to be IntPtrs, so wrapping the array in one.
GCHandle handle1 = GCHandle.Alloc(开发者_Python百科imageSource, GCHandleType.Pinned);
try
{
imageSourcePointer = handle1.AddrOfPinnedObject();
}
finally
{
if (handle1.IsAllocated)
{
handle1.Free();
}
}
imagePointer = IntPtr.Zero;
//Getting the camera information.
IntPtr camera = CLNUIDevice.CreateCamera(CLNUIDevice.GetDeviceSerial(0));
//Pulling from the image.
CLNUIDevice.GetCameraColorFrameRGB24(camera, imageSourcePointer, 0);
imagePointer = CvInvoke.cvCreateImageHeader(new Size(640, 480), IPL_DEPTH.IPL_DEPTH_8S, 1);
//TODO change the widtstep to be generic based on the camera.
MIplImage image = (MIplImage) Marshal.PtrToStructure(imagePointer, typeof(MIplImage));
//Connecting the data array to the image definition's header.
CvInvoke.cvSetData(imagePointer, imageSourcePointer, image.widthStep);
Now, all my IntPtr wrapping seems to work since the data they point to get updated just fine.
The problem comes when I try to use the function:
//For finding the corners of a chessboard in the given image.
int found = CvInvoke.cvFindChessboardCorners(imagePointer, board_sz, cornerPointer, ref corner_count, Emgu.CV.CvEnum.CALIB_CB_TYPE.ADAPTIVE_THRESH | Emgu.CV.CvEnum.CALIB_CB_TYPE.FILTER_QUADS);
And I get the runtime exception which says
"OpenCV: Only 8-bit grayscale or color images are supported"
I've tried all the color pull methods from the Code Laboratory Kinect - the RGB24, RGB32 and RAW pull commands, but the exception remains. I've declared my image (imageSource) as an 8 bit signed integer image, and didn't expect the error to come on.
I tried to narrow down why this was happening, and thought -
The image pulled from the Kinect, despite being stored in an 8-bit OpenCV image header, still has its own bit depth properties.
The uint[] that I'm using as the data array for the Kinect remains a 32 bit array, which leads the entire image into becoming a 32-bit image. This still doesn't seem as likely, though possible.
I've been stuck on this for a while, so any suggestions would be really helpful. Thanks so much!
EDIT - I think I've figured this out - some things that I didn't initially understand about Emgu. I'll post solution code soon if anyone does end up need to look at this.
精彩评论