I'm trying to convert a System::Drawing::Bitmap into a cv::Mat for what will eventually be a wrapper for c# (can't use EMGU in this case). I've seen lots of examples of how to construct a cv::Mat using a pointer to the Bitmap's data but my cv image is junk (a few pixels of junk and then nothing).
My code is:
System::Drawing::Rectangle blank = System::Drawing::Rectangle(0, 0, _image->Width, _image->Height);
System::Drawing::Imaging::BitmapData^ bmpdata = image.LockBits(blank,System::Drawing::Imaging::ImageLockMode::ReadWrite,System::Drawing::Imaging::PixelFormat::Format24bppRgb);
cv::Mat thisimage(cv::Size(image.Width, image.Height), CV_8UC3,bmpdata->Scan0.ToPointer(),cv::Mat::AUTO_STEP);
image.UnlockBits(bmpdata);
I've tried all sorts of things and attempted to copy the bytes directly but can't seem to get the syntax correctly. However, no matter what I do the image never seems to be converted correctly. I'm using visual studio's image watch add-on to check my images and if I load a cv::Mat directly from file it's all fine.