code is simple!
Main.cpp
#include <opencv2/opencv.hpp>
#include <opencv2/core/core.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2//video.hpp>
#include <opencv2/videoio/videoio.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <iostream>
int main()
{
cv::VideoCapture cap(1); //if(!cap.isOpened()) throw std::runtime_error(“Can’t open camera!”);
cv::Mat frame; // = cv::Mat::zeros(640, 480, CV_8U);
cv::namedWindow(“Test”);
while(true) {
cap >> frame;
cv::imshow(“Test”, frame);
if(cv::waitKey(20) == 27) break;
}
std::cout << "Hello, World!" << std::endl;
return 0;
}
CMakeLists.txt
cmake_minimum_required(VERSION 3.17)
project(Test)
set(CMAKE_CXX_STANDARD 14)
find_package(OpenCV REQUIRED)
#message(${CMAKE_MODULE_PATH})
include_directories({OpenCV_INCLUDE_DIRS})
#set(OpenCV_LIB_PATH "{OpenCV_DIR}/lib")
add_executable(Test main.cpp)
target_link_libraries(Test ${OpenCV_LIBS})
"OpenCV/x64/mingw/bin" is in PATH!