opencv c++配置测试

操作系统:ubuntu20.04
版本:opencv4.x

CMakeLists.txt

cmake_minimum_required(VERSION 3.0 FATAL_ERROR)
project(main)
find_package(OpenCV REQUIRED)
include_directories(${OpenCV_INCLUDE_DIRS})
message("OpenCV include: " ${OpenCV_INCLUDE_DIRS})
link_directories(${OpenCV_LIBRARY_DIRS})

add_executable(main test.cpp)
target_link_libraries(main ${OpenCV_LIBS})

test.cpp

#include 
#include 
#include 
#include 

using namespace std;
using namespace cv;

int main(int argc, char** argv)
{
    // if (argc != 2)
    // {
    //     cout << "Usage: opencv_test " << endl;
    //     return -1;
    // }

    char *imgName = "demo.jpeg";
    Mat image;

    image = imread(imgName, 1);
    // cv::imshow()
    cv::imshow("test", image);
    cv::waitKey(0);
    if (!image.data)
    {
        cout << "No image data" << endl;
        return -1;
    }
    // cout << image << endl;
    Mat gray_img;

    cvtColor(image, gray_img, COLOR_BGR2GRAY);
    imwrite("result.jpg", gray_img);

    return 0;
}

vscode c_cpp_properties.json
增加头文件

"/usr/local/include/opencv4"

你可能感兴趣的:(opencv,c++,计算机视觉)