Probolem
I am currenly working on a application uing openCV for ios. The step right now is to make a color histogram on iphone 11 pro. openCV is not supported in swift, therefore I am wrapping openCV framework to enable it to ios. When I build the target, the error "OpenCV 4.x+ requires enabled C++11 support" occurs.
The steps to the occurance of the error is
1.xcode somehow could not recognize IplImage → occurance of error "expected a type"
2.Added <#opencv2/core/types_c.h> to the file openCVWrapper.h → Fixed the former error
3.After building the project, the error "OpenCV 4.x+ requires enabled C++11 support" occurs
The current Errors
"OpenCV 4.x+ requires enabled C++11 support" //The error i am working on roght now
"'array'file not found" //It seems like this error will be fixed once the upper error has been fixed
Codes
openCVWrapper.h
#ifndef OpenCVWrapper_h
#define OpenCVWrapper_h
#endif /* OpenCVWrapper_h */
#import <UIKit/UIKit.h>
#import <opencv2/core/types_c.h> //added to fix the "expected type"
@interface OpenCVManager : NSObject
+(void) makeHistgramFromImage:(UIImage*)image;
+ (IplImage *)createIplImageFromUIImage:(UIImage *)uiImage;
@end
openCVWrapper.mm
#import <opencv2/opencv.hpp>
#import <opencv2/imgcodecs/ios.h>
#import <opencv2/imgproc/imgproc_c.h>
#import <opencv2/core/types_c.h>
#import "OpenCVWrapper.h"
@implementation OpenCVWrapper
+(void) makeHistgramFromImage:(UIImage *)image
{
cv::Mat imageMat;
UIImageToMat(image, imageMat);
cv::Mat grayMat;
cv::cvtColor (imageMat, grayMat, CV_BGR2GRAY);
image = MatToUIImage(grayMat);
IplImage *gray = [OpenCVManager createIplImageFromUIImage:image];
float range[]={0,255};
float* ranges[]={range};
int histSize;
histSize=256;
CvHistogram* hist;
hist=cvCreateHist(1,&histSize,CV_HIST_ARRAY,ranges,1);
cvCalcHist(&gray,hist,0,NULL);
cvReleaseImage(&gray);
}
+ (IplImage *)createIplImageFromUIImage:(UIImage *)uiImage
{
CGImageRef imageRef = uiImage.CGImage;
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
IplImage *iplimage = cvCreateImage(cvSize(uiImage.size.width, uiImage.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, uiImage.size.width, uiImage.size.height), imageRef);
CGContextRelease(contextRef);
CGColorSpaceRelease(colorSpace);
IplImage *outputImage = cvCreateImage(cvGetSize(iplimage), IPL_DEPTH_8U, 3);
cvCvtColor(iplimage, outputImage, CV_RGBA2BGR);
cvReleaseImage(&iplimage);
return outputImage;
}
@end
openCV-Bridging-Header.h
#import"OpenCVWrapper.h"
opencv2.framework/Headers/core/cvdef.h line 691-705
#ifndef CV_CXX11
# if __cplusplus >= 201103L || (defined(_MSC_VER) && _MSC_VER >= 1800)
# define CV_CXX11 1
# endif
#else
# if CV_CXX11 == 0
# undef CV_CXX11
# endif
#endif
#ifndef CV_CXX11
# error "OpenCV 4.x+ requires enabled C++11 support" //where the error is occuring
#endif
What I have done
In
Build Settings → Basic → Levels
Changed C++ Language Dialect to C++11
Changed C++ Standard Library to libc++(LLVM C++ standard library with C++11 support)
Right now I am implementing openCV4.x to xcode,however according to similar questions it said that I should be using openCV3.x (because C++11 became only available from version 4.x). Therefore i DID once implement openCV3.x to my project however another error occured inside the framework and it seemed like a harder issue to solve therefore I have decided to use openCV4.x and ask this question in stackoverflow
Although I do know that all I havw to do is to enable C++11 to my xcode, however first to all how do I and how do I fux this error? Or was it the former error "Expected a type" pointing IplImage?
I have searched many web pages, many similar questions in stackflow, but never found the best solution for myself and now have been fighting this error for more than 3 days...... Just to note, as you can see, I do not use computer well, so if you have any solution, I would be very pleased if you tell me in very conscientious way.
Versions I am using
xcode 11.4 openCV ver4.2.1
Aucun commentaire:
Enregistrer un commentaire