Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions binding.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
"cc/io/VideoWriter.cc",
"cc/photo/photo.cc",
"cc/photo/photoConstants.cc",
"cc/photo/MatPhoto.cc",
"cc/video/video.cc",
"cc/video/BackgroundSubtractor.cc",
"cc/video/BackgroundSubtractorMOG2.cc",
Expand Down
6 changes: 6 additions & 0 deletions cc/core/Mat.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
#ifdef HAVE_OPENCV_IMGPROC
#include "../imgproc/MatImgproc.h"
#endif
#ifdef HAVE_OPENCV_PHOTO
#include "../photo/MatPhoto.h"
#endif
#ifdef HAVE_OPENCV_XIMGPROC
#include "../ximgproc/MatXimgproc.h"
#endif
Expand Down Expand Up @@ -126,6 +129,9 @@ NAN_MODULE_INIT(Mat::Init) {
#ifdef HAVE_OPENCV_IMGPROC
MatImgproc::Init(ctor);
#endif
#ifdef HAVE_OPENCV_PHOTO
MatPhoto::Init(ctor);
#endif
#ifdef HAVE_OPENCV_XIMGPROC
MatXimgproc::Init(ctor);
#endif
Expand Down
21 changes: 21 additions & 0 deletions cc/photo/MatPhoto.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#include "opencv_modules.h"

#ifdef HAVE_OPENCV_PHOTO

#include "MatPhoto.h"
#include "photoBindings.h"

void MatPhoto::Init(v8::Local<v8::FunctionTemplate> ctor) {
Nan::SetPrototypeMethod(ctor, "seamlessClone", SeamlessClone);
Nan::SetPrototypeMethod(ctor, "seamlessCloneAsync", SeamlessCloneAsync);
};

NAN_METHOD(MatPhoto::SeamlessClone) {
Mat::syncBinding<PhotoBindings::SeamlessClone>("SeamlessClone", info);
}

NAN_METHOD(MatPhoto::SeamlessCloneAsync) {
Mat::asyncBinding<PhotoBindings::SeamlessClone>("SeamlessClone", info);
}

#endif
15 changes: 15 additions & 0 deletions cc/photo/MatPhoto.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#include "Mat.h"
#include <opencv2/photo.hpp>

#ifndef __FF_MATPHOTO_H__
#define __FF_MATPHOTO_H__

class MatPhoto {
public:
static void Init(v8::Local<v8::FunctionTemplate> ctor);

static NAN_METHOD(SeamlessClone);
static NAN_METHOD(SeamlessCloneAsync);
};

#endif
10 changes: 10 additions & 0 deletions cc/photo/photo.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ NAN_MODULE_INIT(Photo::Init) {
Nan::SetMethod(target, "fastNlMeansDenoisingColoredAsync", FastNlMeansDenoisingColoredAsync);
Nan::SetMethod(target, "inpaint", Inpaint);
Nan::SetMethod(target, "inpaintAsync", InpaintAsync);
Nan::SetMethod(target, "seamlessClone", SeamlessClone);
Nan::SetMethod(target, "seamlessCloneAsync", SeamlessCloneAsync);
};

NAN_METHOD(Photo::FastNlMeansDenoisingColored) {
Expand Down Expand Up @@ -46,4 +48,12 @@ NAN_METHOD(Photo::InpaintAsync) {
);
}

NAN_METHOD(Photo::SeamlessClone) {
FF::syncBinding<PhotoBindings::SeamlessClone>("Photo", "SeamlessClone", info);
}

NAN_METHOD(Photo::SeamlessCloneAsync) {
FF::asyncBinding<PhotoBindings::SeamlessClone>("Photo", "SeamlessClone", info);
}

#endif
2 changes: 2 additions & 0 deletions cc/photo/photo.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ class Photo {
static NAN_METHOD(FastNlMeansDenoisingColoredAsync);
static NAN_METHOD(Inpaint);
static NAN_METHOD(InpaintAsync);
static NAN_METHOD(SeamlessClone);
static NAN_METHOD(SeamlessCloneAsync);
};

#endif
17 changes: 16 additions & 1 deletion cc/photo/photoBindings.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include "CvBinding.h"
#include "photo.h"

#ifndef __FF_PHOTOBINDINGS_H_
Expand Down Expand Up @@ -86,7 +87,21 @@ namespace PhotoBindings {
return Mat::Converter::wrap(dst);
}
};


class SeamlessClone : public CvClassMethodBinding<Mat> {
public:
void createBinding(std::shared_ptr<FF::Value<cv::Mat>> self) {
auto dst = req<Mat::Converter>();
auto mask = req<Mat::Converter>();
auto p = req<Point2::Converter>();
auto flags = req<FF::IntConverter>();
auto blend = ret<Mat::Converter>("blend");

executeBinding = [=]() {
cv::seamlessClone(self->ref(), dst->ref(), mask->ref(), p->ref(), blend->ref(), flags->ref());
};
};
};

}

Expand Down
3 changes: 3 additions & 0 deletions cc/photo/photoConstants.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ using namespace cv;
void PhotoConstants::Init(v8::Local<v8::Object> target) {
FF_SET_CV_CONSTANT(target, INPAINT_NS);
FF_SET_CV_CONSTANT(target, INPAINT_TELEA);
FF_SET_CV_CONSTANT(target, NORMAL_CLONE);
FF_SET_CV_CONSTANT(target, MIXED_CLONE);
FF_SET_CV_CONSTANT(target, MONOCHROME_TRANSFER);
}

#endif
2 changes: 2 additions & 0 deletions lib/typings/Mat.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,8 @@ export class Mat {
rqDecomp3x3Async(): Promise<{ returnValue: Vec3, mtxR: Mat, mtxQ: Mat, Qx: Mat, Qy: Mat, Qz: Mat }>;
scharr(ddepth: number, dx: number, dy: number, scale?: number, delta?: number, borderType?: number): Mat;
scharrAsync(ddepth: number, dx: number, dy: number, scale?: number, delta?: number, borderType?: number): Promise<Mat>;
seamlessClone(dst: Mat, mask: Mat, p: Point2, flags: number): Mat;
seamlessCloneAsync(dst: Mat, mask: Mat, p: Point2, flags: number): Promise<Mat>;
sepFilter2D(ddepth: number, kernelX: Mat, kernelY: Mat, anchor?: Point2, delta?: number, borderType?: number): Mat;
sepFilter2DAsync(ddepth: number, kernelX: Mat, kernelY: Mat, anchor?: Point2, delta?: number, borderType?: number): Promise<Mat>;
set(row: number, col: number, value: number): void;
Expand Down
3 changes: 3 additions & 0 deletions lib/typings/constants.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,8 @@ export const LINE_4: number;
export const LINE_8: number;
export const LINE_AA: number;
export const LMEDS: number;
export const MIXED_CLONE: number;
export const MONOCHROME_TRANSFER: number;
export const MORPH_BLACKHAT: number;
export const MORPH_CLOSE: number;
export const MORPH_CROSS: number;
Expand All @@ -455,6 +457,7 @@ export const NORM_L2SQR: number;
export const NORM_MINMAX: number;
export const NORM_RELATIVE: number;
export const NORM_const_MASK: number;
export const NORMAL_CLONE: number;
export const RANSAC: number;
export const REGULAR: number;
export const RETR_CCOMP: number;
Expand Down
2 changes: 2 additions & 0 deletions lib/typings/cv.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,8 @@ export function reduce(mat: Mat, dim: number, rtype: number, dtype?: number): Ma
export function reduceAsync(mat: Mat, dim: number, rtype: number, dtype?: number): Promise<Mat>;
export function sampsonDistance(pt1: Vec2, pt2: Vec2, F: Mat): number;
export function sampsonDistanceAsync(pt1: Vec2, pt2: Vec2, F: Mat): Promise<number>;
export function seamlessClone(src: Mat, dst: Mat, mask: Mat, p: Point2, flags: number): Mat;
export function seamlessCloneAsync(src: Mat, dst: Mat, mask: Mat, p: Point2, flags: number): Promise<Mat>;
export function solve(mat: Mat, mat2: Mat, flags?: number): Mat;
export function solveAsync(mat: Mat, mat2: Mat, flags?: number): Promise<Mat>;
export function solveP3P(objectPoints: Point3[], imagePoints: Point2[], cameraMatrix: Mat, distCoeffs: number[], flags?: number): { returnValue: boolean, rvecs: Mat[], tvecs: Mat[] };
Expand Down
37 changes: 35 additions & 2 deletions test/tests/photo/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module.exports = function ({ cv, utils }) {
assertMetaData,
funcShouldRequireArgs,
readTestImage,
generateAPITests
generateClassMethodTests
} = utils;

describe('inpaint', () => {
Expand Down Expand Up @@ -59,6 +59,39 @@ module.exports = function ({ cv, utils }) {
done();
}).catch(done);
});
})
});

describe('seamlessClone', () => {

it('should have constants', () => {
expect(isNaN(cv.NORMAL_CLONE)).to.be.equal(false);
expect(isNaN(cv.MIXED_CLONE)).to.be.equal(false);
expect(isNaN(cv.MONOCHROME_TRANSFER)).to.be.equal(false);
});

const src = new cv.Mat(5, 5, cv.CV_8UC3, [128, 128, 128]);
const dest = new cv.Mat(10, 10, cv.CV_8UC3, [32, 32, 32]);
const mask = new cv.Mat(5, 5, cv.CV_8UC3, [255, 255, 255]);
const center = new cv.Point2(5, 5);
const cloneType = cv.NORMAL_CLONE;

const expectOutput = (res) => {
assertMetaData(res)(dest.rows, dest.cols, cv.CV_8UC3);
};

generateClassMethodTests({
getClassInstance: () => src,
methodName: 'seamlessClone',
classNameSpace: 'Mat',
methodNameSpace: 'Photo',
getRequiredArgs: () => ([
dest,
mask,
center,
cloneType
]),
expectOutput
});
});

};