opencv_contrib
opencv_contrib copied to clipboard
qrcode in iOS Crash
When I compile wechat_qrcode in opencv4.6.0 and 4.7.0, using wechat_qrcode in iOS will crash immediately when scanning a picture with a QR code. The crash will happen in detectAndDecode and NSArray *results = [wechatQRCode detectAndDecode:mat]; Both of the following codes crash,I'm sure the model file already exists in the Xcode project and the path is correct,And make sure the image file Mat is not empty.AnyOne can help me?Thanks!
Just OC
NSString *path = [[NSBundle mainBundle] pathForResource:@"detect" ofType:@"prototxt"];
NSString *path1 = [[NSBundle mainBundle] pathForResource:@"detect" ofType:@"caffemodel"];
NSString *path2 = [[NSBundle mainBundle] pathForResource:@"sr" ofType:@"prototxt"];
NSString *path3 = [[NSBundle mainBundle] pathForResource:@"sr" ofType:@"caffemodel"];
WeChatQRCode * wechatQRCode = [[WeChatQRCode alloc] initWithDetector_prototxt_path:path
detector_caffe_model_path:path1 super_resolution_prototxt_path:path2 super_resolution_caffe_model_path:path3];
Mat *mat = [[Mat alloc] init];
UIImageToMat(image, mat.nativeRef);
NSArray *results = [wechatQRCode detectAndDecode:mat];//=======================crash here`
C++
(NSArray<NSDictionary *> *)scanQRCodeInImage:(UIImage *)inputImage {
cv::Mat matImage;
UIImageToMat(inputImage, matImage);
NSString *path = [[NSBundle mainBundle] pathForResource:@"detect" ofType:@"prototxt"];
NSString *path1 = [[NSBundle mainBundle] pathForResource:@"detect" ofType:@"caffemodel"];
NSString *path2 = [[NSBundle mainBundle] pathForResource:@"sr" ofType:@"prototxt"];
NSString *path3 = [[NSBundle mainBundle] pathForResource:@"sr" ofType:@"caffemodel"];
if (![fileManager fileExistsAtPath:path] || ![fileManager fileExistsAtPath:path1] || ![fileManager fileExistsAtPath:path2] ||
! [fileManager fileExistsAtPath:path3]) {
NSLog(@"One or more model files are missing");
}
cv::Ptr<cv::wechat_qrcode::WeChatQRCode> detector = cv::makePtr<cv::wechat_qrcode::WeChatQRCode>
(path.UTF8String,path1.UTF8String,path2.UTF8String,path3.UTF8String);
std::vector<std::string> strDecoded;
std::vector<cv::Mat> points;
if (detector) {
strDecoded = detector->detectAndDecode(matImage, points);//=======================crash here
} else {
NSLog(@"Detector is null");
}
NSMutableArray<NSDictionary *> *results = [NSMutableArray arrayWithCapacity:strDecoded.size()];
for (size_t i = 0; i < strDecoded.size(); i++) {
NSString *decodedString = [NSString stringWithCString:strDecoded[i].c_str() encoding:NSUTF8StringEncoding];
NSDictionary *result = @{@"decodedString": decodedString};
[results addObject:result];
}
return [results copy];
}