Merge pull request #459 from piercus/dct

Direct Cosine Transform implemntation and example
This commit is contained in:
Peter Braden 2016-11-07 23:27:13 -08:00 committed by GitHub
commit 1337e75a80
3 changed files with 42 additions and 0 deletions

22
examples/mat-dct.js Normal file
View File

@ -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');
});

View File

@ -65,6 +65,7 @@ void Matrix::Init(Local<Object> 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<Matrix>(info.This());
int cols = self->mat.cols;
int rows = self->mat.rows;
bool inverse = info[1]->ToBoolean()->Value();
Local<Object> out = Nan::New(Matrix::constructor)->GetFunction()->NewInstance();
Matrix *m_out = Nan::ObjectWrap::Unwrap<Matrix>(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;

View File

@ -68,6 +68,7 @@ public:
JSFUNC(ROI)
JSFUNC(Ptr)
JSFUNC(AbsDiff)
JSFUNC(Dct)
JSFUNC(AddWeighted)
JSFUNC(BitwiseXor)
JSFUNC(BitwiseNot)