0

I am using EmguCV and OpenNi in C# to retrieve the pointcloud from the Kinect. The code I am using is below:


IntPtr img = CvInvoke.cvRetrieveFrame(kCapture.Ptr, 1);
                if (img != IntPtr.Zero)
                {
                    MIplImage iplImage = (MIplImage)Marshal.PtrToStructure(img, typeof(MIplImage));

                    MCvPoint3D32f[] points = new MCvPoint3D32f[iplImage.width * iplImage.height];

                    GCHandle handle = GCHandle.Alloc(points, GCHandleType.Pinned);
                    using (Matrix m = new Matrix(iplImage.height, iplImage.width, handle.AddrOfPinnedObject()))
                    {
                        CvInvoke.cvCopy(img, m, IntPtr.Zero);
                    }
                    handle.Free();

                }

I get an exception with the message "OpenCV: src.channels() == dst.channels()" when I am trying to perform the copy operation.

Shivam
  • 144
  • 2
  • 9
  • Is actually img.channels() same as m.channels()? – Sassa Oct 02 '12 at 14:32
  • yes same size and same number of channels. It is supposed to copy the data from the img which has only one channel into the matrix m. This error seems very odd, I get get depth data in pixel intensity but not the point cloud. – Shivam Oct 02 '12 at 14:40

1 Answers1

-1

I have been tinkering with the opencv and Emgu CV all weekend and I have managed to sort it out. Turns out you can use the RetrieveBgrFrame to retrieve the point cloud.


Image pcl = kCapture.RetrieveBgrFrame((int)Emgu.CV.KinectCapture.OpenNIDataType.PointCloudMap);
                Image pclf = new Image(pcl.MIplImage.width, pcl.MIplImage.height, pcl.MIplImage.widthStep, pcl.MIplImage.imageData);

Shivam
  • 144
  • 2
  • 9
  • The code you posted might be dated. I'm assuming kCapture is a KinectCapture object from Emgu.CV. There is now a 'RetrievePointCloudMap' in that object, see here for reference: http://www.emgu.com/wiki/files/3.0.0/document/html/ae627911-05a3-99ac-c417-b0bc6152d738.htm – Mathias Siig Nørregaard Oct 18 '16 at 09:41