From 1300265317ff07a1a157051ea3fef2b605488492 Mon Sep 17 00:00:00 2001 From: Piercus Date: Mon, 7 Nov 2016 22:07:01 +0100 Subject: [PATCH 1/2] add dct method --- src/Matrix.cc | 19 +++++++++++++++++++ src/Matrix.h | 1 + 2 files changed, 20 insertions(+) diff --git a/src/Matrix.cc b/src/Matrix.cc index 06dbce4..d95ab1e 100755 --- a/src/Matrix.cc +++ b/src/Matrix.cc @@ -65,6 +65,7 @@ void Matrix::Init(Local target) { Nan::SetPrototypeMethod(ctor, "roi", ROI); Nan::SetPrototypeMethod(ctor, "ptr", Ptr); Nan::SetPrototypeMethod(ctor, "absDiff", AbsDiff); + Nan::SetPrototypeMethod(ctor, "dct", Dct); Nan::SetPrototypeMethod(ctor, "addWeighted", AddWeighted); Nan::SetPrototypeMethod(ctor, "bitwiseXor", BitwiseXor); Nan::SetPrototypeMethod(ctor, "bitwiseNot", BitwiseNot); @@ -1277,6 +1278,24 @@ NAN_METHOD(Matrix::AbsDiff) { info.GetReturnValue().Set(Nan::Null()); } +NAN_METHOD(Matrix::Dct) { + Nan::HandleScope scope; + + Matrix *self = Nan::ObjectWrap::Unwrap(info.This()); + int cols = self->mat.cols; + int rows = self->mat.rows; + + bool inverse = info[1]->ToBoolean()->Value(); + + Local out = Nan::New(Matrix::constructor)->GetFunction()->NewInstance(); + Matrix *m_out = Nan::ObjectWrap::Unwrap(out); + m_out->mat.create(rows, cols, CV_32F); + + cv::dct(self->mat, m_out->mat, inverse ? 1 : 0); + + info.GetReturnValue().Set(out); +} + NAN_METHOD(Matrix::AddWeighted) { Nan::HandleScope scope; diff --git a/src/Matrix.h b/src/Matrix.h index ffa8ca6..ee337e6 100755 --- a/src/Matrix.h +++ b/src/Matrix.h @@ -68,6 +68,7 @@ public: JSFUNC(ROI) JSFUNC(Ptr) JSFUNC(AbsDiff) + JSFUNC(Dct) JSFUNC(AddWeighted) JSFUNC(BitwiseXor) JSFUNC(BitwiseNot) From efe9776c5d3641250876a6cc88e2a537017b69f1 Mon Sep 17 00:00:00 2001 From: Piercus Date: Mon, 7 Nov 2016 22:10:50 +0100 Subject: [PATCH 2/2] add example for dct --- examples/mat-dct.js | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 examples/mat-dct.js diff --git a/examples/mat-dct.js b/examples/mat-dct.js new file mode 100644 index 0000000..b3fa89f --- /dev/null +++ b/examples/mat-dct.js @@ -0,0 +1,22 @@ +var cv = require('../lib/opencv'); + +cv.readImage("./files/mona.png", function(err, orig) { + if (err) throw err; + + var chan1 = orig.split()[0]; + + var floatInputMatrix = new cv.Matrix(); + chan1.convertTo(floatInputMatrix, cv.Constants.CV_32F) + + var foatAfterDct = floatInputMatrix.dct(); + + // for inverse dct, set argument to "true" + var afterDoubleDct = foatAfterDct.dct(true); + + var intOutImage = new cv.Matrix(); + + afterDoubleDct.convertTo(intOutImage, cv.Constants.CV_8U); + intOutImage.save("./tmp/dct.png"); + console.log('Image saved to ./tmp/dct.png'); + +});