Open Source Bridge Live coding - woohoo

This commit is contained in:
Peter Braden 2013-06-19 11:21:59 -07:00
parent ca87972037
commit 45846cd3b2
2 changed files with 25 additions and 2 deletions

View File

@ -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')
})

View File

@ -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<Object> img_to_return = Matrix::constructor->GetFunction()->NewInstance();
Matrix *img = ObjectWrap::Unwrap<Matrix>(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);
}