0

I use OpenCV 2.4.8 in python to segment images and find objects. I want to use findContours to list the objects and analyse their area, shape and so on. But if I have two objects that are only separated by a thin (1 px wide) diagonal line or even only diagonally touch at the corners, they will be recognised as one object.

This image illustrates the problem:

enter image description here

There are obviously two objects, but they are recognised as one.

In Matlab one can specify a connectivity parameter (neighbourhood of 4 or 8) to solve this problem. Can this also be done in some way using opencv? Maybe using the hierarchy of the contours or some other work around?

I know, that I could use morphological erosion or opening to separate the two objects, but this can cause problems in other parts of my image. I already tried this.

Cyril Durand
  • 15,834
  • 5
  • 54
  • 62
Stefan D
  • 1
  • 1
  • OpenCV 3.0 now has `connectedComponents` and `connectedComponentsWithStats` methods that allow you to choose between 4- and 8-neighbor connectivity. If changing versions is an option, see my answer [here](http://stackoverflow.com/questions/9018016/how-to-compare-two-colors) – beaker May 28 '15 at 17:20

1 Answers1

0

If your objects are circular, you can try using circular Hough transform.

If such an image is represented as a single contour, then it is bound to have defects. You can search for convexity defects and proceed from there. But this again depends on the objects in your image.

I'm not sure what kind of objects your image contains, so its hard to come to a definitive answer.

Specas
  • 98
  • 1
  • 8