From 9faf0f5a772a97da155d1f8979af09d38d1f427f Mon Sep 17 00:00:00 2001 From: Adrian Sieber Date: Thu, 8 Oct 2015 22:00:12 +0200 Subject: [PATCH] Add function argument to specify the threshold algorithm --- src/Matrix.cc | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/src/Matrix.cc b/src/Matrix.cc index 06928c4..b2bd640 100755 --- a/src/Matrix.cc +++ b/src/Matrix.cc @@ -1635,7 +1635,7 @@ NAN_METHOD(Matrix::Threshold) { double maxVal = info[1]->NumberValue(); int typ = cv::THRESH_BINARY; - if (info.Length() == 3) { + if (info.Length() >= 3) { Nan::Utf8String typstr(info[2]); if (strcmp(*typstr, "Binary") == 0) { @@ -1669,6 +1669,29 @@ NAN_METHOD(Matrix::Threshold) { } } + if (info.Length() >= 4) { + Nan::Utf8String algorithm(info[3]); + + if (strcmp(*algorithm, "Simple") == 0) { + // Uses default + } + else if (strcmp(*algorithm, "Otsu") == 0) { + typ += 8; + } + else { + char *algo = *algorithm; + char text[] = "\" is no supported threshold algorithm. " + "Use \"Simple\" (default) or \"Otsu\"."; + char errorMessage[strlen(algo) + strlen(text) + 2]; + strcpy(errorMessage, "\""); + strcat(errorMessage, algo); + strcat(errorMessage, text); + + Nan::ThrowError(errorMessage); + return; + } + } + Local < Object > img_to_return = Nan::New(Matrix::constructor)->GetFunction()->NewInstance(); Matrix *img = Nan::ObjectWrap::Unwrap(img_to_return);