Functions

The following functions are available globally.

  • Creates a RGB pixel buffer of the specified width and height.

    Declaration

    Swift

    public func createPixelBuffer(width: Int, height: Int) -> CVPixelBuffer?
  • First crops the pixel buffer, then resizes it.

    Declaration

    Swift

    public func resizePixelBuffer(_ srcPixelBuffer: CVPixelBuffer,
                                  cropX: Int,
                                  cropY: Int,
                                  cropWidth: Int,
                                  cropHeight: Int,
                                  scaleWidth: Int,
                                  scaleHeight: Int) -> CVPixelBuffer?
  • Resizes a CVPixelBuffer to a new width and height.

    Declaration

    Swift

    public func resizePixelBuffer(_ pixelBuffer: CVPixelBuffer,
                                  width: Int, height: Int) -> CVPixelBuffer?
  • Resizes a CVPixelBuffer to a new width and height.

    Declaration

    Swift

    public func resizePixelBuffer(_ pixelBuffer: CVPixelBuffer,
                                  width: Int, height: Int,
                                  output: CVPixelBuffer, context: CIContext)
  • Rotates CVPixelBuffer by the provided factor of 90 counterclock-wise.

    Declaration

    Swift

    public func rotate90PixelBuffer(_ srcPixelBuffer: CVPixelBuffer, factor: UInt8) -> CVPixelBuffer?
  • Declaration

    Swift

    public func clamp<T>(_ x: T, min: T, max: T) -> T where T : Comparable
  • Computes intersection-over-union overlap between two bounding boxes.

    Declaration

    Swift

    public func IOU(_ a: CGRect, _ b: CGRect) -> Float
  • Removes bounding boxes that overlap too much with other boxes that have a higher score.

    Declaration

    Swift

    public func nonMaxSuppression(predictions: [NMSPrediction], iouThreshold: Float, maxBoxes: Int) -> [Int]
  • Removes bounding boxes that overlap too much with other boxes that have a higher score.

    Based on code from https://github.com/tensorflow/tensorflow/blob/master/tensorflow/core/kernels/non_max_suppression_op.cc

    Note

    This version of NMS ignores the class of the bounding boxes. Since it selects the bounding boxes in a greedy fashion, if a certain class has many boxes that are selected, then it is possible none of the boxes of the other classes get selected.

    Declaration

    Swift

    public func nonMaxSuppression(predictions: [NMSPrediction],
                                  indices: [Int],
                                  iouThreshold: Float,
                                  maxBoxes: Int) -> [Int]

    Parameters

    predictions

    an array of bounding boxes and their scores

    indices

    which predictions to look at

    iouThreshold

    used to decide whether boxes overlap too much

    maxBoxes

    the maximum number of boxes that will be selected

    Return Value

    the array indices of the selected bounding boxes

  • Multi-class version of non maximum suppression.

    Where nonMaxSuppression() does not look at the class of the predictions at all, the multi-class version first selects the best bounding boxes for each class, and then keeps the best ones of those.

    With this method you can usually expect to see at least one bounding box for each class (unless all the scores for a given class are really low).

    Based on code from: https://github.com/tensorflow/models/blob/master/object_detection/core/post_processing.py

    Declaration

    Swift

    public func nonMaxSuppressionMultiClass(numClasses: Int,
                                            predictions: [NMSPrediction],
                                            scoreThreshold: Float,
                                            iouThreshold: Float,
                                            maxPerClass: Int,
                                            maxTotal: Int) -> [Int]

    Parameters

    numClasses

    the number of classes

    predictions

    an array of bounding boxes and their scores

    scoreThreshold

    used to only keep bounding boxes with a high enough score

    iouThreshold

    used to decide whether boxes overlap too much

    maxPerClass

    the maximum number of boxes that will be selected per class

    maxTotal

    maximum number of boxes that will be selected over all classes

    Return Value

    the array indices of the selected bounding boxes

  • Returns the top k predictions from Core ML classification results as an array of (String, Double) pairs.

    Declaration

    Swift

    public func top(_ k: Int, _ prob: [String : Double]) -> [(String, Double)]
  • Returns the top k predictions from Vision classification results as an array of (String, Double) pairs.

    Declaration

    Swift

    @available(iOS 11.0, *)
    public func top(_ k: Int, _ observations: [VNClassificationObservation]) -> [(String, Double)]