Frage

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

Wrong display

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);
}
War es hilfreich?

Lösung

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,

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top