From 71da46939b660aaec92facd6b3073c7f32ee2908 Mon Sep 17 00:00:00 2001 From: Thomas Hoffmann Date: Thu, 11 Jun 2015 13:40:04 +0200 Subject: [PATCH] added brightness support for gray images --- src/Matrix.cc | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/src/Matrix.cc b/src/Matrix.cc index 221b834..b4ffacf 100755 --- a/src/Matrix.cc +++ b/src/Matrix.cc @@ -316,11 +316,18 @@ NAN_METHOD(Matrix::Brightness){ if (args.Length() == 2){ Matrix *self = ObjectWrap::Unwrap(args.This()); + cv::Mat image; + + if(self->mat.channels() == 3){ + image = self->mat; + }else if(self->mat.channels() == 1){ + cv::Mat myimg = self->mat; + cv::cvtColor(myimg, image, CV_GRAY2RGB); + }else{ + NanThrowError("those channels are not supported"); + } - if(self->mat.channels() != 3) - NanThrowError("Image is no 3-channel"); - 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(); @@ -332,7 +339,15 @@ NAN_METHOD(Matrix::Brightness){ } } } - new_image.copyTo(self->mat); + + if(self->mat.channels() == 3){ + new_image.copyTo(self->mat); + }else if(self->mat.channels() == 1){ + cv::Mat gray; + cv::cvtColor(new_image, gray, CV_BGR2GRAY); + gray.copyTo(self->mat); + } + }else{ NanReturnValue(NanNew("Insufficient or wrong arguments")); }