SBSDKBarcodeScanner

@interface SBSDKBarcodeScanner : NSObject

A class to search and decode multiple types of barcodes in a 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)initWithTypes:
                                (nonnull NSArray<SBSDKBarcodeType *> *)barCodeTypes
                                 liveMode:(BOOL)useLiveMode;

    Swift

    init(types barCodeTypes: [SBSDKBarcodeType], liveMode useLiveMode: Bool)

    Parameters

    barCodeTypes

    Bar code types to limit detection results to.

    useLiveMode

    Whether you want to recognize in live mode or not.

  • 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.

  • Bar code types to limit detection results to. The default value is nil, the common code types are being detected; see [SBSBDKBarcodeType commonTypes].

    Declaration

    Objective-C

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

    Swift

    var acceptedBarcodeTypes: [SBSDKBarcodeType]? { get set }
  • Bar code document types to limit detection results to. When nil or empty - all document can be returned. Default is nil.

    Declaration

    Objective-C

    @property (nonatomic, strong, nullable) NSArray<SBSDKBarcodeDocumentType *> *acceptedDocumentTypes;

    Swift

    var acceptedDocumentTypes: [SBSDKBarcodeDocumentType]? { get set }
  • Filter for extended EAN and UPC barcodes. By default the filter is disabled (SBSDKBarcodesExtensionFilterNoFilter).

    Declaration

    Objective-C

    @property (nonatomic) SBSDKBarcodesExtensionFilter extensionFilter;

    Swift

    var extensionFilter: SBSDKBarcodesExtensionFilter { get set }
  • Additional parameters for tweaking the detection of barcodes.

    Declaration

    Objective-C

    @property (nonatomic, strong, nonnull) SBSDKBarcodeAdditionalParameters *additionalParameters;

    Swift

    var additionalParameters: SBSDKBarcodeAdditionalParameters { get set }
  • The barcode detectors engine mode. The default value is SBSDKBarcodeEngineModeNextGen.

    Declaration

    Objective-C

    @property (nonatomic) SBSDKBarcodeEngineMode engineMode;

    Swift

    var engineMode: SBSDKBarcodeEngineMode { get set }
  • Set to YES, if you want to recognize barcodes on consecutive video frames. Otherwise, if you want to recognize on a single image, set to NO. The default value is NO.

    Declaration

    Objective-C

    @property (nonatomic) BOOL useLiveMode;

    Swift

    var useLiveMode: Bool { get set }