I got a question regarding to OpenCV 2.3.1
with C++/CLI
. I take the output of C++/CLI
and display it into C# pictureBox
.
When I use Gaussian background subtraction to analyse image, the format of output when converting to cvMat
is not what I expected. The BG subtraction frame is split & duplicated into 3 sessions. Also, its. type()
and channels()
is different from the raw frame
However, when display frames sequence using cvShowImage()
(instead of C# picturebox), it shows correctly.
Here is the code for Background subtraction
void NormalBGSubtraction_Adapter::BackgroundSubtraction(IplImage *proImg, IplImage* &maskImg)
{
Mat pImg(proImg);
Mat mImg;
bg.operator()(pImg, mImg);
erode(mImg, mImg, cv::Mat());
dilate(mImg, mImg, cv::Mat());
maskImg = cvCloneImage(&(IplImage)mImg);
}
Thank you for your concerns. Finally, after some days, I figure it out the reason of errors: Because of the incorrect format produced by background subtraction methods above.
My C# pictureBox expects RGB
, not GRAY
. However, after erode
and dilate
, it by somehow make the mImg to GRAY
format.
All I done is just converting back to RGB
:
void NormalBGSubtraction_Adapter::BackgroundSubtraction(IplImage *proImg, IplImage* &maskImg)
{
Mat pImg(proImg);
Mat mImg;
bg.operator()(pImg, mImg);
/*
erode and dilate meaning : Removing noise
Isolation of individual elements and joining disparate elements in an image.
Finding of intensity bumps or holes in an image
*/
erode(mImg, mImg, cv::Mat());
dilate(mImg, mImg, cv::Mat());
cvtColor(mImg, mImg, CV_GRAY2RGB);
maskImg = cvCloneImage(&(IplImage)mImg);
}
Hope it helps if anyone face with the same situation :)
Cheers,
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.