From 45846cd3b2c62924fa73f8cd809a1f0247671c0c Mon Sep 17 00:00:00 2001 From: Peter Braden Date: Wed, 19 Jun 2013 11:21:59 -0700 Subject: [PATCH] Open Source Bridge Live coding - woohoo --- smoke/smoketest.js | 2 +- src/Matrix.cc | 25 ++++++++++++++++++++++++- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/smoke/smoketest.js b/smoke/smoketest.js index cd37a7f..258eb1e 100755 --- a/smoke/smoketest.js +++ b/smoke/smoketest.js @@ -21,7 +21,7 @@ cv.readImage("/Users/peterbraden/Downloads/orl_faces/s6/10.pgm", function(e, im) */ cv.readImage("/Users/peterbraden/Desktop/repos/node-opencv/examples/mona.png", function(e, mat){ - var th = mat.threshold(20, 200); + var th = mat.threshold(200, 200, "Threshold to Zero Inverted"); th.save('out.png') }) diff --git a/src/Matrix.cc b/src/Matrix.cc index 6ef03e4..5a9bc52 100755 --- a/src/Matrix.cc +++ b/src/Matrix.cc @@ -1009,11 +1009,34 @@ Matrix::Threshold(const v8::Arguments& args) { double threshold = args[0]->NumberValue(); double maxVal = args[1]->NumberValue(); + int typ = cv::THRESH_BINARY; + if (args.Length() == 3){ +// typ = args[2]->IntegerValue(); + String::AsciiValue typstr(args[2]); + if (strcmp(*typstr, "Binary") == 0){ + typ=0; + } + if (strcmp(*typstr, "Binary Inverted") == 0){ + typ=1; + } + if (strcmp(*typstr, "Threshold Truncated") == 0){ + typ=2; + } + if (strcmp(*typstr, "Threshold to Zero") == 0){ + typ=3; + } + if (strcmp(*typstr, "Threshold to Zero Inverted") == 0){ + typ=4; + } + } + + + Local img_to_return = Matrix::constructor->GetFunction()->NewInstance(); Matrix *img = ObjectWrap::Unwrap(img_to_return); self->mat.copyTo(img->mat); - cv::threshold(self->mat, img->mat, threshold, maxVal, cv::THRESH_BINARY); + cv::threshold(self->mat, img->mat, threshold, maxVal, typ); return scope.Close(img_to_return); }