GeekAlexis / FastMOT

High-performance multiple object tracking based on YOLO, Deep SORT, and KLT 🚀
MIT License
1.16k stars 255 forks source link

Camera Motion #224

Closed rafcy closed 2 years ago

rafcy commented 3 years ago

On my version of this application, I manually add some lines on the opencv window using my mouse. The footage I have is taken using a drone, topdown view. Since the drone is not always static, I want the lines to change their points according to the camera motion. In order to do so, i use cv2.estimateAffinePartial2D(self.prev_bg_keypoints, self.bg_keypoints ) https://github.com/GeekAlexis/FastMOT/blob/8f59591aa10adaab84af7c083bc98d1071a56bd8/fastmot/flow.py#L227, and use the output affine_mat to transform the points of the line. The result is having the line moving across the window while slightly rotating according to the camera movement. I don't really know if I am doing this right, if not please guide me how to use the camera motion to estimate the pixel correction in order to fix my issue.

The code i use for the transformation is this one: line_pt1 = self._estimate_line(line_pt1,affine_mat) line_pt2 = self._estimate_line(line_pt2,affine_mat) @staticmethod @nb.njit(fastmath=True, cache=True) def _estimate_line(xy, affine_mat): tl = transform(xy, affine_mat).ravel() return int(tl[0]),int(tl[1]) A video showcasing the issue, https://youtu.be/MMAUoWw17_c . Thanks in advance.

GeekAlexis commented 3 years ago

I suggest you try using the homography matrix below directly and utils.numba.perspective_transform() to warp the end points of the line.

https://github.com/GeekAlexis/FastMOT/blob/8f59591aa10adaab84af7c083bc98d1071a56bd8/fastmot/flow.py#L223

rafcy commented 3 years ago

You are right once again. It works, my main issue actually was that I was doing int(tl[0]) instead of round(tl[0]) and since the pixel difference was 0.5 -0.9 it was reducing the pixel by 1 and it was decreasing to zero. My issue right now though it's that in some videos the pixel difference after the transformation is 0.01-0.03 and the line does not move at all but you can clearly see the video rotating slowly anti-clockwise. Is there any scale-wise parameter that I have to address to fix this issue?