Differentiating between circular, rectangular, and square shapes

Viewed 314

Given this image,

, how do I find the number of circular, rectangular and square shaped pipes? I am using the following filter for now to get the edges of the pipes. Given these edges, I am using Hough Circles and findContours to calculate the circle and rectangular count. But the problem is that the algorithm finds circles inside the rectangular pipes and vice versa. How do I resolve this issue?

blur_hor = cv2.filter2D(
    img_bw[:, :, 0], cv2.CV_32F, kernel=np.ones((11, 1, 1), np.float32) / 11.0,
    borderType=cv2.BORDER_CONSTANT
)
blur_vert = cv2.filter2D(
    img_bw[:, :, 0], cv2.CV_32F, kernel=np.ones((1, 11, 1), np.float32) / 11.0,
    borderType=cv2.BORDER_CONSTANT
)
mask = (
    (img_bw[:, :, 0] > blur_hor * 1.2) | (img_bw[:, :, 0] > blur_vert * 1.2)
).astype(np.uint8) * 255

This is how the image looks after the filter/mask is applied:

0 Answers
Related