0

I am using a DeepSORT to gather the x and y coordinates of an object. I am using homography to get a zoomed in bird's-eye-view of a specific portion of the video. I know the real-world distances of the area I zoom into, and want to know the real world position and speed of the object as it moves through the identified area. Here is my current code for the homographical transformation

# points for tracking window 
pt_A = [x_0, y_0]
pt_B = [x_1, y_1]
pt_C = [x_2, y_2]
pt_D = [x_3, y_3]
# euclidean distances between each point
width_AD = np.sqrt(((pt_A[0] - pt_D[0]) ** 2) + ((pt_A[1] - pt_D[1]) ** 2))
width_BC = np.sqrt(((pt_B[0] - pt_C[0]) ** 2) + ((pt_B[1] - pt_C[1]) ** 2))
max_width = max(int(width_AD), int(width_BC))

height_AB = np.sqrt(((pt_A[0] - pt_B[0]) ** 2) + ((pt_A[1] - pt_B[1]) ** 2))
height_CD = np.sqrt(((pt_C[0] - pt_D[0]) ** 2) + ((pt_C[1] - pt_D[1]) ** 2))
max_height = max(int(height_AB), int(height_CD))

input_pts = np.float32([pt_A, pt_B, pt_C, pt_D])
output_pts = np.float32([[0, 0], [0, max_height - 1], [max_width - 1, max_height - 1], [max_width - 1, 0]])
# Compute the perspective transform h_transform
h_transform = cv2.getPerspectiveTransform(input_pts, output_pts)

This h_transform warps the video in the orientation I would like to use when using warpPerspective. I want to know how I can now apply the transformation to the tracked points of objects moving through the area and measure the position and speed of the objects in m/s using the known length and width of the area I zoom into.

This was one thing I tried to convert the points of each object into the new plane, would this be correct or seem correct?

#Finally, any 2d point in rectangle A can be found in rectangle B using this operation:
point_in_A = (x,y,1)
tempMatrix (1x3) = h_transform * point_in_A(1x3)
tempMatrix will be (x, y, scale);
#using tempMatrix values below:
result xy_in_B = (x / scale , y / scale);

Once this is correct, how do I convert these pixel coordinates into real world coordinates? I believe the above transformation would place the coordinates onto a plane where the corners are the selected area with the origin being in the bottom left side.

I have confused myself trying to wrap my head around this so I apologize if this is not a viable question or is very confusing!

0 Answers0