Skip to content
This repository was archived by the owner on Oct 18, 2023. It is now read-only.

Commit 611fcfe

Browse files
author
kunkkaliu
committed
add guidedFilter guidedFilterAsync
1 parent 8124347 commit 611fcfe

File tree

9 files changed

+146
-0
lines changed

9 files changed

+146
-0
lines changed

Diff for: binding.gyp

+1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
"cc/core/core.cc",
2828
"cc/core/Mat.cc",
2929
"cc/core/MatImgproc.cc",
30+
"cc/core/MatXimgproc.cc",
3031
"cc/core/MatCalib3d.cc",
3132
"cc/core/Point.cc",
3233
"cc/core/Vec.cc",

Diff for: cc/core/Mat.cc

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include "Mat.h"
22
#include "MatImgproc.h"
3+
#include "MatXimgproc.h"
34
#include "MatCalib3d.h"
45
#include "MatBindings.h"
56

@@ -111,6 +112,7 @@ NAN_MODULE_INIT(Mat::Init) {
111112
FF_PROTO_SET_MAT_OPERATIONS(ctor);
112113

113114
MatImgproc::Init(ctor);
115+
MatXimgproc::Init(ctor);
114116
MatCalib3d::Init(ctor);
115117

116118
target->Set(Nan::New("Mat").ToLocalChecked(), ctor->GetFunction());

Diff for: cc/core/MatXimgproc.cc

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#include "MatXimgproc.h"
2+
#include "MatXimgprocBindings.h"
3+
4+
void MatXimgproc::Init(v8::Local<v8::FunctionTemplate> ctor) {
5+
Nan::SetPrototypeMethod(ctor, "guidedFilter", GuidedFilter);
6+
Nan::SetPrototypeMethod(ctor, "guidedFilterAsync", GuidedFilterAsync);
7+
};
8+
9+
NAN_METHOD(MatXimgproc::GuidedFilter) {
10+
FF::SyncBinding(
11+
std::make_shared<MatXimgprocBindings::GuidedFilterWorker>(Mat::Converter::unwrap(info.This())),
12+
"Mat::GuidedFilter",
13+
info
14+
);
15+
}
16+
17+
NAN_METHOD(MatXimgproc::GuidedFilterAsync) {
18+
FF::AsyncBinding(
19+
std::make_shared<MatXimgprocBindings::GuidedFilterWorker>(Mat::Converter::unwrap(info.This())),
20+
"Mat::GuidedFilterAsync",
21+
info
22+
);
23+
}

Diff for: cc/core/MatXimgproc.h

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#include "Mat.h"
2+
#include <opencv2/ximgproc.hpp>
3+
4+
#ifndef __FF_MATXIMGPROC_H__
5+
#define __FF_MATXIMGPROC_H__
6+
7+
class MatXimgproc {
8+
public:
9+
static void Init(v8::Local<v8::FunctionTemplate> ctor);
10+
11+
static NAN_METHOD(GuidedFilter);
12+
static NAN_METHOD(GuidedFilterAsync);
13+
14+
};
15+
16+
#endif

Diff for: cc/core/MatXimgprocBindings.h

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
#include "MatXimgproc.h"
2+
3+
#ifndef __FF_MATXIMGPROCBINDINGS_H__
4+
#define __FF_MATXIMGPROCBINDINGS_H__
5+
6+
namespace MatXimgprocBindings {
7+
8+
struct GuidedFilterWorker : public CatchCvExceptionWorker {
9+
public:
10+
cv::Mat self;
11+
GuidedFilterWorker(cv::Mat self) {
12+
this->self = self;
13+
}
14+
15+
cv::Mat guide;
16+
int radius;
17+
double eps;
18+
int ddepth = -1;
19+
20+
cv::Mat dst;
21+
22+
std::string executeCatchCvExceptionWorker() {
23+
cv::ximgproc::guidedFilter(guide, self, dst, radius, eps, ddepth);
24+
return "";
25+
}
26+
27+
v8::Local<v8::Value> getReturnValue() {
28+
return Mat::Converter::wrap(dst);
29+
}
30+
31+
bool unwrapRequiredArgs(Nan::NAN_METHOD_ARGS_TYPE info) {
32+
return (
33+
Mat::Converter::arg(0, &guide, info) ||
34+
IntConverter::arg(1, &radius, info) ||
35+
DoubleConverter::arg(2, &eps, info)
36+
);
37+
}
38+
39+
bool unwrapOptionalArgs(Nan::NAN_METHOD_ARGS_TYPE info) {
40+
return (
41+
IntConverter::optArg(3, &ddepth, info)
42+
);
43+
}
44+
45+
bool hasOptArgsObject(Nan::NAN_METHOD_ARGS_TYPE info) {
46+
return FF_ARG_IS_OBJECT(3);
47+
}
48+
49+
bool unwrapOptionalArgsFromOpts(Nan::NAN_METHOD_ARGS_TYPE info) {
50+
v8::Local<v8::Object> opts = info[3]->ToObject();
51+
return (
52+
IntConverter::optProp(&ddepth, "ddepth", opts)
53+
);
54+
}
55+
};
56+
57+
}
58+
59+
#endif

Diff for: examples/guidedFilter.js

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
const path = require('path');
2+
const cv = require('../');
3+
4+
const image = cv.imread(path.resolve(__dirname, '../data/Lenna.png'));
5+
6+
const dst = image.guidedFilter(image, 10, 500, -1);
7+
8+
cv.imshowWait("dst", dst);

Diff for: lib/typings/Mat.d.ts

+2
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,8 @@ export class Mat {
179179
goodFeaturesToTrackAsync(maxCorners: number, qualityLevel: number, minDistance: number, mask?: Mat, blockSize?: number, gradientSize?: number, useHarrisDetector?: boolean, harrisK?: number): Promise<Point2[]>;
180180
grabCut(mask: Mat, rect: Rect, bgdModel: Mat, fgdModel: Mat, iterCount: number, mode: number): void;
181181
grabCutAsync(mask: Mat, rect: Rect, bgdModel: Mat, fgdModel: Mat, iterCount: number, mode: number): Promise<void>;
182+
guidedFilter(guide: Mat, radius: number, eps: number, ddepth?: number): Mat;
183+
guidedFilterAsync(guide: Mat, radius: number, eps: number, ddepth?: number): Promise<Mat>;
182184
hDiv(otherMat: Mat): Mat;
183185
hMul(otherMat: Mat): Mat;
184186
houghCircles(method: number, dp: number, minDist: number, param1?: number, param2?: number, minRadius?: number, maxRadius?: number): Vec3[];

Diff for: test/tests/core/Mat/Mat.test.js

+2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ const constructorTestsFromJsArray = require('./constructorTestsFromJsArray');
1818
const constructorTestsFromFillVector = require('./constructorTestsFromFillVector');
1919
const operatorTests = require('./operatorTests');
2020
const imgprocTests = require('./imgprocTests');
21+
const ximgprocTests = require('./ximgprocTests');
2122
const calib3dTests = require('./calib3dTests');
2223
const { doubleMin, doubleMax } = require('./typeRanges');
2324

@@ -48,6 +49,7 @@ describe('Mat', () => {
4849
accessorTests();
4950

5051
describe('imgproc methods', () => imgprocTests(getTestImg));
52+
describe('ximgproc methods', () => ximgprocTests());
5153
describe('calib3d methods', () => calib3dTests());
5254

5355
describe('constructor from channels', () => {

Diff for: test/tests/core/Mat/ximgprocTests.js

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
const cv = global.dut;
2+
3+
const {
4+
generateAPITests,
5+
assertMetaData,
6+
} = global.utils;
7+
8+
module.exports = () => {
9+
describe('guidedFilter', () => {
10+
const getDut = () => new cv.Mat(100, 100, cv.CV_8UC3);
11+
12+
const guide = new cv.Mat(100, 100, cv.CV_8UC3);
13+
const radius = 3;
14+
const eps = 100;
15+
const ddepth = -1;
16+
generateAPITests({
17+
getDut,
18+
methodName: 'guidedFilter',
19+
methodNameSpace: 'Mat',
20+
getRequiredArgs: () => ([
21+
guide,
22+
radius,
23+
eps
24+
]),
25+
getOptionalArgs: () => ([
26+
ddepth
27+
]),
28+
expectOutput: (res) => {
29+
assertMetaData(res)(100, 100, cv.CV_8UC3);
30+
}
31+
});
32+
});
33+
}

0 commit comments

Comments
 (0)