Skip to content

Commit

Permalink
Merge pull request #269 from rainyl/workflows
Browse files Browse the repository at this point in the history
fix formatter, coveragee
  • Loading branch information
rainyl authored Oct 23, 2024
2 parents 9bbf19c + 1c73d7d commit c25505b
Show file tree
Hide file tree
Showing 26 changed files with 94 additions and 135 deletions.
11 changes: 6 additions & 5 deletions .github/workflows/coverage.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ jobs:
runs-on: windows-2019
steps:
- uses: actions/checkout@v4
with:
submodules: true
- uses: robinraju/release-downloader@v1.10
with:
repository: "rainyl/opencv_dart"
Expand All @@ -36,10 +34,13 @@ jobs:
cd "${{github.workspace}}\packages\dartcv"
$env:PATH="${{github.workspace}}\packages\dartcv\libdartcv\lib;$env:PATH"
dart pub global activate coverage
dart pub global run coverage:test_with_coverage --package . --package-name dartcv
dart pub global run coverage:test_with_coverage --package . --package-name dartcv4
- name: Upload to Codecov
uses: codecov/codecov-action@v4.0.1
with:
token: ${{ secrets.CODECOV_TOKEN }}
slug: rainyl/opencv_dart
file: ./coverage/lcov.info
fail_ci_if_error: true
flags: unittests
directory: ${{github.workspace}}/packages/dartcv/coverage
file: ${{github.workspace}}/packages/dartcv/coverage/lcov.info
verbose: true
3 changes: 1 addition & 2 deletions .github/workflows/formatter.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
on:
push:
pull_request:

name: Format Code

Expand All @@ -16,7 +15,7 @@ jobs:
- name: Format code
run: |
dart format --line-length 110 \
$(find lib test -name '*.dart' -not -name '*.g.dart' -and -not -name '*.freezed.dart')
$(find packages -name '*.dart' -not -name '*.g.dart' -and -not -name '*.freezed.dart')
- name: Commit changes
uses: stefanzweifel/git-auto-commit-action@v5
with:
Expand Down
1 change: 1 addition & 0 deletions packages/dartcv/ffigen/ffigen_const.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ headers:
- ../src/dartcv/core/constants.h

preamble: |
// coverage:ignore-file
// opencv_dart - OpenCV bindings for Dart language
// c wrappers were from gocv: https://github.com/hybridgroup/gocv
// License: Apache-2.0 https://github.com/hybridgroup/gocv/blob/release/LICENSE.txt
Expand Down
25 changes: 13 additions & 12 deletions packages/dartcv/lib/src/calib3d/calib3d_async.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,19 @@ Future<(Mat, Mat)> initUndistortRectifyMapAsync(
map1 ??= Mat.empty();
map2 ??= Mat.empty();
return cvRunAsync0<(Mat, Mat)>(
(callback) => ccalib3d.cv_initUndistortRectifyMap(
cameraMatrix.ref,
distCoeffs.ref,
R.ref,
newCameraMatrix.ref,
size.cvd.ref,
m1type,
map1!.ref,
map2!.ref,
callback,
),
(c) => c.complete((map1!, map2!)));
(callback) => ccalib3d.cv_initUndistortRectifyMap(
cameraMatrix.ref,
distCoeffs.ref,
R.ref,
newCameraMatrix.ref,
size.cvd.ref,
m1type,
map1!.ref,
map2!.ref,
callback,
),
(c) => c.complete((map1!, map2!)),
);
}

/// GetOptimalNewCameraMatrixWithParams computes and returns the optimal new camera matrix based on the free scaling parameter.
Expand Down
4 changes: 2 additions & 2 deletions packages/dartcv/lib/src/contrib/ximgproc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class ximgproc {
/// Smoothes an image using the Edge-Preserving filter.
///
/// The function smoothes Gaussian noise as well as salt & pepper noise.
/// For more details about this implementation, please see [ReiWoe18] Reich,
/// For more details about this implementation, please see ReiWoe18 Reich,
/// S. and Wörgötter, F. and Dellen, B. (2018). A Real-Time Edge-Preserving Denoising Filter.
/// Proceedings of the 13th International Joint Conference on Computer Vision,
/// Imaging and Computer Graphics Theory and Applications (VISIGRAPP): Visapp, 85-94, 4.
Expand All @@ -76,7 +76,7 @@ class ximgproc {
/// Smoothes an image using the Edge-Preserving filter.
///
/// The function smoothes Gaussian noise as well as salt & pepper noise.
/// For more details about this implementation, please see [ReiWoe18] Reich,
/// For more details about this implementation, please see ReiWoe18 Reich,
/// S. and Wörgötter, F. and Dellen, B. (2018). A Real-Time Edge-Preserving Denoising Filter.
/// Proceedings of the 13th International Joint Conference on Computer Vision,
/// Imaging and Computer Graphics Theory and Applications (VISIGRAPP): Visapp, 85-94, 4.
Expand Down
4 changes: 2 additions & 2 deletions packages/dartcv/lib/src/contrib/xobjdetect.dart
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ class WBDetector extends CvStruct<cvg.PtrWBDetector> {
///
/// return:
///
/// [bboxes] Bounding boxes coordinates output vector
/// bboxes Bounding boxes coordinates output vector
///
/// [confidences] Confidence values for bounding boxes output vector
/// confidences Confidence values for bounding boxes output vector
///
/// https://docs.opencv.org/4.x/de/d0e/classcv_1_1xobjdetect_1_1WBDetector.html#ad19680e6545f49a9ca42dfc3457319e2
(VecRect bboxes, VecF64 confidences) detect(Mat img) {
Expand Down
27 changes: 0 additions & 27 deletions packages/dartcv/lib/src/core/base.dart
Original file line number Diff line number Diff line change
Expand Up @@ -195,33 +195,6 @@ Future<T> cvRunAsync5<T>(
return completer.future;
}

// async completers
void voidCompleter(Completer<void> completer) => completer.complete();

void boolCompleter(Completer<bool> completer, VoidPtr p) {
final value = p.cast<ffi.Bool>().value;
calloc.free(p);
completer.complete(value);
}

void intCompleter(Completer<int> completer, VoidPtr p) {
final value = p.cast<ffi.Int>().value;
calloc.free(p);
completer.complete(value);
}

void doubleCompleter(Completer<double> completer, VoidPtr p) {
final value = p.cast<ffi.Double>().value;
calloc.free(p);
completer.complete(value);
}

void floatCompleter(Completer<double> completer, VoidPtr p) {
final value = p.cast<ffi.Float>().value;
calloc.free(p);
completer.complete(value);
}

// Arena wrapper
R cvRunArena<R>(
R Function(Arena arena) computation, [
Expand Down
8 changes: 6 additions & 2 deletions packages/dartcv/lib/src/core/core_async.dart
Original file line number Diff line number Diff line change
Expand Up @@ -556,8 +556,12 @@ Future<(Mat mean, Mat eigenvalues, Mat eigenvectors)> PCACompute1Async(
});
}

Future<(Mat mean, Mat result)> PCAProjectAsync(Mat data, Mat mean, Mat eigenvectors,
{OutputArray? result}) async {
Future<(Mat mean, Mat result)> PCAProjectAsync(
Mat data,
Mat mean,
Mat eigenvectors, {
OutputArray? result,
}) async {
result ??= Mat.empty();
return cvRunAsync0(
(callback) => ccore.cv_PCAProject(data.ref, mean.ref, eigenvectors.ref, result!.ref, callback),
Expand Down
18 changes: 2 additions & 16 deletions packages/dartcv/lib/src/core/mat.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// Use of this source code is governed by a Apache-2.0 license
// that can be found in the LICENSE file.

import 'dart:async';
import 'dart:ffi' as ffi;
import 'dart:typed_data';

Expand Down Expand Up @@ -1336,7 +1335,8 @@ class Mat extends CvStruct<cvg.Mat> {
}) {
final p = calloc<ffi.Pointer<ffi.Char>>();
cvRun(
() => ccore.cv_Mat_toFmtString(ref, fmtType, f16Precision, f32Precision, f64Precision, multiLine, p));
() => ccore.cv_Mat_toFmtString(ref, fmtType, f16Precision, f32Precision, f64Precision, multiLine, p),
);
final rval = p.value.toDartString();
calloc.free(p);
return rval;
Expand Down Expand Up @@ -1444,17 +1444,3 @@ extension ListMatExtension on List<Mat> {
VecMat asVecMat() => asVec();
VecMat asVec() => VecMat.fromList(this);
}

// Completers for async
void matCompleter(Completer<Mat> completer, VoidPtr p) =>
completer.complete(Mat.fromPointer(p.cast<cvg.Mat>()));
void matCompleter2(Completer<(Mat, Mat)> completer, VoidPtr p, VoidPtr p1) =>
completer.complete((Mat.fromPointer(p.cast<cvg.Mat>()), Mat.fromPointer(p1.cast<cvg.Mat>())));
void matCompleter3(Completer<(Mat, Mat, Mat)> completer, VoidPtr p, VoidPtr p1, VoidPtr p2) =>
completer.complete(
(
Mat.fromPointer(p.cast<cvg.Mat>()),
Mat.fromPointer(p1.cast<cvg.Mat>()),
Mat.fromPointer(p2.cast<cvg.Mat>())
),
);
4 changes: 2 additions & 2 deletions packages/dartcv/lib/src/core/mat_async.dart
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ extension MatAsync on Mat {
(callback) => mask == null
? ccore.cv_Mat_copyTo(ref, dst.ref, callback)
: ccore.cv_Mat_copyTo_1(ref, dst.ref, mask.ref, callback),
voidCompleter,
(c) => c.complete(),
);

Future<Mat> convertToAsync(MatType type, {double alpha = 1, double beta = 0}) async {
Expand Down Expand Up @@ -158,5 +158,5 @@ extension MatAsync on Mat {

/// PatchNaNs converts NaN's to zeros.
Future<void> patchNaNsAsync({double val = 0.0}) async =>
cvRunAsync0<void>((callback) => ccore.cv_Mat_patchNaNs(ref, val, callback), voidCompleter);
cvRunAsync0<void>((callback) => ccore.cv_Mat_patchNaNs(ref, val, callback), (c) => c.complete());
}
6 changes: 0 additions & 6 deletions packages/dartcv/lib/src/core/moments.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// Use of this source code is governed by a Apache-2.0 license
// that can be found in the LICENSE file.

import 'dart:async';
import 'dart:ffi' as ffi;

import 'package:ffi/ffi.dart';
Expand Down Expand Up @@ -90,8 +89,3 @@ class Moments extends CvStruct<cvg.Moment> {
nu03,
];
}

// async completer
void momentsCompleter(Completer<Moments> completer, VoidPtr p) {
completer.complete(Moments.fromPointer(p.cast<cvg.Moment>()));
}
8 changes: 0 additions & 8 deletions packages/dartcv/lib/src/core/point.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// Use of this source code is governed by a Apache-2.0 license
// that can be found in the LICENSE file.

import 'dart:async';
import 'dart:ffi' as ffi;

import 'package:ffi/ffi.dart';
Expand Down Expand Up @@ -743,10 +742,3 @@ extension Point3fRecordExtension on (double x, double y, double z) {
Point3f get asPoint3f => Point3f(this.$1, this.$2, this.$3);
Point3f toPoint3f() => Point3f(this.$1, this.$2, this.$3);
}

// completers
void vecPointCompleter(Completer<VecPoint> completer, VoidPtr p) =>
completer.complete(VecPoint.fromPointer(p.cast<cvg.VecPoint>()));

void vecPoint2fCompleter(Completer<VecPoint2f> completer, VoidPtr p) =>
completer.complete(VecPoint2f.fromPointer(p.cast<cvg.VecPoint2f>()));
8 changes: 0 additions & 8 deletions packages/dartcv/lib/src/core/rect.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// Use of this source code is governed by a Apache-2.0 license
// that can be found in the LICENSE file.

import 'dart:async';
import 'dart:ffi' as ffi;

import 'package:ffi/ffi.dart';
Expand Down Expand Up @@ -253,10 +252,3 @@ extension ListRectExtension on List<Rect> {
VecRect get cvd => asVec();
VecRect asVec() => VecRect.fromList(this);
}

// Completers for async
void rectCompleter(Completer<Rect> completer, VoidPtr p) =>
completer.complete(Rect.fromPointer(p.cast<cvg.CvRect>()));

void rotatedRectCompleter(Completer<RotatedRect> completer, VoidPtr p) =>
completer.complete(RotatedRect.fromPointer(p.cast<cvg.RotatedRect>()));
6 changes: 0 additions & 6 deletions packages/dartcv/lib/src/core/scalar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// Use of this source code is governed by a Apache-2.0 license
// that can be found in the LICENSE file.

import 'dart:async';
import 'dart:ffi' as ffi;
import 'dart:math' as math;

Expand Down Expand Up @@ -107,8 +106,3 @@ class Scalar extends CvStruct<cvg.Scalar> {
extension RecordScalarExtension on (double val1, double val2, double val3, double val4) {
Scalar get asScalar => Scalar(this.$1, this.$2, this.$3, this.$4);
}

// async completer
void scalarCompleter(Completer<Scalar> completer, VoidPtr p) {
completer.complete(Scalar.fromPointer(p.cast<cvg.Scalar>()));
}
11 changes: 0 additions & 11 deletions packages/dartcv/lib/src/core/vec.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// Use of this source code is governed by a Apache-2.0 license
// that can be found in the LICENSE file.

import 'dart:async';
import 'dart:collection';
import 'dart:convert';
import 'dart:ffi' as ffi;
Expand Down Expand Up @@ -809,13 +808,3 @@ extension ListFloatExtension on List<double> {
extension ListStringExtension on List<String> {
VecVecChar get i8 => VecVecChar.fromList(map((e) => e.i8.toList()).toList());
}

// async completers
void vecI32Completer(Completer<VecI32> completer, VoidPtr p) =>
completer.complete(VecI32.fromPointer(p.cast<cvg.VecI32>()));

void vecF32Completer(Completer<VecF32> completer, VoidPtr p) =>
completer.complete(VecF32.fromPointer(p.cast<cvg.VecF32>()));

void vecF64Completer(Completer<VecF64> completer, VoidPtr p) =>
completer.complete(VecF64.fromPointer(p.cast<cvg.VecF64>()));
1 change: 1 addition & 0 deletions packages/dartcv/lib/src/g/constants.g.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// coverage:ignore-file
// opencv_dart - OpenCV bindings for Dart language
// c wrappers were from gocv: https://github.com/hybridgroup/gocv
// License: Apache-2.0 https://github.com/hybridgroup/gocv/blob/release/LICENSE.txt
Expand Down
4 changes: 3 additions & 1 deletion packages/dartcv/lib/src/gapi/gcomputation.dart
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ class GComputation extends CvStruct<cvg.GComputation> {
}

Future<Mat> apply(Mat inMat) async =>
cvRunAsync1((callback) => cgapi.gapi_GComputation_apply(ref, inMat.ref, callback), matCompleter);
cvRunAsync1((callback) => cgapi.gapi_GComputation_apply(ref, inMat.ref, callback), (c, p) {
c.complete(Mat.fromPointer(p.cast()));
});

// Mat applyMIMO(Mat inMat) => apply(inMat);

Expand Down
12 changes: 8 additions & 4 deletions packages/dartcv/lib/src/imgproc/imgproc_async.dart
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ Future<double> arcLengthAsync(VecPoint curve, bool closed) async {
///
/// For further details, please see:
/// https:///docs.opencv.org/master/d3/dc0/group__imgproc__shape.html#ga014b28e56cb8854c0de4a211cb2be656
Future<Mat> convexHullAsync(VecPoint points, {Mat? hull, bool clockwise = false, bool returnPoints = true}) async {
Future<Mat> convexHullAsync(VecPoint points,
{Mat? hull, bool clockwise = false, bool returnPoints = true}) async {
hull ??= Mat.empty();
return cvRunAsync0(
(callback) => cimgproc.cv_convexHull(points.ref, hull!.ref, clockwise, returnPoints, callback),
Expand Down Expand Up @@ -217,7 +218,8 @@ Future<(bool, Point, Point)> clipLineAsync(Rect imgRect, Point pt1, Point pt2) a
///
/// For further details, please see:
/// https:///docs.opencv.org/master/d4/d86/group__imgproc__filter.html#ga9d7064d478c95d60003cf839430737ed
Future<Mat> bilateralFilterAsync(Mat src, int diameter, double sigmaColor, double sigmaSpace, {Mat? dst}) async {
Future<Mat> bilateralFilterAsync(Mat src, int diameter, double sigmaColor, double sigmaSpace,
{Mat? dst}) async {
dst ??= Mat.empty();
return cvRunAsync0(
(callback) => cimgproc.cv_bilateralFilter(src.ref, dst!.ref, diameter, sigmaColor, sigmaSpace, callback),
Expand Down Expand Up @@ -1718,7 +1720,8 @@ Future<Mat> getPerspectiveTransformAsync(VecPoint src, VecPoint dst, [int solveM
///
/// For further details, please see:
/// https:///docs.opencv.org/master/da/d54/group__imgproc__transform.html#ga8c1ae0e3589a9d77fffc962c49b22043
Future<Mat> getPerspectiveTransform2fAsync(VecPoint2f src, VecPoint2f dst, [int solveMethod = DECOMP_LU]) async {
Future<Mat> getPerspectiveTransform2fAsync(VecPoint2f src, VecPoint2f dst,
[int solveMethod = DECOMP_LU]) async {
final mat = Mat.empty();
return cvRunAsync0(
(callback) => cimgproc.cv_getPerspectiveTransform2f(src.ref, dst.ref, mat.ptr, solveMethod, callback),
Expand Down Expand Up @@ -2072,7 +2075,8 @@ Future<Mat> accumulateProductAsync(
///
/// For further details, please see:
/// https:///docs.opencv.org/master/d7/df3/group__imgproc__motion.html#ga4f9552b541187f61f6818e8d2d826bc7
Future<Mat> accumulateWeightedAsync(InputArray src, InputOutputArray dst, double alpha, {InputArray? mask}) async {
Future<Mat> accumulateWeightedAsync(InputArray src, InputOutputArray dst, double alpha,
{InputArray? mask}) async {
if (mask == null) {
return cvRunAsync0(
(callback) => cimgproc.cv_accumulatedWeighted(src.ref, dst.ref, alpha, callback),
Expand Down
7 changes: 5 additions & 2 deletions packages/dartcv/lib/src/objdetect/objdetect_async.dart
Original file line number Diff line number Diff line change
Expand Up @@ -445,8 +445,11 @@ extension FaceRecognizerSFAsync on FaceRecognizerSF {
);
}

Future<double> matchAsync(Mat faceFeature1, Mat faceFeature2,
{int disType = FaceRecognizerSF.FR_COSINE}) async {
Future<double> matchAsync(
Mat faceFeature1,
Mat faceFeature2, {
int disType = FaceRecognizerSF.FR_COSINE,
}) async {
final distance = calloc<ffi.Double>();
return cvRunAsync0(
(callback) => cobjdetect.cv_FaceRecognizerSF_match(
Expand Down
2 changes: 1 addition & 1 deletion packages/dartcv/lib/src/photo/photo.dart
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ class AlignMTB extends CvStruct<cvg.AlignMTB> {

VecMat process(VecMat src) {
final dst = calloc<cvg.VecMat>();
cvRun(()=>cphoto.cv_AlignMTB_process(ref, src.ref, dst, ffi.nullptr));
cvRun(() => cphoto.cv_AlignMTB_process(ref, src.ref, dst, ffi.nullptr));
return VecMat.fromPointer(dst);
}

Expand Down
5 changes: 3 additions & 2 deletions packages/dartcv/lib/src/video/video.dart
Original file line number Diff line number Diff line change
Expand Up @@ -345,8 +345,9 @@ class KalmanFilter extends CvStruct<cvg.KalmanFilter> {
int controlParams = 0,
int type = MatType.CV_32F,
}) {
cvRun(() =>
cvideo.cv_KalmanFilter_init_1(ref, dynamParams, measureParams, controlParams, type, ffi.nullptr));
cvRun(
() => cvideo.cv_KalmanFilter_init_1(ref, dynamParams, measureParams, controlParams, type, ffi.nullptr),
);
}

@override
Expand Down
Loading

0 comments on commit c25505b

Please sign in to comment.