OpenCV C++ absdiff() unhandled exception

  c++, opencv, visual-studio

I tried finding the frame difference between a still image and a frame taken from my webcam, using absdiff(). My code is as follows:

#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc.hpp>
#include <opencv2/objdetect.hpp>
#include <iostream>

using namespace std;
using namespace cv;

int main() {
    VideoCapture webcam(0);
    Mat img, web, diff;
    
    webcam >> web;
    img = imread("/Users/dnxv2/Desktop/test.jpg");

    cvtColor(web, web, COLOR_BGR2GRAY);
    cvtColor(img, img, COLOR_BGR2GRAY);

    absdiff(img, web, diff);
    
    imshow("test", diff);
    waitKey(0);
}

Upon running it, I ran into an error, and I could not resolve it.

Unhandled exception at 0x00007FF937E24F99 in test.exe: Microsoft C++ exception: cv::Exception at memory location 0x000000FA29CFE1B0.

Was there something I missed? Your help is much appreciated!

Source: Windows Questions C++

LEAVE A COMMENT