I am trying to open a window of my webcam using opencv in c++ but it seems the webcam does not want to open. I tested before in other apps like cheese and it works.
#include <opencv2/highgui.hpp>
#include <iostream>
int main() {
int PORT = 0;
cv::Mat image;
cv::namedWindow("Webcam window", cv::WINDOW_AUTOSIZE);
cv::VideoCapture cap(PORT);
cap.set(cv::CAP_PROP_FRAME_WIDTH, 640);
cap.set(cv::CAP_PROP_FRAME_HEIGHT, 480);
if (!cap.isOpened()) {
std::cout << "Could not open the camera" << std::endl;
return -1;
}
while (true) {
cap >> image;
if (!image.empty())
cv::imshow("Webcam window", image);
if (cv::waitKey(10) >= 0) {
break;
}
}
return 0;
}
I am using ubuntu budgie 21.10.