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,