1. 若未安装cmake,使用命令brew install cmake安装。
若未安装pkg-config,使用命令brew install pkg-config安装。若安装后未能找到pkg-config程序,则将其复制到/usr/local/bin目录下。
2. 安装opencv
brew install opencv
3. 测试程序
#include#include #include #include using namespace std;using namespace cv;int main(){ cv::Mat img_encode; img_encode = imread("./obito.jpeg", CV_LOAD_IMAGE_COLOR); vector data_encode; imencode(".jpeg", img_encode, data_encode); string str_encode(data_encode.begin(), data_encode.end()); //cout << str_encode << endl; cv::Mat img_decode; vector data(str_encode.begin(), str_encode.end()); img_decode = imdecode(data, CV_LOAD_IMAGE_COLOR); imshow("pic", img_decode); cvWaitKey(10000); //cout << "Hello" << endl;}
编译命令为:g++ Cpp_Opencv.cpp -o Cpp_Opencv `pkg-config --cflags --libs opencv`
或者直接将链接库列出来:g++ Cpp_Opencv.cpp -L/usr/local/lib/ -lopencv_highgui.3.4.2 -lopencv_core.3.4.2 -lopencv_imgcodecs