|
| 1 | +import 'package:test/test.dart'; |
| 2 | + |
| 3 | +import 'package:opencv_dart/opencv_dart.dart' as cv; |
| 4 | + |
| 5 | +void main() { |
| 6 | + final src = cv.Mat.fromScalar(400, 400, cv.MatType.CV_8UC3, cv.Scalar.white); |
| 7 | + final points = [ |
| 8 | + cv.Point2f(23, 45), |
| 9 | + cv.Point2f(243, 145), |
| 10 | + cv.Point2f(308, 25), |
| 11 | + cv.Point2f(180, 230), |
| 12 | + cv.Point2f(343, 145), |
| 13 | + cv.Point2f(108, 25), |
| 14 | + ]; |
| 15 | + for (var pt in points) { |
| 16 | + cv.circle(src, cv.Point(pt.x.toInt(), pt.y.toInt()), 1, cv.Scalar.black, thickness: 2); |
| 17 | + } |
| 18 | + |
| 19 | + test("cv.Subdiv2D", () { |
| 20 | + final subdiv = cv.Subdiv2D.fromRect(cv.Rect(0, 0, src.width, src.height)); |
| 21 | + subdiv.insertVec(points.cvd); |
| 22 | + |
| 23 | + final triangleList = subdiv.getTriangleList(); |
| 24 | + expect(triangleList.length, greaterThan(0)); |
| 25 | + for (var tri in triangleList) { |
| 26 | + final p1 = cv.Point(tri.val1.toInt(), tri.val2.toInt()); |
| 27 | + final p2 = cv.Point(tri.val3.toInt(), tri.val4.toInt()); |
| 28 | + final p3 = cv.Point(tri.val5.toInt(), tri.val6.toInt()); |
| 29 | + cv.line(src, p1, p2, cv.Scalar.red, thickness: 1); |
| 30 | + cv.line(src, p1, p3, cv.Scalar.red, thickness: 1); |
| 31 | + cv.line(src, p2, p3, cv.Scalar.red, thickness: 1); |
| 32 | + } |
| 33 | + // cv.imwrite("subdiv2d.png", src); |
| 34 | + final win = cv.Window("Subdiv2D"); |
| 35 | + win.imshow(src); |
| 36 | + // win.waitKey(0); |
| 37 | + cv.destroyAllWindows(); |
| 38 | + }); |
| 39 | + |
| 40 | + test('cv.Subdiv2D.empty', () { |
| 41 | + final sub1 = cv.Subdiv2D.empty(); |
| 42 | + sub1.initDelaunay(cv.Rect(0, 0, src.width, src.height)); |
| 43 | + sub1.insert(cv.Point2f(241, 241)); |
| 44 | + }); |
| 45 | + |
| 46 | + test('cv.Subdiv2D others', () { |
| 47 | + final subdiv = cv.Subdiv2D.fromRect(cv.Rect(0, 0, src.width, src.height)); |
| 48 | + subdiv.insertVec(points.cvd); |
| 49 | + |
| 50 | + { |
| 51 | + final (rval, pt) = subdiv.edgeDst(1); |
| 52 | + expect(rval, 0); |
| 53 | + expect(pt, cv.Point2f(0, 0)); |
| 54 | + } |
| 55 | + |
| 56 | + { |
| 57 | + final (rval, pt) = subdiv.edgeOrg(1); |
| 58 | + expect(rval, 0); |
| 59 | + expect(pt, cv.Point2f(0, 0)); |
| 60 | + } |
| 61 | + |
| 62 | + { |
| 63 | + final (rval, pt) = subdiv.findNearest(cv.Point2f(241, 241)); |
| 64 | + expect(rval, 7); |
| 65 | + expect(pt, cv.Point2f(180, 230)); |
| 66 | + } |
| 67 | + |
| 68 | + { |
| 69 | + final edge = subdiv.getEdge(1, cv.Subdiv2D.NEXT_AROUND_LEFT); |
| 70 | + expect(edge, 1); |
| 71 | + } |
| 72 | + |
| 73 | + { |
| 74 | + final edges = subdiv.getEdgeList(); |
| 75 | + expect(edges.length, greaterThan(0)); |
| 76 | + } |
| 77 | + |
| 78 | + { |
| 79 | + final r = subdiv.getLeadingEdgeList(); |
| 80 | + expect(r.length, greaterThan(0)); |
| 81 | + } |
| 82 | + |
| 83 | + { |
| 84 | + final (pt, v) = subdiv.getVertex(0); |
| 85 | + expect(pt, cv.Point2f(0, 0)); |
| 86 | + expect(v, 0); |
| 87 | + } |
| 88 | + |
| 89 | + { |
| 90 | + final (fl, fc) = subdiv.getVoronoiFacetList([0, 1].i32); |
| 91 | + expect(fl.length, greaterThan(0)); |
| 92 | + expect(fc.length, greaterThan(0)); |
| 93 | + } |
| 94 | + |
| 95 | + { |
| 96 | + final (rval, edge, vertex) = subdiv.locate(cv.Point2f(241, 241)); |
| 97 | + expect(rval, cv.Subdiv2D.PTLOC_INSIDE); |
| 98 | + expect(edge, 72); |
| 99 | + expect(vertex, 0); |
| 100 | + } |
| 101 | + |
| 102 | + { |
| 103 | + final nextEdge = subdiv.nextEdge(0); |
| 104 | + expect(nextEdge, 0); |
| 105 | + final rEdge = subdiv.rotateEdge(0, 90); |
| 106 | + expect(rEdge, 2); |
| 107 | + final sEdge = subdiv.symEdge(0); |
| 108 | + expect(sEdge, 2); |
| 109 | + } |
| 110 | + }); |
| 111 | +} |
0 commit comments