1
0
mirror of https://github.com/opencv/opencv.git synced 2026-07-31 08:13:04 +04:00

Merge pull request #18270 from komakai:swift-inout-arrays

This commit is contained in:
Alexander Alekhin
2020-09-06 20:12:15 +00:00
13 changed files with 347 additions and 136 deletions
@@ -15,7 +15,7 @@ public class ColorBlobDetector {
// Color radius for range checking in HSV color space
var colorRadius = Scalar(25.0, 50.0, 50.0, 0.0)
let spectrum = Mat()
let contours = NSMutableArray()
var contours = [[Point]]()
// Cache
let pyrDownMat = Mat()
@@ -50,25 +50,25 @@ public class ColorBlobDetector {
Core.inRange(src: hsvMat, lowerb: lowerBound, upperb: upperBound, dst: mask)
Imgproc.dilate(src: mask, dst: dilatedMask, kernel: Mat())
let contoursTmp = NSMutableArray()
var contoursTmp = [[Point]]()
Imgproc.findContours(image: dilatedMask, contours: contoursTmp, hierarchy: hierarchy, mode: .RETR_EXTERNAL, method: .CHAIN_APPROX_SIMPLE)
Imgproc.findContours(image: dilatedMask, contours: &contoursTmp, hierarchy: hierarchy, mode: .RETR_EXTERNAL, method: .CHAIN_APPROX_SIMPLE)
// Find max contour area
var maxArea = 0.0
for contour in contoursTmp {
let contourMat = MatOfPoint(array: (contour as! NSMutableArray) as! [Point])
let contourMat = MatOfPoint(array: contour)
let area = Imgproc.contourArea(contour: contourMat)
maxArea = max(area, maxArea)
}
// Filter contours by area and resize to fit the original image size
contours.removeAllObjects()
contours.removeAll()
for contour in contoursTmp {
let contourMat = MatOfPoint(array: (contour as! NSMutableArray) as! [Point])
let contourMat = MatOfPoint(array: contour)
if (Imgproc.contourArea(contour: contourMat) > ColorBlobDetector.minContourArea * maxArea) {
Core.multiply(src1: contourMat, srcScalar: Scalar(4.0,4.0), dst: contourMat)
contours.add(NSMutableArray(array: contourMat.toArray()))
contours.append(contourMat.toArray())
}
}
}
@@ -62,12 +62,14 @@ class ViewController: UIViewController, CvVideoCameraDelegate2 {
}
}
let faces = NSMutableArray()
var faces = [Rect]()
swiftDetector.detectMultiScale(image: gray, objects: faces, scaleFactor: 1.1, minNeighbors: Int32(2), flags: Int32(2), minSize: Size(width: absoluteFaceSize, height: absoluteFaceSize), maxSize: Size())
//nativeDetector!.detect(gray, faces: faces)
swiftDetector.detectMultiScale(image: gray, objects: &faces, scaleFactor: 1.1, minNeighbors: Int32(2), flags: Int32(2), minSize: Size(width: absoluteFaceSize, height: absoluteFaceSize), maxSize: Size())
//let facesArray = NSMutableArray()
//nativeDetector!.detect(gray, faces: facesArray)
//faces.append(contentsOf: facesArray)
for face in faces as! [Rect] {
for face in faces {
if orientation == .landscapeLeft {
face.rotateClockwise(parentHeight: gray.rows())
} else if orientation == .landscapeRight {