peterbraden / node-opencv

OpenCV Bindings for node.js
MIT License
4.38k stars 858 forks source link

findContour examples not working #182

Open rajendrant opened 10 years ago

rajendrant commented 10 years ago

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 commented 10 years ago

\ Update

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

npm install opencv@0.7.0

Thanks Rajendran

marcbachmann commented 10 years ago

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.

peterbraden commented 10 years ago

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 commented 10 years ago

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...

kaosat-dev commented 10 years ago

@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

madshall commented 10 years ago

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 commented 10 years ago

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 commented 10 years ago

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.

frank-trampe commented 6 years ago

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

contour_test_1