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。

导入头文件:

iOS导入OpenCV解决的一些问题_第1张图片

然后出现了几个问题:

1:#import

导入此头文件报红,拷贝以上保存解决之

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

你可能感兴趣的:(iOS导入OpenCV解决的一些问题)