[C++][opencv][cmakelists]opencv读取图像并显示

CMakeLists.txt


cmake_minimum_required (VERSION 3.8)
project(opencv_test VERSION 1.0.0)
find_package (OpenCV REQUIRED)
include_directories (${OpenCV_INCLUDE_DIRS}
add_executable (main main.cpp)
target_link_libraries (main ${OpenCV_LIBS})

main.cpp

#include <opencv2/opencv.hpp>
#include <iostream>
using namespace cv;
using namespace std;
int main() {
Mat img = imread("test.jpg");
if(img.empty())
{
std::cout<<"image data is empty, image path not right!\n";
return 0;
}
namedWindow("demo",CV_WINDOW_NORMAL);
imshow("demo", img);
waitKey(0);
destroyAllWindows(); 
return 0;
}

猜你喜欢

转载自blog.csdn.net/FL1623863129/article/details/129943625