mac系统怎么编opencv_mac下opencv编译使用

1、安装cmake

brew install cmake

brew link cmake

2、下载

3、解压后

mkdir build

cd build

cmake -G "Unix Makefiles" -DCMAKE_INSTALL_PREFIX=./output ..输出路径

make

make install

在XCode中使用OpenCV

1. 创建一个空的command line工程。

2. 添加lib文件:在Build Phases 选项卡的Link Binary With Libraries 添加{buildpath编译的路径}/output/lib文件夹下的全部dylib文件

3. 添加lib文件查找支持: 在Build Settings选项卡,在“Library Search Paths”栏中输入"{buildpath编译的路径}/output/lib"

4. 添加头文件:在“Build Settings”选项卡,在“Header Search Paths”栏中输入:{buildpath编译的路径}/output/include

这时候可以编译了,但是跑不了

还需要在“Build Settings”选项卡的"Runpath Search Paths"也加上"{buildpath编译的路径}/output/lib"

还需要改库的签名

1)、codesign -f -s "Apple Development: your_name@email(XXXXXXXX)" your_path/output/lib/lib*.dylib

2)、codesign -f -s "Apple Development: your_name@email(XXXXXXXX)" /usr/local/opt/openjpeg/lib/*.dylib

demo代码

#include

#include

#include

//BGR -> Gray

cv::MatBGR2GRAY(cv::Mat img){

//get height and width

intwidth = img.cols;

intheight = img.rows;

//prepare output

cv::Mat out =cv::Mat::zeros(height, width, CV_8UC1);

//each y, x

for(inty =0; y < height; y++){

for(intx =0; x < width; x++){

//BGR -> Gray

out.at(y, x) =0.2126* (float)img.at(y, x)[2] \

+0.7152* (float)img.at(y, x)[1] \

+0.0722* (float)img.at(y, x)[0];

}

}

returnout;

}

intmain(intargc,constchar* argv[]){

//read image

cv::Mat img =cv::imread("imori.jpg", cv::IMREAD_COLOR);

//BGR -> Gray

cv::Mat out =BGR2GRAY(img);

//cv::imwrite("out.jpg", out);

cv::imshow("sample", out);

cv::waitKey(0);

cv::destroyAllWindows();

return0;

}

50b6a0be1722

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值