首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >从静止/静态图像读取二维码

从静止/静态图像读取二维码
EN

Stack Overflow用户
提问于 2017-09-20 12:44:36
回答 1查看 529关注 0票数 0

我在一个应用程序上工作,我必须从静止图像读取二维码。以下是我用来读取二维码的代码:

代码语言:javascript
复制
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;
            }

这段代码可以很好地处理一些二维码,但有时它不能处理静止图像和返回空格数组。我已经搜索了很多,也看到了苹果论坛,他们也描述了相同的代码,我使用过。我还附加了未解码的图像。

请任何机构对此有任何类型的信息,然后与我分享。我将不胜感激。提前谢谢。

EN

回答 1

Stack Overflow用户

发布于 2017-09-21 07:23:30

我刚刚在本地测试了你的图像,我可以确认,二维码没有被读取。我相信你的问题是二维码。看起来可能徽标干扰了CIDetector。我用另一个二维码替换了你的二维码,它起作用了。

代码语言:javascript
复制
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

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/46313458

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档