Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ml module imp #63

Draft
wants to merge 10 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ set(OpenCV_LIBS
opencv_aruco opencv_core opencv_calib3d opencv_dnn opencv_highgui
opencv_features2d opencv_gapi opencv_photo opencv_imgproc
opencv_objdetect opencv_video opencv_videoio opencv_stitching
opencv_img_hash opencv_wechat_qrcode
opencv_img_hash opencv_wechat_qrcode opencv_ml
)

if(ANDROID)
Expand Down
2 changes: 1 addition & 1 deletion conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from pathlib import Path
import yaml

OPENCV_VERSION = "4.9.0+2"
OPENCV_VERSION = "4.9.0+3"
OPENCV_FILES_URL = (
f"https://github.com/rainyl/opencv.full/releases/download/{OPENCV_VERSION}"
)
Expand Down
24 changes: 24 additions & 0 deletions ffigen.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,18 @@ headers:
- src/highgui/highgui.h
- src/imgcodecs/imgcodecs.h
- src/imgproc/imgproc.h
- src/ml/ml.h
- src/ml/train_data.h
- src/ml/ann_mlp.h
- src/ml/boost.h
- src/ml/dtrees.h
- src/ml/em.h
- src/ml/knearest.h
- src/ml/logistic_regression.h
- src/ml/normal_bayes_classifier.h
- src/ml/rtrees.h
- src/ml/svm.h
- src/ml/svmsgd.h
- src/objdetect/objdetect.h
- src/photo/photo.h
- src/stitching/stitching.h
Expand All @@ -50,6 +62,18 @@ headers:
- src/highgui/highgui.h
- src/imgcodecs/imgcodecs.h
- src/imgproc/imgproc.h
- src/ml/ml.h
- src/ml/train_data.h
- src/ml/svm.h
- src/ml/ann_mlp.h
- src/ml/boost.h
- src/ml/dtrees.h
- src/ml/em.h
- src/ml/knearest.h
- src/ml/logistic_regression.h
- src/ml/normal_bayes_classifier.h
- src/ml/rtrees.h
- src/ml/svmsgd.h
- src/objdetect/objdetect.h
- src/photo/photo.h
- src/stitching/stitching.h
Expand Down
4 changes: 2 additions & 2 deletions ffigen_const.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ output:
compiler-opts: ""
headers:
entry-points:
- src/constants.h
- src/core/constants.h
include-directives:
- src/constants.h
- src/core/constants.h

preamble: |
// opencv_dart - OpenCV bindings for Dart language
Expand Down
14 changes: 7 additions & 7 deletions lib/src/calib3d/calib3d.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import '../core/rect.dart';
import '../core/base.dart';
import '../core/mat.dart';
import '../core/size.dart';
import '../core/termcriteria.dart';
import '../constants.g.dart';
import '../core/termcriteria.dart';
import '../opencv.g.dart' as cvg;

class Fisheye {
Expand Down Expand Up @@ -189,7 +189,7 @@ class Fisheye {
rvecs!.ref,
tvecs!.ref,
flags,
criteria.toTermCriteria(arena).ref,
criteria.toNativePtr(arena).ref,
rmsErr,
),
);
Expand Down Expand Up @@ -233,19 +233,19 @@ Mat undistortPoints(
R ??= Mat.empty();
P ??= Mat.empty();
dst ??= Mat.empty();
cvRunArena(
(arena) => cvRun(
cvRunArena((arena) {
cvRun(
() => CFFI.UndistortPoints(
src.ref,
dst!.ref,
cameraMatrix.ref,
distCoeffs.ref,
R!.ref,
P!.ref,
criteria.toTermCriteria(arena).ref,
criteria.toNativePtr(arena).ref,
),
),
);
);
});
return dst;
}

Expand Down
14 changes: 14 additions & 0 deletions lib/src/constants.g.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2090,3 +2090,17 @@ const int CALIB_ZERO_DISPARITY = 1024;
const int CALIB_USE_LU = 131072;

const int CALIB_USE_EXTRINSIC_GUESS = 4194304;

const int VAR_NUMERICAL = 0;

const int VAR_ORDERED = 0;

const int VAR_CATEGORICAL = 1;

const int TEST_ERROR = 0;

const int TRAIN_ERROR = 1;

const int ROW_SAMPLE = 0;

const int COL_SAMPLE = 1;
6 changes: 3 additions & 3 deletions lib/src/core/core.dart
Original file line number Diff line number Diff line change
Expand Up @@ -674,7 +674,7 @@ Mat insertChannel(InputArray src, InputOutputArray dst, int coi) {
final rval = cvRunArena<double>((arena) {
final p = arena<ffi.Double>();
cvRun(
() => CFFI.KMeans(data.ref, K, bestLabels.ref, criteria.toTermCriteria(arena).ref, attempts,
() => CFFI.KMeans(data.ref, K, bestLabels.ref, criteria.toNativePtr(arena).ref, attempts,
flags, centers!.ref, p),
);
return p.value;
Expand All @@ -699,8 +699,8 @@ Mat insertChannel(InputArray src, InputOutputArray dst, int coi) {
final rval = cvRunArena<double>((arena) {
final p = arena<ffi.Double>();
cvRun(
() => CFFI.KMeansPoints(pts.ref, K, bestLabels.ref, criteria.toTermCriteria(arena).ref,
attempts, flags, centers!.ref, p),
() => CFFI.KMeansPoints(pts.ref, K, bestLabels.ref, criteria.toNativePtr(arena).ref, attempts,
flags, centers!.ref, p),
);
return p.value;
});
Expand Down
29 changes: 16 additions & 13 deletions lib/src/core/termcriteria.dart
Original file line number Diff line number Diff line change
@@ -1,22 +1,25 @@
library cv;

import 'dart:ffi' as ffi;

import 'package:ffi/ffi.dart';

import 'base.dart';
import '../opencv.g.dart' as cvg;

typedef TermCriteria = (int type, int count, double eps);

extension TermCriteriaExtension on TermCriteria {
/// TermCriteria is the criteria for iterative algorithms.
///
/// For further details, please see:
/// https://docs.opencv.org/master/d9/d5d/classcv_1_1TermCriteria.html
cvg.TermCriteriaPtr toTermCriteria(Arena arena) {
final p = arena<cvg.TermCriteria>();
cvRun(() => CFFI.TermCriteria_New($1, $2, $3, p));
return p;
extension TermCriteriaX on TermCriteria {
ffi.Pointer<cvg.TermCriteria> toNativePtr(Arena arena) {
return arena<cvg.TermCriteria>()
..ref.type = this.$1
..ref.maxCount = this.$2
..ref.epsilon = this.$3;
}

int get type => this.$1;
int get count => this.$2;
double get eps => this.$3;
}

extension TermCriteriaX1 on cvg.TermCriteria {
TermCriteria toDart() {
return (type, maxCount, epsilon);
}
}
4 changes: 2 additions & 2 deletions lib/src/imgproc/imgproc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -700,8 +700,8 @@ VecPoint2f cornerSubPix(
cvRunArena((arena) {
final size = winSize.toSize(arena);
final zone = zeroZone.toSize(arena);
final c = criteria.toTermCriteria(arena);
cvRun(() => CFFI.CornerSubPix(image.ref, corners.ref, size.ref, zone.ref, c.ref));
final tc = criteria.toNativePtr(arena);
cvRun(() => CFFI.CornerSubPix(image.ref, corners.ref, size.ref, zone.ref, tc.ref));
});
return corners;
}
Expand Down
Loading