mirror of
https://github.com/peterbraden/node-opencv.git
synced 2025-12-08 19:45:55 +00:00
Merge pull request #459 from piercus/dct
Direct Cosine Transform implemntation and example
This commit is contained in:
commit
1337e75a80
22
examples/mat-dct.js
Normal file
22
examples/mat-dct.js
Normal 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');
|
||||
|
||||
});
|
||||
@ -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;
|
||||
|
||||
|
||||
@ -68,6 +68,7 @@ public:
|
||||
JSFUNC(ROI)
|
||||
JSFUNC(Ptr)
|
||||
JSFUNC(AbsDiff)
|
||||
JSFUNC(Dct)
|
||||
JSFUNC(AddWeighted)
|
||||
JSFUNC(BitwiseXor)
|
||||
JSFUNC(BitwiseNot)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user