SBSDKDocumentDetector

@interface SBSDKDocumentDetector : NSObject



  • A class to detect a document’s outline polygon in a UIImage or CMSampleBufferRef.
  • Executes an edge detection algorithm on the given image and returns a polygon describing the extends of the detected documents box. For a short period of time the uncompressed image data is hold twice in memory. Use with attention.

    Declaration

    Objective-C

    - (nonnull SBSDKDocumentDetectorResult *)
        detectDocumentPolygonOnImage:(nonnull UIImage *)image
                    visibleImageRect:(CGRect)visibleRect
                    smoothingEnabled:(BOOL)smooth
          useLiveDetectionParameters:(BOOL)liveDetection;

    Swift

    func detectDocumentPolygon(on image: UIImage, visibleImageRect visibleRect: CGRect, smoothingEnabled smooth: Bool, useLiveDetectionParameters liveDetection: Bool) -> SBSDKDocumentDetectorResult

    Parameters

    image

    The image to analyze.

    visibleRect

    The unified image rectangle that should be analyzed. (0, 0)-(1, 1) or an empty rect means the whole image is being analyzed.

    smooth

    Set to YES if you want the polygon output to be smoothed with latest frames. If you choose to use smooting you should call resetSmoothingData regularly.

    liveDetection

    Set YES if you want to use faster live detection. Live detection is less reliable than normal detection.

    Return Value

    The detection result containing the status and a polygon.

  • Executes an edge detection algorithm on the given image and returns a polygon describing the extends of the detected photos box. For a short period of time the uncompressed image data is hold twice in memory. Use with attention.

    Declaration

    Objective-C

    - (nonnull SBSDKDocumentDetectorResult *)
        detectPhotoPolygonOnImage:(nonnull UIImage *)image
                 visibleImageRect:(CGRect)visibleRect
                 smoothingEnabled:(BOOL)smooth;

    Swift

    func detectPhotoPolygon(on image: UIImage, visibleImageRect visibleRect: CGRect, smoothingEnabled smooth: Bool) -> SBSDKDocumentDetectorResult

    Parameters

    image

    The image to analyze.

    visibleRect

    The unified image rectangle that should be analyzed. (0, 0)-(1, 1) or an empty rect means the whole image is being analyzed.

    smooth

    Set to YES if you want the polygon output to be smoothed with latest frames. If you choose to use smooting you should call resetSmoothingData regularly.

    Return Value

    The detection result containing the status and a polygon.

  • Executes an edge detection algorithm on the given sample buffer and returns a polygon describing the extends of the detected documents box. For a short period of time the uncompressed image data is hold twice in memory. Use with attention.

    Declaration

    Objective-C

    - (nonnull SBSDKDocumentDetectorResult *)
        detectDocumentPolygonOnSampleBuffer:(nonnull CMSampleBufferRef)sampleBuffer
                           visibleImageRect:(CGRect)visibleRect
                           smoothingEnabled:(BOOL)smooth
                 useLiveDetectionParameters:(BOOL)liveDetection;

    Swift

    func detectDocumentPolygon(on sampleBuffer: CMSampleBuffer, visibleImageRect visibleRect: CGRect, smoothingEnabled smooth: Bool, useLiveDetectionParameters liveDetection: Bool) -> SBSDKDocumentDetectorResult

    Parameters

    sampleBuffer

    The CMSampleBufferRef to analyze.

    visibleRect

    The unified image rectangle that should be analyzed. (0, 0)-(1, 1) or an empty rect means the whole image is being analyzed.

    smooth

    Set to YES if you want the polygon output to be smoothed with latest frames. If you choose to use smooting you should call resetSmoothingData regularly.

    liveDetection

    Set YES if you want to use faster live detection. Live detection is less reliable than normal detection.

    Return Value

    The detection result containing the status and a polygon.

  • Executes an edge detection algorithm on the given sample buffer and returns a polygon describing the extends of the detected photos box. For a short period of time the uncompressed image data is hold twice in memory. Use with attention.

    Declaration

    Objective-C

    - (nonnull SBSDKDocumentDetectorResult *)
        detectPhotoPolygonOnSampleBuffer:(nonnull CMSampleBufferRef)sampleBuffer
                        visibleImageRect:(CGRect)visibleRect
                        smoothingEnabled:(BOOL)smooth;

    Swift

    func detectPhotoPolygon(on sampleBuffer: CMSampleBuffer, visibleImageRect visibleRect: CGRect, smoothingEnabled smooth: Bool) -> SBSDKDocumentDetectorResult

    Parameters

    sampleBuffer

    The CMSampleBufferRef to analyze.

    visibleRect

    The unified image rectangle that should be analyzed. (0, 0)-(1, 1) or an empty rect means the whole image is being analyzed.

    smooth

    Set to YES if you want the polygon output to be smoothed with latest frames. If you choose to use smooting you should call resetSmoothingData regularly.

    Return Value

    The detection result containing the status and a polygon.

  • The current mode of the detector: standard or machine-learning-based. Defaults to ML mode.

    Declaration

    Objective-C

    @property (nonatomic, readonly) SBSDKDocumentDetectorMode detectorMode;

    Swift

    var detectorMode: SBSDKDocumentDetectorMode { get }
  • Default detectorMode parameter value. Unless the new instance of detector is initialized with

    • - (nonnull instancetype)initWithMode:(SBSDKDocumentDetectorMode)mode; initializer,
    • this new instance will have this mode set.

    Declaration

    Objective-C

    + (SBSDKDocumentDetectorMode)defaultDetectorMode;

    Swift

    class func defaultDetectorMode() -> SBSDKDocumentDetectorMode
  • Set default detector mode. Unless the new instance of detector is initialized with

    • - (nonnull instancetype)initWithMode:(SBSDKDocumentDetectorMode)mode; initializer,
    • this new instance will have this mode set.

    Declaration

    Objective-C

    + (void)setDefaultDetectorMode:
        (SBSDKDocumentDetectorMode)newDefaultDetectorMode;

    Swift

    class func setDefaultDetectorMode(_ newDefaultDetectorMode: SBSDKDocumentDetectorMode)
  • Designated initialiizer.

    Declaration

    Objective-C

    - (nonnull instancetype)initWithMode:(SBSDKDocumentDetectorMode)mode;

    Swift

    init(mode: SBSDKDocumentDetectorMode)

    Parameters

    mode

    The detection mode of the receiver.

  • Resets the smootingData. If smoothing is enabled the polygon detector smoothes the result with results from previous detections. You should call this method once per second or if the device has been moved.

    Declaration

    Objective-C

    - (void)resetSmoothingData;

    Swift

    func resetSmoothingData()
  • The minimum size in percent (0 - 100) of the screen size to accept a detected document. It is sufficient that height or width match the score. Default is 80.0. Warning: Lower values result in low resolution document images.

    Declaration

    Objective-C

    @property (nonatomic) double acceptedSizeScore;

    Swift

    var acceptedSizeScore: Double { get set }
  • The minimum score in percent (0 - 100) of the perspective distortion to accept a detected document. Default is 75.0. Set lower values to accept more perspective distortion. Warning: Lower values result in more blurred document images.

    Declaration

    Objective-C

    @property (nonatomic) double acceptedAngleScore;

    Swift

    var acceptedAngleScore: Double { get set }
  • The total score of the latest detected polygon (0 - 100).

    Declaration

    Objective-C

    @property (readonly) double currentTotalScore;

    Swift

    var currentTotalScore: Double { get }
  • The size score of the latest detected polygon (0 - 100). Part of the total score.

    Declaration

    Objective-C

    @property (readonly) double currentSizeScore;

    Swift

    var currentSizeScore: Double { get }
  • The width score of the latest detected polygon (0 - 100). Part of the size score.

    Declaration

    Objective-C

    @property (readonly) double currentWidthScore;

    Swift

    var currentWidthScore: Double { get }
  • The height score of the latest detected polygon (0 - 100). Part of the size score.

    Declaration

    Objective-C

    @property (readonly) double currentHeightScore;

    Swift

    var currentHeightScore: Double { get }
  • The angles score of the latest detected polygon (0 - 100). Part of the total score.

    Declaration

    Objective-C

    @property (readonly) double currentAngleScore;

    Swift

    var currentAngleScore: Double { get }
  • The distance-from-center score of the latest detected polygon (0 - 100). Part of the total score.

    Declaration

    Objective-C

    @property (readonly) double currentDistanceScore;

    Swift

    var currentDistanceScore: Double { get }
  • The metrics of the last detection or nil. *

    Declaration

    Objective-C

    @property (readonly, nullable) SBSDKDocumentDetectionMetrics *detectionMetrics;

    Swift

    var detectionMetrics: SBSDKDocumentDetectionMetrics? { get }
  • Preferred aspect ratios for detector. If nil or empty, aspect ratio will not take part in defining best document polygon. If set, polygons with set aspect ratio will be more preferrable. Default is nil.

    Declaration

    Objective-C

    @property (nonatomic, strong, nullable) NSArray<SBSDKAspectRatio *> *preferredAspectRatios;

    Swift

    var preferredAspectRatios: [SBSDKAspectRatio]? { get set }
  • Required aspect ratios for detector. If not nil or empty, only polygons resulting in crops with one of the required aspect ratios will be detected. Default is nil.

    Declaration

    Objective-C

    @property (nonatomic, strong, nullable) NSArray<SBSDKAspectRatio *> *requiredAspectRatios;

    Swift

    var requiredAspectRatios: [SBSDKAspectRatio]? { get set }
  • Array of all detected horizontal edges during last detection. Can be used for manual magnetic cropping.

    Declaration

    Objective-C

    @property (nonatomic, strong, readonly, nullable) NSArray<SBSDKPolygonEdge *> *detectedHorizontalEdges;

    Swift

    var detectedHorizontalEdges: [SBSDKPolygonEdge]? { get }
  • Array of all detected vertical edges during last detection. Can be used for manual magnetic cropping.

    Declaration

    Objective-C

    @property (nonatomic, strong, readonly, nullable) NSArray<SBSDKPolygonEdge *> *detectedVerticalEdges;

    Swift

    var detectedVerticalEdges: [SBSDKPolygonEdge]? { get }