我正在开发一个应用程序,我必须从静止图像中读取QR码。以下是我用来阅读QR码的代码:
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;
}
此代码适用于某些QR码,但有时它不能处理静止图像并返回空白数组。我已经搜索了很多,也看到了Apple论坛,他们也描述了我用过的相同代码。我还附加了未解码的图像。请任何机构有关于此的任何类型的信息然后与我分享。非常感谢。提前谢谢。
答案 0 :(得分:1)
我刚刚在本地测试了您的图像,我可以确认,未读取QR码。我相信你的问题是二维码。似乎徽标可能会干扰CIDetector。我用另一个QR码替换了你的二维码,然后就可以了。
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