Skip to content

Commit

Permalink
init - export global and class methods
Browse files Browse the repository at this point in the history
  • Loading branch information
justadudewhohacks committed Jun 11, 2019
1 parent 4f9792d commit 82d9b01
Show file tree
Hide file tree
Showing 19 changed files with 314 additions and 177 deletions.
14 changes: 14 additions & 0 deletions cc/CvBinding.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,18 @@ class CvBinding : public FF::BindingBase, public FF::ISyncWorker, public FF::IAs
std::function<void(void)> executeBinding = [](){};
};

template<class TClass>
class CvClassMethodBinding : public CvBinding {
public:
void setup() {
createBinding(req<TClass::Converter>());
}

void setup(typename TClass::Converter::Type self) {
createBinding(std::make_shared<FF::Value<TClass::Converter::Type>>(self));
}

virtual void createBinding(std::shared_ptr<FF::Value<typename TClass::Converter::Type>> self) = 0;
};

#endif
82 changes: 42 additions & 40 deletions cc/core/Mat.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include "MatImgproc.h"
#include "MatCalib3d.h"
#include "MatBindings.h"
#include "CoreBindings.h"

#ifdef HAVE_XIMGPROC
#include "MatXimgproc.h"
Expand Down Expand Up @@ -60,14 +61,6 @@ NAN_MODULE_INIT(Mat::Init) {
Nan::SetPrototypeMethod(ctor, "splitAsync", SplitChannelsAsync);
Nan::SetPrototypeMethod(ctor, "splitChannels", SplitChannels);
Nan::SetPrototypeMethod(ctor, "splitChannelsAsync", SplitChannelsAsync);
Nan::SetPrototypeMethod(ctor, "addWeighted", AddWeighted);
Nan::SetPrototypeMethod(ctor, "addWeightedAsync", AddWeightedAsync);
Nan::SetPrototypeMethod(ctor, "minMaxLoc", MinMaxLoc);
Nan::SetPrototypeMethod(ctor, "minMaxLocAsync", MinMaxLocAsync);
Nan::SetPrototypeMethod(ctor, "findNonZero", FindNonZero);
Nan::SetPrototypeMethod(ctor, "findNonZeroAsync", FindNonZeroAsync);
Nan::SetPrototypeMethod(ctor, "countNonZero", CountNonZero);
Nan::SetPrototypeMethod(ctor, "countNonZeroAsync", CountNonZeroAsync);
Nan::SetPrototypeMethod(ctor, "padToSquare", PadToSquare);
Nan::SetPrototypeMethod(ctor, "padToSquareAsync", PadToSquareAsync);
Nan::SetPrototypeMethod(ctor, "dct", Dct);
Expand Down Expand Up @@ -112,6 +105,15 @@ NAN_MODULE_INIT(Mat::Init) {

Nan::SetPrototypeMethod(ctor, "release", Release);

Nan::SetPrototypeMethod(ctor, "addWeighted", AddWeighted);
Nan::SetPrototypeMethod(ctor, "addWeightedAsync", AddWeightedAsync);
Nan::SetPrototypeMethod(ctor, "minMaxLoc", MinMaxLoc);
Nan::SetPrototypeMethod(ctor, "minMaxLocAsync", MinMaxLocAsync);
Nan::SetPrototypeMethod(ctor, "findNonZero", FindNonZero);
Nan::SetPrototypeMethod(ctor, "findNonZeroAsync", FindNonZeroAsync);
Nan::SetPrototypeMethod(ctor, "countNonZero", CountNonZero);
Nan::SetPrototypeMethod(ctor, "countNonZeroAsync", CountNonZeroAsync);


FF_PROTO_SET_MAT_OPERATIONS(ctor);

Expand Down Expand Up @@ -514,38 +516,6 @@ NAN_METHOD(Mat::SplitChannelsAsync) {
Mat::asyncBinding<MatBindings::SplitChannels>("SplitChannels", info);
}

NAN_METHOD(Mat::AddWeighted) {
Mat::syncBinding<MatBindings::AddWeighted>("AddWeighted", info);
}

NAN_METHOD(Mat::AddWeightedAsync) {
Mat::asyncBinding<MatBindings::AddWeighted>("AddWeighted", info);
}

NAN_METHOD(Mat::MinMaxLoc) {
Mat::syncBinding<MatBindings::MinMaxLoc>("MinMaxLoc", info);
}

NAN_METHOD(Mat::MinMaxLocAsync) {
Mat::asyncBinding<MatBindings::MinMaxLoc>("MinMaxLoc", info);
}

NAN_METHOD(Mat::FindNonZero) {
Mat::syncBinding<MatBindings::FindNonZero>("FindNonZero", info);
}

NAN_METHOD(Mat::FindNonZeroAsync) {
Mat::asyncBinding<MatBindings::FindNonZero>("FindNonZero", info);
}

NAN_METHOD(Mat::CountNonZero) {
Mat::syncBinding<MatBindings::CountNonZero>("CountNonZero", info);
}

NAN_METHOD(Mat::CountNonZeroAsync) {
Mat::asyncBinding<MatBindings::CountNonZero>("CountNonZero", info);
}

NAN_METHOD(Mat::PadToSquare) {
Mat::syncBinding<MatBindings::PadToSquare>("PadToSquare", info);
}
Expand Down Expand Up @@ -779,3 +749,35 @@ NAN_METHOD(Mat::RotateAsync) {
);
}
#endif

NAN_METHOD(Mat::AddWeighted) {
Mat::syncBinding<CoreBindings::AddWeighted>("AddWeighted", info);
}

NAN_METHOD(Mat::AddWeightedAsync) {
Mat::asyncBinding<CoreBindings::AddWeighted>("AddWeighted", info);
}

NAN_METHOD(Mat::MinMaxLoc) {
Mat::syncBinding<CoreBindings::MinMaxLoc>("MinMaxLoc", info);
}

NAN_METHOD(Mat::MinMaxLocAsync) {
Mat::asyncBinding<CoreBindings::MinMaxLoc>("MinMaxLoc", info);
}

NAN_METHOD(Mat::FindNonZero) {
Mat::syncBinding<CoreBindings::FindNonZero>("FindNonZero", info);
}

NAN_METHOD(Mat::FindNonZeroAsync) {
Mat::asyncBinding<CoreBindings::FindNonZero>("FindNonZero", info);
}

NAN_METHOD(Mat::CountNonZero) {
Mat::syncBinding<CoreBindings::CountNonZero>("CountNonZero", info);
}

NAN_METHOD(Mat::CountNonZeroAsync) {
Mat::asyncBinding<CoreBindings::CountNonZero>("CountNonZero", info);
}
21 changes: 11 additions & 10 deletions cc/core/Mat.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,16 +79,6 @@ class Mat : public FF::ObjectWrap<Mat, cv::Mat> {
static NAN_METHOD(ConvertToAsync);
static NAN_METHOD(SplitChannels);
static NAN_METHOD(SplitChannelsAsync);
static NAN_METHOD(AddWeighted);
static NAN_METHOD(AddWeightedAsync);
static NAN_METHOD(MinMaxLoc);
static NAN_METHOD(MinMaxLocAsync);
static NAN_METHOD(FindNonZero);
static NAN_METHOD(FindNonZeroAsync);
static NAN_METHOD(CountNonZero);
static NAN_METHOD(CountNonZeroAsync);
static NAN_METHOD(PadToSquare);
static NAN_METHOD(PadToSquareAsync);
static NAN_METHOD(Dct);
static NAN_METHOD(DctAsync);
static NAN_METHOD(Idct);
Expand Down Expand Up @@ -129,6 +119,17 @@ class Mat : public FF::ObjectWrap<Mat, cv::Mat> {
static NAN_METHOD(RotateAsync);
#endif

static NAN_METHOD(AddWeighted);
static NAN_METHOD(AddWeightedAsync);
static NAN_METHOD(MinMaxLoc);
static NAN_METHOD(MinMaxLocAsync);
static NAN_METHOD(FindNonZero);
static NAN_METHOD(FindNonZeroAsync);
static NAN_METHOD(CountNonZero);
static NAN_METHOD(CountNonZeroAsync);
static NAN_METHOD(PadToSquare);
static NAN_METHOD(PadToSquareAsync);

};

#endif
87 changes: 17 additions & 70 deletions cc/core/MatBindings.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ namespace MatBindings {

class PushBack : public CvBinding {
public:
PushBack(cv::Mat self) {
void setup(cv::Mat self) {
auto mat = req<Mat::Converter>();
auto res = ret<Mat::Converter>("res", self);
executeBinding = [=]() {
Expand All @@ -82,7 +82,7 @@ namespace MatBindings {

class PopBack : public CvBinding {
public:
PopBack(cv::Mat self) {
void setup(cv::Mat self) {
auto num = opt<FF::IntConverter>("num", 1);
auto res = ret<Mat::Converter>("res", self);
executeBinding = [=]() {
Expand Down Expand Up @@ -128,7 +128,7 @@ namespace MatBindings {

class Copy : public CvBinding {
public:
Copy(cv::Mat self) {
void setup(cv::Mat self) {
auto mask = opt<Mat::Converter>("mask", cv::noArray().getMat());
auto dst = ret<Mat::Converter>("dst");

Expand All @@ -140,7 +140,7 @@ namespace MatBindings {

class CopyTo : public CvBinding {
public:
CopyTo(cv::Mat self) {
void setup(cv::Mat self) {
auto dst = req<Mat::Converter>();
auto mask = opt<Mat::Converter>("mask", cv::noArray().getMat());
auto dstRet = ret<Mat::Converter>("dst");
Expand All @@ -154,7 +154,7 @@ namespace MatBindings {

class ConvertTo : public CvBinding {
public:
ConvertTo(cv::Mat self) {
void setup(cv::Mat self) {
auto rtype = req<FF::IntConverter>();
auto alpha = opt<FF::DoubleConverter>("alpha", 1.0);
auto beta = opt<FF::DoubleConverter>("beta", 0.0);
Expand All @@ -168,7 +168,7 @@ namespace MatBindings {

class SplitChannels : public CvBinding {
public:
SplitChannels(cv::Mat self) {
void setup(cv::Mat self) {
auto mv = ret<Mat::ArrayConverter>("mv");

executeBinding = [=]() {
Expand All @@ -177,63 +177,9 @@ namespace MatBindings {
};
};

class AddWeighted : public CvBinding {
public:
AddWeighted(cv::Mat self) {

auto alpha = req<FF::DoubleConverter>();
auto src2 = req<Mat::Converter>();
auto beta = req<FF::DoubleConverter>();
auto gamma = req<FF::DoubleConverter>();
auto dtype = opt<FF::IntConverter>("dtype" , -1);
auto dst = ret<Mat::Converter>("dst");

executeBinding = [=]() {
cv::addWeighted(self, alpha->ref(), src2->ref(), beta->ref(), gamma->ref(), dst->ref(), dtype->ref());
};
};
};

class MinMaxLoc : public CvBinding {
public:
MinMaxLoc(cv::Mat self) {
auto mask = opt<Mat::Converter>("mask", cv::noArray().getMat());
auto minVal = ret<FF::DoubleConverter>("minVal");
auto maxVal = ret<FF::DoubleConverter>("maxVal");
auto minLoc = ret<Point2::WithCastConverter<cv::Point2i>>("minLoc");
auto maxLoc = ret<Point2::WithCastConverter<cv::Point2i>>("maxLoc");

executeBinding = [=]() {
cv::minMaxLoc(self, minVal->ptr(), maxVal->ptr(), minLoc->ptr(), maxLoc->ptr(), mask->ref());
};
};
};

class FindNonZero : public CvBinding {
public:
FindNonZero(cv::Mat self) {
auto idx = ret<Point2::ArrayWithCastConverter<cv::Point2i>>("idx");

executeBinding = [=]() {
cv::findNonZero(self, idx->ref());
};
};
};

class CountNonZero : public CvBinding {
public:
CountNonZero(cv::Mat self) {
auto num = ret<FF::IntConverter>("num");

executeBinding = [=]() {
num->ref() = cv::countNonZero(self);
};
};
};

class PadToSquare : public CvBinding {
public:
PadToSquare(cv::Mat self) {
void setup(cv::Mat self) {
auto fillVec = opt<Vec3::Converter>("fillVec", cv::Vec3d());
auto out = ret<Mat::Converter>("out");

Expand Down Expand Up @@ -461,7 +407,8 @@ namespace MatBindings {
public:
int channels;
cv::Scalar sum;
Sum(cv::Mat self): channels(self.channels()) {
void setup(cv::Mat self) {
channels = self.channels();
executeBinding = [=]() {
sum = cv::sum(self);
};
Expand All @@ -485,7 +432,7 @@ namespace MatBindings {

class ConvertScaleAbs : public CvBinding {
public:
ConvertScaleAbs(cv::Mat self) {
void setup(cv::Mat self) {
auto alpha = opt<FF::DoubleConverter>("alpha", 1);
auto beta = opt<FF::DoubleConverter>("beta", 0);
auto dst = ret<Mat::Converter>("dst");
Expand All @@ -498,7 +445,7 @@ namespace MatBindings {

class GoodFeaturesToTrack : public CvBinding {
public:
GoodFeaturesToTrack(cv::Mat self) {
void setup(cv::Mat self) {
auto maxCorners = req<FF::IntConverter>();
auto qualityLevel = req<FF::DoubleConverter>();
auto minDistance = req<FF::DoubleConverter>();
Expand All @@ -524,7 +471,7 @@ namespace MatBindings {

class Mean : public CvBinding {
public:
Mean(cv::Mat self) {
void setup(cv::Mat self) {
auto mask = opt<Mat::Converter>("mask", cv::noArray().getMat());
auto mean = ret<Vec4::Converter>("mean");

Expand All @@ -536,7 +483,7 @@ namespace MatBindings {

class MeanStdDev : public CvBinding {
public:
MeanStdDev(cv::Mat self) {
void setup(cv::Mat self) {
auto mask = opt<Mat::Converter>("mask", cv::noArray().getMat());
auto mean = ret<Mat::Converter>("mean");
auto stddev = ret<Mat::Converter>("stddev");
Expand Down Expand Up @@ -619,7 +566,7 @@ namespace MatBindings {

class Reduce : public CvBinding {
public:
Reduce(cv::Mat self) {
void setup(cv::Mat self) {
auto dim = req<FF::IntConverter>();
auto rtype = req<FF::IntConverter>();
auto dtype = opt<FF::IntConverter>("dtype", -1);
Expand All @@ -633,7 +580,7 @@ namespace MatBindings {

class Eigen : public CvBinding {
public:
Eigen(cv::Mat self) {
void setup(cv::Mat self) {
auto eigenvalues = ret<Mat::Converter>("eigenvalues");

executeBinding = [=]() {
Expand All @@ -644,7 +591,7 @@ namespace MatBindings {

class Solve : public CvBinding {
public:
Solve(cv::Mat self) {
void setup(cv::Mat self) {
auto mat2 = req<Mat::Converter>();
auto flags = opt<FF::IntConverter>("flags", 0);
auto dst = ret<Mat::Converter>("dst");
Expand All @@ -657,7 +604,7 @@ namespace MatBindings {

class Normalize : public CvBinding {
public:
Normalize(cv::Mat self) {
void setup(cv::Mat self) {
auto alpha = opt<FF::DoubleConverter>("alpha", 1);
auto beta = opt<FF::DoubleConverter>("beta", 0);
auto normType = opt<FF::IntConverter>("normType", cv::NORM_L2);
Expand Down
2 changes: 1 addition & 1 deletion cc/core/MatCalib3dBindings.h
Original file line number Diff line number Diff line change
Expand Up @@ -812,7 +812,7 @@ namespace MatCalib3dBindings {
// since 4.0.0 cv::undistort has been moved from imgproc to calib3d
class Undistort : public CvBinding {
public:
Undistort(cv::Mat self) {
void setup(cv::Mat self) {
auto cameraMatrix = req<Mat::Converter>();
auto distCoeffs = req<Mat::Converter>();
auto undistortedMat = ret<Mat::Converter>("undistortedMat");
Expand Down
Loading

0 comments on commit 82d9b01

Please sign in to comment.