From 987e10eb67a89d6489e6070d50845663bc6956db Mon Sep 17 00:00:00 2001 From: rainyl Date: Sat, 23 Mar 2024 12:11:35 +0800 Subject: [PATCH] add some gapi, refactor Mat releated API in core --- .github/workflows/build_catch_exceptions.yaml | 53 + .gitignore | 2 + CMakeLists.txt | 8 +- src/core.cpp | 1643 ++++++++++------- src/core.h | 1226 ++++++------ src/gapi.cpp | 19 + src/gapi.h | 33 + 7 files changed, 1720 insertions(+), 1264 deletions(-) create mode 100644 .github/workflows/build_catch_exceptions.yaml create mode 100644 src/gapi.cpp create mode 100644 src/gapi.h diff --git a/.github/workflows/build_catch_exceptions.yaml b/.github/workflows/build_catch_exceptions.yaml new file mode 100644 index 00000000..d745906e --- /dev/null +++ b/.github/workflows/build_catch_exceptions.yaml @@ -0,0 +1,53 @@ +name: build for catch exceptions + +on: + push: + branches: ["catch-exceptions"] + tags: + - "v*.*.*" + pull_request: + branches: [ "catch-exceptions" ] + +env: + ANDROID_NDK_VERSION: r26c + OPENCV_VERSION: 4.9.0 + LIB_NAME: libopencv_dart + +jobs: + build-ubuntu: + name: build-ubuntu + runs-on: ubuntu-latest + + steps: + - name: setup + run: | + sudo apt-get update + sudo apt-get install -y curl git wget python3 unzip build-essential \ + libgtk-3-dev ffmpeg libavcodec-dev \ + cmake ninja-build ccache nasm libavformat-dev libavutil-dev \ + libswscale-dev libgflags-dev \ + libjpeg-dev libpng-dev libtiff-dev python3-pip + + python3 -m pip install conan + conan profile detect -f + + - uses: actions/checkout@v4 + with: + submodules: true + - name: build-opencv-dart + run: | + conan build . -b missing -c tools.cmake.cmaketoolchain:generator=Ninja + - uses: subosito/flutter-action@v2 + with: + # flutter-version: '3.16.9' + channel: "stable" + - uses: actions/upload-artifact@v4 + name: upload-linux-x64 + with: + path: build/publish/libopencv_dart-linux-x64.tar.gz + name: libopencv_dart-linux-x64.tar.gz + - name: Run Test + run: | + export LD_LIBRARY_PATH=$GITHUB_WORKSPACE/linux:$LD_LIBRARY_PATH + flutter pub get + flutter test -x skip-workflow,no-local-files diff --git a/.gitignore b/.gitignore index 4376e3a5..f7f47128 100644 --- a/.gitignore +++ b/.gitignore @@ -26,6 +26,8 @@ test/models/ *.dylib CMakeUserPresets* *.framework +.clang-format +CMakePresets.json # Files and directories created by pub .dart_tool/ diff --git a/CMakeLists.txt b/CMakeLists.txt index ee5c4152..7492f103 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,7 +9,7 @@ find_package(OpenCV REQUIRED) set(OpenCV_LIBS opencv_aruco opencv_core opencv_calib3d opencv_dnn opencv_highgui - opencv_features2d opencv_photo opencv_imgproc + opencv_features2d opencv_gapi opencv_photo opencv_imgproc opencv_objdetect opencv_video opencv_videoio opencv_stitching ) @@ -73,6 +73,7 @@ endif(IOS) if(WIN32) set_target_properties(${library_name} PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS ON + COMPILE_FLAGS "/EHsc" ) endif(WIN32) @@ -89,6 +90,11 @@ if(WITH_OPENCV_DART_DEMO) ${OpenCV_LIBS} ${library_name} ) + if(WIN32) + set_target_properties(demo PROPERTIES + COMPILE_FLAGS "/EHsc" + ) + endif(WIN32) endif() # ## install diff --git a/src/core.cpp b/src/core.cpp index 396d667f..9784cc96 100644 --- a/src/core.cpp +++ b/src/core.cpp @@ -7,1275 +7,1596 @@ */ #include "core.h" +#include #include // cv::noArray() InputOutputArray noArray() { - return new cv::_InputOutputArray(); + return new cv::_InputOutputArray(); } // Mat_New creates a new empty Mat -Mat Mat_New() +CvStatus Mat_New(Mat *rval) { - return new cv::Mat(); + BEGIN_WRAP + *rval = new cv::Mat(); + END_WRAP } -// Mat_NewWithSize creates a new Mat with a specific size dimension and number of channels. -Mat Mat_NewWithSize(int rows, int cols, int type) +// Mat_NewWithSize creates a new Mat with a specific size dimension and number +// of channels. +CvStatus Mat_NewWithSize(int rows, int cols, int type, Mat *rval) { - return new cv::Mat(rows, cols, type, 0.0); + BEGIN_WRAP + *rval = new cv::Mat(rows, cols, type, 0.0); + END_WRAP } -// Mat_NewWithSizes creates a new Mat with specific dimension sizes and number of channels. -Mat Mat_NewWithSizes(struct IntVector sizes, int type) +// Mat_NewWithSizes creates a new Mat with specific dimension sizes and number +// of channels. +CvStatus Mat_NewWithSizes(IntVector sizes, int type, Mat *rval) { - std::vector sizess; - for (int i = 0; i < sizes.length; ++i) - { - sizess.push_back(sizes.val[i]); - } - return new cv::Mat(sizess, type); + BEGIN_WRAP + std::vector sizess; + for (int i = 0; i < sizes.length; ++i) { + sizess.push_back(sizes.val[i]); + } + *rval = new cv::Mat(sizess, type); + END_WRAP } // Mat_NewFromScalar creates a new Mat from a Scalar. Intended to be used // for Mat comparison operation such as InRange. -Mat Mat_NewFromScalar(Scalar ar, int type) +CvStatus Mat_NewFromScalar(const Scalar ar, int type, Mat *rval) { - cv::Scalar c = cv::Scalar(ar.val1, ar.val2, ar.val3, ar.val4); - return new cv::Mat(1, 1, type, c); + BEGIN_WRAP + cv::Scalar c = cv::Scalar(ar.val1, ar.val2, ar.val3, ar.val4); + *rval = new cv::Mat(1, 1, type, c); + END_WRAP } -// Mat_NewWithSizeFromScalar creates a new Mat from a Scalar with a specific size dimension and number of channels -Mat Mat_NewWithSizeFromScalar(Scalar ar, int rows, int cols, int type) +// Mat_NewWithSizeFromScalar creates a new Mat from a Scalar with a specific +// size dimension and number of channels +CvStatus Mat_NewWithSizeFromScalar(const Scalar ar, int rows, int cols, int type, Mat *rval) { - cv::Scalar c = cv::Scalar(ar.val1, ar.val2, ar.val3, ar.val4); - return new cv::Mat(rows, cols, type, c); + BEGIN_WRAP + cv::Scalar c = cv::Scalar(ar.val1, ar.val2, ar.val3, ar.val4); + *rval = new cv::Mat(rows, cols, type, c); + END_WRAP } -Mat Mat_NewFromBytes(int rows, int cols, int type, struct ByteArray buf) +CvStatus Mat_NewFromBytes(int rows, int cols, int type, ByteArray buf, Mat *rval) { - return new cv::Mat(rows, cols, type, buf.data); + BEGIN_WRAP + *rval = new cv::Mat(rows, cols, type, buf.data); + END_WRAP } // Mat_NewWithSizesFromScalar creates multidimensional Mat from a scalar -Mat Mat_NewWithSizesFromScalar(IntVector sizes, int type, Scalar ar) +CvStatus Mat_NewWithSizesFromScalar(IntVector sizes, int type, Scalar ar, Mat *rval) { - std::vector _sizes; - for (int i = 0, *v = sizes.val; i < sizes.length; ++v, ++i) - { - _sizes.push_back(*v); - } + BEGIN_WRAP + std::vector _sizes; + for (int i = 0, *v = sizes.val; i < sizes.length; ++v, ++i) { + _sizes.push_back(*v); + } - cv::Scalar c = cv::Scalar(ar.val1, ar.val2, ar.val3, ar.val4); - return new cv::Mat(_sizes, type, c); + cv::Scalar c = cv::Scalar(ar.val1, ar.val2, ar.val3, ar.val4); + *rval = new cv::Mat(_sizes, type, c); + END_WRAP } // Mat_NewWithSizesFromBytes creates multidimensional Mat from a bytes -Mat Mat_NewWithSizesFromBytes(IntVector sizes, int type, struct ByteArray buf) +CvStatus Mat_NewWithSizesFromBytes(IntVector sizes, int type, ByteArray buf, Mat *rval) { - std::vector _sizes; - for (int i = 0, *v = sizes.val; i < sizes.length; ++v, ++i) - { - _sizes.push_back(*v); - } + BEGIN_WRAP + std::vector _sizes; + for (int i = 0, *v = sizes.val; i < sizes.length; ++v, ++i) { + _sizes.push_back(*v); + } - return new cv::Mat(_sizes, type, buf.data); + *rval = new cv::Mat(_sizes, type, buf.data); + END_WRAP } -Mat Eye(int rows, int cols, int type) +CvStatus Mat_FromPtr(Mat m, int rows, int cols, int type, int prows, int pcols, Mat *rval) { - cv::Mat *mat = new cv::Mat(rows, cols, type); - *mat = cv::Mat::eye(rows, cols, type); - return mat; -} - -Mat Zeros(int rows, int cols, int type) -{ - cv::Mat *mat = new cv::Mat(rows, cols, type); - *mat = cv::Mat::zeros(rows, cols, type); - return mat; -} - -Mat Ones(int rows, int cols, int type) -{ - cv::Mat *mat = new cv::Mat(rows, cols, type); - *mat = cv::Mat::ones(rows, cols, type); - return mat; -} - -Mat Mat_FromPtr(Mat m, int rows, int cols, int type, int prow, int pcol) -{ - return new cv::Mat(rows, cols, type, m->ptr(prow, pcol)); + BEGIN_WRAP + *rval = new cv::Mat(rows, cols, type, m->ptr(prows, pcols)); + END_WRAP } // Mat_Close deletes an existing Mat void Mat_Close(Mat m) { - delete m; + delete m; } // Mat_Empty tests if a Mat is empty -bool Mat_Empty(Mat m) +CvStatus Mat_Empty(Mat m, bool *rval) { - return m->empty(); + BEGIN_WRAP + *rval = m->empty(); + END_WRAP } // Mat_IsContinuous tests if a Mat is continuous -bool Mat_IsContinuous(Mat m) +CvStatus Mat_IsContinuous(Mat m, bool *rval) { - return m->isContinuous(); + BEGIN_WRAP + *rval = m->isContinuous(); + END_WRAP } // Mat_Clone returns a clone of this Mat -Mat Mat_Clone(Mat m) +CvStatus Mat_Clone(Mat m, Mat *rval) { - return new cv::Mat(m->clone()); + BEGIN_WRAP + *rval = new cv::Mat(m->clone()); + END_WRAP } // Mat_CopyTo copies this Mat to another Mat. -void Mat_CopyTo(Mat m, Mat dst) +CvStatus Mat_CopyTo(Mat m, Mat dst) { - m->copyTo(*dst); + BEGIN_WRAP + m->copyTo(*dst); + END_WRAP } // Mat_CopyToWithMask copies this Mat to another Mat while applying the mask -void Mat_CopyToWithMask(Mat m, Mat dst, Mat mask) +CvStatus Mat_CopyToWithMask(Mat m, Mat dst, Mat mask) { - m->copyTo(*dst, *mask); + BEGIN_WRAP + m->copyTo(*dst, *mask); + END_WRAP } -void Mat_ConvertTo(Mat m, Mat dst, int type) +CvStatus Mat_ConvertTo(Mat m, Mat dst, int type) { - m->convertTo(*dst, type); + BEGIN_WRAP + m->convertTo(*dst, type); + END_WRAP } -void Mat_ConvertToWithParams(Mat m, Mat dst, int type, float alpha, float beta) +CvStatus Mat_ConvertToWithParams(Mat m, Mat dst, int type, float alpha, + float beta) { - m->convertTo(*dst, type, alpha, beta); + BEGIN_WRAP + m->convertTo(*dst, type, alpha, beta); + END_WRAP } // Mat_ToBytes returns the bytes representation of the underlying data. -struct ByteArray Mat_ToBytes(Mat m) +CvStatus Mat_ToBytes(Mat m, ByteArray *rval) { - return toByteArray(reinterpret_cast(m->data), m->total() * m->elemSize()); + BEGIN_WRAP + *rval = toByteArray(reinterpret_cast(m->data), + m->total() * m->elemSize()); + END_WRAP } -struct ByteArray Mat_DataPtr(Mat m) +CvStatus Mat_DataPtr(Mat m, ByteArray *rval) { - return ByteArray{reinterpret_cast(m->data), static_cast(m->total() * m->elemSize())}; + BEGIN_WRAP + *rval = ByteArray{reinterpret_cast(m->data), + static_cast(m->total() * m->elemSize())}; + END_WRAP } // Mat_Region returns a Mat of a region of another Mat -Mat Mat_Region(Mat m, Rect r) +CvStatus Mat_Region(Mat m, Rect r, Mat *rval) { - return new cv::Mat(*m, cv::Rect(r.x, r.y, r.width, r.height)); + BEGIN_WRAP + *rval = new cv::Mat(*m, cv::Rect(r.x, r.y, r.width, r.height)); + END_WRAP } -Mat Mat_Reshape(Mat m, int cn, int rows) +CvStatus Mat_Reshape(Mat m, int cn, int rows, Mat *rval) { - return new cv::Mat(m->reshape(cn, rows)); + BEGIN_WRAP + *rval = new cv::Mat(m->reshape(cn, rows)); + END_WRAP } -void Mat_PatchNaNs(Mat m, double val) +CvStatus Mat_PatchNaNs(Mat m, double val) { - cv::patchNaNs(*m, val); + BEGIN_WRAP + cv::patchNaNs(*m, val); + END_WRAP } -Mat Mat_ConvertFp16(Mat m) +CvStatus Mat_ConvertFp16(Mat m, Mat *rval) { - Mat dst = new cv::Mat(); - cv::convertFp16(*m, *dst); - return dst; + BEGIN_WRAP + Mat dst = new cv::Mat(); + cv::convertFp16(*m, *dst); + *rval = dst; + END_WRAP } -Mat Mat_Sqrt(Mat m) +CvStatus Mat_Sqrt(Mat m, Mat *rval) { - Mat dst = new cv::Mat(); - cv::sqrt(*m, *dst); - return dst; + BEGIN_WRAP + Mat dst = new cv::Mat(); + cv::sqrt(*m, *dst); + *rval = dst; + END_WRAP } -// Mat_Mean calculates the mean value M of array elements, independently for each channel, and return it as Scalar vector -Scalar Mat_Mean(Mat m) +// Mat_Mean calculates the mean value M of array elements, independently for +// each channel, and return it as Scalar vector +CvStatus Mat_Mean(Mat m, Scalar *rval) { - cv::Scalar c = cv::mean(*m); - Scalar scal = Scalar(); - scal.val1 = c.val[0]; - scal.val2 = c.val[1]; - scal.val3 = c.val[2]; - scal.val4 = c.val[3]; - return scal; + BEGIN_WRAP + cv::Scalar c = cv::mean(*m); + Scalar scal = Scalar(); + scal.val1 = c.val[0]; + scal.val2 = c.val[1]; + scal.val3 = c.val[2]; + scal.val4 = c.val[3]; + *rval = scal; + END_WRAP } // Mat_MeanWithMask calculates the mean value M of array elements, // independently for each channel, and returns it as Scalar vector // while applying the mask. -Scalar Mat_MeanWithMask(Mat m, Mat mask) +CvStatus Mat_MeanWithMask(Mat m, Mat mask, Scalar *rval) { - cv::Scalar c = cv::mean(*m, *mask); - Scalar scal = Scalar(); - scal.val1 = c.val[0]; - scal.val2 = c.val[1]; - scal.val3 = c.val[2]; - scal.val4 = c.val[3]; - return scal; -} - -void LUT(Mat src, Mat lut, Mat dst) -{ - cv::LUT(*src, *lut, *dst); + BEGIN_WRAP + cv::Scalar c = cv::mean(*m, *mask); + Scalar scal = Scalar(); + scal.val1 = c.val[0]; + scal.val2 = c.val[1]; + scal.val3 = c.val[2]; + scal.val4 = c.val[3]; + *rval = scal; + END_WRAP } // Mat_Rows returns how many rows in this Mat. -int Mat_Rows(Mat m) +CvStatus Mat_Rows(Mat m, int *rval) { - return m->rows; + BEGIN_WRAP + *rval = m->rows; + END_WRAP } // Mat_Cols returns how many columns in this Mat. -int Mat_Cols(Mat m) +CvStatus Mat_Cols(Mat m, int *rval) { - return m->cols; + BEGIN_WRAP + *rval = m->cols; + END_WRAP } // Mat_Channels returns how many channels in this Mat. -int Mat_Channels(Mat m) +CvStatus Mat_Channels(Mat m, int *rval) { - return m->channels(); + BEGIN_WRAP + *rval = m->channels(); + END_WRAP } // Mat_Type returns the type from this Mat. -int Mat_Type(Mat m) +CvStatus Mat_Type(Mat m, int *rval) { - return m->type(); + BEGIN_WRAP + *rval = m->type(); + END_WRAP } // Mat_Step returns the number of bytes each matrix row occupies. -int Mat_Step(Mat m) +CvStatus Mat_Step(Mat m, int *rval) { - return m->step; + BEGIN_WRAP + *rval = m->step; + END_WRAP } -int Mat_Total(Mat m) +CvStatus Mat_Total(Mat m, int *rval) { - return m->total(); + BEGIN_WRAP + *rval = m->total(); + END_WRAP } -int Mat_ElemSize(Mat m) +CvStatus Mat_ElemSize(Mat m, int *rval) { - return m->elemSize(); + BEGIN_WRAP + *rval = m->elemSize(); + END_WRAP } -void Mat_Size(Mat m, IntVector *res) +CvStatus Eye(int rows, int cols, int type, Mat *rval) { - cv::MatSize ms(m->size); - int *ids = new int[ms.dims()]; + BEGIN_WRAP + cv::Mat *mat = new cv::Mat(rows, cols, type); + *mat = cv::Mat::eye(rows, cols, type); + *rval = mat; + END_WRAP +} - for (size_t i = 0; i < ms.dims(); ++i) - { - ids[i] = ms[i]; - } +CvStatus Zeros(int rows, int cols, int type, Mat *rval) +{ + BEGIN_WRAP + cv::Mat *mat = new cv::Mat(rows, cols, type); + *mat = cv::Mat::zeros(rows, cols, type); + *rval = mat; + END_WRAP +} - res->length = ms.dims(); - res->val = ids; - return; +CvStatus Ones(int rows, int cols, int type, Mat *rval) +{ + BEGIN_WRAP + cv::Mat *mat = new cv::Mat(rows, cols, type); + *mat = cv::Mat::ones(rows, cols, type); + *rval = mat; + END_WRAP } // Mat_GetUChar returns a specific row/col value from this Mat expecting // each element to contain a schar aka CV_8U. -uint8_t Mat_GetUChar(Mat m, int row, int col) +CvStatus Mat_GetUChar(Mat m, int row, int col, uint8_t *rval) { - return m->at(row, col); + BEGIN_WRAP + *rval = m->at(row, col); + END_WRAP } -uint8_t Mat_GetUChar3(Mat m, int x, int y, int z) +CvStatus Mat_GetUChar3(Mat m, int x, int y, int z, uint8_t *rval) { - return m->at(x, y, z); + BEGIN_WRAP + *rval = m->at(x, y, z); + END_WRAP } // Mat_GetSChar returns a specific row/col value from this Mat expecting // each element to contain a schar aka CV_8S. -int8_t Mat_GetSChar(Mat m, int row, int col) +CvStatus Mat_GetSChar(Mat m, int row, int col, int8_t *rval) { - return m->at(row, col); + BEGIN_WRAP + *rval = m->at(row, col); + END_WRAP } -int8_t Mat_GetSChar3(Mat m, int x, int y, int z) +CvStatus Mat_GetSChar3(Mat m, int x, int y, int z, int8_t *rval) { - return m->at(x, y, z); + BEGIN_WRAP + *rval = m->at(x, y, z); + END_WRAP } // Mat_GetUShort returns a specific row/col value from this Mat expecting // each element to contain a short aka CV_16U. -uint16_t Mat_GetUShort(Mat m, int row, int col) +CvStatus Mat_GetUShort(Mat m, int row, int col, uint16_t *rval) { - return m->at(row, col); + BEGIN_WRAP + *rval = m->at(row, col); + END_WRAP } -uint16_t Mat_GetUShort3(Mat m, int x, int y, int z) +CvStatus Mat_GetUShort3(Mat m, int x, int y, int z, uint16_t *rval) { - return m->at(x, y, z); + BEGIN_WRAP + *rval = m->at(x, y, z); + END_WRAP } // Mat_GetShort returns a specific row/col value from this Mat expecting // each element to contain a short aka CV_16S. -int16_t Mat_GetShort(Mat m, int row, int col) +CvStatus Mat_GetShort(Mat m, int row, int col, int16_t *rval) { - return m->at(row, col); + BEGIN_WRAP + *rval = m->at(row, col); + END_WRAP } -int16_t Mat_GetShort3(Mat m, int x, int y, int z) +CvStatus Mat_GetShort3(Mat m, int x, int y, int z, int16_t *rval) { - return m->at(x, y, z); + BEGIN_WRAP + *rval = m->at(x, y, z); + END_WRAP } // Mat_GetInt returns a specific row/col value from this Mat expecting // each element to contain an int aka CV_32S. -int32_t Mat_GetInt(Mat m, int row, int col) +CvStatus Mat_GetInt(Mat m, int row, int col, int32_t *rval) { - return m->at(row, col); + BEGIN_WRAP + *rval = m->at(row, col); + END_WRAP } -int32_t Mat_GetInt3(Mat m, int x, int y, int z) +CvStatus Mat_GetInt3(Mat m, int x, int y, int z, int32_t *rval) { - return m->at(x, y, z); + BEGIN_WRAP + *rval = m->at(x, y, z); + END_WRAP } // Mat_GetFloat returns a specific row/col value from this Mat expecting // each element to contain a float aka CV_32F. -float Mat_GetFloat(Mat m, int row, int col) +CvStatus Mat_GetFloat(Mat m, int row, int col, float *rval) { - return m->at(row, col); + BEGIN_WRAP + *rval = m->at(row, col); + END_WRAP } -float Mat_GetFloat3(Mat m, int x, int y, int z) +CvStatus Mat_GetFloat3(Mat m, int x, int y, int z, float *rval) { - return m->at(x, y, z); + BEGIN_WRAP + *rval = m->at(x, y, z); + END_WRAP } // Mat_GetDouble returns a specific row/col value from this Mat expecting // each element to contain a double aka CV_64F. -double Mat_GetDouble(Mat m, int row, int col) +CvStatus Mat_GetDouble(Mat m, int row, int col, double *rval) { - return m->at(row, col); + BEGIN_WRAP + *rval = m->at(row, col); + END_WRAP } -double Mat_GetDouble3(Mat m, int x, int y, int z) +CvStatus Mat_GetDouble3(Mat m, int x, int y, int z, double *rval) { - return m->at(x, y, z); + BEGIN_WRAP + *rval = m->at(x, y, z); + END_WRAP } -void Mat_SetTo(Mat m, Scalar value) +CvStatus Mat_SetTo(Mat m, Scalar value) { - cv::Scalar c_value(value.val1, value.val2, value.val3, value.val4); - m->setTo(c_value); + BEGIN_WRAP + cv::Scalar c_value(value.val1, value.val2, value.val3, value.val4); + m->setTo(c_value); + END_WRAP } // Mat_SetUChar set a specific row/col value from this Mat expecting // each element to contain a schar aka CV_8U. -void Mat_SetUChar(Mat m, int row, int col, uint8_t val) +CvStatus Mat_SetUChar(Mat m, int row, int col, uint8_t val) { - m->at(row, col) = val; + BEGIN_WRAP + m->at(row, col) = val; + END_WRAP } -void Mat_SetUChar3(Mat m, int x, int y, int z, uint8_t val) +CvStatus Mat_SetUChar3(Mat m, int x, int y, int z, uint8_t val) { - m->at(x, y, z) = val; + BEGIN_WRAP + m->at(x, y, z) = val; + END_WRAP } // Mat_SetSChar set a specific row/col value from this Mat expecting // each element to contain a schar aka CV_8S. -void Mat_SetSChar(Mat m, int row, int col, int8_t val) +CvStatus Mat_SetSChar(Mat m, int row, int col, int8_t val) { - m->at(row, col) = val; + BEGIN_WRAP + m->at(row, col) = val; + END_WRAP } -void Mat_SetSChar3(Mat m, int x, int y, int z, int8_t val) +CvStatus Mat_SetSChar3(Mat m, int x, int y, int z, int8_t val) { - m->at(x, y, z) = val; + BEGIN_WRAP + m->at(x, y, z) = val; + END_WRAP } // Mat_SetShort set a specific row/col value from this Mat expecting // each element to contain a short aka CV_16S. -void Mat_SetShort(Mat m, int row, int col, int16_t val) +CvStatus Mat_SetShort(Mat m, int row, int col, int16_t val) { - m->at(row, col) = val; + BEGIN_WRAP + m->at(row, col) = val; + END_WRAP } -void Mat_SetShort3(Mat m, int x, int y, int z, int16_t val) +CvStatus Mat_SetShort3(Mat m, int x, int y, int z, int16_t val) { - m->at(x, y, z) = val; + BEGIN_WRAP + m->at(x, y, z) = val; + END_WRAP } -void Mat_SetUShort(Mat m, int row, int col, uint16_t val) +CvStatus Mat_SetUShort(Mat m, int row, int col, uint16_t val) { - m->at(row, col) = val; + BEGIN_WRAP + m->at(row, col) = val; + END_WRAP } -void Mat_SetUShort3(Mat m, int x, int y, int z, uint16_t val) +CvStatus Mat_SetUShort3(Mat m, int x, int y, int z, uint16_t val) { - m->at(x, y, z) = val; + BEGIN_WRAP + m->at(x, y, z) = val; + END_WRAP } // Mat_SetInt set a specific row/col value from this Mat expecting // each element to contain an int aka CV_32S. -void Mat_SetInt(Mat m, int row, int col, int32_t val) +CvStatus Mat_SetInt(Mat m, int row, int col, int32_t val) { - m->at(row, col) = val; + BEGIN_WRAP + m->at(row, col) = val; + END_WRAP } -void Mat_SetInt3(Mat m, int x, int y, int z, int32_t val) +CvStatus Mat_SetInt3(Mat m, int x, int y, int z, int32_t val) { - m->at(x, y, z) = val; + BEGIN_WRAP + m->at(x, y, z) = val; + END_WRAP } // Mat_SetFloat set a specific row/col value from this Mat expecting // each element to contain a float aka CV_32F. -void Mat_SetFloat(Mat m, int row, int col, float val) +CvStatus Mat_SetFloat(Mat m, int row, int col, float val) { - m->at(row, col) = val; + BEGIN_WRAP + m->at(row, col) = val; + END_WRAP } -void Mat_SetFloat3(Mat m, int x, int y, int z, float val) +CvStatus Mat_SetFloat3(Mat m, int x, int y, int z, float val) { - m->at(x, y, z) = val; + BEGIN_WRAP + m->at(x, y, z) = val; + END_WRAP } // Mat_SetDouble set a specific row/col value from this Mat expecting // each element to contain a double aka CV_64F. -void Mat_SetDouble(Mat m, int row, int col, double val) +CvStatus Mat_SetDouble(Mat m, int row, int col, double val) { - m->at(row, col) = val; + BEGIN_WRAP + m->at(row, col) = val; + END_WRAP } -void Mat_SetDouble3(Mat m, int x, int y, int z, double val) +CvStatus Mat_SetDouble3(Mat m, int x, int y, int z, double val) { - m->at(x, y, z) = val; + BEGIN_WRAP + m->at(x, y, z) = val; + END_WRAP } -void Mat_AddUChar(Mat m, uint8_t val) +CvStatus Mat_AddUChar(Mat m, uint8_t val) { - *m += val; + BEGIN_WRAP + *m += val; + END_WRAP } -void Mat_SubtractUChar(Mat m, uint8_t val) +CvStatus Mat_SubtractUChar(Mat m, uint8_t val) { - *m -= val; + BEGIN_WRAP + *m -= val; + END_WRAP } -void Mat_MultiplyUChar(Mat m, uint8_t val) +CvStatus Mat_MultiplyUChar(Mat m, uint8_t val) { - *m *= val; + BEGIN_WRAP + *m *= val; + END_WRAP } -void Mat_DivideUChar(Mat m, uint8_t val) +CvStatus Mat_DivideUChar(Mat m, uint8_t val) { - *m /= val; + BEGIN_WRAP + *m /= val; + END_WRAP } -void Mat_AddI32(Mat m, int32_t val) +CvStatus Mat_AddI32(Mat m, int32_t val) { - *m += val; + BEGIN_WRAP + *m += val; + END_WRAP } -void Mat_SubtractI32(Mat m, int32_t val) +CvStatus Mat_SubtractI32(Mat m, int32_t val) { - *m -= val; + BEGIN_WRAP + *m -= val; + END_WRAP } -void Mat_MultiplyI32(Mat m, int32_t val) +CvStatus Mat_MultiplyI32(Mat m, int32_t val) { - *m *= val; + BEGIN_WRAP + *m *= val; + END_WRAP } -void Mat_DivideI32(Mat m, int32_t val) +CvStatus Mat_DivideI32(Mat m, int32_t val) { - *m /= val; + BEGIN_WRAP + *m /= val; + END_WRAP } -void Mat_AddFloat(Mat m, float val) +CvStatus Mat_AddFloat(Mat m, float val) { - *m += val; + BEGIN_WRAP + *m += val; + END_WRAP } -void Mat_SubtractFloat(Mat m, float val) +CvStatus Mat_SubtractFloat(Mat m, float val) { - *m -= val; + BEGIN_WRAP + *m -= val; + END_WRAP } -void Mat_MultiplyFloat(Mat m, float val) +CvStatus Mat_MultiplyFloat(Mat m, float val) { - *m *= val; + BEGIN_WRAP + *m *= val; + END_WRAP } -void Mat_DivideFloat(Mat m, float val) +CvStatus Mat_DivideFloat(Mat m, float val) { - *m /= val; + BEGIN_WRAP + *m /= val; + END_WRAP } -void Mat_AddF64(Mat m, double_t val) +CvStatus Mat_AddF64(Mat m, double_t val) { - *m += val; + BEGIN_WRAP + *m += val; + END_WRAP } -void Mat_SubtractF64(Mat m, double_t val) +CvStatus Mat_SubtractF64(Mat m, double_t val) { - *m -= val; + BEGIN_WRAP + *m -= val; + END_WRAP } -void Mat_MultiplyF64(Mat m, double_t val) +CvStatus Mat_MultiplyF64(Mat m, double_t val) { - *m *= val; + BEGIN_WRAP + *m *= val; + END_WRAP } -void Mat_DivideF64(Mat m, double_t val) +CvStatus Mat_DivideF64(Mat m, double_t val) { - *m /= val; + BEGIN_WRAP + *m /= val; + END_WRAP } -Mat Mat_MultiplyMatrix(Mat x, Mat y) +CvStatus Mat_MultiplyMatrix(Mat x, Mat y, Mat *rval) { - return new cv::Mat((*x) * (*y)); + BEGIN_WRAP + *rval = new cv::Mat((*x) * (*y)); + END_WRAP } -Mat Mat_T(Mat x) +CvStatus Mat_T(Mat x, Mat *rval) { - return new cv::Mat(x->t()); + BEGIN_WRAP + *rval = new cv::Mat(x->t()); + END_WRAP } -void Mat_AbsDiff(Mat src1, Mat src2, Mat dst) +CvStatus LUT(Mat src, Mat lut, Mat dst) { - cv::absdiff(*src1, *src2, *dst); + BEGIN_WRAP + cv::LUT(*src, *lut, *dst); + END_WRAP } -void Mat_Add(Mat src1, Mat src2, Mat dst) +CvStatus Mat_AbsDiff(Mat src1, Mat src2, Mat dst) { - cv::add(*src1, *src2, *dst); + BEGIN_WRAP + cv::absdiff(*src1, *src2, *dst); + END_WRAP } -void Mat_AddWeighted(Mat src1, double alpha, Mat src2, double beta, double gamma, Mat dst) +CvStatus Mat_Add(Mat src1, Mat src2, Mat dst) { - cv::addWeighted(*src1, alpha, *src2, beta, gamma, *dst); + BEGIN_WRAP + cv::add(*src1, *src2, *dst); + END_WRAP } -void Mat_BitwiseAnd(Mat src1, Mat src2, Mat dst) +CvStatus Mat_AddWeighted(Mat src1, double alpha, Mat src2, double beta, + double gamma, Mat dst) { - cv::bitwise_and(*src1, *src2, *dst); + BEGIN_WRAP + cv::addWeighted(*src1, alpha, *src2, beta, gamma, *dst); + END_WRAP } -void Mat_BitwiseAndWithMask(Mat src1, Mat src2, Mat dst, Mat mask) +CvStatus Mat_BitwiseAnd(Mat src1, Mat src2, Mat dst) { - cv::bitwise_and(*src1, *src2, *dst, *mask); + BEGIN_WRAP + cv::bitwise_and(*src1, *src2, *dst); + END_WRAP } -void Mat_BitwiseNot(Mat src1, Mat dst) +CvStatus Mat_BitwiseAndWithMask(Mat src1, Mat src2, Mat dst, Mat mask) { - cv::bitwise_not(*src1, *dst); + BEGIN_WRAP + cv::bitwise_and(*src1, *src2, *dst, *mask); + END_WRAP } -void Mat_BitwiseNotWithMask(Mat src1, Mat dst, Mat mask) +CvStatus Mat_BitwiseNot(Mat src1, Mat dst) { - cv::bitwise_not(*src1, *dst, *mask); + BEGIN_WRAP + cv::bitwise_not(*src1, *dst); + END_WRAP } -void Mat_BitwiseOr(Mat src1, Mat src2, Mat dst) +CvStatus Mat_BitwiseNotWithMask(Mat src1, Mat dst, Mat mask) { - cv::bitwise_or(*src1, *src2, *dst); + BEGIN_WRAP + cv::bitwise_not(*src1, *dst, *mask); + END_WRAP } -void Mat_BitwiseOrWithMask(Mat src1, Mat src2, Mat dst, Mat mask) +CvStatus Mat_BitwiseOr(Mat src1, Mat src2, Mat dst) { - cv::bitwise_or(*src1, *src2, *dst, *mask); + BEGIN_WRAP + cv::bitwise_or(*src1, *src2, *dst); + END_WRAP } -void Mat_BitwiseXor(Mat src1, Mat src2, Mat dst) +CvStatus Mat_BitwiseOrWithMask(Mat src1, Mat src2, Mat dst, Mat mask) { - cv::bitwise_xor(*src1, *src2, *dst); + BEGIN_WRAP + cv::bitwise_or(*src1, *src2, *dst, *mask); + END_WRAP } -void Mat_BitwiseXorWithMask(Mat src1, Mat src2, Mat dst, Mat mask) +CvStatus Mat_BitwiseXor(Mat src1, Mat src2, Mat dst) { - cv::bitwise_xor(*src1, *src2, *dst, *mask); + BEGIN_WRAP + cv::bitwise_xor(*src1, *src2, *dst); + END_WRAP } -void Mat_BatchDistance(Mat src1, Mat src2, Mat dist, int dtype, Mat nidx, int normType, int K, - Mat mask, int update, bool crosscheck) +CvStatus Mat_BitwiseXorWithMask(Mat src1, Mat src2, Mat dst, Mat mask) { - cv::batchDistance(*src1, *src2, *dist, dtype, *nidx, normType, K, *mask, update, crosscheck); + BEGIN_WRAP + cv::bitwise_xor(*src1, *src2, *dst, *mask); + END_WRAP } -int Mat_BorderInterpolate(int p, int len, int borderType) +CvStatus Mat_BatchDistance(Mat src1, Mat src2, Mat dist, int dtype, Mat nidx, + int normType, int K, Mat mask, int update, + bool crosscheck) { - return cv::borderInterpolate(p, len, borderType); + BEGIN_WRAP + cv::batchDistance(*src1, *src2, *dist, dtype, *nidx, normType, K, *mask, + update, crosscheck); + END_WRAP } -void Mat_CalcCovarMatrix(Mat samples, Mat covar, Mat mean, int flags, int ctype) +CvStatus Mat_BorderInterpolate(int p, int len, int borderType, int *rval) { - cv::calcCovarMatrix(*samples, *covar, *mean, flags, ctype); + BEGIN_WRAP + *rval = cv::borderInterpolate(p, len, borderType); + END_WRAP } -void Mat_CartToPolar(Mat x, Mat y, Mat magnitude, Mat angle, bool angleInDegrees) +CvStatus Mat_CalcCovarMatrix(Mat samples, Mat covar, Mat mean, int flags, + int ctype) { - cv::cartToPolar(*x, *y, *magnitude, *angle, angleInDegrees); + BEGIN_WRAP + cv::calcCovarMatrix(*samples, *covar, *mean, flags, ctype); + END_WRAP } -bool Mat_CheckRange(Mat m, bool quiet, Point *pos, double minVal, double maxVal) +CvStatus Mat_CartToPolar(Mat x, Mat y, Mat magnitude, Mat angle, + bool angleInDegrees) { - cv::Point pos1; - bool ret = cv::checkRange(*m, quiet, &pos1, minVal, maxVal); - pos->x = pos1.x; - pos->y = pos1.y; - return ret; + BEGIN_WRAP + cv::cartToPolar(*x, *y, *magnitude, *angle, angleInDegrees); + END_WRAP } -void Mat_Compare(Mat src1, Mat src2, Mat dst, int ct) +CvStatus Mat_CheckRange(Mat m, bool quiet, Point *pos, double minVal, + double maxVal, bool *rval) { - cv::compare(*src1, *src2, *dst, ct); + BEGIN_WRAP + cv::Point pos1; + *rval = cv::checkRange(*m, quiet, &pos1, minVal, maxVal); + pos->x = pos1.x; + pos->y = pos1.y; + END_WRAP } -int Mat_CountNonZero(Mat src) +CvStatus Mat_Compare(Mat src1, Mat src2, Mat dst, int ct) { - return cv::countNonZero(*src); + BEGIN_WRAP + cv::compare(*src1, *src2, *dst, ct); + END_WRAP } -void Mat_CompleteSymm(Mat m, bool lowerToUpper) +CvStatus Mat_CompleteSymm(Mat m, bool lowerToUpper) { - cv::completeSymm(*m, lowerToUpper); + BEGIN_WRAP + cv::completeSymm(*m, lowerToUpper); + END_WRAP } -void Mat_ConvertScaleAbs(Mat src, Mat dst, double alpha, double beta) +CvStatus Mat_ConvertScaleAbs(Mat src, Mat dst, double alpha, double beta) { - cv::convertScaleAbs(*src, *dst, alpha, beta); + BEGIN_WRAP + cv::convertScaleAbs(*src, *dst, alpha, beta); + END_WRAP } -void Mat_CopyMakeBorder(Mat src, Mat dst, int top, int bottom, int left, int right, int borderType, - Scalar value) +CvStatus Mat_CopyMakeBorder(Mat src, Mat dst, int top, int bottom, int left, + int right, int borderType, Scalar value) { - cv::Scalar c_value(value.val1, value.val2, value.val3, value.val4); - cv::copyMakeBorder(*src, *dst, top, bottom, left, right, borderType, c_value); + BEGIN_WRAP + cv::Scalar c_value(value.val1, value.val2, value.val3, value.val4); + cv::copyMakeBorder(*src, *dst, top, bottom, left, right, borderType, c_value); + END_WRAP } -void Mat_DCT(Mat src, Mat dst, int flags) +CvStatus Mat_CountNonZero(Mat src, int *rval) { - cv::dct(*src, *dst, flags); + BEGIN_WRAP + *rval = cv::countNonZero(*src); + END_WRAP } -double Mat_Determinant(Mat m) +CvStatus Mat_DCT(Mat src, Mat dst, int flags) { - return cv::determinant(*m); + BEGIN_WRAP + cv::dct(*src, *dst, flags); + END_WRAP } -void Mat_DFT(Mat m, Mat dst, int flags) +CvStatus Mat_Determinant(Mat m, double *rval) { - cv::dft(*m, *dst, flags); + BEGIN_WRAP + *rval = cv::determinant(*m); + END_WRAP } -void Mat_Divide(Mat src1, Mat src2, Mat dst) +CvStatus Mat_DFT(Mat m, Mat dst, int flags) { - cv::divide(*src1, *src2, *dst); + BEGIN_WRAP + cv::dft(*m, *dst, flags); + END_WRAP } -bool Mat_Eigen(Mat src, Mat eigenvalues, Mat eigenvectors) +CvStatus Mat_Divide(Mat src1, Mat src2, Mat dst) { - return cv::eigen(*src, *eigenvalues, *eigenvectors); + BEGIN_WRAP + cv::divide(*src1, *src2, *dst); + END_WRAP } -void Mat_EigenNonSymmetric(Mat src, Mat eigenvalues, Mat eigenvectors) +CvStatus Mat_Eigen(Mat src, Mat eigenvalues, Mat eigenvectors, bool *rval) { - cv::eigenNonSymmetric(*src, *eigenvalues, *eigenvectors); + BEGIN_WRAP + *rval = cv::eigen(*src, *eigenvalues, *eigenvectors); + END_WRAP } -void Mat_PCACompute(Mat src, Mat mean, Mat eigenvectors, Mat eigenvalues, int maxComponents) +CvStatus Mat_EigenNonSymmetric(Mat src, Mat eigenvalues, Mat eigenvectors) { - cv::PCACompute(*src, *mean, *eigenvectors, *eigenvalues, maxComponents); + BEGIN_WRAP + cv::eigenNonSymmetric(*src, *eigenvalues, *eigenvectors); + END_WRAP } -void Mat_Exp(Mat src, Mat dst) +CvStatus Mat_PCACompute(Mat src, Mat mean, Mat eigenvectors, Mat eigenvalues, + int maxComponents) { - cv::exp(*src, *dst); + BEGIN_WRAP + cv::PCACompute(*src, *mean, *eigenvectors, *eigenvalues, maxComponents); + END_WRAP } -void Mat_ExtractChannel(Mat src, Mat dst, int coi) +CvStatus Mat_Exp(Mat src, Mat dst) { - cv::extractChannel(*src, *dst, coi); + BEGIN_WRAP + cv::exp(*src, *dst); + END_WRAP } -void Mat_FindNonZero(Mat src, Mat idx) +CvStatus Mat_ExtractChannel(Mat src, Mat dst, int coi) { - cv::findNonZero(*src, *idx); + BEGIN_WRAP + cv::extractChannel(*src, *dst, coi); + END_WRAP } -void Mat_Flip(Mat src, Mat dst, int flipCode) +CvStatus Mat_FindNonZero(Mat src, Mat idx) { - cv::flip(*src, *dst, flipCode); + BEGIN_WRAP + cv::findNonZero(*src, *idx); + END_WRAP } -void Mat_Gemm(Mat src1, Mat src2, double alpha, Mat src3, double beta, Mat dst, int flags) +CvStatus Mat_Flip(Mat src, Mat dst, int flipCode) { - cv::gemm(*src1, *src2, alpha, *src3, beta, *dst, flags); + BEGIN_WRAP + cv::flip(*src, *dst, flipCode); + END_WRAP } -int Mat_GetOptimalDFTSize(int vecsize) +CvStatus Mat_Gemm(Mat src1, Mat src2, double alpha, Mat src3, double beta, Mat dst, + int flags) { - return cv::getOptimalDFTSize(vecsize); + BEGIN_WRAP + cv::gemm(*src1, *src2, alpha, *src3, beta, *dst, flags); + END_WRAP } -void Mat_Hconcat(Mat src1, Mat src2, Mat dst) +CvStatus Mat_GetOptimalDFTSize(int vecsize, int *rval) { - cv::hconcat(*src1, *src2, *dst); + BEGIN_WRAP + *rval = cv::getOptimalDFTSize(vecsize); + END_WRAP } -void Mat_Vconcat(Mat src1, Mat src2, Mat dst) +CvStatus Mat_Hconcat(Mat src1, Mat src2, Mat dst) { - cv::vconcat(*src1, *src2, *dst); + BEGIN_WRAP + cv::hconcat(*src1, *src2, *dst); + END_WRAP } -void Rotate(Mat src, Mat dst, int rotateCode) +CvStatus Mat_Vconcat(Mat src1, Mat src2, Mat dst) { - cv::rotate(*src, *dst, rotateCode); + BEGIN_WRAP + cv::vconcat(*src1, *src2, *dst); + END_WRAP } -void Mat_Idct(Mat src, Mat dst, int flags) +CvStatus Rotate(Mat src, Mat dst, int rotateCode) { - cv::idct(*src, *dst, flags); + BEGIN_WRAP + cv::rotate(*src, *dst, rotateCode); + END_WRAP } -void Mat_Idft(Mat src, Mat dst, int flags, int nonzeroRows) +CvStatus Mat_Idct(Mat src, Mat dst, int flags) { - cv::idft(*src, *dst, flags, nonzeroRows); + BEGIN_WRAP + cv::idct(*src, *dst, flags); + END_WRAP } -void Mat_InRange(Mat src, Mat lowerb, Mat upperb, Mat dst) +CvStatus Mat_Idft(Mat src, Mat dst, int flags, int nonzeroRows) { - cv::inRange(*src, *lowerb, *upperb, *dst); + BEGIN_WRAP + cv::idft(*src, *dst, flags, nonzeroRows); + END_WRAP } -void Mat_InRangeWithScalar(Mat src, Scalar lowerb, Scalar upperb, Mat dst) +CvStatus Mat_InRange(Mat src, Mat lowerb, Mat upperb, Mat dst) { - cv::Scalar lb = cv::Scalar(lowerb.val1, lowerb.val2, lowerb.val3, lowerb.val4); - cv::Scalar ub = cv::Scalar(upperb.val1, upperb.val2, upperb.val3, upperb.val4); - cv::inRange(*src, lb, ub, *dst); + BEGIN_WRAP + cv::inRange(*src, *lowerb, *upperb, *dst); + END_WRAP } -void Mat_InsertChannel(Mat src, Mat dst, int coi) +CvStatus Mat_InRangeWithScalar(Mat src, Scalar lowerb, Scalar upperb, Mat dst) { - cv::insertChannel(*src, *dst, coi); + BEGIN_WRAP + cv::Scalar lb = + cv::Scalar(lowerb.val1, lowerb.val2, lowerb.val3, lowerb.val4); + cv::Scalar ub = + cv::Scalar(upperb.val1, upperb.val2, upperb.val3, upperb.val4); + cv::inRange(*src, lb, ub, *dst); + END_WRAP } -double Mat_Invert(Mat src, Mat dst, int flags) +CvStatus Mat_InsertChannel(Mat src, Mat dst, int coi) { - double ret = cv::invert(*src, *dst, flags); - return ret; + BEGIN_WRAP + cv::insertChannel(*src, *dst, coi); + END_WRAP } -double KMeans(Mat data, int k, Mat bestLabels, TermCriteria criteria, int attempts, int flags, Mat centers) +CvStatus Mat_Invert(Mat src, Mat dst, int flags, double *rval) { - double ret = cv::kmeans(*data, k, *bestLabels, *criteria, attempts, flags, *centers); - return ret; + BEGIN_WRAP + *rval = cv::invert(*src, *dst, flags); + END_WRAP } -double -KMeansPoints(PointVector points, int k, Mat bestLabels, TermCriteria criteria, int attempts, int flags, Mat centers) +CvStatus KMeans(Mat data, int k, Mat bestLabels, TermCriteria criteria, + int attempts, int flags, Mat centers, double *rval) { - std::vector pts; - copyPointVectorToPoint2fVector(points, &pts); - double ret = cv::kmeans(pts, k, *bestLabels, *criteria, attempts, flags, *centers); - return ret; + BEGIN_WRAP + END_WRAP + *rval = cv::kmeans(*data, k, *bestLabels, *criteria, attempts, flags, *centers); } -void Mat_Log(Mat src, Mat dst) +CvStatus KMeansPoints(PointVector points, int k, Mat bestLabels, + TermCriteria criteria, int attempts, int flags, + Mat centers, double *rval) { - cv::log(*src, *dst); + BEGIN_WRAP + std::vector pts; + copyPointVectorToPoint2fVector(points, &pts); + *rval = + cv::kmeans(pts, k, *bestLabels, *criteria, attempts, flags, *centers); + END_WRAP } -void Mat_Magnitude(Mat x, Mat y, Mat magnitude) +CvStatus Mat_Log(Mat src, Mat dst) { - cv::magnitude(*x, *y, *magnitude); + BEGIN_WRAP + cv::log(*src, *dst); + END_WRAP } -void Mat_Max(Mat src1, Mat src2, Mat dst) +CvStatus Mat_Magnitude(Mat x, Mat y, Mat magnitude) { - cv::max(*src1, *src2, *dst); + BEGIN_WRAP + cv::magnitude(*x, *y, *magnitude); + END_WRAP } -void Mat_MeanStdDev(Mat src, Mat dstMean, Mat dstStdDev) +CvStatus Mat_Max(Mat src1, Mat src2, Mat dst) { - cv::meanStdDev(*src, *dstMean, *dstStdDev); + BEGIN_WRAP + cv::max(*src1, *src2, *dst); + END_WRAP } -void Mat_Merge(struct Mats mats, Mat dst) +CvStatus Mat_MeanStdDev(Mat src, Mat dstMean, Mat dstStdDev) { - std::vector images; + BEGIN_WRAP + cv::meanStdDev(*src, *dstMean, *dstStdDev); + END_WRAP +} - for (int i = 0; i < mats.length; ++i) - { - images.push_back(*mats.mats[i]); - } +CvStatus Mat_Merge(Mats mats, Mat dst) +{ + BEGIN_WRAP + std::vector images; + + for (int i = 0; i < mats.length; ++i) { + images.push_back(*mats.mats[i]); + } - cv::merge(images, *dst); + cv::merge(images, *dst); + END_WRAP } -void Mat_Min(Mat src1, Mat src2, Mat dst) +CvStatus Mat_Min(Mat src1, Mat src2, Mat dst) { - cv::min(*src1, *src2, *dst); + BEGIN_WRAP + cv::min(*src1, *src2, *dst); + END_WRAP } -void Mat_MinMaxIdx(Mat m, double *minVal, double *maxVal, int *minIdx, int *maxIdx) +CvStatus Mat_MinMaxIdx(Mat m, double *minVal, double *maxVal, int *minIdx, + int *maxIdx) { - cv::minMaxIdx(*m, minVal, maxVal, minIdx, maxIdx); + BEGIN_WRAP + cv::minMaxIdx(*m, minVal, maxVal, minIdx, maxIdx); + END_WRAP } -void Mat_MinMaxLoc(Mat m, double *minVal, double *maxVal, Point *minLoc, Point *maxLoc) +CvStatus Mat_MinMaxLoc(Mat m, double *minVal, double *maxVal, Point *minLoc, + Point *maxLoc) { - cv::Point cMinLoc; - cv::Point cMaxLoc; - cv::minMaxLoc(*m, minVal, maxVal, &cMinLoc, &cMaxLoc); + BEGIN_WRAP + cv::Point cMinLoc; + cv::Point cMaxLoc; + cv::minMaxLoc(*m, minVal, maxVal, &cMinLoc, &cMaxLoc); - minLoc->x = cMinLoc.x; - minLoc->y = cMinLoc.y; - maxLoc->x = cMaxLoc.x; - maxLoc->y = cMaxLoc.y; + minLoc->x = cMinLoc.x; + minLoc->y = cMinLoc.y; + maxLoc->x = cMaxLoc.x; + maxLoc->y = cMaxLoc.y; + END_WRAP } -void Mat_MixChannels(struct Mats src, struct Mats dst, struct IntVector fromTo) +CvStatus Mat_MixChannels(Mats src, Mats dst, IntVector fromTo) { - std::vector srcMats; + BEGIN_WRAP + std::vector srcMats; - for (int i = 0; i < src.length; ++i) - { - srcMats.push_back(*src.mats[i]); - } + for (int i = 0; i < src.length; ++i) { + srcMats.push_back(*src.mats[i]); + } - std::vector dstMats; + std::vector dstMats; - for (int i = 0; i < dst.length; ++i) - { - dstMats.push_back(*dst.mats[i]); - } + for (int i = 0; i < dst.length; ++i) { + dstMats.push_back(*dst.mats[i]); + } - std::vector fromTos; + std::vector fromTos; - for (int i = 0; i < fromTo.length; ++i) - { - fromTos.push_back(fromTo.val[i]); - } + for (int i = 0; i < fromTo.length; ++i) { + fromTos.push_back(fromTo.val[i]); + } - cv::mixChannels(srcMats, dstMats, fromTos); + cv::mixChannels(srcMats, dstMats, fromTos); + END_WRAP } -void Mat_MulSpectrums(Mat a, Mat b, Mat c, int flags) +CvStatus Mat_MulSpectrums(Mat a, Mat b, Mat c, int flags) { - cv::mulSpectrums(*a, *b, *c, flags); + BEGIN_WRAP + cv::mulSpectrums(*a, *b, *c, flags); + END_WRAP } -void Mat_Multiply(Mat src1, Mat src2, Mat dst) +CvStatus Mat_Multiply(Mat src1, Mat src2, Mat dst) { - cv::multiply(*src1, *src2, *dst); + BEGIN_WRAP + cv::multiply(*src1, *src2, *dst); + END_WRAP } -void Mat_MultiplyWithParams(Mat src1, Mat src2, Mat dst, double scale, int dtype) +CvStatus Mat_MultiplyWithParams(Mat src1, Mat src2, Mat dst, double scale, + int dtype) { - cv::multiply(*src1, *src2, *dst, scale, dtype); + BEGIN_WRAP + cv::multiply(*src1, *src2, *dst, scale, dtype); + END_WRAP } -void Mat_Normalize(Mat src, Mat dst, double alpha, double beta, int typ) +CvStatus Mat_Normalize(Mat src, Mat dst, double alpha, double beta, int typ) { - cv::normalize(*src, *dst, alpha, beta, typ); + BEGIN_WRAP + cv::normalize(*src, *dst, alpha, beta, typ); + END_WRAP } -double Norm(Mat src1, int normType) +CvStatus Norm(Mat src1, int normType, double *rval) { - return cv::norm(*src1, normType); + BEGIN_WRAP + *rval = cv::norm(*src1, normType); + END_WRAP } -double NormWithMats(Mat src1, Mat src2, int normType) +CvStatus NormWithMats(Mat src1, Mat src2, int normType, double *rval) { - return cv::norm(*src1, *src2, normType); + BEGIN_WRAP + *rval = cv::norm(*src1, *src2, normType); + END_WRAP } -void Mat_PerspectiveTransform(Mat src, Mat dst, Mat tm) +CvStatus Mat_PerspectiveTransform(Mat src, Mat dst, Mat tm) { - cv::perspectiveTransform(*src, *dst, *tm); + BEGIN_WRAP + cv::perspectiveTransform(*src, *dst, *tm); + END_WRAP } -bool Mat_Solve(Mat src1, Mat src2, Mat dst, int flags) +CvStatus Mat_Solve(Mat src1, Mat src2, Mat dst, int flags, bool *rval) { - return cv::solve(*src1, *src2, *dst, flags); + BEGIN_WRAP + *rval = cv::solve(*src1, *src2, *dst, flags); + END_WRAP } -int Mat_SolveCubic(Mat coeffs, Mat roots) +CvStatus Mat_SolveCubic(Mat coeffs, Mat roots, int *rval) { - return cv::solveCubic(*coeffs, *roots); + BEGIN_WRAP + *rval = cv::solveCubic(*coeffs, *roots); + END_WRAP } -double Mat_SolvePoly(Mat coeffs, Mat roots, int maxIters) +CvStatus Mat_SolvePoly(Mat coeffs, Mat roots, int maxIters, double *rval) { - return cv::solvePoly(*coeffs, *roots, maxIters); + BEGIN_WRAP + *rval = cv::solvePoly(*coeffs, *roots, maxIters); + END_WRAP } -void Mat_Reduce(Mat src, Mat dst, int dim, int rType, int dType) +CvStatus Mat_Reduce(Mat src, Mat dst, int dim, int rType, int dType) { - cv::reduce(*src, *dst, dim, rType, dType); + BEGIN_WRAP + cv::reduce(*src, *dst, dim, rType, dType); + END_WRAP } -void Mat_ReduceArgMax(Mat src, Mat dst, int axis, bool lastIndex) +CvStatus Mat_ReduceArgMax(Mat src, Mat dst, int axis, bool lastIndex) { - cv::reduceArgMax(*src, *dst, axis, lastIndex); + BEGIN_WRAP + cv::reduceArgMax(*src, *dst, axis, lastIndex); + END_WRAP } -void Mat_ReduceArgMin(Mat src, Mat dst, int axis, bool lastIndex) +CvStatus Mat_ReduceArgMin(Mat src, Mat dst, int axis, bool lastIndex) { - cv::reduceArgMin(*src, *dst, axis, lastIndex); + BEGIN_WRAP + cv::reduceArgMin(*src, *dst, axis, lastIndex); + END_WRAP } -void Mat_Repeat(Mat src, int nY, int nX, Mat dst) +CvStatus Mat_Repeat(Mat src, int nY, int nX, Mat dst) { - cv::repeat(*src, nY, nX, *dst); + BEGIN_WRAP + cv::repeat(*src, nY, nX, *dst); + END_WRAP } -void Mat_ScaleAdd(Mat src1, double alpha, Mat src2, Mat dst) +CvStatus Mat_ScaleAdd(Mat src1, double alpha, Mat src2, Mat dst) { - cv::scaleAdd(*src1, alpha, *src2, *dst); + BEGIN_WRAP + cv::scaleAdd(*src1, alpha, *src2, *dst); + END_WRAP } -void Mat_SetIdentity(Mat src, double scalar) +CvStatus Mat_SetIdentity(Mat src, double scalar) { - cv::setIdentity(*src, scalar); + BEGIN_WRAP + cv::setIdentity(*src, scalar); + END_WRAP } -void Mat_Sort(Mat src, Mat dst, int flags) +CvStatus Mat_Sort(Mat src, Mat dst, int flags) { - cv::sort(*src, *dst, flags); + BEGIN_WRAP + cv::sort(*src, *dst, flags); + END_WRAP } -void Mat_SortIdx(Mat src, Mat dst, int flags) +CvStatus Mat_SortIdx(Mat src, Mat dst, int flags) { - cv::sortIdx(*src, *dst, flags); + BEGIN_WRAP + cv::sortIdx(*src, *dst, flags); + END_WRAP } -void Mat_Split(Mat src, struct Mats *mats) +CvStatus Mat_Split(Mat src, Mats *mats) { - std::vector channels; - cv::split(*src, channels); - mats->mats = new Mat[channels.size()]; + BEGIN_WRAP + std::vector channels; + cv::split(*src, channels); + mats->mats = new Mat[channels.size()]; - for (size_t i = 0; i < channels.size(); ++i) - { - mats->mats[i] = new cv::Mat(channels[i]); - } + for (size_t i = 0; i < channels.size(); ++i) { + mats->mats[i] = new cv::Mat(channels[i]); + } - mats->length = (int)channels.size(); + mats->length = (int)channels.size(); + END_WRAP } -void Mat_Subtract(Mat src1, Mat src2, Mat dst) +CvStatus Mat_Subtract(Mat src1, Mat src2, Mat dst) { - cv::subtract(*src1, *src2, *dst); + BEGIN_WRAP + cv::subtract(*src1, *src2, *dst); + END_WRAP } -Scalar Mat_Trace(Mat src) +CvStatus Mat_Trace(Mat src, Scalar *rval) { - cv::Scalar c = cv::trace(*src); - Scalar scal = Scalar(); - scal.val1 = c.val[0]; - scal.val2 = c.val[1]; - scal.val3 = c.val[2]; - scal.val4 = c.val[3]; - return scal; + BEGIN_WRAP + cv::Scalar c = cv::trace(*src); + Scalar scal = Scalar(); + scal.val1 = c.val[0]; + scal.val2 = c.val[1]; + scal.val3 = c.val[2]; + scal.val4 = c.val[3]; + *rval = scal; + END_WRAP } -void Mat_Transform(Mat src, Mat dst, Mat tm) +CvStatus Mat_Transform(Mat src, Mat dst, Mat tm) { - cv::transform(*src, *dst, *tm); + BEGIN_WRAP + cv::transform(*src, *dst, *tm); + END_WRAP } -int Mat_Transpose(Mat src, Mat dst) +CvStatus Mat_Transpose(Mat src, Mat dst) { - try - { - cv::transpose(*src, *dst); - return cv::Error::Code::StsOk; - } - catch (...) - { - return cv::Error::Code::StsError; - } + BEGIN_WRAP + cv::transpose(*src, *dst); + END_WRAP } -void Mat_PolarToCart(Mat magnitude, Mat degree, Mat x, Mat y, bool angleInDegrees) +CvStatus Mat_PolarToCart(Mat magnitude, Mat degree, Mat x, Mat y, + bool angleInDegrees) { - cv::polarToCart(*magnitude, *degree, *x, *y, angleInDegrees); + BEGIN_WRAP + cv::polarToCart(*magnitude, *degree, *x, *y, angleInDegrees); + END_WRAP } -void Mat_Pow(Mat src, double power, Mat dst) +CvStatus Mat_Pow(Mat src, double power, Mat dst) { - cv::pow(*src, power, *dst); + BEGIN_WRAP + cv::pow(*src, power, *dst); + END_WRAP } -void Mat_Phase(Mat x, Mat y, Mat angle, bool angleInDegrees) +CvStatus Mat_Phase(Mat x, Mat y, Mat angle, bool angleInDegrees) { - cv::phase(*x, *y, *angle, angleInDegrees); + BEGIN_WRAP + cv::phase(*x, *y, *angle, angleInDegrees); + END_WRAP } -Scalar Mat_Sum(Mat src) +CvStatus Mat_Sum(Mat src, Scalar *rval) { - cv::Scalar c = cv::sum(*src); - Scalar scal = Scalar(); - scal.val1 = c.val[0]; - scal.val2 = c.val[1]; - scal.val3 = c.val[2]; - scal.val4 = c.val[3]; - return scal; + BEGIN_WRAP + cv::Scalar c = cv::sum(*src); + Scalar scal = Scalar(); + scal.val1 = c.val[0]; + scal.val2 = c.val[1]; + scal.val3 = c.val[2]; + scal.val4 = c.val[3]; + *rval = scal; + END_WRAP } // TermCriteria_New creates a new TermCriteria TermCriteria TermCriteria_New(int typ, int maxCount, double epsilon) { - return new cv::TermCriteria(typ, maxCount, epsilon); + return new cv::TermCriteria(typ, maxCount, epsilon); } -void Contours_Close(struct Contours cs) +void Contours_Close(Contours cs) { - for (int i = 0; i < cs.length; i++) - { - Points_Close(cs.contours[i]); - } + for (int i = 0; i < cs.length; i++) { + Points_Close(cs.contours[i]); + } - delete[] cs.contours; + delete[] cs.contours; } -void CStrings_Close(struct CStrings cstrs) +void CStrings_Close(CStrings cstrs) { - for (int i = 0; i < cstrs.length; i++) - { - delete[] cstrs.strs[i]; - } - delete[] cstrs.strs; + for (int i = 0; i < cstrs.length; i++) { + delete[] cstrs.strs[i]; + } + delete[] cstrs.strs; } -void KeyPoints_Close(struct KeyPoints ks) +void KeyPoints_Close(KeyPoints ks) { - delete[] ks.keypoints; + delete[] ks.keypoints; } void Points_Close(Points ps) { - for (size_t i = 0; i < ps.length; i++) - { - Point_Close(ps.points[i]); - } + for (size_t i = 0; i < ps.length; i++) { + Point_Close(ps.points[i]); + } - delete[] ps.points; + delete[] ps.points; } -void Point_Close(Point p) {} +void Point_Close(Point p) +{ +} -void Point2f_Close(Point2f p) {} +void Point2f_Close(Point2f p) +{ +} -void Point3f_Close(Point3f p) {} +void Point3f_Close(Point3f p) +{ +} -void Rects_Close(struct Rects rs) +void Rects_Close(Rects rs) { - delete[] rs.rects; + delete[] rs.rects; } -void DMatches_Close(struct DMatches ds) +void DMatches_Close(DMatches ds) { - delete[] ds.dmatches; + delete[] ds.dmatches; } -void MultiDMatches_Close(struct MultiDMatches mds) +void MultiDMatches_Close(MultiDMatches mds) { - for (size_t i = 0; i < mds.length; i++) - { - DMatches_Close(mds.dmatches[i]); - } + for (size_t i = 0; i < mds.length; i++) { + DMatches_Close(mds.dmatches[i]); + } - delete[] mds.dmatches; + delete[] mds.dmatches; } -struct DMatches MultiDMatches_get(struct MultiDMatches mds, int index) +CvStatus MultiDMatches_get(MultiDMatches mds, int index, DMatches *rval) { - return mds.dmatches[index]; + BEGIN_WRAP + *rval = mds.dmatches[index]; + END_WRAP } // since it is next to impossible to iterate over mats.mats on the cgo side -Mat Mats_get(struct Mats mats, int i) +CvStatus Mats_get(Mats mats, int i, Mat *rval) { - return mats.mats[i]; + BEGIN_WRAP + *rval = mats.mats[i]; + END_WRAP } -void Mats_Close(struct Mats mats) +void Mats_Close(Mats mats) { - delete[] mats.mats; + delete[] mats.mats; } -void ByteArray_Release(struct ByteArray buf) +void ByteArray_Release(ByteArray buf) { - delete[] buf.data; + delete[] buf.data; } -struct ByteArray toByteArray(const char *buf, int len) +ByteArray toByteArray(const char *buf, int len) { - ByteArray ret = {new char[len], len}; - memcpy(ret.data, buf, len); - return ret; + ByteArray ret = {new char[len], len}; + memcpy(ret.data, buf, len); + return ret; } int64 GetCVTickCount() { - return cv::getTickCount(); + return cv::getTickCount(); } double GetTickFrequency() { - return cv::getTickFrequency(); + return cv::getTickFrequency(); } Mat Mat_rowRange(Mat m, int startrow, int endrow) { - return new cv::Mat(m->rowRange(startrow, endrow)); + return new cv::Mat(m->rowRange(startrow, endrow)); } Mat Mat_colRange(Mat m, int startrow, int endrow) { - return new cv::Mat(m->colRange(startrow, endrow)); + return new cv::Mat(m->colRange(startrow, endrow)); } PointVector PointVector_New() { - return new std::vector; + return new std::vector; } PointVector PointVector_NewFromPoints(Contour points) { - std::vector *cntr = new std::vector; + std::vector *cntr = new std::vector; - for (size_t i = 0; i < points.length; i++) - { - cntr->push_back(cv::Point(points.points[i].x, points.points[i].y)); - } + for (size_t i = 0; i < points.length; i++) { + cntr->push_back(cv::Point(points.points[i].x, points.points[i].y)); + } - return cntr; + return cntr; } PointVector PointVector_NewFromMat(Mat mat) { - std::vector *pts = new std::vector; - *pts = (std::vector)*mat; - return pts; + std::vector *pts = new std::vector; + *pts = (std::vector)*mat; + return pts; } Point PointVector_At(PointVector pv, int idx) { - cv::Point p = pv->at(idx); - return Point{.x = p.x, .y = p.y}; + cv::Point p = pv->at(idx); + return Point{.x = p.x, .y = p.y}; } void PointVector_Append(PointVector pv, Point p) { - pv->push_back(cv::Point(p.x, p.y)); + pv->push_back(cv::Point(p.x, p.y)); } int PointVector_Size(PointVector p) { - return p->size(); + return p->size(); } void PointVector_Close(PointVector p) { - p->clear(); - delete p; + p->clear(); + delete p; } PointsVector PointsVector_New() { - return new std::vector>; + return new std::vector>; } PointsVector PointsVector_NewFromPoints(Contours points) { - std::vector> *pv = new std::vector>; - - for (size_t i = 0; i < points.length; i++) - { - Contour contour = points.contours[i]; + std::vector> *pv = + new std::vector>; - std::vector cntr; + for (size_t i = 0; i < points.length; i++) { + Contour contour = points.contours[i]; - for (size_t i = 0; i < contour.length; i++) - { - cntr.push_back(cv::Point(contour.points[i].x, contour.points[i].y)); - } + std::vector cntr; - pv->push_back(cntr); + for (size_t i = 0; i < contour.length; i++) { + cntr.push_back(cv::Point(contour.points[i].x, contour.points[i].y)); } - return pv; + pv->push_back(cntr); + } + + return pv; } int PointsVector_Size(PointsVector ps) { - return ps->size(); + return ps->size(); } PointVector PointsVector_At(PointsVector ps, int idx) { - std::vector *p = &(ps->at(idx)); - return p; + std::vector *p = &(ps->at(idx)); + return p; } void PointsVector_Append(PointsVector psv, PointVector pv) { - psv->push_back(*pv); + psv->push_back(*pv); } void PointsVector_Close(PointsVector ps) { - ps->clear(); - delete ps; + ps->clear(); + delete ps; } Point2fVector Point2fVector_New() { - return new std::vector; + return new std::vector; } Point2fVector Point2fVector_NewFromPoints(Contour2f points) { - std::vector *cntr = new std::vector; + std::vector *cntr = new std::vector; - for (size_t i = 0; i < points.length; i++) - { - cntr->push_back(cv::Point2f(points.points[i].x, points.points[i].y)); - } + for (size_t i = 0; i < points.length; i++) { + cntr->push_back(cv::Point2f(points.points[i].x, points.points[i].y)); + } - return cntr; + return cntr; } Point2fVector Point2fVector_NewFromMat(Mat mat) { - std::vector *pts = new std::vector; - *pts = (std::vector)*mat; - return pts; + std::vector *pts = new std::vector; + *pts = (std::vector)*mat; + return pts; } Point2f Point2fVector_At(Point2fVector pfv, int idx) { - cv::Point2f p = pfv->at(idx); - return Point2f{.x = p.x, .y = p.y}; + cv::Point2f p = pfv->at(idx); + return Point2f{.x = p.x, .y = p.y}; } int Point2fVector_Size(Point2fVector pfv) { - return pfv->size(); + return pfv->size(); } void Point2fVector_Close(Point2fVector pv) { - pv->clear(); - delete pv; + pv->clear(); + delete pv; } // IntVector* IntVector_New(){ @@ -1283,9 +1604,9 @@ void Point2fVector_Close(Point2fVector pv) // return new IntVector {.val=vec->data(), .length=(int)vec->size()}; // } -void IntVector_Close(struct IntVector ivec) +void IntVector_Close(IntVector ivec) { - delete[] ivec.val; + delete[] ivec.val; } // FloatVector* FloatVector_New(){ @@ -1293,295 +1614,287 @@ void IntVector_Close(struct IntVector ivec) // return new FloatVector {.val=vec->data(), .length=(int)vec->size()}; // } -void FloatVector_Close(struct FloatVector fvec) +void FloatVector_Close(FloatVector fvec) { - delete[] fvec.val; + delete[] fvec.val; } RNG Rng_New() { - return new cv::RNG(); + return new cv::RNG(); } RNG Rng_NewWithState(uint64_t state) { - return new cv::RNG(state); + return new cv::RNG(state); } void Rng_Close(RNG rng) { - delete rng; + delete rng; } RNG TheRNG() { - return &cv::theRNG(); + return &cv::theRNG(); } void SetRNGSeed(int seed) { - cv::setRNGSeed(seed); + cv::setRNGSeed(seed); } -void RNG_Fill(RNG rng, Mat mat, int distType, double a, double b, bool saturateRange) +void RNG_Fill(RNG rng, Mat mat, int distType, double a, double b, + bool saturateRange) { - rng->fill(*mat, distType, a, b, saturateRange); + rng->fill(*mat, distType, a, b, saturateRange); } double RNG_Gaussian(RNG rng, double sigma) { - return rng->gaussian(sigma); + return rng->gaussian(sigma); } int RNG_Uniform(RNG rng, int a, int b) { - return rng->uniform(a, b); + return rng->uniform(a, b); } double RNG_UniformDouble(RNG rng, double a, double b) { - return rng->uniform(a, b); + return rng->uniform(a, b); } unsigned int RNG_Next(RNG rng) { - return rng->next(); + return rng->next(); } void RandN(Mat mat, Scalar mean, Scalar stddev) { - cv::Scalar m = cv::Scalar(mean.val1, mean.val2, mean.val3, mean.val4); - cv::Scalar s = cv::Scalar(stddev.val1, stddev.val2, stddev.val3, stddev.val4); - cv::randn(*mat, m, s); + cv::Scalar m = cv::Scalar(mean.val1, mean.val2, mean.val3, mean.val4); + cv::Scalar s = cv::Scalar(stddev.val1, stddev.val2, stddev.val3, stddev.val4); + cv::randn(*mat, m, s); } void RandShuffle(Mat mat) { - cv::randShuffle(*mat); + cv::randShuffle(*mat); } void RandShuffleWithParams(Mat mat, double iterFactor, RNG rng) { - cv::randShuffle(*mat, iterFactor, rng); + cv::randShuffle(*mat, iterFactor, rng); } void RandU(Mat mat, Scalar low, Scalar high) { - cv::Scalar l = cv::Scalar(low.val1, low.val2, low.val3, low.val4); - cv::Scalar h = cv::Scalar(high.val1, high.val2, high.val3, high.val4); - cv::randu(*mat, l, h); + cv::Scalar l = cv::Scalar(low.val1, low.val2, low.val3, low.val4); + cv::Scalar h = cv::Scalar(high.val1, high.val2, high.val3, high.val4); + cv::randu(*mat, l, h); } void copyPointVectorToPoint2fVector(PointVector src, Point2fVector dest) { - for (size_t i = 0; i < src->size(); i++) - { - dest->push_back(cv::Point2f(src->at(i).x, src->at(i).y)); - } + for (size_t i = 0; i < src->size(); i++) { + dest->push_back(cv::Point2f(src->at(i).x, src->at(i).y)); + } } void StdByteVectorInitialize(void *data) { - new (data) std::vector(); + new (data) std::vector(); } void StdByteVectorFree(void *data) { - reinterpret_cast *>(data)->~vector(); + reinterpret_cast *>(data)->~vector(); } size_t StdByteVectorLen(void *data) { - return reinterpret_cast *>(data)->size(); + return reinterpret_cast *>(data)->size(); } uint8_t *StdByteVectorData(void *data) { - return reinterpret_cast *>(data)->data(); + return reinterpret_cast *>(data)->data(); } UCharVector UCharVector_New() { - return new std::vector(); + return new std::vector(); } void UCharVector_Free(UCharVector vec) { - if (vec != nullptr) - { - vec->clear(); - delete vec; - } + if (vec != nullptr) { + vec->clear(); + delete vec; + } } int UCharVector_Size(UCharVector vec) { - return vec->size(); + return vec->size(); } void UCharVector_Append(UCharVector vec, uchar c) { - vec->push_back(c); + vec->push_back(c); } uchar UCharVector_At(UCharVector vec, int idx) { - return vec->at(idx); + return vec->at(idx); } Points2fVector Points2fVector_New() { - return new std::vector>; + return new std::vector>; } Points2fVector Points2fVector_NewFromPoints(Contours2f points) { - Points2fVector pv = Points2fVector_New(); - for (size_t i = 0; i < points.length; i++) - { - Contour2f contour2f = points.contours[i]; - Point2fVector cntr = Point2fVector_NewFromPoints(contour2f); - Points2fVector_Append(pv, cntr); - } + Points2fVector pv = Points2fVector_New(); + for (size_t i = 0; i < points.length; i++) { + Contour2f contour2f = points.contours[i]; + Point2fVector cntr = Point2fVector_NewFromPoints(contour2f); + Points2fVector_Append(pv, cntr); + } - return pv; + return pv; } int Points2fVector_Size(Points2fVector ps) { - return ps->size(); + return ps->size(); } Point2fVector Points2fVector_At(Points2fVector ps, int idx) { - return &(ps->at(idx)); + return &(ps->at(idx)); } void Points2fVector_Append(Points2fVector psv, Point2fVector pv) { - psv->push_back(*pv); + psv->push_back(*pv); } void Points2fVector_Close(Points2fVector ps) { - ps->clear(); - delete ps; + ps->clear(); + delete ps; } Point3fVector Point3fVector_New() { - return new std::vector; + return new std::vector; } Point3fVector Point3fVector_NewFromPoints(Contour3f points) { - std::vector *cntr = new std::vector; - for (size_t i = 0; i < points.length; i++) - { - cntr->push_back(cv::Point3f( - points.points[i].x, - points.points[i].y, - points.points[i].z)); - } + std::vector *cntr = new std::vector; + for (size_t i = 0; i < points.length; i++) { + cntr->push_back(cv::Point3f(points.points[i].x, points.points[i].y, + points.points[i].z)); + } - return cntr; + return cntr; } Point3fVector Point3fVector_NewFromMat(Mat mat) { - std::vector *pts = new std::vector; - *pts = (std::vector)*mat; - return pts; + std::vector *pts = new std::vector; + *pts = (std::vector)*mat; + return pts; } Point3f Point3fVector_At(Point3fVector pfv, int idx) { - cv::Point3f p = pfv->at(idx); - Point3f pp = Point3f{ - .x = p.x, - .y = p.y, - .z = p.z}; - return pp; + cv::Point3f p = pfv->at(idx); + Point3f pp = Point3f{.x = p.x, .y = p.y, .z = p.z}; + return pp; } void Point3fVector_Append(Point3fVector pfv, Point3f point) { - pfv->push_back(cv::Point3f(point.x, point.y, point.z)); + pfv->push_back(cv::Point3f(point.x, point.y, point.z)); } int Point3fVector_Size(Point3fVector pfv) { - return pfv->size(); + return pfv->size(); } void Point3fVector_Close(Point3fVector pv) { - pv->clear(); - delete pv; + pv->clear(); + delete pv; } Points3fVector Points3fVector_New() { - return new std::vector>; + return new std::vector>; } Points3fVector Points3fVector_NewFromPoints(Contours3f points) { - Points3fVector pv = Points3fVector_New(); - for (size_t i = 0; i < points.length; i++) - { - Contour3f contour3f = points.contours[i]; - Point3fVector cntr = Point3fVector_NewFromPoints(contour3f); - Points3fVector_Append(pv, cntr); - } + Points3fVector pv = Points3fVector_New(); + for (size_t i = 0; i < points.length; i++) { + Contour3f contour3f = points.contours[i]; + Point3fVector cntr = Point3fVector_NewFromPoints(contour3f); + Points3fVector_Append(pv, cntr); + } - return pv; + return pv; } int Points3fVector_Size(Points3fVector ps) { - return ps->size(); + return ps->size(); } Point3fVector Points3fVector_At(Points3fVector ps, int idx) { - return &(ps->at(idx)); + return &(ps->at(idx)); } void Points3fVector_Append(Points3fVector psv, Point3fVector pv) { - psv->push_back(*pv); + psv->push_back(*pv); } void Points3fVector_Close(Points3fVector ps) { - ps->clear(); - delete ps; + ps->clear(); + delete ps; } void SetNumThreads(int n) { - cv::setNumThreads(n); + cv::setNumThreads(n); } int GetNumThreads() { - return cv::getNumThreads(); + return cv::getNumThreads(); } void Point2fVector_Append(Point2fVector pv, Point2f p) { - pv->push_back(cv::Point2f(p.x, p.y)); + pv->push_back(cv::Point2f(p.x, p.y)); } -Mats Mats_New() +CvStatus Mats_New(Mats *rval) { - std::vector v; - Mats mats = { - (Mat *)v.data(), - (int)v.size(), - }; - return mats; + BEGIN_WRAP + std::vector v; + *rval = { + (Mat *)v.data(), + (int)v.size(), + }; + END_WRAP } // void Mats_Append(Mats mats, Mat mat) { diff --git a/src/core.h b/src/core.h index 11aa296b..8bf63707 100644 --- a/src/core.h +++ b/src/core.h @@ -16,8 +16,7 @@ #ifdef __cplusplus #include -extern "C" -{ +extern "C" { #endif // #if 0 || defined WIN32 || defined _WIN32 @@ -27,608 +26,639 @@ extern "C" // return s; // #else #define BEGIN_WRAP \ - try \ - { -#define END_WRAP \ - CvStatus s = {.code = 0}; \ - return s; \ - } \ - catch (cv::Exception & e) \ - { \ - CvStatus s = {.code = e.code, .msg = strdup(e.msg.c_str()), .err = strdup(e.err.c_str()), .func = strdup(e.func.c_str()), .file = strdup(e.file.c_str()), .line = e.line}; \ - return s; \ - } - // #endif - - typedef int CV_STATUS; - - // Wrapper for std::vector - typedef struct CStrings - { - char **strs; - int length; - } CStrings; - - typedef struct ByteArray - { - char *data; - int length; - } ByteArray; - - // Wrapper for std::vector - typedef struct IntVector - { - int *val; - int length; - } IntVector; - - // Wrapper for std::vector - typedef struct FloatVector - { - float *val; - int length; - } FloatVector; - - typedef struct RawData - { - int width; - int height; - struct ByteArray data; - } RawData; - - // Wrapper for an individual cv::Point2f - typedef struct Point2f - { - float x; - float y; - } Point2f; - - typedef struct Point3f - { - float x; - float y; - float z; - } Point3f; - - // Wrapper for an individual cv::cvPoint - typedef struct Point - { - int x; - int y; - } Point; - - // Wrapper for the vector of Point structs aka std::vector - typedef struct Points - { - Point *points; - int length; - } Points; - - // Wrapper for the vector of Point2f structs aka std::vector - typedef struct Points2f - { - Point2f *points; - int length; - } Points2f; - - typedef struct Points3f - { - Point3f *points; - int length; - } Points3f; - - // Contour is alias for Points - typedef Points Contour; - - // Contour2f is alias for Points2f - typedef Points2f Contour2f; - - typedef struct Contours2f - { - Contour2f *contours; - int length; - } Contours2f; - - // Contour3f is alias for Points3f - typedef Points3f Contour3f; - - // Wrapper for the vector of Points3f vectors aka std::vector< std::vector > - typedef struct Contours3f - { - Contour3f *contours; - int length; - } Contours3f; - - // Wrapper for the vector of Points vectors aka std::vector< std::vector > - typedef struct Contours - { - Contour *contours; - int length; - } Contours; - - // Wrapper for an individual cv::cvRect - typedef struct Rect - { - int x; - int y; - int width; - int height; - } Rect; - - // Wrapper for the vector of Rect struct aka std::vector - typedef struct Rects - { - Rect *rects; - int length; - } Rects; - - // Wrapper for an individual cv::cvSize - typedef struct Size - { - int width; - int height; - } Size; - - // Wrapper for an individual cv::RotatedRect - typedef struct RotatedRect - { - Points pts; - Rect boundingRect; - Point center; - Size size; - double angle; - } RotatedRect; - - // Wrapper for an individual cv::cvScalar - typedef struct Scalar - { - double val1; - double val2; - double val3; - double val4; - } Scalar; - - // Wrapper for a individual cv::KeyPoint - typedef struct KeyPoint - { - double x; - double y; - double size; - double angle; - double response; - int octave; - int classID; - } KeyPoint; - - // Wrapper for the vector of KeyPoint struct aka std::vector - typedef struct KeyPoints - { - KeyPoint *keypoints; - int length; - } KeyPoints; - - // Wrapper for SimpleBlobDetectorParams aka SimpleBlobDetector::Params - typedef struct SimpleBlobDetectorParams - { - unsigned char blobColor; - bool filterByArea; - bool filterByCircularity; - bool filterByColor; - bool filterByConvexity; - bool filterByInertia; - float maxArea; - float maxCircularity; - float maxConvexity; - float maxInertiaRatio; - float maxThreshold; - float minArea; - float minCircularity; - float minConvexity; - float minDistBetweenBlobs; - float minInertiaRatio; - size_t minRepeatability; - float minThreshold; - float thresholdStep; - } SimpleBlobDetectorParams; - - // Wrapper for an individual cv::DMatch - typedef struct DMatch - { - int queryIdx; - int trainIdx; - int imgIdx; - float distance; - } DMatch; - - // Wrapper for the vector of DMatch struct aka std::vector - typedef struct DMatches - { - DMatch *dmatches; - int length; - } DMatches; - - // Wrapper for the vector vector of DMatch struct aka std::vector> - typedef struct MultiDMatches - { - DMatches *dmatches; - int length; - } MultiDMatches; - - // Wrapper for an individual cv::Moment - typedef struct Moment - { - double m00; - double m10; - double m01; - double m20; - double m11; - double m02; - double m30; - double m21; - double m12; - double m03; - - double mu20; - double mu11; - double mu02; - double mu30; - double mu21; - double mu12; - double mu03; - - double nu20; - double nu11; - double nu02; - double nu30; - double nu21; - double nu12; - double nu03; - } Moment; + try { +#define END_WRAP \ + CvStatus s = {.code = 0, .msg = strdup("success")}; \ + return s; \ + } \ + catch (cv::Exception & e) \ + { \ + CvStatus s = { \ + .code = e.code, \ + .msg = strdup(e.msg.c_str()), \ + .err = strdup(e.err.c_str()), \ + .func = strdup(e.func.c_str()), \ + .file = strdup(e.file.c_str()), \ + .line = e.line, \ + }; \ + return s; \ + } \ + catch (std::exception & e) \ + { \ + CvStatus s = { \ + .code = 1, \ + .msg = strdup(e.what()), \ + .err = strdup(e.what()), \ + .func = strdup(__FUNCTION__), \ + .file = strdup(__FILE__), \ + .line = __LINE__, \ + }; \ + return s; \ + } \ + catch (...) \ + { \ + CvStatus s = { \ + .code = 1, \ + .msg = strdup("Unknown error"), \ + .err = strdup("Unknown error"), \ + .func = strdup(__FUNCTION__), \ + .file = strdup(__FILE__), \ + .line = __LINE__, \ + }; \ + return s; \ + } +// #endif + +typedef int CV_STATUS; + +// Wrapper for std::vector +typedef struct CStrings { + char **strs; + int length; +} CStrings; + +typedef struct ByteArray { + char *data; + int length; +} ByteArray; + +// Wrapper for std::vector +typedef struct IntVector { + int *val; + int length; +} IntVector; + +// Wrapper for std::vector +typedef struct FloatVector { + float *val; + int length; +} FloatVector; + +typedef struct RawData { + int width; + int height; + ByteArray data; +} RawData; + +// Wrapper for an individual cv::Point2f +typedef struct Point2f { + float x; + float y; +} Point2f; + +typedef struct Point3f { + float x; + float y; + float z; +} Point3f; + +// Wrapper for an individual cv::cvPoint +typedef struct Point { + int x; + int y; +} Point; + +// Wrapper for the vector of Point structs aka std::vector +typedef struct Points { + Point *points; + int length; +} Points; + +// Wrapper for the vector of Point2f structs aka std::vector +typedef struct Points2f { + Point2f *points; + int length; +} Points2f; + +typedef struct Points3f { + Point3f *points; + int length; +} Points3f; + +// Contour is alias for Points +typedef Points Contour; + +// Contour2f is alias for Points2f +typedef Points2f Contour2f; + +typedef struct Contours2f { + Contour2f *contours; + int length; +} Contours2f; + +// Contour3f is alias for Points3f +typedef Points3f Contour3f; + +// Wrapper for the vector of Points3f vectors aka std::vector< +// std::vector > +typedef struct Contours3f { + Contour3f *contours; + int length; +} Contours3f; + +// Wrapper for the vector of Points vectors aka std::vector< std::vector +// > +typedef struct Contours { + Contour *contours; + int length; +} Contours; + +// Wrapper for an individual cv::cvRect +typedef struct Rect { + int x; + int y; + int width; + int height; +} Rect; + +// Wrapper for the vector of Rect struct aka std::vector +typedef struct Rects { + Rect *rects; + int length; +} Rects; + +// Wrapper for an individual cv::cvSize +typedef struct Size { + int width; + int height; +} Size; + +// Wrapper for an individual cv::RotatedRect +typedef struct RotatedRect { + Points pts; + Rect boundingRect; + Point center; + Size size; + double angle; +} RotatedRect; + +// Wrapper for an individual cv::cvScalar +typedef struct Scalar { + double val1; + double val2; + double val3; + double val4; +} Scalar; + +// Wrapper for a individual cv::KeyPoint +typedef struct KeyPoint { + double x; + double y; + double size; + double angle; + double response; + int octave; + int classID; +} KeyPoint; + +// Wrapper for the vector of KeyPoint struct aka std::vector +typedef struct KeyPoints { + KeyPoint *keypoints; + int length; +} KeyPoints; + +// Wrapper for SimpleBlobDetectorParams aka SimpleBlobDetector::Params +typedef struct SimpleBlobDetectorParams { + unsigned char blobColor; + bool filterByArea; + bool filterByCircularity; + bool filterByColor; + bool filterByConvexity; + bool filterByInertia; + float maxArea; + float maxCircularity; + float maxConvexity; + float maxInertiaRatio; + float maxThreshold; + float minArea; + float minCircularity; + float minConvexity; + float minDistBetweenBlobs; + float minInertiaRatio; + size_t minRepeatability; + float minThreshold; + float thresholdStep; +} SimpleBlobDetectorParams; + +// Wrapper for an individual cv::DMatch +typedef struct DMatch { + int queryIdx; + int trainIdx; + int imgIdx; + float distance; +} DMatch; + +// Wrapper for the vector of DMatch struct aka std::vector +typedef struct DMatches { + DMatch *dmatches; + int length; +} DMatches; + +// Wrapper for the vector vector of DMatch struct aka +// std::vector> +typedef struct MultiDMatches { + DMatches *dmatches; + int length; +} MultiDMatches; + +// Wrapper for an individual cv::Moment +typedef struct Moment { + double m00; + double m10; + double m01; + double m20; + double m11; + double m02; + double m30; + double m21; + double m12; + double m03; + + double mu20; + double mu11; + double mu02; + double mu30; + double mu21; + double mu12; + double mu03; + + double nu20; + double nu11; + double nu02; + double nu30; + double nu21; + double nu12; + double nu03; +} Moment; #ifdef __cplusplus - typedef cv::Mat *Mat; - typedef cv::_InputOutputArray *InputOutputArray; - typedef cv::TermCriteria *TermCriteria; - typedef cv::RNG *RNG; - typedef std::vector *PointVector; - typedef std::vector> *PointsVector; - typedef std::vector *Point2fVector; - typedef std::vector> *Points2fVector; - typedef std::vector *Point3fVector; - typedef std::vector> *Points3fVector; - typedef std::vector *UCharVector; - typedef cv::Exception *CvException; +typedef cv::Mat *Mat; +typedef cv::_InputOutputArray *InputOutputArray; +typedef cv::TermCriteria *TermCriteria; +typedef cv::RNG *RNG; +typedef std::vector *PointVector; +typedef std::vector> *PointsVector; +typedef std::vector *Point2fVector; +typedef std::vector> *Points2fVector; +typedef std::vector *Point3fVector; +typedef std::vector> *Points3fVector; +typedef std::vector *UCharVector; +typedef cv::Exception *CvException; #else -typedef void *Mat; -typedef void *InputOutputArray; -typedef void *TermCriteria; -typedef void *RNG; -typedef void *PointVector; -typedef void *PointsVector; -typedef void *Point2fVector; -typedef void *Points2fVector; -typedef void *Point3fVector; -typedef void *Points3fVector; -typedef void *UCharVector; +typedef void *Mat; +typedef void *InputOutputArray; +typedef void *TermCriteria; +typedef void *RNG; +typedef void *PointVector; +typedef void *PointsVector; +typedef void *Point2fVector; +typedef void *Points2fVector; +typedef void *Point3fVector; +typedef void *Points3fVector; +typedef void *UCharVector; typedef unsigned char uchar; -typedef void *CvException; +typedef void *CvException; #endif - typedef struct CvStatus - { - int code; - char *msg; - char *err; - char *func; - char *file; - int line; - } CvStatus; - - InputOutputArray noArray(); - // Wrapper for the vector of Mat aka std::vector - typedef struct Mats - { - Mat *mats; - int length; - } Mats; - - Mats Mats_New(); - // void Mats_Append(Mats mats, Mat mat); - Mat Mats_get(struct Mats mats, int i); - struct DMatches MultiDMatches_get(struct MultiDMatches mds, int index); - - struct ByteArray toByteArray(const char *buf, int len); - void ByteArray_Release(struct ByteArray buf); - - void Contours_Close(struct Contours cs); - void KeyPoints_Close(struct KeyPoints ks); - void Rects_Close(struct Rects rs); - void Mats_Close(struct Mats mats); - void Point_Close(struct Point p); - void Point2f_Close(struct Point2f p); - void Point3f_Close(Point3f p); - void Points_Close(struct Points ps); - void DMatches_Close(struct DMatches ds); - void MultiDMatches_Close(struct MultiDMatches mds); - - Mat Mat_New(); - Mat Mat_NewWithSize(int rows, int cols, int type); - Mat Mat_NewWithSizes(struct IntVector sizes, int type); - Mat Mat_NewWithSizesFromScalar(IntVector sizes, int type, Scalar ar); - Mat Mat_NewWithSizesFromBytes(IntVector sizes, int type, struct ByteArray buf); - Mat Mat_NewFromScalar(const Scalar ar, int type); - Mat Mat_NewWithSizeFromScalar(const Scalar ar, int rows, int cols, int type); - Mat Mat_NewFromBytes(int rows, int cols, int type, struct ByteArray buf); - Mat Mat_FromPtr(Mat m, int rows, int cols, int type, int prows, int pcols); - void Mat_Close(Mat m); - bool Mat_Empty(Mat m); - bool Mat_IsContinuous(Mat m); - Mat Mat_Clone(Mat m); - void Mat_CopyTo(Mat m, Mat dst); - int Mat_Total(Mat m); - void Mat_Size(Mat m, IntVector *res); - void Mat_CopyToWithMask(Mat m, Mat dst, Mat mask); - void Mat_ConvertTo(Mat m, Mat dst, int type); - void Mat_ConvertToWithParams(Mat m, Mat dst, int type, float alpha, float beta); - struct ByteArray Mat_ToBytes(Mat m); - struct ByteArray Mat_DataPtr(Mat m); - Mat Mat_Region(Mat m, Rect r); - Mat Mat_Reshape(Mat m, int cn, int rows); - void Mat_PatchNaNs(Mat m, double val); - Mat Mat_ConvertFp16(Mat m); - Scalar Mat_Mean(Mat m); - Scalar Mat_MeanWithMask(Mat m, Mat mask); - Mat Mat_Sqrt(Mat m); - int Mat_Rows(Mat m); - int Mat_Cols(Mat m); - int Mat_Channels(Mat m); - int Mat_Type(Mat m); - int Mat_Step(Mat m); - int Mat_ElemSize(Mat m); - Mat Eye(int rows, int cols, int type); - Mat Zeros(int rows, int cols, int type); - Mat Ones(int rows, int cols, int type); - - uint8_t Mat_GetUChar(Mat m, int row, int col); - uint8_t Mat_GetUChar3(Mat m, int x, int y, int z); - int8_t Mat_GetSChar(Mat m, int row, int col); - int8_t Mat_GetSChar3(Mat m, int x, int y, int z); - uint16_t Mat_GetUShort(Mat m, int row, int col); - uint16_t Mat_GetUShort3(Mat m, int x, int y, int z); - int16_t Mat_GetShort(Mat m, int row, int col); - int16_t Mat_GetShort3(Mat m, int x, int y, int z); - int32_t Mat_GetInt(Mat m, int row, int col); - int32_t Mat_GetInt3(Mat m, int x, int y, int z); - float Mat_GetFloat(Mat m, int row, int col); - float Mat_GetFloat3(Mat m, int x, int y, int z); - double Mat_GetDouble(Mat m, int row, int col); - double Mat_GetDouble3(Mat m, int x, int y, int z); - - void Mat_SetTo(Mat m, Scalar value); - void Mat_SetUChar(Mat m, int row, int col, uint8_t val); - void Mat_SetUChar3(Mat m, int x, int y, int z, uint8_t val); - void Mat_SetSChar(Mat m, int row, int col, int8_t val); - void Mat_SetSChar3(Mat m, int x, int y, int z, int8_t val); - void Mat_SetShort(Mat m, int row, int col, int16_t val); - void Mat_SetShort3(Mat m, int x, int y, int z, int16_t val); - void Mat_SetUShort(Mat m, int row, int col, uint16_t val); - void Mat_SetUShort3(Mat m, int x, int y, int z, uint16_t val); - void Mat_SetInt(Mat m, int row, int col, int32_t val); - void Mat_SetInt3(Mat m, int x, int y, int z, int32_t val); - void Mat_SetFloat(Mat m, int row, int col, float val); - void Mat_SetFloat3(Mat m, int x, int y, int z, float val); - void Mat_SetDouble(Mat m, int row, int col, double val); - void Mat_SetDouble3(Mat m, int x, int y, int z, double val); - - void Mat_AddUChar(Mat m, uint8_t val); - void Mat_SubtractUChar(Mat m, uint8_t val); - void Mat_MultiplyUChar(Mat m, uint8_t val); - void Mat_DivideUChar(Mat m, uint8_t val); - - void Mat_AddI32(Mat m, int32_t val); - void Mat_SubtractI32(Mat m, int32_t val); - void Mat_MultiplyI32(Mat m, int32_t val); - void Mat_DivideI32(Mat m, int32_t val); - - void Mat_AddFloat(Mat m, float_t val); - void Mat_SubtractFloat(Mat m, float_t val); - void Mat_MultiplyFloat(Mat m, float_t val); - void Mat_DivideFloat(Mat m, float_t val); - - void Mat_AddF64(Mat m, double_t val); - void Mat_SubtractF64(Mat m, double_t val); - void Mat_MultiplyF64(Mat m, double_t val); - void Mat_DivideF64(Mat m, double_t val); - Mat Mat_MultiplyMatrix(Mat x, Mat y); - - Mat Mat_T(Mat x); - - void LUT(Mat src, Mat lut, Mat dst); - - void Mat_AbsDiff(Mat src1, Mat src2, Mat dst); - void Mat_Add(Mat src1, Mat src2, Mat dst); - void Mat_AddWeighted(Mat src1, double alpha, Mat src2, double beta, double gamma, Mat dst); - void Mat_BitwiseAnd(Mat src1, Mat src2, Mat dst); - void Mat_BitwiseAndWithMask(Mat src1, Mat src2, Mat dst, Mat mask); - void Mat_BitwiseNot(Mat src1, Mat dst); - void Mat_BitwiseNotWithMask(Mat src1, Mat dst, Mat mask); - void Mat_BitwiseOr(Mat src1, Mat src2, Mat dst); - void Mat_BitwiseOrWithMask(Mat src1, Mat src2, Mat dst, Mat mask); - void Mat_BitwiseXor(Mat src1, Mat src2, Mat dst); - void Mat_BitwiseXorWithMask(Mat src1, Mat src2, Mat dst, Mat mask); - void Mat_Compare(Mat src1, Mat src2, Mat dst, int ct); - void Mat_BatchDistance(Mat src1, Mat src2, Mat dist, int dtype, Mat nidx, int normType, int K, - Mat mask, int update, bool crosscheck); - int Mat_BorderInterpolate(int p, int len, int borderType); - void Mat_CalcCovarMatrix(Mat samples, Mat covar, Mat mean, int flags, int ctype); - void Mat_CartToPolar(Mat x, Mat y, Mat magnitude, Mat angle, bool angleInDegrees); - bool Mat_CheckRange(Mat m, bool quiet, Point *pos, double minVal, double maxVal); - void Mat_CompleteSymm(Mat m, bool lowerToUpper); - void Mat_ConvertScaleAbs(Mat src, Mat dst, double alpha, double beta); - void Mat_CopyMakeBorder(Mat src, Mat dst, int top, int bottom, int left, int right, int borderType, - Scalar value); - int Mat_CountNonZero(Mat src); - void Mat_DCT(Mat src, Mat dst, int flags); - double Mat_Determinant(Mat m); - void Mat_DFT(Mat m, Mat dst, int flags); - void Mat_Divide(Mat src1, Mat src2, Mat dst); - bool Mat_Eigen(Mat src, Mat eigenvalues, Mat eigenvectors); - void Mat_EigenNonSymmetric(Mat src, Mat eigenvalues, Mat eigenvectors); - void Mat_PCACompute(Mat src, Mat mean, Mat eigenvectors, Mat eigenvalues, int maxComponents); - void Mat_Exp(Mat src, Mat dst); - void Mat_ExtractChannel(Mat src, Mat dst, int coi); - void Mat_FindNonZero(Mat src, Mat idx); - void Mat_Flip(Mat src, Mat dst, int flipCode); - void Mat_Gemm(Mat src1, Mat src2, double alpha, Mat src3, double beta, Mat dst, int flags); - int Mat_GetOptimalDFTSize(int vecsize); - void Mat_Hconcat(Mat src1, Mat src2, Mat dst); - void Mat_Vconcat(Mat src1, Mat src2, Mat dst); - void Rotate(Mat src, Mat dst, int rotationCode); - void Mat_Idct(Mat src, Mat dst, int flags); - void Mat_Idft(Mat src, Mat dst, int flags, int nonzeroRows); - void Mat_InRange(Mat src, Mat lowerb, Mat upperb, Mat dst); - void Mat_InRangeWithScalar(Mat src, const Scalar lowerb, const Scalar upperb, Mat dst); - void Mat_InsertChannel(Mat src, Mat dst, int coi); - double Mat_Invert(Mat src, Mat dst, int flags); - double KMeans(Mat data, int k, Mat bestLabels, TermCriteria criteria, int attempts, int flags, Mat centers); - double KMeansPoints(PointVector pts, int k, Mat bestLabels, TermCriteria criteria, int attempts, int flags, Mat centers); - void Mat_Log(Mat src, Mat dst); - void Mat_Magnitude(Mat x, Mat y, Mat magnitude); - void Mat_Max(Mat src1, Mat src2, Mat dst); - void Mat_MeanStdDev(Mat src, Mat dstMean, Mat dstStdDev); - void Mat_Merge(struct Mats mats, Mat dst); - void Mat_Min(Mat src1, Mat src2, Mat dst); - void Mat_MinMaxIdx(Mat m, double *minVal, double *maxVal, int *minIdx, int *maxIdx); - void Mat_MinMaxLoc(Mat m, double *minVal, double *maxVal, Point *minLoc, Point *maxLoc); - void Mat_MixChannels(struct Mats src, struct Mats dst, struct IntVector fromTo); - void Mat_MulSpectrums(Mat a, Mat b, Mat c, int flags); - void Mat_Multiply(Mat src1, Mat src2, Mat dst); - void Mat_MultiplyWithParams(Mat src1, Mat src2, Mat dst, double scale, int dtype); - void Mat_Subtract(Mat src1, Mat src2, Mat dst); - void Mat_Normalize(Mat src, Mat dst, double alpha, double beta, int typ); - double Norm(Mat src1, int normType); - double NormWithMats(Mat src1, Mat src2, int normType); - void Mat_PerspectiveTransform(Mat src, Mat dst, Mat tm); - bool Mat_Solve(Mat src1, Mat src2, Mat dst, int flags); - int Mat_SolveCubic(Mat coeffs, Mat roots); - double Mat_SolvePoly(Mat coeffs, Mat roots, int maxIters); - void Mat_Reduce(Mat src, Mat dst, int dim, int rType, int dType); - void Mat_ReduceArgMax(Mat src, Mat dst, int axis, bool lastIndex); - void Mat_ReduceArgMin(Mat src, Mat dst, int axis, bool lastIndex); - void Mat_Repeat(Mat src, int nY, int nX, Mat dst); - void Mat_ScaleAdd(Mat src1, double alpha, Mat src2, Mat dst); - void Mat_SetIdentity(Mat src, double scalar); - void Mat_Sort(Mat src, Mat dst, int flags); - void Mat_SortIdx(Mat src, Mat dst, int flags); - void Mat_Split(Mat src, struct Mats *mats); - void Mat_Subtract(Mat src1, Mat src2, Mat dst); - Scalar Mat_Trace(Mat src); - void Mat_Transform(Mat src, Mat dst, Mat tm); - int Mat_Transpose(Mat src, Mat dst); - void Mat_PolarToCart(Mat magnitude, Mat degree, Mat x, Mat y, bool angleInDegrees); - void Mat_Pow(Mat src, double power, Mat dst); - void Mat_Phase(Mat x, Mat y, Mat angle, bool angleInDegrees); - Scalar Mat_Sum(Mat src1); - - TermCriteria TermCriteria_New(int typ, int maxCount, double epsilon); - - int64_t GetCVTickCount(); - double GetTickFrequency(); - - Mat Mat_rowRange(Mat m, int startrow, int endrow); - Mat Mat_colRange(Mat m, int startrow, int endrow); - - PointVector PointVector_New(); - PointVector PointVector_NewFromPoints(Contour points); - PointVector PointVector_NewFromMat(Mat mat); - Point PointVector_At(PointVector pv, int idx); - void PointVector_Append(PointVector pv, Point p); - int PointVector_Size(PointVector pv); - void PointVector_Close(PointVector pv); - - PointsVector PointsVector_New(); - PointsVector PointsVector_NewFromPoints(Contours points); - PointVector PointsVector_At(PointsVector psv, int idx); - void PointsVector_Append(PointsVector psv, PointVector pv); - int PointsVector_Size(PointsVector psv); - void PointsVector_Close(PointsVector psv); - - Point2fVector Point2fVector_New(); - void Point2fVector_Close(Point2fVector pfv); - Point2fVector Point2fVector_NewFromPoints(Contour2f pts); - Point2fVector Point2fVector_NewFromMat(Mat mat); - void Point2fVector_Append(Point2fVector pv, Point2f p); - Point2f Point2fVector_At(Point2fVector pfv, int idx); - int Point2fVector_Size(Point2fVector pfv); - - // IntVector* IntVector_New(); - void IntVector_Close(struct IntVector ivec); - - // FloatVector* FloatVector_New(); - void FloatVector_Close(struct FloatVector ivec); - - void CStrings_Close(struct CStrings cstrs); - - RNG Rng_New(); - RNG Rng_NewWithState(uint64_t state); - void Rng_Close(RNG rng); - RNG TheRNG(); - - void SetRNGSeed(int seed); - - void RNG_Fill(RNG rng, Mat mat, int distType, double a, double b, bool saturateRange); - - double RNG_Gaussian(RNG rng, double sigma); - int RNG_Uniform(RNG rng, int a, int b); - double RNG_UniformDouble(RNG rng, double a, double b); - - unsigned int RNG_Next(RNG rng); - - void RandN(Mat mat, Scalar mean, Scalar stddev); - - void RandShuffle(Mat mat); - - void RandShuffleWithParams(Mat mat, double iterFactor, RNG rng); - - void RandU(Mat mat, Scalar low, Scalar high); - - void copyPointVectorToPoint2fVector(PointVector src, Point2fVector dest); - - void StdByteVectorInitialize(void *data); - void StdByteVectorFree(void *data); - size_t StdByteVectorLen(void *data); - uint8_t *StdByteVectorData(void *data); - - UCharVector UCharVector_New(); - void UCharVector_Free(UCharVector vec); - int UCharVector_Size(UCharVector vec); - void UCharVector_Append(UCharVector vec, uchar c); - uchar UCharVector_At(UCharVector vec, int idx); - // uchar UCharVector_GetData(UCharVector vec); - - Points2fVector Points2fVector_New(); - Points2fVector Points2fVector_NewFromPoints(Contours2f points); - int Points2fVector_Size(Points2fVector ps); - Point2fVector Points2fVector_At(Points2fVector ps, int idx); - void Points2fVector_Append(Points2fVector psv, Point2fVector pv); - void Points2fVector_Close(Points2fVector ps); - - Point3fVector Point3fVector_New(); - Point3fVector Point3fVector_NewFromPoints(Contour3f points); - Point3fVector Point3fVector_NewFromMat(Mat mat); - void Point3fVector_Append(Point3fVector pfv, Point3f point); - Point3f Point3fVector_At(Point3fVector pfv, int idx); - int Point3fVector_Size(Point3fVector pfv); - void Point3fVector_Close(Point3fVector pv); - Points3fVector Points3fVector_New(); - Points3fVector Points3fVector_NewFromPoints(Contours3f points); - int Points3fVector_Size(Points3fVector ps); - Point3fVector Points3fVector_At(Points3fVector ps, int idx); - void Points3fVector_Append(Points3fVector psv, Point3fVector pv); - void Points3fVector_Close(Points3fVector ps); - - void SetNumThreads(int n); - int GetNumThreads(); +typedef struct CvStatus { + int code; + char *msg; + char *err; + char *func; + char *file; + int line; +} CvStatus; + +InputOutputArray noArray(); +// Wrapper for the vector of Mat aka std::vector +typedef struct Mats { + Mat *mats; + int length; +} Mats; + +CvStatus Mats_New(Mats *rval); +// void Mats_Append(Mats mats, Mat mat); +CvStatus Mats_get(Mats mats, int i, Mat *rval); +CvStatus MultiDMatches_get(MultiDMatches mds, int index, DMatches *rval); + +ByteArray toByteArray(const char *buf, int len); +void ByteArray_Release(ByteArray buf); + +void Contours_Close(Contours cs); +void KeyPoints_Close(KeyPoints ks); +void Rects_Close(Rects rs); +void Mats_Close(Mats mats); +void Point_Close(Point p); +void Point2f_Close(Point2f p); +void Point3f_Close(Point3f p); +void Points_Close(Points ps); +void DMatches_Close(DMatches ds); +void MultiDMatches_Close(MultiDMatches mds); + +CvStatus Mat_New(Mat *rval); +CvStatus Mat_NewWithSize(int rows, int cols, int type, Mat *rval); +CvStatus Mat_NewWithSizes(IntVector sizes, int type, Mat *rval); +CvStatus Mat_NewWithSizesFromScalar(IntVector sizes, int type, Scalar ar, Mat *rval); +CvStatus Mat_NewWithSizesFromBytes(IntVector sizes, int type, ByteArray buf, Mat *rval); +CvStatus Mat_NewFromScalar(const Scalar ar, int type, Mat *rval); +CvStatus Mat_NewWithSizeFromScalar(const Scalar ar, int rows, int cols, int type, Mat *rval); +CvStatus Mat_NewFromBytes(int rows, int cols, int type, ByteArray buf, Mat *rval); +CvStatus Mat_FromPtr(Mat m, int rows, int cols, int type, int prows, int pcols, Mat *rval); +void Mat_Close(Mat m); +CvStatus Mat_Empty(Mat m, bool *rval); +CvStatus Mat_IsContinuous(Mat m, bool *rval); +CvStatus Mat_Clone(Mat m, Mat *rval); +CvStatus Mat_CopyTo(Mat m, Mat dst); +CvStatus Mat_CopyToWithMask(Mat m, Mat dst, Mat mask); +CvStatus Mat_ConvertTo(Mat m, Mat dst, int type); +CvStatus Mat_ConvertToWithParams(Mat m, Mat dst, int type, float alpha, float beta); +CvStatus Mat_ToBytes(Mat m, ByteArray *rval); +CvStatus Mat_DataPtr(Mat m, ByteArray *rval); +CvStatus Mat_Region(Mat m, Rect r, Mat *rval); +CvStatus Mat_Reshape(Mat m, int cn, int rows, Mat *rval); +CvStatus Mat_PatchNaNs(Mat m, double val); +CvStatus Mat_ConvertFp16(Mat m, Mat *rval); +CvStatus Mat_Mean(Mat m, Scalar *rval); +CvStatus Mat_MeanWithMask(Mat m, Mat mask, Scalar *rval); +CvStatus Mat_Sqrt(Mat m, Mat *rval); +CvStatus Mat_Rows(Mat m, int *rval); +CvStatus Mat_Cols(Mat m, int *rval); +CvStatus Mat_Channels(Mat m, int *rval); +CvStatus Mat_Type(Mat m, int *rval); +CvStatus Mat_Step(Mat m, int *rval); +CvStatus Mat_Total(Mat m, int *rval); +CvStatus Mat_Size(Mat m, IntVector *rval); +CvStatus Mat_ElemSize(Mat m, int *rval); +CvStatus Eye(int rows, int cols, int type, Mat *rval); +CvStatus Zeros(int rows, int cols, int type, Mat *rval); +CvStatus Ones(int rows, int cols, int type, Mat *rval); + +#pragma region Mat_getter + +CvStatus Mat_GetUChar(Mat m, int row, int col, uint8_t *rval); +CvStatus Mat_GetUChar3(Mat m, int x, int y, int z, uint8_t *rval); +CvStatus Mat_GetSChar(Mat m, int row, int col, int8_t *rval); +CvStatus Mat_GetSChar3(Mat m, int x, int y, int z, int8_t *rval); +CvStatus Mat_GetUShort(Mat m, int row, int col, uint16_t *rval); +CvStatus Mat_GetUShort3(Mat m, int x, int y, int z, uint16_t *rval); +CvStatus Mat_GetShort(Mat m, int row, int col, int16_t *rval); +CvStatus Mat_GetShort3(Mat m, int x, int y, int z, int16_t *rval); +CvStatus Mat_GetInt(Mat m, int row, int col, int32_t *rval); +CvStatus Mat_GetInt3(Mat m, int x, int y, int z, int32_t *rval); +CvStatus Mat_GetFloat(Mat m, int row, int col); +CvStatus Mat_GetFloat3(Mat m, int x, int y, int z); +CvStatus Mat_GetDouble(Mat m, int row, int col); +CvStatus Mat_GetDouble3(Mat m, int x, int y, int z); + +#pragma endregion + +#pragma region Mat_setter + +CvStatus Mat_SetTo(Mat m, Scalar value); +CvStatus Mat_SetUChar(Mat m, int row, int col, uint8_t val); +CvStatus Mat_SetUChar3(Mat m, int x, int y, int z, uint8_t val); +CvStatus Mat_SetSChar(Mat m, int row, int col, int8_t val); +CvStatus Mat_SetSChar3(Mat m, int x, int y, int z, int8_t val); +CvStatus Mat_SetShort(Mat m, int row, int col, int16_t val); +CvStatus Mat_SetShort3(Mat m, int x, int y, int z, int16_t val); +CvStatus Mat_SetUShort(Mat m, int row, int col, uint16_t val); +CvStatus Mat_SetUShort3(Mat m, int x, int y, int z, uint16_t val); +CvStatus Mat_SetInt(Mat m, int row, int col, int32_t val); +CvStatus Mat_SetInt3(Mat m, int x, int y, int z, int32_t val); +CvStatus Mat_SetFloat(Mat m, int row, int col, float val); +CvStatus Mat_SetFloat3(Mat m, int x, int y, int z, float val); +CvStatus Mat_SetDouble(Mat m, int row, int col, double val); +CvStatus Mat_SetDouble3(Mat m, int x, int y, int z, double val); + +#pragma endregion Mat_setter + +#pragma region Mat_operation + +CvStatus Mat_AddUChar(Mat m, uint8_t val); +CvStatus Mat_SubtractUChar(Mat m, uint8_t val); +CvStatus Mat_MultiplyUChar(Mat m, uint8_t val); +CvStatus Mat_DivideUChar(Mat m, uint8_t val); + +CvStatus Mat_AddI32(Mat m, int32_t val); +CvStatus Mat_SubtractI32(Mat m, int32_t val); +CvStatus Mat_MultiplyI32(Mat m, int32_t val); +CvStatus Mat_DivideI32(Mat m, int32_t val); + +CvStatus Mat_AddFloat(Mat m, float_t val); +CvStatus Mat_SubtractFloat(Mat m, float_t val); +CvStatus Mat_MultiplyFloat(Mat m, float_t val); +CvStatus Mat_DivideFloat(Mat m, float_t val); + +CvStatus Mat_AddF64(Mat m, double_t val); +CvStatus Mat_SubtractF64(Mat m, double_t val); +CvStatus Mat_MultiplyF64(Mat m, double_t val); +CvStatus Mat_DivideF64(Mat m, double_t val); +CvStatus Mat_MultiplyMatrix(Mat x, Mat y, Mat rval); + +CvStatus Mat_T(Mat x, Mat *rval); +CvStatus LUT(Mat src, Mat lut, Mat dst); + +CvStatus Mat_AbsDiff(Mat src1, Mat src2, Mat dst); +CvStatus Mat_Add(Mat src1, Mat src2, Mat dst); +CvStatus Mat_AddWeighted(Mat src1, double alpha, Mat src2, double beta, + double gamma, Mat dst); +CvStatus Mat_BitwiseAnd(Mat src1, Mat src2, Mat dst); +CvStatus Mat_BitwiseAndWithMask(Mat src1, Mat src2, Mat dst, Mat mask); +CvStatus Mat_BitwiseNot(Mat src1, Mat dst); +CvStatus Mat_BitwiseNotWithMask(Mat src1, Mat dst, Mat mask); +CvStatus Mat_BitwiseOr(Mat src1, Mat src2, Mat dst); +CvStatus Mat_BitwiseOrWithMask(Mat src1, Mat src2, Mat dst, Mat mask); +CvStatus Mat_BitwiseXor(Mat src1, Mat src2, Mat dst); +CvStatus Mat_BitwiseXorWithMask(Mat src1, Mat src2, Mat dst, Mat mask); +CvStatus Mat_Compare(Mat src1, Mat src2, Mat dst, int ct); +CvStatus Mat_BatchDistance(Mat src1, Mat src2, Mat dist, int dtype, Mat nidx, + int normType, int K, Mat mask, int update, + bool crosscheck); +CvStatus Mat_BorderInterpolate(int p, int len, int borderType, int *rval); +CvStatus Mat_CalcCovarMatrix(Mat samples, Mat covar, Mat mean, int flags, + int ctype); +CvStatus Mat_CartToPolar(Mat x, Mat y, Mat magnitude, Mat angle, + bool angleInDegrees); +CvStatus Mat_CheckRange(Mat m, bool quiet, Point *pos, double minVal, + double maxVal, bool *rval); +CvStatus Mat_CompleteSymm(Mat m, bool lowerToUpper); +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); +CvStatus Mat_DCT(Mat src, Mat dst, int flags); +CvStatus Mat_Determinant(Mat m, double *rval); +CvStatus Mat_DFT(Mat m, Mat dst, int flags); +CvStatus Mat_Divide(Mat src1, Mat src2, Mat dst); +CvStatus Mat_Eigen(Mat src, Mat eigenvalues, Mat eigenvectors, bool *rval); +CvStatus Mat_EigenNonSymmetric(Mat src, Mat eigenvalues, Mat eigenvectors); +CvStatus Mat_PCACompute(Mat src, Mat mean, Mat eigenvectors, Mat eigenvalues, + int maxComponents); +CvStatus Mat_Exp(Mat src, Mat dst); +CvStatus Mat_ExtractChannel(Mat src, Mat dst, int coi); +CvStatus Mat_FindNonZero(Mat src, Mat idx); +CvStatus Mat_Flip(Mat src, Mat dst, int flipCode); +CvStatus Mat_Gemm(Mat src1, Mat src2, double alpha, Mat src3, double beta, Mat dst, + int flags); +CvStatus Mat_GetOptimalDFTSize(int vecsize, int *rval); +CvStatus Mat_Hconcat(Mat src1, Mat src2, Mat dst); +CvStatus Mat_Vconcat(Mat src1, Mat src2, Mat dst); +CvStatus Rotate(Mat src, Mat dst, int rotationCode); +CvStatus Mat_Idct(Mat src, Mat dst, int flags); +CvStatus Mat_Idft(Mat src, Mat dst, int flags, int nonzeroRows); +CvStatus Mat_InRange(Mat src, Mat lowerb, Mat upperb, Mat dst); +CvStatus Mat_InRangeWithScalar(Mat src, const Scalar lowerb, const Scalar upperb, + Mat dst); +CvStatus Mat_InsertChannel(Mat src, Mat dst, int coi); +CvStatus Mat_Invert(Mat src, Mat dst, int flags, double *rval); +CvStatus KMeans(Mat data, int k, Mat bestLabels, TermCriteria criteria, + int attempts, int flags, Mat centers, double *rval); +CvStatus KMeansPoints(PointVector pts, int k, Mat bestLabels, + TermCriteria criteria, int attempts, int flags, + Mat centers, double *rval); +CvStatus Mat_Log(Mat src, Mat dst); +CvStatus Mat_Magnitude(Mat x, Mat y, Mat magnitude); +CvStatus Mat_Max(Mat src1, Mat src2, Mat dst); +CvStatus Mat_MeanStdDev(Mat src, Mat dstMean, Mat dstStdDev); +CvStatus Mat_Merge(Mats mats, Mat dst); +CvStatus Mat_Min(Mat src1, Mat src2, Mat dst); +CvStatus Mat_MinMaxIdx(Mat m, double *minVal, double *maxVal, int *minIdx, + int *maxIdx); +CvStatus Mat_MinMaxLoc(Mat m, double *minVal, double *maxVal, Point *minLoc, + Point *maxLoc); +CvStatus Mat_MixChannels(Mats src, Mats dst, IntVector fromTo); +CvStatus Mat_MulSpectrums(Mat a, Mat b, Mat c, int flags); +CvStatus Mat_Multiply(Mat src1, Mat src2, Mat dst); +CvStatus Mat_MultiplyWithParams(Mat src1, Mat src2, Mat dst, double scale, + int dtype); +CvStatus Mat_Normalize(Mat src, Mat dst, double alpha, double beta, int typ); +CvStatus Norm(Mat src1, int normType, double *rval); +CvStatus NormWithMats(Mat src1, Mat src2, int normType, double *rval); +CvStatus Mat_PerspectiveTransform(Mat src, Mat dst, Mat tm); +CvStatus Mat_Solve(Mat src1, Mat src2, Mat dst, int flags, bool *rval); +CvStatus Mat_SolveCubic(Mat coeffs, Mat roots, int *rval); +CvStatus Mat_SolvePoly(Mat coeffs, Mat roots, int maxIters, double *rval); +CvStatus Mat_Reduce(Mat src, Mat dst, int dim, int rType, int dType); +CvStatus Mat_ReduceArgMax(Mat src, Mat dst, int axis, bool lastIndex); +CvStatus Mat_ReduceArgMin(Mat src, Mat dst, int axis, bool lastIndex); +CvStatus Mat_Repeat(Mat src, int nY, int nX, Mat dst); +CvStatus Mat_ScaleAdd(Mat src1, double alpha, Mat src2, Mat dst); +CvStatus Mat_SetIdentity(Mat src, double scalar); +CvStatus Mat_Sort(Mat src, Mat dst, int flags); +CvStatus Mat_SortIdx(Mat src, Mat dst, int flags); +CvStatus Mat_Split(Mat src, Mats *mats); +CvStatus Mat_Subtract(Mat src1, Mat src2, Mat dst); +CvStatus Mat_Trace(Mat src, Scalar *rval); +CvStatus Mat_Transform(Mat src, Mat dst, Mat tm); +CvStatus Mat_Transpose(Mat src, Mat dst); +CvStatus Mat_PolarToCart(Mat magnitude, Mat degree, Mat x, Mat y, + bool angleInDegrees); +CvStatus Mat_Pow(Mat src, double power, Mat dst); +CvStatus Mat_Phase(Mat x, Mat y, Mat angle, bool angleInDegrees); +CvStatus Mat_Sum(Mat src1, Scalar *rval); + +#pragma endregion + +TermCriteria TermCriteria_New(int typ, int maxCount, double epsilon); + +int64_t GetCVTickCount(); +double GetTickFrequency(); + +Mat Mat_rowRange(Mat m, int startrow, int endrow); +Mat Mat_colRange(Mat m, int startrow, int endrow); + +PointVector PointVector_New(); +PointVector PointVector_NewFromPoints(Contour points); +PointVector PointVector_NewFromMat(Mat mat); +Point PointVector_At(PointVector pv, int idx); +void PointVector_Append(PointVector pv, Point p); +int PointVector_Size(PointVector pv); +void PointVector_Close(PointVector pv); + +PointsVector PointsVector_New(); +PointsVector PointsVector_NewFromPoints(Contours points); +PointVector PointsVector_At(PointsVector psv, int idx); +void PointsVector_Append(PointsVector psv, PointVector pv); +int PointsVector_Size(PointsVector psv); +void PointsVector_Close(PointsVector psv); + +Point2fVector Point2fVector_New(); +void Point2fVector_Close(Point2fVector pfv); +Point2fVector Point2fVector_NewFromPoints(Contour2f pts); +Point2fVector Point2fVector_NewFromMat(Mat mat); +void Point2fVector_Append(Point2fVector pv, Point2f p); +Point2f Point2fVector_At(Point2fVector pfv, int idx); +int Point2fVector_Size(Point2fVector pfv); + +// IntVector* IntVector_New(); +void IntVector_Close(IntVector ivec); + +// FloatVector* FloatVector_New(); +void FloatVector_Close(FloatVector ivec); + +void CStrings_Close(CStrings cstrs); + +RNG Rng_New(); +RNG Rng_NewWithState(uint64_t state); +void Rng_Close(RNG rng); +RNG TheRNG(); + +void SetRNGSeed(int seed); + +void RNG_Fill(RNG rng, Mat mat, int distType, double a, double b, + bool saturateRange); + +double RNG_Gaussian(RNG rng, double sigma); +int RNG_Uniform(RNG rng, int a, int b); +double RNG_UniformDouble(RNG rng, double a, double b); + +unsigned int RNG_Next(RNG rng); + +void RandN(Mat mat, Scalar mean, Scalar stddev); + +void RandShuffle(Mat mat); + +void RandShuffleWithParams(Mat mat, double iterFactor, RNG rng); + +void RandU(Mat mat, Scalar low, Scalar high); + +void copyPointVectorToPoint2fVector(PointVector src, Point2fVector dest); + +void StdByteVectorInitialize(void *data); +void StdByteVectorFree(void *data); +size_t StdByteVectorLen(void *data); +uint8_t *StdByteVectorData(void *data); + +UCharVector UCharVector_New(); +void UCharVector_Free(UCharVector vec); +int UCharVector_Size(UCharVector vec); +void UCharVector_Append(UCharVector vec, uchar c); +uchar UCharVector_At(UCharVector vec, int idx); +// uchar UCharVector_GetData(UCharVector vec); + +Points2fVector Points2fVector_New(); +Points2fVector Points2fVector_NewFromPoints(Contours2f points); +int Points2fVector_Size(Points2fVector ps); +Point2fVector Points2fVector_At(Points2fVector ps, int idx); +void Points2fVector_Append(Points2fVector psv, Point2fVector pv); +void Points2fVector_Close(Points2fVector ps); + +Point3fVector Point3fVector_New(); +Point3fVector Point3fVector_NewFromPoints(Contour3f points); +Point3fVector Point3fVector_NewFromMat(Mat mat); +void Point3fVector_Append(Point3fVector pfv, Point3f point); +Point3f Point3fVector_At(Point3fVector pfv, int idx); +int Point3fVector_Size(Point3fVector pfv); +void Point3fVector_Close(Point3fVector pv); +Points3fVector Points3fVector_New(); +Points3fVector Points3fVector_NewFromPoints(Contours3f points); +int Points3fVector_Size(Points3fVector ps); +Point3fVector Points3fVector_At(Points3fVector ps, int idx); +void Points3fVector_Append(Points3fVector psv, Point3fVector pv); +void Points3fVector_Close(Points3fVector ps); + +void SetNumThreads(int n); +int GetNumThreads(); #ifdef __cplusplus } diff --git a/src/gapi.cpp b/src/gapi.cpp new file mode 100644 index 00000000..88b532a5 --- /dev/null +++ b/src/gapi.cpp @@ -0,0 +1,19 @@ +#include "gapi.h" + +CvStatus GMat_New_Empty(GMat* rval){ + BEGIN_WRAP + *rval = new cv::GMat(); + END_WRAP +} + +CvStatus GMat_New_FromMat(Mat mat, GMat* rval){ + BEGIN_WRAP + *rval = new cv::GMat(*mat); + END_WRAP +} + +CvStatus GMat_Close(GMat mat){ + BEGIN_WRAP + delete mat; + END_WRAP +} diff --git a/src/gapi.h b/src/gapi.h new file mode 100644 index 00000000..22acfee7 --- /dev/null +++ b/src/gapi.h @@ -0,0 +1,33 @@ +/* + Created by Rainyl. + Licensed: Apache 2.0 license. Copyright (c) 2024 Rainyl. +*/ + +#ifndef OPENCV_DART_GAPI_H +#define OPENCV_DART_GAPI_H + +#include "core.h" + +#ifdef __cplusplus +#include +#include +#include +extern "C" +{ +#endif + +#ifdef __cplusplus + typedef cv::GMat *GMat; +#else +typedef void *GMat; +#endif + + CvStatus GMat_New_Empty(GMat *rval); + CvStatus GMat_New_FromMat(Mat mat, GMat *rval); + CvStatus GMat_Close(GMat mat); + +#ifdef __cplusplus +} +#endif + +#endif // OPENCV_DART_GAPI_H \ No newline at end of file