之前學習人臉識別,使用的是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.
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