ConvertersTest.swift 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. //
  2. // ConvertersTest.swift
  3. //
  4. // Created by Giles Payne on 2020/06/01.
  5. //
  6. import XCTest
  7. import OpenCV
  8. class ConvertersTest: OpenCVTestCase {
  9. func testPoint2iToMat() {
  10. let pointsIn = [Point(x:3, y:4), Point(x:6, y:7), Point(x:7, y:6), Point(x:-78, y:14), Point(x:-93, y:700)]
  11. let pointsOut = Converters.Mat_to_vector_Point(Converters.vector_Point_to_Mat(pointsIn))
  12. XCTAssertEqual(pointsIn, pointsOut)
  13. }
  14. func testPoint2fToMat() {
  15. let pointsIn = [Point2f(x:3.8, y:4.2), Point2f(x:6.01, y:7), Point2f(x:7, y:6), Point2f(x:-78, y:14), Point2f(x:-93, y:700)]
  16. let pointsOut = Converters.Mat_to_vector_Point2f(Converters.vector_Point2f_to_Mat(pointsIn))
  17. XCTAssertEqual(pointsIn, pointsOut)
  18. }
  19. func testPoint2dToMat() {
  20. let pointsIn = [Point2d(x:3.80004, y:73.2), Point2d(x:16.01, y:7.1111), Point2d(x:3.14, y:6), Point2d(x:-78, y:14)]
  21. let pointsOut = Converters.Mat_to_vector_Point2d(Converters.vector_Point2d_to_Mat(pointsIn))
  22. XCTAssertEqual(pointsIn, pointsOut)
  23. }
  24. func testPoint3iToMat() {
  25. let pointsIn = [Point3i(x:3, y:4, z:2), Point3i(x:6, y:7, z:1), Point3i(x:7, y:6, z:9), Point3i(x:-78, y:14, z:0), Point3i(x:-93, y:700, z:54)]
  26. let pointsOut = Converters.Mat_to_vector_Point3i(Converters.vector_Point3i_to_Mat(pointsIn))
  27. XCTAssertEqual(pointsIn, pointsOut)
  28. }
  29. func testPoint3fToMat() {
  30. let pointsIn = [Point3f(x:3.8, y:4.2, z:1200), Point3f(x:6.01, y:7, z: 12), Point3f(x:7, y:6, z:8.88128), Point3f(x:-78, y:14, z:-1), Point3f(x:-93, y:700, z:200)]
  31. let pointsOut = Converters.Mat_to_vector_Point3f(Converters.vector_Point3f_to_Mat(pointsIn))
  32. XCTAssertEqual(pointsIn, pointsOut)
  33. }
  34. func testPoint3dToMat() {
  35. let pointsIn = [Point3d(x:3.80004, y:73.2, z:1), Point3d(x:16.01, y:7.1111, z:2), Point3d(x:3.14, y:6, z:3), Point3d(x:-78, y:14, z:4)]
  36. let pointsOut = Converters.Mat_to_vector_Point3d(Converters.vector_Point3d_to_Mat(pointsIn))
  37. XCTAssertEqual(pointsIn, pointsOut)
  38. }
  39. func testFloatToMat() {
  40. let floatsIn:[Float] = [23.8, 999.89, 93, 0.9, 12]
  41. let floatsOut = Converters.Mat_to_vector_float(Converters.vector_float_to_Mat(floatsIn as [NSNumber])) as! [Float]
  42. XCTAssertEqual(floatsIn, floatsOut)
  43. }
  44. func testIntToMat() {
  45. let intsIn:[Int32] = [23, 999, -93, 0, 4412]
  46. let intsOut = Converters.Mat_to_vector_int(Converters.vector_int_to_Mat(intsIn as [NSNumber])) as! [Int32]
  47. XCTAssertEqual(intsIn, intsOut)
  48. }
  49. func testCharToMat() {
  50. let charsIn:[Int8] = [23, -23, 93, 0, -127]
  51. let charsOut = Converters.Mat_to_vector_char(Converters.vector_char_to_Mat(charsIn as [NSNumber])) as! [Int8]
  52. XCTAssertEqual(charsIn, charsOut)
  53. }
  54. func testUCharToMat() {
  55. let ucharsIn:[UInt8] = [23, 190, 93, 0, 255]
  56. let ucharsOut = Converters.Mat_to_vector_uchar(Converters.vector_uchar_to_Mat(ucharsIn as [NSNumber])) as! [UInt8]
  57. XCTAssertEqual(ucharsIn, ucharsOut)
  58. }
  59. func testDoubleToMat() {
  60. let doublesIn:[Double] = [23.8, 999.89, 93, 0.9, 12]
  61. let doublesOut = Converters.Mat_to_vector_double(Converters.vector_double_to_Mat(doublesIn as [NSNumber])) as! [Double]
  62. XCTAssertEqual(doublesIn, doublesOut)
  63. }
  64. func testRectToMat() {
  65. let rectsIn = [Rect(x: 0, y: 0, width: 3, height: 4), Rect(x: 10, y: 23, width: 7, height: 6), Rect(x: 0, y: 1111110, width: 1, height: 4000)]
  66. let rectsOut = Converters.Mat_to_vector_Rect(Converters.vector_Rect_to_Mat(rectsIn))
  67. XCTAssertEqual(rectsIn, rectsOut)
  68. }
  69. func testRect2dToMat() {
  70. let rectsIn = [Rect2d(x: 0.001, y: 0.00001, width: 3.2, height: 4.556555555), Rect2d(x: 10.009, y: -6623, width: 7.9, height: 6), Rect2d(x: 0, y: 1111.33110, width: 0.99999, height: 3999.999)]
  71. let rectsOut = Converters.Mat_to_vector_Rect2d(Converters.vector_Rect2d_to_Mat(rectsIn))
  72. XCTAssertEqual(rectsIn, rectsOut)
  73. }
  74. func testKeyPointToMat() {
  75. let keyPointsIn = [KeyPoint(x: 8.99, y: 9.00, size: 3, angle: 3.23, response: 0.001, octave: 3, classId: 5), KeyPoint(x: 58.99, y: 9.488, size: 3.4, angle: 2.223, response: 0.006, octave: 4, classId: 7), KeyPoint(x: 7, y: 9.003, size: 12, angle: -3.23, response: 0.02, octave: 1, classId: 8)]
  76. let keyPointsOut = Converters.Mat_to_vector_KeyPoint(Converters.vector_KeyPoint_to_Mat(keyPointsIn))
  77. XCTAssertEqual(keyPointsIn, keyPointsOut)
  78. }
  79. func testDMatchToMat() {
  80. let dmatchesIn = [DMatch(queryIdx: 2, trainIdx: 4, distance: 0.7), DMatch(queryIdx: 3, trainIdx: 7, distance: 0.1), DMatch(queryIdx: 4, trainIdx: 8, distance: 0.01)]
  81. let dmatchesOut = Converters.Mat_to_vector_DMatch(Converters.vector_DMatch_to_Mat(dmatchesIn))
  82. XCTAssertEqual(dmatchesIn, dmatchesOut)
  83. }
  84. func testRotatedRectToMat() {
  85. let rectsIn = [RotatedRect(center: Point2f(x: 0.4, y: 0.9), size: Size2f(width: 3.0, height: 8.9), angle: 0.3342)]
  86. let rectsOut = Converters.Mat_to_vector_RotatedRect(Converters.vector_RotatedRect_to_Mat(rectsIn))
  87. XCTAssertEqual(rectsIn[0].center, rectsOut[0].center)
  88. XCTAssertEqual(rectsIn[0].size, rectsOut[0].size)
  89. XCTAssertEqual(rectsIn[0].angle, rectsOut[0].angle, accuracy: OpenCVTestCase.EPS)
  90. }
  91. }