def shot_homography(shotTracks, homTh):
"""
Filter foreground points i.e. the outlier points found by fitting
homography using RANSAC
Input:
shotTracks: (numFrames, numAllPoints, 2)
fgTracks: (numFrames, numForegroundPoints, 2)
"""
if shotTracks.ndim < 3 or shotTracks.shape[0] < 2 or homTh < 0:
return shotTracks
import cv2
status = 1
for i in range(1, shotTracks.shape[0]):
if shotTracks[i - 1, 0, 2] > -1000:
p1 = shotTracks[i - 1, :, 2:].astype('float')
else:
p1 = shotTracks[i - 1, :, :2].astype('float')
p2 = shotTracks[i, :, :2].astype('float')
_, new_status = cv2.findHomography(
p1, p2, cv2.RANSAC, ransacReprojThreshold=homTh)
status = new_status * status
fgTracks = shotTracks[:, status[:, 0] == 0, :]
print(shotTracks.shape[0], shotTracks.shape[1], fgTracks.shape[1])
return fgTracks
评论列表
文章目录