Actually I'm using "gaussian mixture based" "BackgroundSubtractorMOG2" to tracking cars in a video, but the result is a video in slowmotion and noise like car shadow. if someone know another algorithm with better performance, please answers me.
1 | initial version |
Actually I'm using "gaussian mixture based" "BackgroundSubtractorMOG2" to tracking cars in a video, but the result is a video in slowmotion and noise like car shadow. if someone know another algorithm with better performance, please answers me.
2 | No.2 Revision |
Actually I'm using "gaussian mixture based" "BackgroundSubtractorMOG2" to tracking cars in a video, but the result is a video in slowmotion and noise like car shadow. if someone know another algorithm with better performance, please answers me.me.
this is the code:
cv::Mat frame;
cv::Mat back;
cv::Mat fore;
cv::VideoCapture cap("CarSurveillance/Video1.avi");
cv::BackgroundSubtractorMOG2 bg;
bg.setInt("nmixtures", 3);
bg.setBool("detectShadows", false);
std::vector<std::vector<cv::Point> > contours;
cv::namedWindow("Frame");
cv::namedWindow("Background");
while (1)
{
cap.read(frame);
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);
cv::imshow("Frame", frame);
cv::imshow("Background", back);
if (cv::waitKey(30) >= 0) break;
}
return 0;
3 | No.3 Revision |
Actually I'm using "gaussian mixture based" "BackgroundSubtractorMOG2" to tracking cars in a video, but the result is a video in slowmotion and noise like car shadow. if someone know another algorithm with better performance, please answers me.
this is the code: code:
cv::Mat frame;
cv::Mat back;
cv::Mat fore;
cv::VideoCapture cap("CarSurveillance/Video1.avi");
cv::BackgroundSubtractorMOG2 bg;
bg.setInt("nmixtures", 3);
bg.setBool("detectShadows", false);
std::vector<std::vector<cv::Point> > contours;
cv::namedWindow("Frame");
cv::namedWindow("Background");
while (1)
{
cap.read(frame);
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);
cv::imshow("Frame", frame);
cv::imshow("Background", back);
if (cv::waitKey(30) >= 0) break;
}
return 0;
4 | No.4 Revision |
Actually I'm using "gaussian mixture based" "BackgroundSubtractorMOG2" to tracking cars in a video, but the result is a video in slowmotion and noise like car shadow. if someone know another algorithm with better performance, please answers me. this is the code:
cv::Mat frame;
cv::Mat back;
cv::Mat fore;
cv::VideoCapture cap("CarSurveillance/Video1.avi");
cv::BackgroundSubtractorMOG2 bg;
bg.setInt("nmixtures", 3);
bg.setBool("detectShadows", false);
std::vector<std::vector<cv::Point> > contours;
cv::namedWindow("Frame");
cv::namedWindow("Background");
while (1)
{
cap.read(frame);
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);
cv::imshow("Frame", frame);
cv::imshow("Background", back);
if (cv::waitKey(30) >= 0) break;
}
return 0;
I changed these lines:
//bg.getBackgroundImage(back);
cv::Mat element = getStructuringElement(MORPH_RECT, Size(3, 3), Point(1, 1));
cv::erode(fore, fore, element);
element = getStructuringElement(MORPH_RECT, Size(9, 9), Point(4, 4));
cv::dilate(fore, fore, element);