Detect Closed loop through from the image
Hi, I am trying to detect the closed loop within the attached images and mentioned below code I am able to draw contours of closed loop and I need to detect the closed-loop contour Image 1 Without any Pattern
Image 2 With the pattern
Image 3 Closed Contour
My major Question is how can I detect the coutour drawn in the image is closed loop or open loop
Note: The pattern can anything if its not enclosed then it will give Flase in output else it will give true
Code:
import cv2, imutils
import numpy as np
image = cv2.imread("mask5.jpg")
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
frame = cv2.imread("mask4.jpg")
static_back = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
while(True):
diff_frame = cv2.absdiff(static_back, gray)
thresh_frame = cv2.threshold(diff_frame, 10, 255, cv2.THRESH_BINARY)[1])
thresh_frame = cv2.dilate(thresh_frame, None, iterations = 1)
(cnts, h) = cv2.findContours(thresh_frame.copy(), cv2.RETR_CCOMP,
cv2.CHAIN_APPROX_NONE)
for contour in cnts:
if cv2.contourArea(contour) > 10000:
cv2.drawContours(frame, contour, -1, (0, 255, 0), 5)
result = imutils.resize(frame, width=320)
cv2.imshow("Frame", result)
cv2.imwrite("Frame.jpg", result)
key = cv2.waitKey(1)
if key == 27:
break
see https://answers.opencv.org/question/2...
any possible suggestion in python and will it work on enclosed loops??