Skip to content

Commit ccf4601

Browse files
authored
Merge pull request #233 from rainyl/mat-tostring
change Mat.toString(), better countNonZero
2 parents 7838e85 + 02bfc23 commit ccf4601

File tree

7 files changed

+15
-30
lines changed

7 files changed

+15
-30
lines changed

CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ file(GLOB_RECURSE CPP_FILES
5555
# "${CMAKE_CURRENT_SOURCE_DIR}/src/stitching/*.cpp"
5656
)
5757
file(GLOB_RECURSE HEADER_FILES
58-
"${CMAKE_CURRENT_SOURCE_DIR}/src/*.h"
58+
"${CMAKE_CURRENT_SOURCE_DIR}/src/**/*.h"
5959
)
6060

6161
add_library(${LIBRARY_NAME} SHARED
@@ -68,7 +68,7 @@ target_include_directories(${LIBRARY_NAME} SYSTEM PUBLIC
6868
target_link_libraries(${LIBRARY_NAME} PRIVATE ${OpenCV_LIBS})
6969

7070
set_target_properties(${LIBRARY_NAME} PROPERTIES
71-
# PUBLIC_HEADER ${GOCV_HEADERS}
71+
# PUBLIC_HEADER ${HEADER_FILES}
7272
OUTPUT_NAME ${LIBRARY_NAME}
7373
CXX_VISIBILITY_PRESET default
7474
C_VISIBILITY_PRESET default

ffigen/ffigen_core.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ functions:
3838
include:
3939
- "Mat_Flags"
4040
- "Mat_Type"
41+
- "Mat_CountNonZero"
4142
- "Mat_IsContinuous"
4243
- "Mat_IsSubmatrix"
4344
- "Mat_Rows"
@@ -55,7 +56,6 @@ functions:
5556
# - ""
5657
# - ""
5758
# - ""
58-
# - ""
5959

6060
symbol-address:
6161
include:

lib/src/core/core.dart

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -294,13 +294,7 @@ Mat compare(InputArray src1, InputArray src2, int cmpop, {OutputArray? dst}) {
294294
///
295295
/// For further details, please see:
296296
/// https://docs.opencv.org/master/d2/de8/group__core__array.html#gaa4b89393263bb4d604e0fe5986723914
297-
int countNonZero(Mat src) {
298-
return cvRunArena<int>((arena) {
299-
final p = arena<ffi.Int>();
300-
ccore.Mat_CountNonZero(src.ref, p);
301-
return p.value;
302-
});
303-
}
297+
int countNonZero(Mat src) => ccore.Mat_CountNonZero(src.ref);
304298

305299
/// CompleteSymm copies the lower or the upper half of a square matrix to its another half.
306300
///

lib/src/core/mat.dart

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -334,11 +334,7 @@ class Mat extends CvStruct<cvg.Mat> {
334334
/// only for [channels] == 1
335335
int get countNoneZero {
336336
cvAssert(channels == 1, "countNoneZero only for channels == 1");
337-
return cvRunArena<int>((arena) {
338-
final p = arena<ffi.Int>();
339-
cvRun(() => ccore.Mat_CountNonZero(ref, p));
340-
return p.value;
341-
});
337+
return ccore.Mat_CountNonZero(ref);
342338
}
343339

344340
//!SECTION - Properties
@@ -1352,7 +1348,8 @@ class Mat extends CvStruct<cvg.Mat> {
13521348
}
13531349

13541350
@override
1355-
String toString() => toFmtString();
1351+
String toString() => "Mat(addr=0x${ptr.address.toRadixString(16)}, "
1352+
"type=${type.asString()}, rows=$rows, cols=$cols, channels=$channels)";
13561353

13571354
static final finalizer = OcvFinalizer<cvg.MatPtr>(ccore.addresses.Mat_Close);
13581355

lib/src/g/core.g.dart

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1063,22 +1063,18 @@ class CvNativeCore {
10631063
late final _Mat_CopyTo_Async = _Mat_CopyTo_AsyncPtr.asFunction<
10641064
ffi.Pointer<CvStatus> Function(Mat, Mat, imp1.CvCallback_0)>();
10651065

1066-
ffi.Pointer<CvStatus> Mat_CountNonZero(
1066+
int Mat_CountNonZero(
10671067
Mat src,
1068-
ffi.Pointer<ffi.Int> rval,
10691068
) {
10701069
return _Mat_CountNonZero(
10711070
src,
1072-
rval,
10731071
);
10741072
}
10751073

1076-
late final _Mat_CountNonZeroPtr = _lookup<
1077-
ffi.NativeFunction<
1078-
ffi.Pointer<CvStatus> Function(
1079-
Mat, ffi.Pointer<ffi.Int>)>>('Mat_CountNonZero');
1080-
late final _Mat_CountNonZero = _Mat_CountNonZeroPtr.asFunction<
1081-
ffi.Pointer<CvStatus> Function(Mat, ffi.Pointer<ffi.Int>)>();
1074+
late final _Mat_CountNonZeroPtr =
1075+
_lookup<ffi.NativeFunction<ffi.Int Function(Mat)>>('Mat_CountNonZero');
1076+
late final _Mat_CountNonZero =
1077+
_Mat_CountNonZeroPtr.asFunction<int Function(Mat)>(isLeaf: true);
10821078

10831079
ffi.Pointer<CvStatus> Mat_DCT(
10841080
Mat src,

src/core/core.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1127,10 +1127,8 @@ CvStatus *Mat_CopyMakeBorder(
11271127
END_WRAP
11281128
}
11291129

1130-
CvStatus *Mat_CountNonZero(Mat src, int *rval) {
1131-
BEGIN_WRAP
1132-
*rval = cv::countNonZero(*src.ptr);
1133-
END_WRAP
1130+
int Mat_CountNonZero(Mat src) {
1131+
return cv::countNonZero(*src.ptr);
11341132
}
11351133

11361134
CvStatus *Mat_DCT(Mat src, Mat dst, int flags) {

src/core/core.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ CvStatus *Mat_ConvertScaleAbs(Mat src, Mat dst, double alpha, double beta);
280280
CvStatus *Mat_CopyMakeBorder(
281281
Mat src, Mat dst, int top, int bottom, int left, int right, int borderType, Scalar value
282282
);
283-
CvStatus *Mat_CountNonZero(Mat src, int *rval);
283+
int Mat_CountNonZero(Mat src);
284284
CvStatus *Mat_DCT(Mat src, Mat dst, int flags);
285285
CvStatus *Mat_Determinant(Mat m, double *rval);
286286
CvStatus *Mat_DFT(Mat src, Mat dst, int flags, int nonzeroRows);

0 commit comments

Comments
 (0)