Search code examples
pythonopencvcontouredge-detectionocclusion

object (parallel lines) detection where a part is occluded


I have encountered some issues while doing object detection with opencv/python.

If you look at the image, I already know the four corners of the two green boxes. The object I am trying to detect is the red lined one, a shape of a hose.

My plan is to get width (w) of the hose from the green box (which I have already done), and find paralleled lines that have the distance of w from each other.

Here I encountered two problems and am looking for potential solutions.

  1. How could I detect all parallel lines? I think it is good to begin with the four corners of the green box because the points are in the path of the red lines. I wish I could project lines from the corners, making them to follow the white pixels until they meet a dead-end or a sharp corner. Is there any way to navigate through the white contours?

  2. The next problem (assuming Q1 was solved) is that the red lines are occluded in the middle by the yellow part. How could I make the two red parts are considered as a same object? I am looking for the very end of the red lines at the bottom.

image


Solution

  • How could I detect all parallel lines?

    One approach I can think of is to use HoughLines to detect lines in your image. From that link:

    lines = cv2.HoughLines(edges,1,np.pi/180,200)
    

    This will return all the lines detected, parametrized by two variables: rho (distance from origin) and theta (angle from origin)

    After that, parallel lines would be those that have the same angle (theta) but different rho values.