Skip to content

Commit

Permalink
finish core types
Browse files Browse the repository at this point in the history
  • Loading branch information
rainyl committed Feb 21, 2025
1 parent 3469daf commit 5a00774
Show file tree
Hide file tree
Showing 14 changed files with 464 additions and 397 deletions.
7 changes: 7 additions & 0 deletions packages/dartcv/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
## 1.1.4

* remove deprecated `MatType.toInt()`, should use MatType.value instead
* add `MatType.elemSize` `MatType.elemSize1`
* remove deprecated `(double x, double y, double z).asPoint3f`
`(double x, double y).asPoint2f` `(int x, int y).asPoint` `VecPoint.toVecVecPoint`

## 1.1.3

* add `VideoCapture.grabAsync`
Expand Down
17 changes: 11 additions & 6 deletions packages/dartcv/lib/src/core/cv_vec.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1404,13 +1404,13 @@ class Vec6d extends CvVec<cvg.Vec6d> {
}

class VecVec4i extends Vec<cvg.VecVec4i, Vec4i> {
VecVec4i.fromPointer(super.ptr, {bool attach = true, int length = 0}) : super.fromPointer() {
VecVec4i.fromPointer(super.ptr, {bool attach = true, int? length}) : super.fromPointer() {
if (attach) {
finalizer.attach(
this,
ptr.cast<ffi.Void>(),
detach: this,
externalSize: length * ffi.sizeOf<cvg.Vec4i>(),
externalSize: length == null ? null : length * ffi.sizeOf<cvg.Vec4i>(),
);
}
}
Expand Down Expand Up @@ -1492,9 +1492,14 @@ class VecVec4iIterator extends VecIterator<Vec4i> {
}

class VecVec4f extends Vec<cvg.VecVec4f, Vec4f> {
VecVec4f.fromPointer(super.ptr, {bool attach = true, int length = 0}) : super.fromPointer() {
VecVec4f.fromPointer(super.ptr, {bool attach = true, int? length}) : super.fromPointer() {
if (attach) {
finalizer.attach(this, ptr.cast<ffi.Void>(), detach: this, externalSize: ffi.sizeOf<cvg.Vec4f>());
finalizer.attach(
this,
ptr.cast<ffi.Void>(),
detach: this,
externalSize: length == null ? null : length * ffi.sizeOf<cvg.Vec4f>(),
);
}
}

Expand Down Expand Up @@ -1575,13 +1580,13 @@ class VecVec4fIterator extends VecIterator<Vec4f> {
}

class VecVec6f extends Vec<cvg.VecVec6f, Vec6f> {
VecVec6f.fromPointer(super.ptr, {bool attach = true, int length = 0}) : super.fromPointer() {
VecVec6f.fromPointer(super.ptr, {bool attach = true, int? length}) : super.fromPointer() {
if (attach) {
finalizer.attach(
this,
ptr.cast<ffi.Void>(),
detach: this,
externalSize: length * ffi.sizeOf<cvg.Vec6f>(),
externalSize: length == null ? null : length * ffi.sizeOf<cvg.Vec6f>(),
);
}
}
Expand Down
9 changes: 4 additions & 5 deletions packages/dartcv/lib/src/core/dmatch.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ import 'base.dart';
import 'vec.dart';

class DMatch extends CvStruct<cvg.DMatch> {
DMatch._(ffi.Pointer<cvg.DMatch> ptr, {bool attach = true, int? externalSize}) : super.fromPointer(ptr) {
DMatch._(ffi.Pointer<cvg.DMatch> ptr, {bool attach = true}) : super.fromPointer(ptr) {
if (attach) {
finalizer.attach(this, ptr.cast(), detach: this, externalSize: externalSize);
finalizer.attach(this, ptr.cast(), detach: this, externalSize: ffi.sizeOf<cvg.DMatch>());
}
}
factory DMatch(int queryIdx, int trainIdx, int imgIdx, double distance) {
Expand All @@ -25,11 +25,10 @@ class DMatch extends CvStruct<cvg.DMatch> {
..ref.trainIdx = trainIdx
..ref.imgIdx = imgIdx
..ref.distance = distance;
return DMatch._(ptr, externalSize: ffi.sizeOf<cvg.DMatch>());
return DMatch._(ptr);
}
factory DMatch.fromNative(cvg.DMatch r) => DMatch(r.queryIdx, r.trainIdx, r.imgIdx, r.distance);
factory DMatch.fromPointer(ffi.Pointer<cvg.DMatch> p, {bool attach = true, int? externalSize}) =>
DMatch._(p, attach: attach, externalSize: externalSize);
factory DMatch.fromPointer(ffi.Pointer<cvg.DMatch> p, {bool attach = true}) => DMatch._(p, attach: attach);

static final finalizer = ffi.NativeFinalizer(calloc.nativeFree);

Expand Down
41 changes: 23 additions & 18 deletions packages/dartcv/lib/src/core/keypoint.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,26 @@ import 'base.dart';
import 'vec.dart';

class KeyPoint extends CvStruct<cvg.KeyPoint> {
KeyPoint._(ffi.Pointer<cvg.KeyPoint> ptr, [bool attach = true]) : super.fromPointer(ptr) {
KeyPoint._(ffi.Pointer<cvg.KeyPoint> ptr, {bool attach = true}) : super.fromPointer(ptr) {
if (attach) {
finalizer.attach(this, ptr.cast(), detach: this);
finalizer.attach(this, ptr.cast(), detach: this, externalSize: ffi.sizeOf<cvg.KeyPoint>());
}
}
factory KeyPoint(double x, double y, double size, double angle, double response, int octave, int classID) {
final ptr =
calloc<cvg.KeyPoint>()
..ref.x = x
..ref.y = y
..ref.size = size
..ref.angle = angle
..ref.response = response
..ref.octave = octave
..ref.classID = classID;
final ptr = calloc<cvg.KeyPoint>()
..ref.x = x
..ref.y = y
..ref.size = size
..ref.angle = angle
..ref.response = response
..ref.octave = octave
..ref.classID = classID;
return KeyPoint._(ptr);
}
factory KeyPoint.fromNative(cvg.KeyPoint r) =>
KeyPoint(r.x, r.y, r.size, r.angle, r.response, r.octave, r.classID);
factory KeyPoint.fromPointer(ffi.Pointer<cvg.KeyPoint> p, [bool attach = true]) => KeyPoint._(p, attach);
factory KeyPoint.fromPointer(ffi.Pointer<cvg.KeyPoint> p, {bool attach = true}) =>
KeyPoint._(p, attach: attach);

static final finalizer = ffi.NativeFinalizer(calloc.nativeFree);

Expand Down Expand Up @@ -69,8 +69,7 @@ class KeyPoint extends CvStruct<cvg.KeyPoint> {
@override
cvg.KeyPoint get ref => ptr.ref;
@override
String toString() =>
"KeyPoint("
String toString() => "KeyPoint("
"${x.toStringAsFixed(3)}, "
"${y.toStringAsFixed(3)}, "
"${size.toStringAsFixed(3)}, "
Expand All @@ -80,13 +79,19 @@ class KeyPoint extends CvStruct<cvg.KeyPoint> {
}

class VecKeyPoint extends Vec<cvg.VecKeyPoint, KeyPoint> {
VecKeyPoint.fromPointer(super.ptr, [bool attach = true]) : super.fromPointer() {
VecKeyPoint.fromPointer(super.ptr, {bool attach = true, int? length}) : super.fromPointer() {
if (attach) {
finalizer.attach(this, ptr.cast<ffi.Void>(), detach: this);
finalizer.attach(
this,
ptr.cast<ffi.Void>(),
detach: this,
externalSize: length == null ? null : length * ffi.sizeOf<cvg.KeyPoint>(),
);
}
}

factory VecKeyPoint([int length = 0]) => VecKeyPoint.fromPointer(ccore.std_VecKeyPoint_new(length));
factory VecKeyPoint([int length = 0]) =>
VecKeyPoint.fromPointer(ccore.std_VecKeyPoint_new(length), length: length);

factory VecKeyPoint.fromList(List<KeyPoint> pts) =>
VecKeyPoint.generate(pts.length, (i) => pts[i], dispose: false);
Expand All @@ -98,7 +103,7 @@ class VecKeyPoint extends Vec<cvg.VecKeyPoint, KeyPoint> {
ccore.std_VecKeyPoint_set(p, i, v.ref);
if (dispose) v.dispose();
}
return VecKeyPoint.fromPointer(p);
return VecKeyPoint.fromPointer(p, length: length);
}

static final finalizer = OcvFinalizer<cvg.VecKeyPointPtr>(ccore.addresses.std_VecKeyPoint_free);
Expand Down
Loading

0 comments on commit 5a00774

Please sign in to comment.