I made a simple c++ code that reads the webcam image and display it. However, when I compile, I get the error - 'Undefined reference to cv::Mat::Mat()'. I don't know why it shows two Mat's. Here is my code:
#include <opencv2/opencv.hpp>
#include <iostream>
#include <math.h>
#include <stdlib.h>
int main() {
cv::VideoCapture cap(0);
if (!cap.isOpened){
std::cout << "Error opening camera" << std::endl;
}
cv::Mat img;
while(1){
cap >> img;
cv::imshow("output", img);
cv::waitKey(1);
}
}
This is how I compile it
g++ example.cpp `pkg-config --libs opencv4`
I can't figure out why the error shows up. Any help is appreciated!