1 year ago
#69050
Didi
Shape & color detection in python and opencv
i found this code on GitHub and it is a function that serves to find circles based on camera frames, yet my problem is that i would like to modify it so that i could choose which shape it has to find. I tried to do it for a square but unfortunately i couldn't do it. Is there someone who could possibly help me? Thanks a lot
This is the code of the function that find circles:
def find_circles(frame, mask):
contours = cv2.findContours(mask.copy(), cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
contours = imutils.grab_contours(contours)
center = None
if len(contours) > 0:
c = max(contours, key=cv2.contourArea)
((x, y), radius) = cv2.minEnclosingCircle(c)
M = cv2.moments(c) #Finds center point
center = (int(M["m10"] / M["m00"]), int(M["m01"] / M["m00"]))
if radius > 10:
cv2.circle(frame, (int(x), int(y)), int(radius),
(0, 255, 255), 2)
cv2.circle(frame, center, 5, (0, 0, 0), -1)
return center
python
opencv
object-detection
contour
shapes
0 Answers
Your Answer