node-opencv icon indicating copy to clipboard operation
node-opencv copied to clipboard

findContour examples not working

Open rajendrant opened this issue 10 years ago • 9 comments

Examples that make use of findContour() are not working - contours.js, detect-shapes.js, quad-crosses.js

findContour() is returning 0 contours. The image after convertGrayscale(), canny(), dialte() looks ok. But findContour() is not working.

car-detection.js works ok.

Let me know if you need further info.

Thanks Rajendran

rajendrant avatar Oct 13 '14 06:10 rajendrant

** Update

After downgrading to 0.7.0, examples work ok - contours.js, detect-shapes.js, quad-crosses.js, car_detection.js

npm install [email protected]

Thanks Rajendran

rajendrant avatar Oct 14 '14 05:10 rajendrant

It must be something in the c++ code. It's not working in 0.7.0 (c1edd1b1ab6f82e5816fec3afa8bf596d2f8972d) when I use the new binaries. @kaosat-dev can you check this. I think your updates are the problem. But I might be wrong. I haven't watched into it.

marcbachmann avatar Oct 15 '14 14:10 marcbachmann

I'm working on a branch that will run all of the examples as tests so we know when we regress them. I'll see if I can repro there.

peterbraden avatar Oct 15 '14 17:10 peterbraden

It's working for me, and I just checked in a branch with this running in the tests, so we'll see if it works for travis-ci too...

peterbraden avatar Oct 15 '14 18:10 peterbraden

@marcbachmann strange, just like @peterbraden , it works without issues for me too...will try to do a clean build from scratch to see if I can reproduce

kaosat-dev avatar Oct 16 '14 12:10 kaosat-dev

Hi guys, @peterbraden as far as I can see, Matrix::FindContours in Matrix.cc(https://github.com/peterbraden/node-opencv/blob/master/src/Matrix.cc) just returns new instance of Contour class. I'm facing the same problem with 0 returned and seems that the whole object is clean. Also, I can see contours on an image after .canny was applied, but they're not available from code.

madshall avatar Oct 17 '14 21:10 madshall

I've possibly found the reason:

First, the cv::findContours call was removed in this commit (line 1234) https://github.com/peterbraden/node-opencv/commit/19058ecea9bffc6966f379ee70ea65b9503bb6c5

And the rest was removed here https://github.com/peterbraden/node-opencv/commit/34eb174ae89af61a42b303cf67af21f1f2a1c716

madshall avatar Oct 20 '14 17:10 madshall

I've managed to make it working with adding this into Matrix::FindContours (Matrix.cc):

/* + */ Matrix *self = ObjectWrap::Unwrap<Matrix>(args.This());
        Local<Object> conts_to_return= NanNew(Contour::constructor)->GetFunction()->NewInstance();
/* + */ Contour *contours = ObjectWrap::Unwrap<Contour>(conts_to_return);

/* + */ cv::findContours(self->mat, contours->contours, contours->hierarchy, mode, chain);

Then recompiled, tested and findContours became working without any visible issues.

madshall avatar Oct 21 '14 15:10 madshall

Even in 6.0.0, I'm getting zero contours on the attached input (with no options to findContours).

contour_test_1

frank-trampe avatar May 10 '18 15:05 frank-trampe