Calculating a trajectory using a homography projection

I have the homography matrix and I projected a scene using that homography matrix. Now I have trajectories in 2D, I want to transform them into the projected scene.

I'm trying to do object detection in one image, and do a homography calculations of trajectories of that image, I don't know how to convert the coordinates from the detected bounding box centers of the first image to converted homography coordinates image

for trk in car_detections:
trk = trk.astype(np.int32)

p = np.array(((trk + trk) / 2,  (trk + trk) / 2, 1)).reshape((3, 1))
temp_p = H.dot(p)
sum = np.sum(temp_p, 1)
px = int(round(sum / sum))
py = int(round(sum / sum))
cv2.circle(img, center = (px, py), radius= 10, color=(255,0,0))

point_lists[trk].append((px, py))
x = [i for i in point_lists[trk]]
y = [i for i in point_lists[trk]]
p = np.polyfit(x, y, deg=1)
y = p + p * np.array(x)
fitted = list(zip(x, y))
cv2.polylines(img, np.int32([fitted]), False, color=(255, 0, 0))
edit retag close merge delete

Sort by » oldest newest most voted

I am not sure to understand everything, but I was thinking about something that might help. If you know the position of the bounding box in the first image, the homography matrix and you are able to transform an image to the projected scene using homography :

1 - Generate a black image and add the bounding box using the function rectangle with white pixels for example

2 - Compute the transformed image using the homography matrix

3 - Get the position of the white pixels in the converted homography coordinates image

more

Why not simply transform the four corners (or any set of points) using the homography? See the link provided as a comment to the question.

Can you post an answer ? with code please ? I don't get you

There is no reason to transform an entire image when you can just transform/warp the bounding box corners. The slides linked above show exactly how this can be accomplished and are worth browsing for how clearly they explain the concept.

I transformed the coordinates of the bounding box, but I can't visualize it, please look at the edited post code. I did what you want. Please post an answer with the fix, It took me a lot of days to do it

Stats

Asked: 2019-03-12 13:31:48 -0500

Seen: 84 times

Last updated: Mar 14