我为视频制作了稳定器,现在我试图将我的算法与其他算法进行比较,所以我想实现筛选并将关键点传递给光流算法。
sift = cv2.xfeatures2d.SIFT_create()
然后
frame.features = sift.detect(frame_img_gray,None)
new_features, _, _ = cv2.calcOpticalFlowPyrLK(prev_frame_img, frame_img, prev_frame.features, None, **lk_params)
new_features_for_validation, _, _ = cv2.calcOpticalFlowPyrLK(frame_img, prev_frame_img, new_features, None,**lk_params)
所以我从编译器得到这条消息:
new_features, _, _ = cv2.calcOpticalFlowPyrLK(prev_frame_img, frame_img, prev_frame.features, None, **lk_params)
TypeError: prevPts is not a numpy array, neither a scalar
答案 0 :(得分:0)
您可以手动重塑SIFT输出以适合cv2.calcOpticalFlowPyrLK:
LK_pts=np.empty((0,1,2), np.float32)
for pts in prev_frame.features:
x, y = pts.pt
LK_pts=np.append(LK_pts,np.array([[[x,y]]],dtype=np.float32),axis=0)