Ask Your Question
0

Error in Detecting Moving Object

asked 2013-06-24 14:55:33 -0500

FLY gravatar image

updated 2013-06-25 04:48:00 -0500

I am trying to detect only the moving object , for that until now , i just delete the background from my video , and now i learn that i have to apply the bitwise function on video to detect only moving object , correct me if i am on wrong direction. Following is the code i did Deleting Background

VideoCapture capture;
Mat current_frame;
Mat previous_frame;
Mat result;    

capture.open("try.avi");
if (!capture.isOpened()) {
    cerr << "can not open camera or video file" << endl;
    return -1;
}

while(1)
{
    capture >> current_frame;
    if (current_frame.empty())
        break;
if (! previous_frame.empty())  {
       // subtract frames
       subtract(current_frame, previous_frame, result);
       imshow("Window", result); 
   }
   waitKey(10);

Than i apply bitwise function for only detecting the moving objects

movement = false;
absdiff(next_frame, current_frame, d1);
absdiff(current_frame, prev_frame, d2);
bitwise_xor(d1, d2, result);
edit retag flag offensive close merge delete

Comments

What is your question? If it's why you have an error, I think it because your video (try.avi) isn't in the right directory (or maybe doesn't exist).

Mathieu Barnachon gravatar imageMathieu Barnachon ( 2013-06-24 17:24:04 -0500 )edit

I dont have error , but i didnt get the right output , i just want to get the moving object , but i also show some other object with it

FLY gravatar imageFLY ( 2013-06-25 04:49:33 -0500 )edit

1 answer

Sort by ยป oldest newest most voted
2

answered 2013-06-25 17:07:24 -0500

updated 2013-06-27 16:53:05 -0500

If you have many small part of "motion", you could use either another background subtraction, like these one, but probably you still have noise. You may have to use Morphological Mathematics to remove this speckles, see erode, dilate, and morphologyEx with OPEN and CLOSE.

Keep in mind, the background subtraction is to see what pixels are moving, if you want to track an object, you have to perform a tracking of this object, with blob or anything else.

[Update] For vehicles detection, there is many workflows. Some of them are even not using background subtraction. You could Google it if your are interested. But in your case, I think you should look at this paper: Robust Vehicle Detection for Tracking in Highway Surveillance Videos using Unsupervised Learning, Tamersoy and Aggarwal, in Advanced Video and Signal Based Surveillance, 2009. It used background subtraction, and histogram of oriented gradient with an SVM for binary classification. All these algorithms are in OpenCV, therefore, you could start testing directly.

edit flag offensive delete link more

Comments

Actually i am detecting vehicles from video , and for that first i am subtracting background , can you help me in that sense , by keeping in my mind my problem of detecting vehicle , +1 for help

FLY gravatar imageFLY ( 2013-06-26 04:19:21 -0500 )edit

Are you looking for vehicle tracking or for background subtraction?

Mathieu Barnachon gravatar imageMathieu Barnachon ( 2013-06-26 17:46:55 -0500 )edit

I am doing background subtraction , and i will do vehicle detect in it , through checking moving objects

FLY gravatar imageFLY ( 2013-06-27 12:40:56 -0500 )edit

I am implementing , but i got some problem in algorithm Backgroundsubtractormog2 implementation which i mention on this forum and as well on stackoverflow http://stackoverflow.com/questions/17284712/error-in-backgroundsubtraction-mog2 well thanks for your guidance and help

FLY gravatar imageFLY ( 2013-06-28 09:54:42 -0500 )edit

See the sample bgfg_segm.cpp to see the MOG2 working, or bgfg_gmg.cpp.

Mathieu Barnachon gravatar imageMathieu Barnachon ( 2013-06-28 17:53:27 -0500 )edit

Hye i've done background subtraction using Backgroundsubtractormog. In my video the moving objects are detected but now i want to track them and classify as either vehicle or people. What should i do next?

Fajre gravatar imageFajre ( 2014-05-01 10:42:56 -0500 )edit
Login/Signup to Answer

Question Tools

Stats

Asked: 2013-06-24 14:55:33 -0500

Seen: 671 times

Last updated: Jun 27 '13