while cap.isOpened(): ret, frame = cap.read() if ret == True: out = frame.copy() rows, cols, _ = frame.shape binary = np.zeros((rows, cols, 3), np.float32) for i in range(rows): for j in range(cols): individualPixel = frame[i, j] temp = individualPixel[0] individualPixel[0] = individualPixel[2] individualPixel[2] = temp #print(i,"x",j,":",individualPixel) if (EM.getProbGMM(individualPixel, 'yellow') >= 3.00e-6): #if (EM.getProbGMM(individualPixel, 'yellow') >= 3.00e-6): binary[i, j] = np.array([255, 255, 255]) # else: # frame[i, j] = np.array([255, 255, 255]) new = cv2.medianBlur(binary, 5) #new = cv2.GaussianBlur(new,(5,5),5) edges = cv2.Canny(np.uint8(new), 50, 255) conts, h = cv2.findContours(edges, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE) (conts_sorted, boundingBoxes) = contours.sort_contours(conts, method="left-to-right") hull = cv2.convexHull(conts_sorted[0]) (x, y), radius = cv2.minEnclosingCircle(hull) if radius > 6: cv2.circle(out, (int(x), int(y)), int(radius), (0, 255, 0), 4)
count = -1 while cap.isOpened(): ret, frame = cap.read() count += 1 # if count < 52: # continue print(count) out = frame.copy() rows, cols, _ = frame.shape binary = np.zeros((rows, cols, 3), np.float32) for i in range(rows): for j in range(cols): individualPixel = frame[i, j, 1] #print(i,"x",j,":",individualPixel) if (EM.getProbGMM(individualPixel, 'green') >= 3.00e-6): binary[i, j] = np.array([255, 255, 255]) # else: # frame[i, j] = np.array([255, 255, 255]) new = cv2.medianBlur(binary, 5) new = cv2.GaussianBlur(new, (5, 5), 5) edges = cv2.Canny(np.uint8(new), 50, 255) conts, h = cv2.findContours(edges, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE) try: (conts_sorted, boundingBoxes) = contours.sort_contours(conts, method="left-to-right") hull = cv2.convexHull(conts_sorted[0]) (x, y), radius = cv2.minEnclosingCircle(hull) except: radius = 0 if radius > 6:
ret, frame = cap.read() count += 1 # if count < 147: # continue if ret == True: out = frame.copy() rows, cols, _ = frame.shape binary = np.zeros((rows, cols, 3), np.float32) for i in range(rows): for j in range(cols): individualPixel = frame[i, j] temp = individualPixel[0] individualPixel[0] = individualPixel[2] individualPixel[2] = temp #print(i,"x",j,":",individualPixel) if (EM.getProbGMM(individualPixel, 'orange') >= 4.00e-6): binary[i, j] = np.array([255, 255, 255]) # else: # frame[i, j] = np.array([255, 255, 255]) new = cv2.medianBlur(binary, 5) #new = cv2.GaussianBlur(new,(5,5),5) edges = cv2.Canny(np.uint8(new), 50, 255) conts, h = cv2.findContours(edges, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE) try: (conts_sorted, boundingBoxes) = contours.sort_contours(conts, method="left-to-right") hull = cv2.convexHull(conts_sorted[0]) (x, y), radius = cv2.minEnclosingCircle(hull) except: