[macos]c++开发opencv_环境搭建
1.安装opencv
brew install opencv
2.测试安装
新建文件夹opencv1
新建test.cpp文件
[test.cpp]
#include "/usr/local/Cellar/opencv/4.5.3_2/include/opencv4/opencv2/opencv.hpp"
//这里改成自己的路径
using namespace cv;
int main() {
Mat img = imread("/Users/workspace/Documents/C/opencv1/test1.png"); //引号内选一张自己计算机内的图片的路径
imshow("deceye", img); //打开一个窗口,显示图片
waitKey(0); //在键盘敲入字符前程序处于等待状态
destroyAllWindows(); //关闭所有窗口
return 0;
}
[CMakeLists.txt]
cmake_minimum_required(VERSION 3.5)
project(app-template)
SET(OPENCVPATH "/usr/local/Cellar/opencv4")
#查找OpenCV是否安装,这里是关键find_package()可以自动查找安装的库
find_package(OpenCV REQUIRED core highgui imgproc imgcodecs)
#if (OPENCV_FOUND)
message(STATUS "找到OpenCV:\"${OpenCV_INCLUDE_DIRS}\",ENABLE_OPENCV宏已打开")
include_directories(${OpenCV_INCLUDE_DIRS})
link_directories(${OpenCV_INCLUDE_DIRS}/opencv2/lib)
#确定编译语言
set(CMAKE_CXX_STANDARD 11)
add_executable(app-template test.cpp)
target_link_libraries(app-template ${OpenCV_LIBS})#${OpenCV_LIBS}是自动生成的路径,写这个不会错
3.编译
命令行
cd ~/opencv1进入文件夹
(没安装cmake->brew install cmake)
cmake .
make
环境搭建完成!
4.参考
https://blog.csdn.net/ryuuei_1984/article/details/52209331?locationNum=2&fps=1
~好记性不如烂键盘~