Skip to content

Commit

Permalink
Merge pull request #233 from rainyl/mat-tostring
Browse files Browse the repository at this point in the history
change Mat.toString(), better countNonZero
  • Loading branch information
rainyl authored Sep 5, 2024
2 parents 7838e85 + 02bfc23 commit ccf4601
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 30 deletions.
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ file(GLOB_RECURSE CPP_FILES
# "${CMAKE_CURRENT_SOURCE_DIR}/src/stitching/*.cpp"
)
file(GLOB_RECURSE HEADER_FILES
"${CMAKE_CURRENT_SOURCE_DIR}/src/*.h"
"${CMAKE_CURRENT_SOURCE_DIR}/src/**/*.h"
)

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

set_target_properties(${LIBRARY_NAME} PROPERTIES
# PUBLIC_HEADER ${GOCV_HEADERS}
# PUBLIC_HEADER ${HEADER_FILES}
OUTPUT_NAME ${LIBRARY_NAME}
CXX_VISIBILITY_PRESET default
C_VISIBILITY_PRESET default
Expand Down
2 changes: 1 addition & 1 deletion ffigen/ffigen_core.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ functions:
include:
- "Mat_Flags"
- "Mat_Type"
- "Mat_CountNonZero"
- "Mat_IsContinuous"
- "Mat_IsSubmatrix"
- "Mat_Rows"
Expand All @@ -55,7 +56,6 @@ functions:
# - ""
# - ""
# - ""
# - ""

symbol-address:
include:
Expand Down
8 changes: 1 addition & 7 deletions lib/src/core/core.dart
Original file line number Diff line number Diff line change
Expand Up @@ -294,13 +294,7 @@ Mat compare(InputArray src1, InputArray src2, int cmpop, {OutputArray? dst}) {
///
/// For further details, please see:
/// https://docs.opencv.org/master/d2/de8/group__core__array.html#gaa4b89393263bb4d604e0fe5986723914
int countNonZero(Mat src) {
return cvRunArena<int>((arena) {
final p = arena<ffi.Int>();
ccore.Mat_CountNonZero(src.ref, p);
return p.value;
});
}
int countNonZero(Mat src) => ccore.Mat_CountNonZero(src.ref);

/// CompleteSymm copies the lower or the upper half of a square matrix to its another half.
///
Expand Down
9 changes: 3 additions & 6 deletions lib/src/core/mat.dart
Original file line number Diff line number Diff line change
Expand Up @@ -334,11 +334,7 @@ class Mat extends CvStruct<cvg.Mat> {
/// only for [channels] == 1
int get countNoneZero {
cvAssert(channels == 1, "countNoneZero only for channels == 1");
return cvRunArena<int>((arena) {
final p = arena<ffi.Int>();
cvRun(() => ccore.Mat_CountNonZero(ref, p));
return p.value;
});
return ccore.Mat_CountNonZero(ref);
}

//!SECTION - Properties
Expand Down Expand Up @@ -1352,7 +1348,8 @@ class Mat extends CvStruct<cvg.Mat> {
}

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

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

Expand Down
14 changes: 5 additions & 9 deletions lib/src/g/core.g.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1063,22 +1063,18 @@ class CvNativeCore {
late final _Mat_CopyTo_Async = _Mat_CopyTo_AsyncPtr.asFunction<
ffi.Pointer<CvStatus> Function(Mat, Mat, imp1.CvCallback_0)>();

ffi.Pointer<CvStatus> Mat_CountNonZero(
int Mat_CountNonZero(
Mat src,
ffi.Pointer<ffi.Int> rval,
) {
return _Mat_CountNonZero(
src,
rval,
);
}

late final _Mat_CountNonZeroPtr = _lookup<
ffi.NativeFunction<
ffi.Pointer<CvStatus> Function(
Mat, ffi.Pointer<ffi.Int>)>>('Mat_CountNonZero');
late final _Mat_CountNonZero = _Mat_CountNonZeroPtr.asFunction<
ffi.Pointer<CvStatus> Function(Mat, ffi.Pointer<ffi.Int>)>();
late final _Mat_CountNonZeroPtr =
_lookup<ffi.NativeFunction<ffi.Int Function(Mat)>>('Mat_CountNonZero');
late final _Mat_CountNonZero =
_Mat_CountNonZeroPtr.asFunction<int Function(Mat)>(isLeaf: true);

ffi.Pointer<CvStatus> Mat_DCT(
Mat src,
Expand Down
6 changes: 2 additions & 4 deletions src/core/core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1127,10 +1127,8 @@ CvStatus *Mat_CopyMakeBorder(
END_WRAP
}

CvStatus *Mat_CountNonZero(Mat src, int *rval) {
BEGIN_WRAP
*rval = cv::countNonZero(*src.ptr);
END_WRAP
int Mat_CountNonZero(Mat src) {
return cv::countNonZero(*src.ptr);
}

CvStatus *Mat_DCT(Mat src, Mat dst, int flags) {
Expand Down
2 changes: 1 addition & 1 deletion src/core/core.h
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ CvStatus *Mat_ConvertScaleAbs(Mat src, Mat dst, double alpha, double beta);
CvStatus *Mat_CopyMakeBorder(
Mat src, Mat dst, int top, int bottom, int left, int right, int borderType, Scalar value
);
CvStatus *Mat_CountNonZero(Mat src, int *rval);
int Mat_CountNonZero(Mat src);
CvStatus *Mat_DCT(Mat src, Mat dst, int flags);
CvStatus *Mat_Determinant(Mat m, double *rval);
CvStatus *Mat_DFT(Mat src, Mat dst, int flags, int nonzeroRows);
Expand Down

0 comments on commit ccf4601

Please sign in to comment.