i want to wrap all min contours into a box or circle and find the center. I want to click it, but I have a problem that after the automatic click is active, it will click everything marked cv2.minEnclosingCircle. i just want to click it once using pydirectinput. here the script
import cv2 as cv
import numpy as np
import pyautogui as py
from PIL import ImageGrab
import pydirectinput as py
import time
import win32gui, win32ui, win32con
import keyboard
def detection():
global key,cap
cap = ImageGrab.grab(bbox=(-8,0,1194,715))
arays = np.array(cap)
a = cv.cvtColor(arays, cv.COLOR_BGR2HSV)
low = np.array([100,137,175])
up = np.array([179,255,199])
rangeFind = cv.inRange(a, low,up)
hq,thres = cv.threshold(rangeFind,200,255,cv.THRESH_BINARY)
findsContours,_ = cv.findContours(thres, cv.RETR_EXTERNAL, cv.CHAIN_APPROX_SIMPLE)
for cnt in findsContours:
area = cv.contourArea(cnt)
if len(cnt) > 1:
(x,y),radius = cv.minEnclosingCircle(cnt[0])
coord = [0,0]
coord[0] = int(x)
coord[1] = int(y)
center = (int(x),int(y))
radius = int(radius)
cv.circle(a, center, radius, (255, 0, 0), 3)
cv.namedWindow("hasil",cv.WINDOW_NORMAL)
cv.resizeWindow("hasil",600,400)
cv.imshow("hasil",a)
key = cv.waitKey(1) & 0xFF
while True:
detection()
if key == ord("q"):
break
cap.release()
cv.destroyAllWindows()
end here the result: