其他分享
首页 > 其他分享> > Mac - 编译OpenCV

Mac - 编译OpenCV

作者:互联网

简介

简单记录Mac下编译OpenCV。

 

使用HomeBrew安装cmake

brew install cmake

 

获取OpenCV源代码

官网地址:https://opencv.org/releases/

选择Sources下载

 

编译OpenCV

mkdir build
cd build
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local ..
make -j8
make install

安装好 OpenCV 后,在 /usr/local/lib 下能看到opencv相关的lib库

 

Clion项目使用OpenCV

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