Mac - 编译OpenCV
作者:互联网
简介
简单记录Mac下编译OpenCV。
使用HomeBrew安装cmake
brew install cmake
获取OpenCV源代码
官网地址:https://opencv.org/releases/
选择Sources下载
编译OpenCV
- 解压文件,在解压后的目录中创建一个临时目录,名称不限,如build,在终端中执行
mkdir build
- 进入创建的目录
cd build
- 配置
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local ..
- 编译(指定并行8个线程)
make -j8
- 安装
make install
安装好 OpenCV 后,在 /usr/local/lib 下能看到opencv相关的lib库
Clion项目使用OpenCV
- Clion新建一个项目
- 配置CMakeLists.txt的内容
cmake_minimum_required(VERSION 3.17) project(OpenCV) set(CMAKE_CXX_STANDARD 14) find_package(OpenCV) include_directories(${OpenCV_INCLUDE_DIRS}) add_executable(OpenCV main.cpp) target_link_libraries(OpenCV ${OpenCV_LIBS})
- 编写代码
#include <iostream> #include <opencv2/opencv.hpp> using namespace std; using namespace cv; int main() { Mat srcImage = imread("/Users/ringle/Downloads/demo.jpeg"); if(!srcImage.data){ cout<<"Image not loaded"; return -1; } namedWindow("origin",WINDOW_AUTOSIZE); imshow("[origin]",srcImage); Mat gray; cvtColor(srcImage,gray,COLOR_RGBA2GRAY); namedWindow("gray"); imshow("[gray]",gray); waitKey(0); return 0; }
运行后可以看到灰度后的图片
参考:https://www.jianshu.com/p/884ca9e3c50d
标签:CMAKE,编译,OpenCV,Mac,build,cmake,include 来源: https://www.cnblogs.com/citrus/p/16598678.html