Binary Video frame by frame in PictureBox in VC++
I am relatively new to the world of Opencv and making graphical applications in vc++. I have a background of working in C# but for the sake of expanding my horizons I have started working in this new environment. My code basically employs GMM on a video and is SUPPOSED to display the results in one window via 2 picture boxes. I have managed to get the code running and to make it display the original video in one picture box but the converted video i.e. on which I have employed the GMM is giving me trouble as the picturebox2->Refresh gives the following error:
"An unhandled exception of type 'System.ArgumentException' occurred in System.Drawing.dll
Additional information: Parameter is not valid." Before you ask, I have tried converting the binary image back into RGB as proposed by a developer on this forum on a similar question by using cvCvtColor(ref,frame,CV_GRAY2RGB) but that didn't work either as I still got the color. Ofc I used the correct picture format after I converted to RGB. Anyhow, help will be much appreciated. The code snippet can be viewed below. Oh and the code works fine if I use cvShowImage
while(key != 'q')
{ // Grab a frame videoFrame = cvQueryFrame(capture); if( !videoFrame ) break;
// Update model
cvCopy(videoFrame,frame);
cvUpdateBGStatModel(frame,bgModel);
// Display results
pictureBox1->Image = gcnew //replacement of cvShowImage
System::Drawing::Bitmap(frame->width,frame->height,frame->widthStep,
System::Drawing::Imaging::PixelFormat::Format24bppRgb,(System::IntPtr) frame->imageData);
pictureBox1->Refresh();
ref=bgModel->foreground;
pictureBox2->Image = gcnew //replacement of cvShowImage
System::Drawing::Bitmap(frame->width,frame->height,frame->widthStep,
System::Drawing::Imaging::PixelFormat::Format16bppGrayScale,(System::IntPtr) ref->imageData);
pictureBox2->Refresh();
key = cvWaitKey(10);
}