# To check if the bot is running if not driveBot.running: # Obtaining the position of white pixels from the mask points = cv2.findNonZero(mask) pointsArr = np.array(points) # To check if object is available if pointsArr.size > 400: avg = np.mean(pointsArr, axis=0) if avg.size > 0: x = avg[0][0] y = avg[0][1] # To close the kalman filter in on true value if initCounter <= 30: initCounter += 1 predictedCords = kalmanFilter.Estimate(x, y) prevX = x prevY = y else: if velCounter <= 10: velCounter += 1 else: delX = x - prevX delY = y - prevY prevX = x prevY = y # Using kalman filter to measure, correct and predict current position predictedCords = kalmanFilter.Estimate(x, y) # Adding points to the path path.append([predictedCords[0], predictedCords[1]]) # Drawing elements and displaying