这段代码很好地扭曲了我的图像
kp1, des1 = self._detector.detectAndCompute(static, None)
kp2, des2 = self._detector.detectAndCompute(moving, None)
matches = self._matcher.match(des1, des2)
assert len(matches) >= 4 # for perspective tform
moving_pts = np.float32([kp1[m.queryIdx].pt for m in matches]).reshape(-1, 1, 2)
static_pts = np.float32([kp2[m.trainIdx].pt for m in matches]).reshape(-1, 1, 2)
tform, mask = cv2.findHomography(moving_pts, static_pts, cv2.RANSAC, 5.0)
tform = self._force_translation_only(tform)
matches_mask = mask.ravel().tolist()
matches_image = cv2.drawMatches(static, kp1, moving, kp2, matches, None,
flags=cv2.DrawMatchesFlags_NOT_DRAW_SINGLE_POINTS,
matchesMask=matches_mask,
matchColor=(0, 255, 0),)
warped = cv2.warpPerspective(moving, tform, (static.shape[1], static.shape[0]), flags=cv2.WARP_INVERSE_MAP)
并得出如下结果
我想要一个非黑色部分的遮罩,当然做warped>0
还不够好,因为它不会捕获真正的黑色数据像素
我相信有一个正确的方法可以做到这一点
正如Miki在评论中所建议的,你可以扭曲同样大小的白色图像。 但是,按照你所说的两次弯曲
相反,您可以扭曲4个角并使用
cv2.polylines
绘制白色多边形,但我不确定这是否比扭曲白色图像更有效相关问题 更多 >
编程相关推荐