SBSDKBarcodeScanner

@interface SBSDKBarcodeScanner : NSObject

Wrapper class for searching and decoding multiple types of barcodes. Recognition is performed on still UIImage or SampleBufferRef, result is incapsulated in an array of SBSDKBarcodeScannerResult instances.

  • Creates an SBSDKBarcodeScanner with no frame accumulator for detecting all supported barcode types

    Declaration

    Objective-C

    - (nonnull instancetype)init;

    Swift

    init()
  • Creates an SBSDKBarcodeScanner with no frame accumulator for detecting only the given barcode types

    Declaration

    Objective-C

    - (nonnull instancetype)initWithTypes:
        (nonnull NSArray<SBSDKBarcodeType *> *)barCodeTypes;

    Swift

    init(types barCodeTypes: [SBSDKBarcodeType])

    Parameters

    barCodeTypes

    Bar code types to limit detection results to.

  • Creates an SBSDKBarcodeScanner that accumulates multiple frames before returning a detection result. The barcode scanner’s detect* methods will return empty results until they’ve been called the given number of times. Then, they will perform detection on the frame with the least amount of blur. Intended for using with live detection.

    Declaration

    Objective-C

    - (nonnull instancetype)
        initWithFrameAccumulator:(NSInteger)accumulatedFrames
                           types:
                               (nonnull NSArray<SBSDKBarcodeType *> *)barCodeTypes;

    Swift

    init(frameAccumulator accumulatedFrames: Int, types barCodeTypes: [SBSDKBarcodeType])

    Parameters

    accumulatedFrames

    Number of frames to accumulate before running detection on the sharpest one.

    barCodeTypes

    Bar code types to limit detection results to.

  • Search and decode specified types of bar codes on given image. Strong recommendation is to use this method with static image barcode detection and not live detection. The reason is that video stream returns rotated image, so for example for portrait device orientation, every frame returned will be in landscape left orientation. This method does not handle this orientation difference. For live detection using detectBarCodesOnImage:orientation:inRect: or detectBarCodesOnSampleBuffer:orientation:inRect: is more preferable.

    Declaration

    Objective-C

    - (nullable NSArray<SBSDKBarcodeScannerResult *> *)detectBarCodesOnImage:
        (nonnull UIImage *)image;

    Swift

    func detectBarCodes(on image: UIImage) -> [SBSDKBarcodeScannerResult]?

    Parameters

    image

    The image where search is to be done.

    Return Value

    List of found barcodes.

  • Search and decode specified types of bar codes on given image. Strong recommendation is to use this method with static image barcode detection and not live detection. The reason is that video stream returns rotated image, so for example for portrait device orientation, every frame returned will be in landscape left orientation. This method does not handle this orientation difference. For live detection using detectBarCodesOnImage:orientation:inRect: or detectBarCodesOnSampleBuffer:orientation:inRect: is more preferable.

    Declaration

    Objective-C

    - (nullable NSArray<SBSDKBarcodeScannerResult *> *)
        detectBarCodesOnImage:(nonnull UIImage *)image
                       inRect:(CGRect)rect;

    Swift

    func detectBarCodes(on image: UIImage, in rect: CGRect) -> [SBSDKBarcodeScannerResult]?

    Parameters

    image

    The image where search is to be done.

    rect

    Rectangle in image coordinates in which to perform the search. Must be inside the image.

    Return Value

    List of found barcodes.

  • Search and decode specified types of bar codes on given image. This function is intended to be used use with live detection. Video stream from device returns a rotated image, so for example for portrait device orientation, every frame returned will be in landscape left orientation. This function handles these orientation differences, so you shouldn’t fix or rotate the input image.

    Declaration

    Objective-C

    - (nullable NSArray<SBSDKBarcodeScannerResult *> *)
        detectBarCodesOnImage:(nonnull UIImage *)image
                  orientation:(AVCaptureVideoOrientation)videoOrientation
                       inRect:(CGRect)rect;

    Swift

    func detectBarCodes(on image: UIImage, orientation videoOrientation: AVCaptureVideoOrientation, in rect: CGRect) -> [SBSDKBarcodeScannerResult]?

    Parameters

    image

    The image where search is to be done.

    videoOrientation

    Video frame orientation. Should be the orientation that the device currently has, not actual image orientation.

    rect

    Rectangle in image coordinates in which to perform the search. Must be within the image frame.

    Return Value

    List of found barcodes.

  • Search and decode specified types of bar codes from sample buffer reference. This function is intended to be used with live detection. Video stream from device returns a rotated image, so for example for portrait device orientation, every frame returned will be in landscape left orientation. This function handles these orientation differences, so you shouldn’t fix or rotate the input buffer. Keep in mind, that the buffer received from the video stream is handled by the system. So in some cases it might be cleaned or changed by the system before recognition occurs. You may convert the buffer to UIImage upon receiving it and use detectBarCodesOnImage:orientation:inRect: function, if that is an issue.

    Declaration

    Objective-C

    - (nullable NSArray<SBSDKBarcodeScannerResult *> *)
        detectBarCodesOnSampleBuffer:(nonnull CMSampleBufferRef)sampleBuffer
                         orientation:(AVCaptureVideoOrientation)videoOrientation;

    Swift

    func detectBarCodes(on sampleBuffer: CMSampleBuffer, orientation videoOrientation: AVCaptureVideoOrientation) -> [SBSDKBarcodeScannerResult]?

    Parameters

    sampleBuffer

    The sample buffer reference.

    videoOrientation

    Video frame orientation. Should be the orientation that the device currently has, not actual image orientation.

    Return Value

    List of found barcodes.

  • Search and decode specified types of bar codes from sample buffer reference. This function is intended to be used with live detection. Video stream from device returns a rotated image, so for example for portrait device orientation, every frame returned will be in landscape left orientation. This function handles these orientation differences, so you shouldn’t fix or rotate the input buffer. Keep in mind, that the buffer received from the video stream is handled by the system. So in some cases it might be cleaned or changed by the system before recognition occurs. You may convert the buffer to UIImage upon receiving it and use detectBarCodesOnImage:orientation:inRect: function, if that is an issue.

    Declaration

    Objective-C

    - (nullable NSArray<SBSDKBarcodeScannerResult *> *)
        detectBarCodesOnSampleBuffer:(nonnull CMSampleBufferRef)sampleBuffer
                         orientation:(AVCaptureVideoOrientation)videoOrientation
                              inRect:(CGRect)rect;

    Swift

    func detectBarCodes(on sampleBuffer: CMSampleBuffer, orientation videoOrientation: AVCaptureVideoOrientation, in rect: CGRect) -> [SBSDKBarcodeScannerResult]?

    Parameters

    sampleBuffer

    The sample buffer reference.

    videoOrientation

    Video frame orientation. Should be the orientation that the device currently has, not actual image orientation.

    rect

    Rectangle in image coordinates in which to perform the search. Must be inside the image.

    Return Value

    List of found barcodes.

  • This method is used only for debugging.

    Declaration

    Objective-C

    - (nullable UIImage *)showOutput:(nonnull CMSampleBufferRef)sampleBuffer
                         orientation:(AVCaptureVideoOrientation)videoOrientation;

    Swift

    func showOutput(_ sampleBuffer: CMSampleBuffer, orientation videoOrientation: AVCaptureVideoOrientation) -> UIImage?
  • Bar code types to limit detection results to. When nil or empty - all codes can be returned.

    Declaration

    Objective-C

    @property (nonatomic, strong, readwrite, nullable)
        NSArray<SBSDKBarcodeType *> *acceptedBarcodeTypes;

    Swift

    var acceptedBarcodeTypes: [SBSDKBarcodeType]? { get set }
  • Number of frames to accumulate before running detection on the sharpest one.

    Declaration

    Objective-C

    @property (nonatomic, assign, unsafe_unretained, readwrite)
        NSInteger accumulatedFramesCount;

    Swift

    var accumulatedFramesCount: Int { get set }
  • A parameter, that switches scanner to high sensitivity detection. Detects barcodes more often, but can have more false-positives results. Generally, it is recommended to set this parameter to false during live detection, but have it enabled for static image recognition. Default is false.

    Declaration

    Objective-C

    @property (nonatomic, assign, unsafe_unretained, readwrite)
        BOOL enableHighSensitivityMode;

    Swift

    var enableHighSensitivityMode: Bool { get set }