iOS導入OpenCV解決的一些問題

之前學習人臉識別,使用的是CIDetector,但是發現這個API給的開放接口少之又少,看到天天p圖上的武則天變裝等,覺得這不是用此法做的,進而查到了OpenCV,學習記錄之:

基于 OpenCV 的人臉識別:這里有對OpenCV的基本介紹和用法。

CGRect rect = [UIScreen mainScreen].bounds;

self.imageView.frame= rect;

UIImage* image = [UIImage imageNamed:@"robin"];

// Convert UIImage * to cv::Mat

UIImageToMat(image,cvImage);

if(!cvImage.empty()) {

cv::Matgray;

// Convert the image to grayscale;

cv::cvtColor(cvImage, gray,CV_RGBA2GRAY);

// Apply Gaussian filter to remove small edges

cv::GaussianBlur(gray, gray,cv::Size(5,5),1.2,1.2);

// Calculate edges with Canny

cv::Matedges;

cv::Canny(gray, edges,0,60);

// Fill image with white color

cvImage.setTo(cv::Scalar::all(255));

// Change color on edges

cvImage.setTo(cv::Scalar(0,128,255,255), edges);

// Convert cv::Mat to UIImage* and show the resulting image

self.imageView.image=MatToUIImage(cvImage);

}

拷了一份代碼在.m文件里,由于是混編,要把.m改成.mm。

導入頭文件:

然后出現了幾個問題:

1:#import <opencv2/opencv.hpp>

導入此頭文件報紅,拷貝以上保存解決之

2:導入庫后Undefined symbols for architecture i386:

Problem solved adding several frameworks :CoreVideo.framework,AssetsLibrary.framework,CoreMedia.framework.

添加系統庫解決:http://stackoverflow.com/questions/23634940/opencv2-framework-not-compile-with-linker-flag-objc/23648133#23648133

3:ld: '/Users/zq/Documents/oc-test/NotePod/NotePod/opencv2.framework/opencv2(cap_avfoundation.o)' does not contain bitcode. You must rebuild it with bitcode enabled (Xcode setting ENABLE_BITCODE), obtain an updated library from the vendor, or disable bitcode for this target. for architecture arm64

clang: error: linker command failed with exit code 1 (use -v to see invocation)、

通過把target里面的Enable Bitcode設置成NO解決:http://stackoverflow.com/questions/30848208/new-warnings-in-ios9

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容