// // Calib3dTest.swift // // Created by Giles Payne on 2020/05/26. // import XCTest import OpenCV class Cv3dTest: OpenCVTestCase { var size = Size() override func setUp() { super.setUp() size = Size(width: 3, height: 3) } override func tearDown() { super.tearDown() } func testComposeRTMatMatMatMatMatMat() throws { let rvec1 = Mat(rows: 3, cols: 1, type: CvType.CV_32F) try rvec1.put(row: 0, col: 0, data: [0.5302828, 0.19925919, 0.40105945] as [Float]) let tvec1 = Mat(rows: 3, cols: 1, type: CvType.CV_32F) try tvec1.put(row: 0, col: 0, data: [0.81438506, 0.43713298, 0.2487897] as [Float]) let rvec2 = Mat(rows: 3, cols: 1, type: CvType.CV_32F) try rvec2.put(row: 0, col: 0, data: [0.77310503, 0.76209372, 0.30779448] as [Float]) let tvec2 = Mat(rows: 3, cols: 1, type: CvType.CV_32F) try tvec2.put(row: 0, col: 0, data: [0.70243168, 0.4784472, 0.79219002] as [Float]) let rvec3 = Mat() let tvec3 = Mat() let outRvec = Mat(rows: 3, cols: 1, type: CvType.CV_32F) try outRvec.put(row: 0, col: 0, data: [1.418641, 0.88665926, 0.56020796]) let outTvec = Mat(rows: 3, cols: 1, type: CvType.CV_32F) try outTvec.put(row: 0, col: 0, data: [1.4560841, 1.0680628, 0.81598103]) Cv3d.composeRT(rvec1: rvec1, tvec1: tvec1, rvec2: rvec2, tvec2: tvec2, rvec3: rvec3, tvec3: tvec3) try assertMatEqual(outRvec, rvec3, OpenCVTestCase.EPS) try assertMatEqual(outTvec, tvec3, OpenCVTestCase.EPS) } func testFindHomographyListOfPointListOfPoint() throws { let NUM:Int32 = 20 let originalPoints = MatOfPoint2f() originalPoints.alloc(NUM) let transformedPoints = MatOfPoint2f() transformedPoints.alloc(NUM) for i:Int32 in 0.. src, List dst, Mat cameraMatrix, Mat distCoeffs) func testUndistortPointsListOfPointListOfPointMatMat() { let src = MatOfPoint2f(array: [Point2f(x: 1, y: 2), Point2f(x: 3, y: 4), Point2f(x: -1, y: -1)]) let dst = MatOfPoint2f() let cameraMatrix = Mat.eye(rows: 3, cols: 3, type: CvType.CV_64FC1) let distCoeffs = Mat(rows: 8, cols: 1, type: CvType.CV_64FC1, scalar: Scalar(0)) Cv3d.undistortPoints(src: src, dst: dst, cameraMatrix: cameraMatrix, distCoeffs: distCoeffs) XCTAssertEqual(src.toArray(), dst.toArray()) } }