Skip to content

Commit f060a8a

Browse files
committed
add EdgeBoxes, more test
1 parent 781ba8a commit f060a8a

File tree

6 files changed

+389
-66
lines changed

6 files changed

+389
-66
lines changed

lib/src/contrib/ximgproc.dart

Lines changed: 130 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import 'package:opencv_dart/src/core/mat_type.dart';
1010
import '../core/base.dart';
1111
import '../core/mat.dart';
1212
import '../core/point.dart';
13+
import '../core/rect.dart';
1314
import '../core/scalar.dart';
1415
import '../core/size.dart';
1516
import '../core/vec.dart';
@@ -233,6 +234,112 @@ class ximgproc {
233234
static const int BINARIZATION_NICK = 3;
234235
}
235236

237+
/// https://docs.opencv.org/4.x/dd/d65/classcv_1_1ximgproc_1_1EdgeBoxes.html#details
238+
class EdgeBoxes extends CvStruct<cvg.EdgeBoxes> {
239+
EdgeBoxes.fromPointer(super.ptr, [bool attach = true]) : super.fromPointer() {
240+
if (attach) finalizer.attach(this, ptr.cast(), detach: this);
241+
}
242+
243+
/// https://docs.opencv.org/4.x/dd/d65/classcv_1_1ximgproc_1_1EdgeBoxes.html#details
244+
factory EdgeBoxes({
245+
double alpha = 0.65,
246+
double beta = 0.75,
247+
double eta = 1,
248+
double minScore = 0.01,
249+
int maxBoxes = 10000,
250+
double edgeMinMag = 0.1,
251+
double edgeMergeThr = 0.5,
252+
double clusterMinMag = 0.5,
253+
double maxAspectRatio = 3,
254+
double minBoxArea = 1000,
255+
double gamma = 2,
256+
double kappa = 1.5,
257+
}) {
258+
final p = calloc<cvg.EdgeBoxes>()
259+
..ref.alpha = alpha
260+
..ref.beta = beta
261+
..ref.eta = eta
262+
..ref.minScore = minScore
263+
..ref.maxBoxes = maxBoxes
264+
..ref.edgeMinMag = edgeMinMag
265+
..ref.edgeMergeThr = edgeMergeThr
266+
..ref.clusterMinMag = clusterMinMag
267+
..ref.maxAspectRatio = maxAspectRatio
268+
..ref.minBoxArea = minBoxArea
269+
..ref.gamma = gamma
270+
..ref.kappa = kappa;
271+
272+
return EdgeBoxes.fromPointer(p);
273+
}
274+
275+
/// Returns array containing proposal boxes.
276+
///
277+
/// https://docs.opencv.org/4.x/dd/d65/classcv_1_1ximgproc_1_1EdgeBoxes.html#a822e422556f8103d01a0a4db6815f0e5
278+
(VecRect boxes, VecFloat scores) getBoundingBoxes(InputArray edge_map, InputArray orientation_map) {
279+
final pvr = calloc<cvg.VecRect>();
280+
final pvf = calloc<cvg.VecFloat>();
281+
cvRun(() => CFFI.ximgproc_EdgeBoxes_getBoundingBoxes(ref, edge_map.ref, orientation_map.ref, pvr, pvf));
282+
return (VecRect.fromPointer(pvr), VecFloat.fromPointer(pvf));
283+
}
284+
285+
double get alpha => ref.alpha;
286+
set alpha(double value) => ref.alpha = value;
287+
288+
double get beta => ref.beta;
289+
set beta(double value) => ref.beta = value;
290+
291+
double get eta => ref.eta;
292+
set eta(double value) => ref.eta = value;
293+
294+
double get minScore => ref.minScore;
295+
set minScore(double value) => ref.minScore = value;
296+
297+
int get maxBoxes => ref.maxBoxes;
298+
set maxBoxes(int value) => ref.maxBoxes = value;
299+
300+
double get edgeMinMag => ref.edgeMinMag;
301+
set edgeMinMag(double value) => ref.edgeMinMag = value;
302+
303+
double get edgeMergeThr => ref.edgeMergeThr;
304+
set edgeMergeThr(double value) => ref.edgeMergeThr = value;
305+
306+
double get clusterMinMag => ref.clusterMinMag;
307+
set clusterMinMag(double value) => ref.clusterMinMag = value;
308+
309+
double get maxAspectRatio => ref.maxAspectRatio;
310+
set maxAspectRatio(double value) => ref.maxAspectRatio = value;
311+
312+
double get minBoxArea => ref.minBoxArea;
313+
set minBoxArea(double value) => ref.minBoxArea = value;
314+
315+
double get gamma => ref.gamma;
316+
set gamma(double value) => ref.gamma = value;
317+
318+
double get kappa => ref.kappa;
319+
set kappa(double value) => ref.kappa = value;
320+
321+
static final finalizer = ffi.NativeFinalizer(calloc.nativeFree);
322+
323+
@override
324+
List<num> get props => [
325+
alpha,
326+
beta,
327+
eta,
328+
minScore,
329+
maxBoxes,
330+
edgeMinMag,
331+
edgeMergeThr,
332+
clusterMinMag,
333+
maxAspectRatio,
334+
minBoxArea,
335+
gamma,
336+
kappa,
337+
];
338+
339+
@override
340+
cvg.EdgeBoxes get ref => ptr.ref;
341+
}
342+
236343
class RFFeatureGetter extends CvStruct<cvg.RFFeatureGetter> {
237344
RFFeatureGetter.fromPointer(super.ptr, [bool attach = true]) : super.fromPointer() {
238345
if (attach) finalizer.attach(this, ptr.cast(), detach: this);
@@ -244,9 +351,6 @@ class RFFeatureGetter extends CvStruct<cvg.RFFeatureGetter> {
244351
return RFFeatureGetter.fromPointer(p);
245352
}
246353

247-
static final finalizer =
248-
OcvFinalizer<cvg.RFFeatureGetterPtr>(CFFI.addresses.ximgproc_RFFeatureGetter_Close);
249-
250354
Mat getFeatures(InputArray src, int gnrmRad, int gsmthRad, int shrink, int outNum, int gradNum) {
251355
final p = calloc<cvg.Mat>();
252356
cvRun(
@@ -274,6 +378,14 @@ class RFFeatureGetter extends CvStruct<cvg.RFFeatureGetter> {
274378
return rval;
275379
}
276380

381+
static final finalizer =
382+
OcvFinalizer<cvg.RFFeatureGetterPtr>(CFFI.addresses.ximgproc_RFFeatureGetter_Close);
383+
384+
void dispose() {
385+
finalizer.detach(this);
386+
CFFI.ximgproc_RFFeatureGetter_Close(ptr);
387+
}
388+
277389
@override
278390
List<int> get props => [ptr.address];
279391

@@ -350,6 +462,11 @@ class StructuredEdgeDetection extends CvStruct<cvg.StructuredEdgeDetection> {
350462
static final finalizer =
351463
OcvFinalizer<cvg.StructuredEdgeDetectionPtr>(CFFI.addresses.ximgproc_StructuredEdgeDetection_Close);
352464

465+
void dispose() {
466+
finalizer.detach(this);
467+
CFFI.ximgproc_StructuredEdgeDetection_Close(ptr);
468+
}
469+
353470
@override
354471
List<int> get props => [ptr.address];
355472

@@ -412,6 +529,11 @@ class GraphSegmentation extends CvStruct<cvg.GraphSegmentation> {
412529
static final finalizer =
413530
OcvFinalizer<cvg.GraphSegmentationPtr>(CFFI.addresses.ximgproc_GraphSegmentation_Close);
414531

532+
void dispose() {
533+
finalizer.detach(this);
534+
CFFI.ximgproc_GraphSegmentation_Close(ptr);
535+
}
536+
415537
@override
416538
List<int> get props => [ptr.address];
417539

@@ -586,6 +708,11 @@ class EdgeDrawing extends CvStruct<cvg.EdgeDrawing> {
586708

587709
static final finalizer = OcvFinalizer<cvg.EdgeDrawingPtr>(CFFI.addresses.ximgproc_EdgeDrawing_Close);
588710

711+
void dispose() {
712+
finalizer.detach(this);
713+
CFFI.ximgproc_EdgeDrawing_Close(ptr);
714+
}
715+
589716
@override
590717
List<int> get props => [ptr.address];
591718

lib/src/opencv.g.dart

Lines changed: 81 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35837,6 +35837,35 @@ class CvNative {
3583735837
late final _undistort_Async = _undistort_AsyncPtr.asFunction<
3583835838
ffi.Pointer<CvStatus> Function(Mat, Mat, Mat, Mat, CvCallback_1)>();
3583935839

35840+
ffi.Pointer<CvStatus> ximgproc_EdgeBoxes_getBoundingBoxes(
35841+
EdgeBoxes self,
35842+
Mat edge_map,
35843+
Mat orientation_map,
35844+
ffi.Pointer<VecRect> boxes,
35845+
ffi.Pointer<VecFloat> scores,
35846+
) {
35847+
return _ximgproc_EdgeBoxes_getBoundingBoxes(
35848+
self,
35849+
edge_map,
35850+
orientation_map,
35851+
boxes,
35852+
scores,
35853+
);
35854+
}
35855+
35856+
late final _ximgproc_EdgeBoxes_getBoundingBoxesPtr = _lookup<
35857+
ffi.NativeFunction<
35858+
ffi.Pointer<CvStatus> Function(
35859+
EdgeBoxes,
35860+
Mat,
35861+
Mat,
35862+
ffi.Pointer<VecRect>,
35863+
ffi.Pointer<VecFloat>)>>('ximgproc_EdgeBoxes_getBoundingBoxes');
35864+
late final _ximgproc_EdgeBoxes_getBoundingBoxes =
35865+
_ximgproc_EdgeBoxes_getBoundingBoxesPtr.asFunction<
35866+
ffi.Pointer<CvStatus> Function(EdgeBoxes, Mat, Mat,
35867+
ffi.Pointer<VecRect>, ffi.Pointer<VecFloat>)>();
35868+
3584035869
void ximgproc_EdgeDrawing_Close(
3584135870
EdgeDrawingPtr self,
3584235871
) {
@@ -37714,6 +37743,23 @@ final class BlockMeanHash extends ffi.Struct {
3771437743

3771537744
typedef BlockMeanHashPtr = ffi.Pointer<BlockMeanHash>;
3771637745

37746+
final class Box extends ffi.Struct {
37747+
@ffi.Int()
37748+
external int h;
37749+
37750+
@ffi.Float()
37751+
external double score;
37752+
37753+
@ffi.Int()
37754+
external int w;
37755+
37756+
@ffi.Int()
37757+
external int x;
37758+
37759+
@ffi.Int()
37760+
external int y;
37761+
}
37762+
3771737763
final class CLAHE extends ffi.Struct {
3771837764
external ffi.Pointer<ffi.Void> ptr;
3771937765
}
@@ -37791,7 +37837,41 @@ final class DMatch extends ffi.Struct {
3779137837
}
3779237838

3779337839
final class EdgeBoxes extends ffi.Struct {
37794-
external ffi.Pointer<ffi.Pointer<ffi.Void>> ptr;
37840+
@ffi.Float()
37841+
external double alpha;
37842+
37843+
@ffi.Float()
37844+
external double beta;
37845+
37846+
@ffi.Float()
37847+
external double eta;
37848+
37849+
@ffi.Float()
37850+
external double minScore;
37851+
37852+
@ffi.Int()
37853+
external int maxBoxes;
37854+
37855+
@ffi.Float()
37856+
external double edgeMinMag;
37857+
37858+
@ffi.Float()
37859+
external double edgeMergeThr;
37860+
37861+
@ffi.Float()
37862+
external double clusterMinMag;
37863+
37864+
@ffi.Float()
37865+
external double maxAspectRatio;
37866+
37867+
@ffi.Float()
37868+
external double minBoxArea;
37869+
37870+
@ffi.Float()
37871+
external double gamma;
37872+
37873+
@ffi.Float()
37874+
external double kappa;
3779537875
}
3779637876

3779737877
final class EdgeDrawing extends ffi.Struct {

src/extra/ximgproc.cpp

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include "ximgproc.h"
22
#include "core/types.h"
33
#include "opencv2/core/types.hpp"
4+
#include "opencv2/ximgproc/edgeboxes.hpp"
45
#include "opencv2/ximgproc/structured_edge_detection.hpp"
56

67
CvStatus *
@@ -159,6 +160,37 @@ CvStatus *ximgproc_StructuredEdgeDetection_edgesNms(
159160
END_WRAP
160161
}
161162

163+
// EdgeBoxes
164+
CvStatus *ximgproc_EdgeBoxes_getBoundingBoxes(
165+
EdgeBoxes self,
166+
Mat edge_map,
167+
Mat orientation_map,
168+
CVD_OUT VecRect *boxes,
169+
CVD_OUT VecFloat *scores
170+
) {
171+
BEGIN_WRAP
172+
std::vector<float> _scores;
173+
std::vector<cv::Rect> _boxes;
174+
auto _self = cv::ximgproc::createEdgeBoxes(
175+
self.alpha,
176+
self.beta,
177+
self.eta,
178+
self.minScore,
179+
self.maxBoxes,
180+
self.edgeMinMag,
181+
self.edgeMergeThr,
182+
self.clusterMinMag,
183+
self.maxAspectRatio,
184+
self.minBoxArea,
185+
self.gamma,
186+
self.kappa
187+
);
188+
_self->getBoundingBoxes(*edge_map.ptr, *orientation_map.ptr, _boxes, _scores);
189+
boxes->ptr = new std::vector<cv::Rect>(_boxes);
190+
scores->ptr = new std::vector<float>(_scores);
191+
END_WRAP
192+
}
193+
162194
// GraphSegmentation
163195
CvStatus *
164196
ximgproc_GraphSegmentation_Create(float sigma, float k, int min_size, GraphSegmentation *rval) {

0 commit comments

Comments
 (0)