My task is to detect the boundary of a fluid flow and draw the associated contour. I have successfully detected the boundary and drawn the contour. The contour gets slightly deformed towards the top due to an irregularity in the image (presence of a feeder pipe). I wish to refine the contour so that I get a circular shape. Also, I wish to fill any gaps in the contour so that I have a closed circular form. This is my code:
contours, hierarchy = cv2.findContours(mask1, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_NONE)
Circle = []
if len(contours) != 0:
for contour in contours:
if cv2.contourArea(contour)>500:
cv2.drawContours(cropped_img, contour,-1, (0,0,255), 2)
Circle = np.append(Circle,[contour])
cv2.imshow("original", cropped_img)
cv2.waitKey(0)
This is what I have managed to get
I want the distortion towards the top to be removed and the contour closed into a circular form