Ask Your Question
1

good algorithm to background subtraction for a car tracking?

asked 2014-06-18 09:52:53 -0600

updated 2014-06-19 13:21:51 -0600

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);
edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2014-06-18 12:29:59 -0600

Witek gravatar image

updated 2014-06-18 16:14:29 -0600

bg.setBool("detectShadows", true);

It should be better. Watch what happens to the fore image now.

Then, before erosion insert this:

cv::threshold(fore,fore,254,255,0);

It will remove shadows from further processing and hopefully get you what you want.

Also have a look here https://www.behance.net/gallery/BGS-Library/3943089

edit flag offensive delete link more

Comments

has the same result

ricardo99 gravatar imagericardo99 ( 2014-06-18 12:53:28 -0600 )edit

just edited my answer, hope it works

Witek gravatar imageWitek ( 2014-06-18 16:15:15 -0600 )edit

I added and modified these lines and had a good result if someone know another way to solve this problem, tell us.

//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);

ricardo99 gravatar imagericardo99 ( 2014-06-19 12:18:02 -0600 )edit

I don't understand. If you had a good result why do you need another way?

Witek gravatar imageWitek ( 2014-06-19 19:21:45 -0600 )edit

Because in this way I don't update the background and I don't know if exist another way with best results and performance.

ricardo99 gravatar imagericardo99 ( 2014-06-20 12:13:10 -0600 )edit

The background IS updated this way. Have a look at the raw fore image. You will see that shadows are marked in gray and moving objects in white if shadow detection is on, and everything that moves is marked in white when shadow detection is off.

Witek gravatar imageWitek ( 2014-06-20 15:25:22 -0600 )edit

Question Tools

Stats

Asked: 2014-06-18 09:52:53 -0600

Seen: 1,794 times

Last updated: Jun 19 '14