我在一个应用程序上工作,我必须从静止图像读取二维码。以下是我用来读取二维码的代码:
CIImage *ciimage = [CIImage imageWithCGImage:[getRotatedImage CGImage]];
NSDictionary *detectorOptions = @{ CIDetectorAccuracy : CIDetectorAccuracyHigh };
CIDetector *faceDetector = [CIDetector detectorOfType:CIDetectorTypeQRCode context:nil options:detectorOptions];
NSArray *features = [faceDetector featuresInImage:ciimage];
CIQRCodeFeature *faceFeature;
for(faceFeature in features)
{
NSString *str = [NSString stringWithFormat:@"%@",faceFeature.messageString];
break;
}这段代码可以很好地处理一些二维码,但有时它不能处理静止图像和返回空格数组。我已经搜索了很多,也看到了苹果论坛,他们也描述了相同的代码,我使用过。我还附加了未解码的图像。

请任何机构对此有任何类型的信息,然后与我分享。我将不胜感激。提前谢谢。
发布于 2017-09-21 07:23:30
我刚刚在本地测试了你的图像,我可以确认,二维码没有被读取。我相信你的问题是二维码。看起来可能徽标干扰了CIDetector。我用另一个二维码替换了你的二维码,它起作用了。
UIImage *image = [UIImage imageNamed:@"qr3"];
CIImage *ciimage = [CIImage imageWithData:UIImageJPEGRepresentation(image, 1.0f)];
NSDictionary *detectorOptions = @{ CIDetectorAccuracy : CIDetectorAccuracyHigh };
CIDetector *faceDetector = [CIDetector detectorOfType:CIDetectorTypeQRCode context:nil options:detectorOptions];
NSArray *features = [faceDetector featuresInImage:ciimage];
CIQRCodeFeature *faceFeature;
for(faceFeature in features) {
NSString *str = [NSString stringWithFormat:@"%@",faceFeature.messageString];
NSLog(@"Found feature: %@", str);
break;
}此日志:Found feature: http://en.m.wikipedia.org

https://stackoverflow.com/questions/46313458
复制相似问题