added brightness support for gray images

This commit is contained in:
Thomas Hoffmann 2015-06-11 13:40:04 +02:00
parent d5441b93ff
commit 71da46939b

View File

@ -316,11 +316,18 @@ NAN_METHOD(Matrix::Brightness){
if (args.Length() == 2){ if (args.Length() == 2){
Matrix *self = ObjectWrap::Unwrap<Matrix>(args.This()); Matrix *self = ObjectWrap::Unwrap<Matrix>(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() ); cv::Mat new_image = cv::Mat::zeros( image.size(), image.type() );
double alpha = args[0]->NumberValue(); double alpha = args[0]->NumberValue();
int beta = args[1]->IntegerValue(); 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{ }else{
NanReturnValue(NanNew("Insufficient or wrong arguments")); NanReturnValue(NanNew("Insufficient or wrong arguments"));
} }