The OpenCV cvFindContour() method gets connected components following the 8-connected neighbors rule. Is there any way to change it into a 4-connected neighbor rule – the corner cells will not be taken into account when checking for connectedness.
Apparently Mathematica does this with a simple CornerNeighbors->False shown here on SO.
Any way of doing this in OpenCV? Even if we were to actually change the function definition in the cv*.h file (which is rather hairy) … any pointers?
I am afraid this is impossible, you could consider suggesting a code-change to opencv, adding a flag that would allow this. Currently in this file:
http://code.opencv.org/projects/opencv/repository/entry/trunk/opencv/modules/imgproc/src/contours.cpp
there is an array called icvCodeDeltas which determines all the neighbours. You could check where it is used and add a
which is used when for example the CV_NEIGHBOURS_CROSS is specified. Then ask the opencv-community to add it, the way open source works. Maybe a quick, dirty, you-should-be-ashamed fix would be something like this:
But I did not test that, and I have no idea if this will avoid the ‘static’ and ‘const’ so be careful 😉