c++ - Error while finding differences in frames from camera -
int main(int argc, char* argv[]) { videocapture cap(0); mat current_frame; mat previous_frame; mat result; mat frame; //cap.open(-1); if (!cap.isopened()) { //cerr << "can not open camera or video file" << endl; return -1; } while(1) { cap >> current_frame; if (current_frame.empty()) break; if (! previous_frame.empty()) { // subtract frames subtract(current_frame, previous_frame, result); } imshow("window", result); waitkey(10); frame.copyto(previous_frame); } }
when run program subtract current frame previous frame , show resultant frame , show me error while start executing
unhandled exception @ 0x755d812f in wk01.exe: microsoft c++ exception: cv::exception @ memory location 0x001fe848..
and want apply same thing on recorded video
in 1st frame, result empty !
imshow("window", result); // crash
also, you're copying empty frame
mat previous_frame
, should current_frame
instead, no ?
try like:
if (! previous_frame.empty()) { // subtract frames subtract(current_frame, previous_frame, result); imshow("window", result); } waitkey(10); current_frame.copyto(previous_frame); }
Comments
Post a Comment