if not args.diameter == None: bound = cv2.minAreaRect(cnts[0]) bound = cv2.boxPoints(bound) bound = numpy.array(bound, dtype="int") bound = perspective.order_points(bound) cv2.drawContours(frame2, [bound.astype("int")], -1, RED, 2) (tl, tr, br, bl) = bound tltrX = int((tl[0] + tr[0]) * 0.5) tltrY = int((tl[1] + tr[1]) * 0.5) blbrX = int((bl[0] + br[0]) * 0.5) blbrY = int((bl[1] + br[1]) * 0.5) cv2.line(frame2, (tltrX, tltrY), (blbrX, blbrY), BLUE, 2) distance = numpy.sqrt(((tltrX - blbrX)**2) + ((tltrY - blbrY)**2)) ratio = args.diameter / distance tracker.diameter_ratio = ratio diameter_unit = "mm" if args.debug: cv2.imwrite("test.bmp", frame2) # process background substraction blur = cv2.medianBlur(frame, 7) # median blur to remove noise foreground = cv2.absdiff(blur, background) # subtract background foreground = cv2.cvtColor( foreground, cv2.COLOR_BGR2GRAY) # turn into grayscale channel cv_8uc1 result = cv2.threshold(foreground, args.threshold, 255, cv2.THRESH_BINARY)[1] # threshold # contour tracking contours, hierachy = cv2.findContours(result, cv2.RETR_LIST,