opencv 编译报错解决办法
image.png将 NO换成NO_EXPOSURE_COMPENSATOR
IplImage 找不到 导入头文件
#import "opencv2/imgproc/imgproc_c.h"
CV_RGB2BGR 找不到 导入头文件
#import <opencv2/imgproc/types_c.h>
cvCvtColor 找不到 导入头文件
#import <opencv2/imgproc/imgproc_c.h>
ocimageView转opencv代码如下
- (IplImage )convertToIplImage:(UIImage)image
{
CGImageRef imageRef = image.CGImage;
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
IplImage *iplImage = cvCreateImage(cvSize(image.size.width, image.size.height), IPL_DEPTH_8U, 4);
CGContextRef contextRef = CGBitmapContextCreate(iplImage->imageData, iplImage->width, iplImage->height, iplImage->depth, iplImage->widthStep, colorSpace, kCGImageAlphaPremultipliedLast | kCGBitmapByteOrderDefault);
CGContextDrawImage(contextRef, CGRectMake(0, 0, image.size.width, image.size.height), imageRef);
CGContextRelease(contextRef);
CGColorSpaceRelease(colorSpace);
IplImage *ret = cvCreateImage(cvGetSize(iplImage), IPL_DEPTH_8U, 3);
cvCvtColor(iplImage, ret, CV_RGB2BGR);
cvReleaseImage(&iplImage);
return ret;
}
/// IplImage类型转换为UIImage类型
-
(UIImage *)convertToUIImage:(IplImage *)image
{
cvCvtColor(image, image, CV_BGR2RGB);
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
NSData *data = [NSData dataWithBytes:image->imageData length:image->imageSize];
CGDataProviderRef provider = CGDataProviderCreateWithCFData((CFDataRef)data);
CGImageRef imageRef = CGImageCreate(image->width, image->height, image->depth, image->depth * image->nChannels, image->widthStep, colorSpace, kCGImageAlphaNone | kCGBitmapByteOrderDefault, provider, NULL, false, kCGRenderingIntentDefault);
UIImage *ret = [UIImage imageWithCGImage:imageRef];
CGImageRelease(imageRef);
CGDataProviderRelease(provider);
CGColorSpaceRelease(colorSpace);
return ret;
} -
(cv::Mat)convertToMatImage:(UIImage *)image{
// 将UIImage 转成 cv::Mat
cv::Mat cvFaceImage;
UIImageToMat(image, cvFaceImage);return cvFaceImage;
} -
(UIImage *)convertMatToUIImage:(cv::Mat)matimage{
//绘制出关键点的image
UIImage *result = MatToUIImage(matimage);
matimage.release();return result;
}
网友评论