1. 若未安装cmake,使用命令brew install cmake安装。
若未安装pkg-config,使用命令brew install pkg-config安装。若安装后未能找到pkg-config程序,则将其复制到/usr/local/bin目录下。
2. 安装opencv
brew install opencv
3. 测试程序
#include <iostream> #include <opencv2/opencv.hpp> #include <vector> #include <string> using namespace std; using namespace cv; int main() { cv::Mat img_encode; img_encode = imread("./obito.jpeg", CV_LOAD_IMAGE_COLOR); vector<uchar> 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<uchar> 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
原文地址:https://www.cnblogs.com/YuZiiiiiD/p/9385276.html
时间: 2024-10-31 13:40:47