biggreen = None max_area = 0 for c in contours: area = cv.contourArea(c) if area == 0: continue if area > max_area: max_area = area biggreen = c pos = num num += 1 ############## PROCESSING OBJECT ############## if (num > 0 # Check if there is any green object and int(cv.contourArea(biggreen)) > min_area # no noise and streamfps.frames() > 50): # Start the predicting at a particular point ######## CALCULATE POSITION ######## # Calculate bounding box #print(streamfps.frames()) (x, y, w, h) = cv.boundingRect(biggreen) # Calculate x and y of the current observation xo = x + int(w / 2) yo = y + int(h / 2) error = w # Error: somewhere in this region is the center ######## KALMAN FILTER Position ######### if yo < error: mu, P, pred = kalman(mu, P, F, Q, B, a, None, H, R)
################ FIND GREEN PIXELS ################ # Convert BGR to HSV hsv1 = cv.cvtColor(frame1, cv.COLOR_BGR2HSV) hsv2 = cv.cvtColor(frame2, cv.COLOR_BGR2HSV) # Threshold the HSV image to get only green colors mask1 = cv.inRange(hsv1, lower, upper) mask2 = cv.inRange(hsv2, lower, upper) ################ Find object ################ # get contours, find biggest contour (which is the ball), noise filter contour1_ball = FindObject(mask1, lower, upper, min_area) contour2_ball = FindObject(mask2, lower, upper, min_area) if (contour1_ball is not None or contour2_ball is not None ) and streamfps.frames() > 0: # Check if there is any green object (x1, y1, w1, h1) = BoundingBox(contour1_ball) (x2, y2, w2, h2) = BoundingBox(contour2_ball) list2dX_1.append(x1) list2dY_1.append(y1) list2dX_2.append(x2) list2dY_2.append(y2) if len(list3dYe) != 0: average_x = sum(list3dXe) / len(list3dXe) average_y = sum(list3dYe) / len(list3dYe) xo, yo, zo = Coordinates3d( x1, y1, x2,