for i in range(5): _,temp = cap.read() while True: _,img = cap.read() if colour == 'q': break masked_img = IP.masked(img,'red') opened_img = IP.opened(masked_img,21) cnt = IP.find_contour(opened_img) cnt_max,area = IP.maxContourArea(cnt,img) rx,ry = IP.centroid(cnt_max) (x,y),radius = cv2.minEnclosingCircle(cnt_max) center = (int(x),int(y)) radius = int(radius) cv2.circle(img,center,radius,(0,255,0),2) cv2.rectangle(img, (rx - 2, ry - 2), (rx + 2, ry + 2), (0, 128, 255), -1) masked_img = IP.masked(img,'blue') opened_img = IP.opened(masked_img,21) cnt = IP.find_contour(opened_img) cnt_max,area = IP.maxContourArea(cnt,img) bx,by = IP.centroid(cnt_max) #print("Blue jewel's x-coordinate:",bx) (x,y),radius = cv2.minEnclosingCircle(cnt_max) center = (int(x),int(y))