diff --git a/src/Matrix.cc b/src/Matrix.cc index fdccaf7..85aab90 100755 --- a/src/Matrix.cc +++ b/src/Matrix.cc @@ -2599,6 +2599,19 @@ NAN_METHOD(Matrix::FloodFill) { setColor(obj->Get(Nan::New("loDiff").ToLocalChecked())->ToObject()), setColor(obj->Get(Nan::New("upDiff").ToLocalChecked())->ToObject()), 4); + // Documentation notes that parameter "rect" is an optional output + // parameter which will hold the smallest possible bounding box of + // affected pixels. If "rect" was provided, let's update the values. + // (https://docs.opencv.org/2.4/modules/imgproc/doc/miscellaneous_transformations.html#floodfill) + if (!obj->Get(Nan::New("rect").ToLocalChecked())->IsUndefined()) { + Local< Object > rectArgument = + obj->Get(Nan::New("rect").ToLocalChecked())->ToObject(); + rectArgument->Get(0)->ToObject()->Set(0, Nan::New(rect.x)); + rectArgument->Get(0)->ToObject()->Set(1, Nan::New(rect.y)); + rectArgument->Get(1)->ToObject()->Set(0, Nan::New(rect.width)); + rectArgument->Get(1)->ToObject()->Set(1, Nan::New(rect.height)); + } + info.GetReturnValue().Set(Nan::New(ret)); } diff --git a/test/unit.js b/test/unit.js index 8a07086..c1e9c46 100755 --- a/test/unit.js +++ b/test/unit.js @@ -552,5 +552,40 @@ test('toArray/fromArray working in both ways', function(assert) { }); }); +test('floodFill optional returned bounding rect', function(assert) { + var cv = require('../lib/opencv'); + var solidImage = new cv.Matrix( + 10, 15, // Create 15px wide by 10px tall image + cv.Constants.CV_8U); + + // Define output rect + var rect = [ + [0, 0], // x, y + [0, 0] // width, height + ]; + + // Set all pixels to black/0 + for (var y=0; y