I'm trying to play with my webcam and OpenCV. I follow this tuto : http://mateuszstankiewicz.eu/?p=189. But the only result I have is one red border and I don't understand why. Could anyone help me to make it right and fix this ?
Here is my code :
#include "mvt_detection.h"
Mvt_detection::Mvt_detection()
{
}
Mvt_detection::~Mvt_detection()
{
}
cv::Mat Mvt_detection::start(cv::Mat frame)
{
cv::Mat back;
cv::Mat fore;
cv::BackgroundSubtractorMOG2 bg(5,3,true) ;
cv::namedWindow("Background");
std::vector<std::vector<cv::Point> > contours;
bg.operator ()(frame,fore);
bg.getBackgroundImage(back);
cv::erode(fore,fore,cv::Mat());
cv::dilate(fore,fore,cv::Mat());
cv::findContours(fore,contours,CV_RETR_EXTERNAL,CV_CHAIN_APPROX_NONE);
cv::drawContours(frame,contours,-1,cv::Scalar(0,0,255),2);
return frame;
}
Here is a screenshot of what our cam returns :

I tried on two other video from there and there and there is the same issue.
Thanks for the help :).
cv::namedWindow("foreground"); cv::imshow("foreground",fore); cv::waitKey(30);? There you can see whether the motion COULD be detected in the image. If no foreground is visible, the background subtraction isn't well suited for your problem. Example images/videos would be nice, too! - Mickaforeimage. The image is all black. So, I guess we cannot use this method ? Is it because the webcam hasn't enough quality capacity ? Thanks - ogdaboucv::BackgroundSubtractorMOG2 bg(5,3,true) ;istrueand black window when it isfalse- LenjycoBackgroundSubtractorMOG2in my object's field and initialise it in constructor make him work well. TY all for contributions. - Lenjycoby reference! Just for you to understand what went wrong there. - Micka