Search code examples
iphoneobjective-ciosbarcodebarcode-scanner

RedLaser SetActiveRegion iPhone


I'm currently in the final stages of of completing a barcode scanning app which takes use of the RedLaser API. There is one challenge though in that I'm not able to set the region within the image for where it should identify barcodes. It identifies the barcode from the complete image and not the ActiveRegion I set.

I don't have the exact code infront of me but it's practically a carbon copy of this source:

(void) setPortraitLayout
{
    // Set portrait
    self.parentPicker.orientation = UIImageOrientationUp;

    // Set the active scanning region for portrait mode
    [self.parentPicker setActiveRegion:CGRectMake(0, 100, 320, 250)];

    // Animate the UI changes
    CGAffineTransform transform = CGAffineTransformMakeRotation(0);

    [UIView beginAnimations:@"rotateToPortrait" context:nil]; // Tell UIView we're ready to start animations.
    [UIView setAnimationDelegate:self];
    [UIView setAnimationCurve: UIViewAnimationCurveLinear ];
    [UIView setAnimationDuration: 0.5];

    redlaserLogo.transform = transform;

    //A visible frame to aim with
    [self setActiveRegionFrame];

    [UIView commitAnimations]; // Animate!
}

(void) setActiveRegionFrame
{
    //this just draws up a visible rectangle slightly smaller than supposed ActiveRegion
    [_rectLayer setFrame:CGRectMake(self.parentPicker.activeRegion.origin.x - 50, self.parentPicker.activeRegion.origin.y - 50, self.parentPicker.activeRegion.size.width - 50, self.parentPicker.activeRegion.size.height - 50)];
    CGPathRef path = [self newRectPathInRect:_rectLayer.bounds];
    [_rectLayer setPath:path];
    CGPathRelease(path);
    [_rectLayer needsLayout];
}

Anyone have any experience setting up RedLaser with a manual ActiveRegion? I am using the 3.1.0 iPhone library (also tried with the latest, 3.2.4, in case a bug was present earlier).


Solution

  • I work for RedLaser, so I can help. I also recommend you refer to the "Using the RedLaser SDK" file in our SDK zip.

    Short answer: ActiveRegions have been deprecated. Use the BarcodeResult class instead. Pages 6-9 of the instructions

    Longer answer: The BarcodeResult class includes the location of all barcodes scanned (a NSArray of NSValues). You can tell your app to ignore all results for which the returned values are not in your desired region.

    The relevant text from the PDF:

    Finally, each barcode will have a NSArray of NSValues, where each NSValue is a CGPoint, indicating where we located the barcode. The coordinates of the points will be in the same coordinate system as the BarcodePickerController's bounds. The first point in the array will be the top left of the barcode, and the second will be the top right of the barcode. Note that if a barcode is recognized 'upside down', these points will be in the lower right and lower left when viewed onscreen. Also, because the preview is mirrored when using a device's front camera for recognizing, the points aren't necessarily in clockwise winding order either. The array will usually contain 4 points, but it could contain more or fewer.

    The path produced from these points may not cover the entire barcode, and may be only one pixel high or wide. The barcode location is only updated on frames where the barcode is actually recognized, so the longer it's been since mostRecentScanTime, the less likely it is that the barcode is still at that position in the camera preview. Barcodes recognized by the partial recognition method (used for some long barcodes, allowing the user to point the camera at each part of the barcode and piece the full code together) will only have recognition information on the most recent part of the barcode to be scanned.

    If you have other questions, please ask via http://support.redlaser.com/ -- our response time there is pretty fast.