Vishal
Vishal

Reputation: 8256

Read QR Code from still/static image

I am working on an app where I have to read QR Code from still image. Following is the code that I have used to read the QR Code:

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;
            }

This code is working fine for some QR Code but some time it is not working with still image and return blank array. I have searched a lot and also see the Apple forum they have also described the same code that I have used. I am also attaching the image that is not decoded.enter image description here Please any body has any type of information regarding this then share with me. It would be very appreciated. Thanks in advance.

Upvotes: 0

Views: 650

Answers (1)

Gabriel Pires
Gabriel Pires

Reputation: 966

I just tested your image locally, and I can confirm, the QR code isn't read. I believe your problem is the QR code. It seems that maybe the logo is interfering with the CIDetector. I replaced your QR Code with another QR code, and it worked.

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;
    }

This logs: Found feature: http://en.m.wikipedia.org

enter image description here

Upvotes: 2

Related Questions