mirror of
https://github.com/peterbraden/node-opencv.git
synced 2025-12-08 19:45:55 +00:00
Add function argument to specify the threshold algorithm
This commit is contained in:
parent
90fe184501
commit
9faf0f5a77
@ -1635,7 +1635,7 @@ NAN_METHOD(Matrix::Threshold) {
|
|||||||
double maxVal = info[1]->NumberValue();
|
double maxVal = info[1]->NumberValue();
|
||||||
int typ = cv::THRESH_BINARY;
|
int typ = cv::THRESH_BINARY;
|
||||||
|
|
||||||
if (info.Length() == 3) {
|
if (info.Length() >= 3) {
|
||||||
Nan::Utf8String typstr(info[2]);
|
Nan::Utf8String typstr(info[2]);
|
||||||
|
|
||||||
if (strcmp(*typstr, "Binary") == 0) {
|
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 =
|
Local < Object > img_to_return =
|
||||||
Nan::New(Matrix::constructor)->GetFunction()->NewInstance();
|
Nan::New(Matrix::constructor)->GetFunction()->NewInstance();
|
||||||
Matrix *img = Nan::ObjectWrap::Unwrap<Matrix>(img_to_return);
|
Matrix *img = Nan::ObjectWrap::Unwrap<Matrix>(img_to_return);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user