Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Error in Detecting Moving Object

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

In this code i got error on this line cerr << "can not open camera or video file" << endl; 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);

Error in Detecting Moving Object

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

In this code i got error on this line cerr << "can not open camera or video file" << endl; 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);