Mac/VScode/Opencv/CMAKE 配环境

新建项目

-创建一个新项目,比如说“LuckyProject”

— 在该 LuckyProject 中创建一个新的 cpp 文件,我们将此文件称为 main.cpp

设置路径

—view — 命令面板 — C++ 编辑配置 (JSON)

Mac/VScode/Opencv/CMAKE 配环境_第1张图片​​​​​​​​​​​​​​​​​​​​​

——插入opencv的路径,我的是这样的:Mac/VScode/Opencv/CMAKE 配环境_第2张图片

 

"/usr/local/Cellar/opencv/4.5.4/include/opencv4”

创建CmakeLists.txt

cmake_minimum_required(VERSION 3.0.0)
project(Start_YTB VERSION 0.1.0)

include(CTest)
enable_testing()

find_package( OpenCV REQUIRED )
add_executable(Start_YTB main.cpp)

target_link_libraries( Start_YTB ${OpenCV_LIBS} )

include_directories(${OpenCV_INCLUDE_DIRS})

set(CMAKE_CXX_STARDARD 11)
set(CMAKE_CXX_STARDARD_REQUIRED true)

set(CPACK_PROJECT_NAME ${PROJECT_NAME})
set(CPACK_PROJECT_VERSION ${PROJECT_VERSION})
include(CPack)

写代码

#include 
#include 
using namespace cv;

int main(int argc, char const *argv[])
{
    /* code */
    std::cout << "opencv test for the first time" << std::endl;
    Mat image;
    image = imread("jar.png", 1);
    imshow("Start image with opencv", image);
    waitKey(0);
    return 0;
}

terminal跑

​​​​​​​Mac/VScode/Opencv/CMAKE 配环境_第3张图片​​​​​​​

 

//运行指令 run command
1.make

上一步会compile一个机器可以读的文件

然后第二步就是跑代码了。

2. 终端输入     ./Start_YTB

​​​​​​​​​​​​​​

 

你可能感兴趣的:(opencv,c++)