The recent project encountered a problem, and then use mixed Gaussian background model to extract the foreground graph displayed on the MFC window, there is a problem, the image is not displayed properly. Display effects such as:
I use the mat type image and the imshow to display, this situation unexpectedly. Because the other can be displayed normally.
After starting to find the problem on the Internet, but after a multi-search, found that there is no such problem online. Embarrassed.
Finally helpless start all parties to help, question and answer Ah, forum posts AH have tried but no one answer ... Finally fortunately through the guidance teacher met a study three seniors, seniors said because the OpenCV and MFC image format is not the same, it will appear this problem, it is necessary to convert the mat into the binary stream into the MFC image format to display .... After listening to really feel trouble. And it doesn't seem like the problem is here. Because the other images can be displayed, there is a problem with the Gaussian background extraction.
After this, and after a hard search, find a piece of the Internet using MFC to display the results of the Gaussian background code, after learning that he is the mat type first to lplimage type after a smooth processing and then the Lplimage type to mat can be displayed smoothly ... I tried it and sure enough ...
Now I still can't figure out what the reason is, maybe it's an unknown bug ...
I hope to meet the same problem of children's shoes to see this blog can help you, but also want to know the specific reasons for the big guy message exchange.
The following is the code that handles the problem:
1 BackgroundSubtractorMOG2 Mog;2 Mat frame, back;3 4 if(!cap.isopened ())5 {6 return;7 }8 9 while(Cap.read (frame))Ten { One if(Frame.empty ()) A { - - Break; the } -Iplimage src =frame; -Iplimage *DST = Cvcreateimage (Cvgetsize (&SRC),8,3); -Cvsmooth (&src, DST, Cv_gaussian); +Mat so =DST; -Mog (So, back,0.001); + AThreshold (back, back, -,255, cv_thresh_binary); at -Mat Kernel (3,3, cv_8u); - Erode (back, back, kernel); - - -Imshow ("Gaussian", back); in - intc = Waitkey ( -); to if(c = = -|| c = ='Q') + { - Break; the } * $}
mfc+opencv+ Gaussian background foreground extraction image display problem