From cfd37af5749bd66bab032332cd6a9a781d784b7b Mon Sep 17 00:00:00 2001 From: Jake Brandt Date: Mon, 8 Jan 2018 23:30:26 -0500 Subject: [PATCH 1/2] Pass back Matrix.floodFill() output bounding rect (plus quick unit test) --- src/Matrix.cc | 13 +++++++++++++ test/unit.js | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+) diff --git a/src/Matrix.cc b/src/Matrix.cc index 01b4443..85f70e7 100755 --- a/src/Matrix.cc +++ b/src/Matrix.cc @@ -2560,6 +2560,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..707e0f9 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 Date: Mon, 8 Jan 2018 23:37:10 -0500 Subject: [PATCH 2/2] Forgot semicolon at end of floodFill bounding rect unit test --- test/unit.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/unit.js b/test/unit.js index 707e0f9..c1e9c46 100755 --- a/test/unit.js +++ b/test/unit.js @@ -585,7 +585,7 @@ test('floodFill optional returned bounding rect', function(assert) { assert.equal(rect[1][0], 15); // Expect fill to create 15px-wide bounding rect assert.equal(rect[1][1], 10); // Expect fill to create 10px-tall bounding rect assert.end(); -}) +}); // Test the examples folder. require('./examples')()