2017-09-20 12 views
0

静止画からQRコードを読まなければならないアプリに取り組んでいます。私は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フォーラムでも私が使ったのと同じコードを記述しているのを見ています。デコードされていない画像も添付しています。 enter image description here身体には、これに関する情報の種類があり、私と共有してください。非常に感謝しています。前もって感謝します。

+0

は、左下隅に常にQRコードの位置ですか? –

+0

@YunCHEN:それは必要ではありません、左上隅、右上隅などにあります。ありがとう! – Vishal

答えて

0

あなたの画像をローカルでテストしたところ、QRコードが読み取られていないことを確認できました。私はあなたの問題がQRコードだと信じています。おそらくロゴがCIDetectorを妨害しているようです。あなたのQRコードを別の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

enter image description here

関連する問題