|
|
|
@ -125,13 +125,13 @@ class ImgprocTest: OpenCVTestCase { |
|
|
|
|
func testApproxPolyDP() { |
|
|
|
|
let curve = [Point2f(x: 1, y: 3), Point2f(x: 2, y: 4), Point2f(x: 3, y: 5), Point2f(x: 4, y: 4), Point2f(x: 5, y: 3)] |
|
|
|
|
|
|
|
|
|
let approxCurve = NSMutableArray() |
|
|
|
|
var approxCurve = [Point2f]() |
|
|
|
|
|
|
|
|
|
Imgproc.approxPolyDP(curve: curve, approxCurve: approxCurve, epsilon: OpenCVTestCase.EPS, closed: true) |
|
|
|
|
Imgproc.approxPolyDP(curve: curve, approxCurve: &approxCurve, epsilon: OpenCVTestCase.EPS, closed: true) |
|
|
|
|
|
|
|
|
|
let approxCurveGold = [Point2f(x: 1, y: 3), Point2f(x: 3, y: 5), Point2f(x: 5, y: 3)] |
|
|
|
|
|
|
|
|
|
XCTAssert(approxCurve as! [Point2f] == approxCurveGold) |
|
|
|
|
XCTAssert(approxCurve == approxCurveGold) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func testArcLength() { |
|
|
|
@ -201,9 +201,9 @@ class ImgprocTest: OpenCVTestCase { |
|
|
|
|
|
|
|
|
|
func testCalcBackProject() { |
|
|
|
|
let images = [grayChess] |
|
|
|
|
let channels = IntVector([0]) |
|
|
|
|
let histSize = IntVector([10]) |
|
|
|
|
let ranges = FloatVector([0, 256]) |
|
|
|
|
let channels:[Int32] = [0] |
|
|
|
|
let histSize:[Int32] = [10] |
|
|
|
|
let ranges:[Float] = [0, 256] |
|
|
|
|
|
|
|
|
|
let hist = Mat() |
|
|
|
|
Imgproc.calcHist(images: images, channels: channels, mask: Mat(), hist: hist, histSize: histSize, ranges: ranges) |
|
|
|
@ -218,9 +218,9 @@ class ImgprocTest: OpenCVTestCase { |
|
|
|
|
|
|
|
|
|
func testCalcHistListOfMatListOfIntegerMatMatListOfIntegerListOfFloat() throws { |
|
|
|
|
let images = [gray128] |
|
|
|
|
let channels = IntVector([0]) |
|
|
|
|
let histSize = IntVector([10]) |
|
|
|
|
let ranges = FloatVector([0, 256]) |
|
|
|
|
let channels:[Int32] = [0] |
|
|
|
|
let histSize:[Int32] = [10] |
|
|
|
|
let ranges:[Float] = [0, 256] |
|
|
|
|
let hist = Mat() |
|
|
|
|
|
|
|
|
|
Imgproc.calcHist(images: images, channels: channels, mask: Mat(), hist: hist, histSize: histSize, ranges: ranges) |
|
|
|
@ -232,9 +232,9 @@ class ImgprocTest: OpenCVTestCase { |
|
|
|
|
|
|
|
|
|
func testCalcHistListOfMatListOfIntegerMatMatListOfIntegerListOfFloat2D() throws { |
|
|
|
|
let images = [gray255, gray128] |
|
|
|
|
let channels = IntVector([0, 1]) |
|
|
|
|
let histSize = IntVector([10, 10]) |
|
|
|
|
let ranges = FloatVector([0, 256, 0, 256]) |
|
|
|
|
let channels:[Int32] = [0, 1] |
|
|
|
|
let histSize:[Int32] = [10, 10] |
|
|
|
|
let ranges:[Float] = [0, 256, 0, 256] |
|
|
|
|
let hist = Mat() |
|
|
|
|
|
|
|
|
|
Imgproc.calcHist(images: images, channels: channels, mask: Mat(), hist: hist, histSize: histSize, ranges: ranges) |
|
|
|
@ -250,11 +250,11 @@ class ImgprocTest: OpenCVTestCase { |
|
|
|
|
let hist3D = Mat() |
|
|
|
|
let histList = [Mat(), Mat(), Mat()] |
|
|
|
|
|
|
|
|
|
let histSize = IntVector([10]) |
|
|
|
|
let ranges = FloatVector([0, 256]) |
|
|
|
|
let histSize: [Int32] = [10] |
|
|
|
|
let ranges: [Float] = [0, 256] |
|
|
|
|
|
|
|
|
|
for i:Int in 0..<Int(rgbLena.channels()) { |
|
|
|
|
Imgproc.calcHist(images: images, channels: IntVector([Int32(i)]), mask: Mat(), hist: histList[i], histSize: histSize, ranges: ranges) |
|
|
|
|
Imgproc.calcHist(images: images, channels: [Int32(i)], mask: Mat(), hist: histList[i], histSize: histSize, ranges: ranges) |
|
|
|
|
|
|
|
|
|
XCTAssertEqual(10, histList[i].checkVector(elemChannels: 1)) |
|
|
|
|
} |
|
|
|
@ -282,9 +282,9 @@ class ImgprocTest: OpenCVTestCase { |
|
|
|
|
|
|
|
|
|
func testCalcHistListOfMatListOfIntegerMatMatListOfIntegerListOfFloatBoolean() throws { |
|
|
|
|
let images = [gray255, gray128] |
|
|
|
|
let channels = IntVector([0, 1]) |
|
|
|
|
let histSize = IntVector([10, 10]) |
|
|
|
|
let ranges = FloatVector([0, 256, 0, 256]) |
|
|
|
|
let channels:[Int32] = [0, 1] |
|
|
|
|
let histSize:[Int32] = [10, 10] |
|
|
|
|
let ranges:[Float] = [0, 256, 0, 256] |
|
|
|
|
let hist = Mat() |
|
|
|
|
|
|
|
|
|
Imgproc.calcHist(images: images, channels: channels, mask: Mat(), hist: hist, histSize: histSize, ranges: ranges, accumulate: true) |
|
|
|
@ -372,12 +372,11 @@ class ImgprocTest: OpenCVTestCase { |
|
|
|
|
Point(x: 20, y: 10), |
|
|
|
|
Point(x: 30, y: 10)] |
|
|
|
|
|
|
|
|
|
let hull = IntVector() |
|
|
|
|
var hull = [Int32]() |
|
|
|
|
|
|
|
|
|
Imgproc.convexHull(points: points, hull: hull) |
|
|
|
|
Imgproc.convexHull(points: points, hull: &hull) |
|
|
|
|
|
|
|
|
|
let expHull = IntVector([0, 1, 2, 3]) |
|
|
|
|
XCTAssert(expHull.array == hull.array) |
|
|
|
|
XCTAssert([0, 1, 2, 3] == hull) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func testConvexHullMatMatBooleanBoolean() { |
|
|
|
@ -388,12 +387,11 @@ class ImgprocTest: OpenCVTestCase { |
|
|
|
|
Point(x: 2, y: 1), |
|
|
|
|
Point(x: 3, y: 1)] |
|
|
|
|
|
|
|
|
|
let hull = IntVector() |
|
|
|
|
var hull = [Int32]() |
|
|
|
|
|
|
|
|
|
Imgproc.convexHull(points: points, hull: hull, clockwise: true) |
|
|
|
|
Imgproc.convexHull(points: points, hull: &hull, clockwise: true) |
|
|
|
|
|
|
|
|
|
let expHull = IntVector([3, 2, 1, 0]) |
|
|
|
|
XCTAssert(expHull.array == hull.array) |
|
|
|
|
XCTAssert([3, 2, 1, 0] == hull) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func testConvexityDefects() throws { |
|
|
|
@ -404,13 +402,13 @@ class ImgprocTest: OpenCVTestCase { |
|
|
|
|
Point(x: 20, y: 10), |
|
|
|
|
Point(x: 30, y: 10)] |
|
|
|
|
|
|
|
|
|
let hull = IntVector() |
|
|
|
|
Imgproc.convexHull(points: points, hull: hull) |
|
|
|
|
var hull = [Int32]() |
|
|
|
|
Imgproc.convexHull(points: points, hull: &hull) |
|
|
|
|
|
|
|
|
|
let convexityDefects = NSMutableArray() |
|
|
|
|
Imgproc.convexityDefects(contour: points, convexhull: hull, convexityDefects: convexityDefects) |
|
|
|
|
var convexityDefects = [Int4]() |
|
|
|
|
Imgproc.convexityDefects(contour: points, convexhull: hull, convexityDefects: &convexityDefects) |
|
|
|
|
|
|
|
|
|
XCTAssertTrue(Int4(v0: 3, v1: 0, v2: 5, v3: 3620) == (convexityDefects[0] as! Int4)) |
|
|
|
|
XCTAssertTrue(Int4(v0: 3, v1: 0, v2: 5, v3: 3620) == convexityDefects[0]) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func testCornerEigenValsAndVecsMatMatIntInt() throws { |
|
|
|
@ -543,10 +541,10 @@ class ImgprocTest: OpenCVTestCase { |
|
|
|
|
func testDrawContoursMatListOfMatIntScalar() { |
|
|
|
|
let gray0clone = gray0.clone() |
|
|
|
|
Imgproc.rectangle(img: gray0clone, pt1: Point(x: 1, y: 2), pt2: Point(x: 7, y: 8), color: Scalar(100)) |
|
|
|
|
let contours = NSMutableArray() |
|
|
|
|
Imgproc.findContours(image: gray0clone, contours: contours, hierarchy: Mat(), mode: .RETR_EXTERNAL, method: .CHAIN_APPROX_SIMPLE) |
|
|
|
|
var contours = [[Point]]() |
|
|
|
|
Imgproc.findContours(image: gray0clone, contours: &contours, hierarchy: Mat(), mode: .RETR_EXTERNAL, method: .CHAIN_APPROX_SIMPLE) |
|
|
|
|
|
|
|
|
|
Imgproc.drawContours(image: gray0clone, contours: contours as! [[Point]], contourIdx: -1, color: Scalar(0)) |
|
|
|
|
Imgproc.drawContours(image: gray0clone, contours: contours, contourIdx: -1, color: Scalar(0)) |
|
|
|
|
|
|
|
|
|
XCTAssertEqual(0, Core.countNonZero(src: gray0clone)) |
|
|
|
|
} |
|
|
|
@ -554,10 +552,10 @@ class ImgprocTest: OpenCVTestCase { |
|
|
|
|
func testDrawContoursMatListOfMatIntScalarInt() { |
|
|
|
|
let gray0clone = gray0.clone() |
|
|
|
|
Imgproc.rectangle(img: gray0clone, pt1: Point(x: 1, y: 2), pt2: Point(x: 7, y: 8), color: Scalar(100)) |
|
|
|
|
let contours = NSMutableArray() |
|
|
|
|
Imgproc.findContours(image: gray0clone, contours: contours, hierarchy: Mat(), mode: .RETR_EXTERNAL, method: .CHAIN_APPROX_SIMPLE) |
|
|
|
|
var contours = [[Point]]() |
|
|
|
|
Imgproc.findContours(image: gray0clone, contours: &contours, hierarchy: Mat(), mode: .RETR_EXTERNAL, method: .CHAIN_APPROX_SIMPLE) |
|
|
|
|
|
|
|
|
|
Imgproc.drawContours(image: gray0clone, contours: contours as! [[Point]], contourIdx: -1, color: Scalar(0), thickness: Core.FILLED) |
|
|
|
|
Imgproc.drawContours(image: gray0clone, contours: contours, contourIdx: -1, color: Scalar(0), thickness: Core.FILLED) |
|
|
|
|
|
|
|
|
|
XCTAssertEqual(0, Core.countNonZero(src: gray0clone)) |
|
|
|
|
} |
|
|
|
@ -631,10 +629,10 @@ class ImgprocTest: OpenCVTestCase { |
|
|
|
|
|
|
|
|
|
func testFindContoursMatListOfMatMatIntInt() { |
|
|
|
|
let img = Mat(rows: 50, cols: 50, type: CvType.CV_8UC1, scalar: Scalar(0)) |
|
|
|
|
let contours = NSMutableArray() |
|
|
|
|
var contours = [[Point]]() |
|
|
|
|
let hierarchy = Mat() |
|
|
|
|
|
|
|
|
|
Imgproc.findContours(image: img, contours: contours, hierarchy: hierarchy, mode: .RETR_EXTERNAL, method: .CHAIN_APPROX_SIMPLE) |
|
|
|
|
Imgproc.findContours(image: img, contours: &contours, hierarchy: hierarchy, mode: .RETR_EXTERNAL, method: .CHAIN_APPROX_SIMPLE) |
|
|
|
|
|
|
|
|
|
// no contours on empty image |
|
|
|
|
XCTAssertEqual(contours.count, 0) |
|
|
|
@ -643,7 +641,7 @@ class ImgprocTest: OpenCVTestCase { |
|
|
|
|
Imgproc.rectangle(img: img, pt1: Point(x: 10, y: 20), pt2: Point(x: 20, y: 30), color: Scalar(100), thickness: 3, lineType: .LINE_AA, shift: 0) |
|
|
|
|
Imgproc.rectangle(img: img, pt1: Point(x: 30, y: 35), pt2: Point(x: 40, y: 45), color: Scalar(200)) |
|
|
|
|
|
|
|
|
|
Imgproc.findContours(image: img, contours: contours, hierarchy: hierarchy, mode: .RETR_EXTERNAL, method: .CHAIN_APPROX_SIMPLE) |
|
|
|
|
Imgproc.findContours(image: img, contours: &contours, hierarchy: hierarchy, mode: .RETR_EXTERNAL, method: .CHAIN_APPROX_SIMPLE) |
|
|
|
|
|
|
|
|
|
// two contours of two rectangles |
|
|
|
|
XCTAssertEqual(contours.count, 2) |
|
|
|
@ -653,18 +651,18 @@ class ImgprocTest: OpenCVTestCase { |
|
|
|
|
func testFindContoursMatListOfMatMatIntIntPoint() throws { |
|
|
|
|
let img = Mat(rows: 50, cols: 50, type: CvType.CV_8UC1, scalar: Scalar(0)) |
|
|
|
|
let img2 = img.submat(rowStart: 5, rowEnd: 50, colStart: 3, colEnd: 50) |
|
|
|
|
let contours = NSMutableArray() |
|
|
|
|
let contours2 = NSMutableArray() |
|
|
|
|
var contours = [[Point]]() |
|
|
|
|
var contours2 = [[Point]]() |
|
|
|
|
let hierarchy = Mat() |
|
|
|
|
|
|
|
|
|
Imgproc.rectangle(img: img, pt1: Point(x: 10, y: 20), pt2: Point(x: 20, y: 30), color: Scalar(100), thickness: 3, lineType: .LINE_AA, shift: 0) |
|
|
|
|
Imgproc.rectangle(img: img, pt1: Point(x: 30, y: 35), pt2: Point(x: 40, y: 45), color: Scalar(200)) |
|
|
|
|
|
|
|
|
|
Imgproc.findContours(image: img, contours: contours, hierarchy: hierarchy, mode: .RETR_EXTERNAL, method: .CHAIN_APPROX_SIMPLE) |
|
|
|
|
Imgproc.findContours(image: img2, contours: contours2, hierarchy: hierarchy, mode: .RETR_EXTERNAL, method: .CHAIN_APPROX_SIMPLE, offset: Point(x: 3, y: 5)) |
|
|
|
|
Imgproc.findContours(image: img, contours: &contours, hierarchy: hierarchy, mode: .RETR_EXTERNAL, method: .CHAIN_APPROX_SIMPLE) |
|
|
|
|
Imgproc.findContours(image: img2, contours: &contours2, hierarchy: hierarchy, mode: .RETR_EXTERNAL, method: .CHAIN_APPROX_SIMPLE, offset: Point(x: 3, y: 5)) |
|
|
|
|
|
|
|
|
|
XCTAssertEqual(contours.count, contours2.count) |
|
|
|
|
XCTAssert(contours[0] as! [Point] == contours2[0] as! [Point]) |
|
|
|
|
XCTAssert(contours[0] == contours2[0]) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func testFitEllipse() { |
|
|
|
@ -853,9 +851,9 @@ class ImgprocTest: OpenCVTestCase { |
|
|
|
|
func testGoodFeaturesToTrackMatListOfPointIntDoubleDouble() { |
|
|
|
|
let src = gray0 |
|
|
|
|
Imgproc.rectangle(img: src, pt1: Point(x: 2, y: 2), pt2: Point(x: 8, y: 8), color: Scalar(100), thickness: -1) |
|
|
|
|
let lp = NSMutableArray() |
|
|
|
|
var lp = [Point]() |
|
|
|
|
|
|
|
|
|
Imgproc.goodFeaturesToTrack(image: src, corners: lp, maxCorners: 100, qualityLevel: 0.01, minDistance: 3) |
|
|
|
|
Imgproc.goodFeaturesToTrack(image: src, corners: &lp, maxCorners: 100, qualityLevel: 0.01, minDistance: 3) |
|
|
|
|
|
|
|
|
|
XCTAssertEqual(4, lp.count) |
|
|
|
|
} |
|
|
|
@ -863,9 +861,9 @@ class ImgprocTest: OpenCVTestCase { |
|
|
|
|
func testGoodFeaturesToTrackMatListOfPointIntDoubleDoubleMatIntBooleanDouble() { |
|
|
|
|
let src = gray0 |
|
|
|
|
Imgproc.rectangle(img: src, pt1: Point(x: 2, y: 2), pt2: Point(x: 8, y: 8), color: Scalar(100), thickness: -1) |
|
|
|
|
let lp = NSMutableArray() |
|
|
|
|
var lp = [Point]() |
|
|
|
|
|
|
|
|
|
Imgproc.goodFeaturesToTrack(image: src, corners: lp, maxCorners: 100, qualityLevel: 0.01, minDistance: 3, mask: gray1, blockSize: 4, gradientSize: 3, useHarrisDetector: true, k: 0) |
|
|
|
|
Imgproc.goodFeaturesToTrack(image: src, corners: &lp, maxCorners: 100, qualityLevel: 0.01, minDistance: 3, mask: gray1, blockSize: 4, gradientSize: 3, useHarrisDetector: true, k: 0) |
|
|
|
|
|
|
|
|
|
XCTAssertEqual(4, lp.count) |
|
|
|
|
} |
|
|
|
@ -1569,12 +1567,12 @@ class ImgprocTest: OpenCVTestCase { |
|
|
|
|
let arcStart:Int32 = 30 |
|
|
|
|
let arcEnd:Int32 = 60 |
|
|
|
|
let delta:Int32 = 2 |
|
|
|
|
let pts = NSMutableArray() |
|
|
|
|
var pts = [Point]() |
|
|
|
|
|
|
|
|
|
Imgproc.ellipse2Poly(center: center, axes: axes, angle: angle, arcStart: arcStart, arcEnd: arcEnd, delta: delta, pts: pts) |
|
|
|
|
Imgproc.ellipse2Poly(center: center, axes: axes, angle: angle, arcStart: arcStart, arcEnd: arcEnd, delta: delta, pts: &pts) |
|
|
|
|
|
|
|
|
|
let truth = [Point(x: 5, y: 6), Point(x: 4, y: 6)] |
|
|
|
|
XCTAssert(truth == pts as! [Point]) |
|
|
|
|
XCTAssert(truth == pts) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func testEllipseMatPointSizeDoubleDoubleDoubleScalar() { |
|
|
|
|