Hello, Im trying to meassure the distance between two objects using Python. I have managed to do it in a still picture but now Im trying to do it in a video. The program measure the distance D in the first frame of the video, but not continiously as the objects move. Im quite new to Python and openCV, so any help is much appreciated. Here is the code:
for c in contours:
if cv2.contourArea(c)<100:
continue
elif cv2.contourArea(c)>2000:
continue
cv2.drawContours(frame, [c], -1, (0,255,0), 3)
M = cv2.moments(c)
cX = int(M['m10'] /M['m00'])
cY = int(M['m01'] /M['m00'])
centers.append([cX,cY])
if len(centers) >=2:
dx= centers[0][0] - centers[1][0]
dy = centers[0][1] - centers[1][1]
D = np.sqrt(dx*dx+dy*dy)
print(D)
How can I get the value of D to change continiously as the two objects move in the video?