Skip to content

Commit dbafbd0

Browse files
committed
Use CvClassMethodBinding instead of CatchCvExceptionWorker for SeamlessClone, add seamlessClone bindings for Mat
1 parent 98c6100 commit dbafbd0

File tree

6 files changed

+58
-41
lines changed

6 files changed

+58
-41
lines changed

binding.gyp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
"cc/io/VideoWriter.cc",
4242
"cc/photo/photo.cc",
4343
"cc/photo/photoConstants.cc",
44+
"cc/photo/MatPhoto.cc",
4445
"cc/video/video.cc",
4546
"cc/video/BackgroundSubtractor.cc",
4647
"cc/video/BackgroundSubtractorMOG2.cc",

cc/core/Mat.cc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
#ifdef HAVE_OPENCV_IMGPROC
1010
#include "../imgproc/MatImgproc.h"
1111
#endif
12+
#ifdef HAVE_OPENCV_PHOTO
13+
#include "../photo/MatPhoto.h"
14+
#endif
1215
#ifdef HAVE_OPENCV_XIMGPROC
1316
#include "../ximgproc/MatXimgproc.h"
1417
#endif
@@ -126,6 +129,9 @@ NAN_MODULE_INIT(Mat::Init) {
126129
#ifdef HAVE_OPENCV_IMGPROC
127130
MatImgproc::Init(ctor);
128131
#endif
132+
#ifdef HAVE_OPENCV_PHOTO
133+
MatPhoto::Init(ctor);
134+
#endif
129135
#ifdef HAVE_OPENCV_XIMGPROC
130136
MatXimgproc::Init(ctor);
131137
#endif

cc/photo/MatPhoto.cc

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#include "opencv_modules.h"
2+
3+
#ifdef HAVE_OPENCV_PHOTO
4+
5+
#include "MatPhoto.h"
6+
#include "photoBindings.h"
7+
8+
void MatPhoto::Init(v8::Local<v8::FunctionTemplate> ctor) {
9+
Nan::SetPrototypeMethod(ctor, "seamlessClone", SeamlessClone);
10+
Nan::SetPrototypeMethod(ctor, "seamlessCloneAsync", SeamlessCloneAsync);
11+
};
12+
13+
NAN_METHOD(MatPhoto::SeamlessClone) {
14+
Mat::syncBinding<PhotoBindings::SeamlessClone>("SeamlessClone", info);
15+
}
16+
17+
NAN_METHOD(MatPhoto::SeamlessCloneAsync) {
18+
Mat::asyncBinding<PhotoBindings::SeamlessClone>("SeamlessClone", info);
19+
}
20+
21+
#endif

cc/photo/MatPhoto.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#include "Mat.h"
2+
#include <opencv2/photo.hpp>
3+
4+
#ifndef __FF_MATPHOTO_H__
5+
#define __FF_MATPHOTO_H__
6+
7+
class MatPhoto {
8+
public:
9+
static void Init(v8::Local<v8::FunctionTemplate> ctor);
10+
11+
static NAN_METHOD(SeamlessClone);
12+
static NAN_METHOD(SeamlessCloneAsync);
13+
};
14+
15+
#endif

cc/photo/photo.cc

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -49,19 +49,11 @@ NAN_METHOD(Photo::InpaintAsync) {
4949
}
5050

5151
NAN_METHOD(Photo::SeamlessClone) {
52-
FF::executeSyncBinding(
53-
std::make_shared<PhotoBindings::SeamlessCloningWorker>(),
54-
"Photo::SeamlessClone",
55-
info
56-
);
52+
FF::syncBinding<PhotoBindings::SeamlessClone>("Photo", "SeamlessClone", info);
5753
}
5854

5955
NAN_METHOD(Photo::SeamlessCloneAsync) {
60-
FF::executeAsyncBinding(
61-
std::make_shared<PhotoBindings::SeamlessCloningWorker>(),
62-
"Photo::SeamlessCloneAsync",
63-
info
64-
);
56+
FF::asyncBinding<PhotoBindings::SeamlessClone>("Photo", "SeamlessClone", info);
6557
}
6658

6759
#endif

cc/photo/photoBindings.h

Lines changed: 13 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#include "CvBinding.h"
12
#include "photo.h"
23

34
#ifndef __FF_PHOTOBINDINGS_H_
@@ -87,38 +88,19 @@ namespace PhotoBindings {
8788
}
8889
};
8990

90-
struct SeamlessCloningWorker : public CatchCvExceptionWorker {
91+
class SeamlessClone : public CvClassMethodBinding<Mat> {
9192
public:
92-
// required function arguments
93-
cv::Mat src;
94-
cv::Mat dst;
95-
cv::Mat mask;
96-
cv::Point2d p;
97-
int flags;
98-
99-
// return value
100-
cv::Mat blend;
101-
102-
bool unwrapRequiredArgs(Nan::NAN_METHOD_ARGS_TYPE info) {
103-
return (
104-
Mat::Converter::arg(0, &src, info) ||
105-
Mat::Converter::arg(1, &dst, info) ||
106-
Mat::Converter::arg(2, &mask, info) ||
107-
Point2::Converter::arg(3, &p, info) ||
108-
FF::IntConverter::arg(4, &flags, info)
109-
);
110-
}
111-
112-
std::string executeCatchCvExceptionWorker() {
113-
cv::seamlessClone(
114-
src, dst, mask, p, blend, flags
115-
);
116-
return "";
117-
}
118-
119-
v8::Local<v8::Value> getReturnValue() {
120-
return Mat::Converter::wrap(blend);
121-
}
93+
void createBinding(std::shared_ptr<FF::Value<cv::Mat>> self) {
94+
auto dst = req<Mat::Converter>();
95+
auto mask = req<Mat::Converter>();
96+
auto p = req<Point2::Converter>();
97+
auto flags = req<FF::IntConverter>();
98+
auto blend = ret<Mat::Converter>("blend");
99+
100+
executeBinding = [=]() {
101+
cv::seamlessClone(self->ref(), dst->ref(), mask->ref(), p->ref(), blend->ref(), flags->ref());
102+
};
103+
};
122104
};
123105

124106
}

0 commit comments

Comments
 (0)