FastMOT icon indicating copy to clipboard operation
FastMOT copied to clipboard

Camera Motion

Open rafcy opened this issue 2 years ago • 2 comments

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.

rafcy avatar Nov 09 '21 13:11 rafcy

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

GeekAlexis avatar Nov 26 '21 01:11 GeekAlexis

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?

rafcy avatar Nov 29 '21 15:11 rafcy