From f9d5c8a4d7b664897a4946c28be57afa1756b0be Mon Sep 17 00:00:00 2001 From: Thomas Hoffmann Date: Thu, 11 Jun 2015 12:23:54 +0200 Subject: [PATCH] added brightness --- src/Matrix.cc | 29 ++++++++++++++++++++++++++++- src/Matrix.h | 1 + 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/src/Matrix.cc b/src/Matrix.cc index a76d1b3..21e2996 100755 --- a/src/Matrix.cc +++ b/src/Matrix.cc @@ -28,6 +28,7 @@ Matrix::Init(Handle target) { NODE_SET_PROTOTYPE_METHOD(ctor, "get", Get); NODE_SET_PROTOTYPE_METHOD(ctor, "set", Set); NODE_SET_PROTOTYPE_METHOD(ctor, "put", Put); + NODE_SET_PROTOTYPE_METHOD(ctor, "brightness", Brightness); NODE_SET_PROTOTYPE_METHOD(ctor, "normalize", Normalize); NODE_SET_PROTOTYPE_METHOD(ctor, "getData", GetData); NODE_SET_PROTOTYPE_METHOD(ctor, "pixel", Pixel); @@ -310,10 +311,36 @@ NAN_METHOD(Matrix::GetData) { } +NAN_METHOD(Matrix::Brightness){ + NanScope(); + + if (args.Length() == 2){ + Matrix *self = ObjectWrap::Unwrap(args.This()); + cv::Mat image = self->mat; + cv::Mat new_image = cv::Mat::zeros( image.size(), image.type() ); + double alpha = args[0]->NumberValue(); + int beta = args[1]->IntegerValue(); + /// Do the operation new_image(i,j) = alpha*image(i,j) + beta + for( int y = 0; y < image.rows; y++ ){ + for( int x = 0; x < image.cols; x++ ){ + for( int c = 0; c < 3; c++ ){ + new_image.at(y,x)[c] = cv::saturate_cast( alpha*( image.at(y,x)[c] ) + beta ); + } + } + } + new_image.copyTo(self->mat); + }else{ + NanReturnValue(NanNew("Insufficient or wrong arguments")); + } + + + NanReturnNull(); +} + // @author tualo // normalize wrapper NAN_METHOD(Matrix::Normalize) { - NanScope(); + if (!args[0]->IsNumber()) NanThrowTypeError("min is required (argument 1)"); diff --git a/src/Matrix.h b/src/Matrix.h index 37477e1..fe24ebc 100755 --- a/src/Matrix.h +++ b/src/Matrix.h @@ -24,6 +24,7 @@ class Matrix: public node::ObjectWrap { JSFUNC(GetData) JSFUNC(Normalize) + JSFUNC(Brightness) JSFUNC(Row) JSFUNC(PixelRow)