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