Mac 编译OpenCV

2021-07-05  本文已影响0人  milovetingting

个人博客

http://www.milovetingting.cn

前言

简单记录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

指定并行8个线程

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

上一篇下一篇

猜你喜欢

热点阅读