Skip to content

Commit d469061

Browse files
committed
add test for subdiv2d
1 parent 8df83f9 commit d469061

File tree

3 files changed

+143
-13
lines changed

3 files changed

+143
-13
lines changed

lib/src/imgproc/subdiv2d.dart

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,8 @@ class Subdiv2D extends CvStruct<cvg.Subdiv2D> {
102102
final psize = arena<ffi.Int>();
103103
cvRun(() => CFFI.Subdiv2D_GetEdgeList(ref, pv, psize));
104104
return List.generate(psize.value, (i) {
105-
final v = pv[i];
106-
return Vec4f(v.ref.val1, v.ref.val2, v.ref.val3, v.ref.val4);
105+
final v = pv.value[i];
106+
return Vec4f(v.val1, v.val2, v.val3, v.val4);
107107
});
108108
});
109109
}
@@ -131,8 +131,8 @@ class Subdiv2D extends CvStruct<cvg.Subdiv2D> {
131131
final psize = arena<ffi.Int>();
132132
cvRun(() => CFFI.Subdiv2D_GetTriangleList(ref, pv, psize));
133133
return List.generate(psize.value, (i) {
134-
final v = pv[i];
135-
return Vec6f(v.ref.val1, v.ref.val2, v.ref.val3, v.ref.val4, v.ref.val5, v.ref.val6);
134+
final v = pv.value[i];
135+
return Vec6f(v.val1, v.val2, v.val3, v.val4, v.val5, v.val6);
136136
});
137137
});
138138
}
@@ -194,6 +194,14 @@ class Subdiv2D extends CvStruct<cvg.Subdiv2D> {
194194

195195
/// Returns the location of a point within a Delaunay triangulation.
196196
///
197+
/// [rval] an integer which specify one of the following five cases for point location:
198+
///
199+
/// - The point falls into some facet. The function returns [PTLOC_INSIDE] and edge will contain one of edges of the facet.
200+
/// - The point falls onto the edge. The function returns [PTLOC_ON_EDGE] and edge will contain this edge.
201+
/// - The point coincides with one of the subdivision vertices. The function returns [PTLOC_VERTEX] and vertex will contain a pointer to the vertex.
202+
/// - The point is outside the subdivision reference rectangle. The function returns [PTLOC_OUTSIDE_RECT] and no pointers are filled.
203+
/// - One of input arguments is invalid. A runtime error is raised or, if silent or "parent" error processing mode is selected, [PTLOC_ERROR] is returned.
204+
///
197205
/// https://docs.opencv.org/4.x/df/dbf/classcv_1_1Subdiv2D.html#aec8f1fd5a802f62faa97520b465897d7
198206
(int rval, int edge, int vertex) locate(Point2f pt) {
199207
return using<(int, int, int)>((arena) {
@@ -241,13 +249,19 @@ class Subdiv2D extends CvStruct<cvg.Subdiv2D> {
241249

242250
@override
243251
cvg.Subdiv2D get ref => ptr.ref;
244-
}
245252

246-
const int NEXT_AROUND_ORG = 0x00;
247-
const int NEXT_AROUND_DST = 0x22;
248-
const int PREV_AROUND_ORG = 0x11;
249-
const int PREV_AROUND_DST = 0x33;
250-
const int NEXT_AROUND_LEFT = 0x13;
251-
const int NEXT_AROUND_RIGHT = 0x31;
252-
const int PREV_AROUND_LEFT = 0x20;
253-
const int PREV_AROUND_RIGHT = 0x02;
253+
static const int NEXT_AROUND_ORG = 0x00;
254+
static const int NEXT_AROUND_DST = 0x22;
255+
static const int PREV_AROUND_ORG = 0x11;
256+
static const int PREV_AROUND_DST = 0x33;
257+
static const int NEXT_AROUND_LEFT = 0x13;
258+
static const int NEXT_AROUND_RIGHT = 0x31;
259+
static const int PREV_AROUND_LEFT = 0x20;
260+
static const int PREV_AROUND_RIGHT = 0x02;
261+
262+
static const int PTLOC_ERROR = -2;
263+
static const int PTLOC_OUTSIDE_RECT = -1;
264+
static const int PTLOC_INSIDE = 0;
265+
static const int PTLOC_VERTEX = 1;
266+
static const int PTLOC_ON_EDGE = 2;
267+
}

test/imgproc/clahe_test.dart

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,10 @@ void main() {
88
final clahe = cv.CLAHE();
99
final dst = clahe.apply(mat);
1010
expect(dst.isEmpty, false);
11+
12+
clahe.clipLimit = 50;
13+
clahe.tilesGridSize = (10, 10);
14+
expect(clahe.tilesGridSize, (10, 10));
15+
expect(clahe.clipLimit, closeTo(50, 1e-6));
1116
});
1217
}

test/imgproc/subdiv2d_test.dart

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
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

Comments
 (0)