SBSDKDocumentDetector

@interface SBSDKDocumentDetector : NSObject



  • This class provides methods for detecting a documents outline polygon in an UIImage or CMSampleBuffer.
  • 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.

  • 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 (assign, readwrite, 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 (assign, readwrite, nonatomic) double acceptedAngleScore;

    Swift

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

    Declaration

    Objective-C

    @property (readonly, atomic) 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, atomic) 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, atomic) 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, atomic) 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, atomic) 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, atomic) double currentDistanceScore;

    Swift

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

    Declaration

    Objective-C

    @property (readonly, atomic, 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 (readwrite, strong, nonatomic, nullable)
        NSArray<SBSDKPageAspectRatio *> *preferredAspectRatios;

    Swift

    var preferredAspectRatios: [SBSDKPageAspectRatio]? { 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 (readwrite, strong, nonatomic, nullable)
        NSArray<SBSDKPageAspectRatio *> *requiredAspectRatios;

    Swift

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

    Declaration

    Objective-C

    @property (readonly, strong, nonatomic, 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 (readonly, strong, nonatomic, nullable)
        NSArray<SBSDKPolygonEdge *> *detectedVerticalEdges;

    Swift

    var detectedVerticalEdges: [SBSDKPolygonEdge]? { get }