影像透视变换未成功发生

问题描述

我不确定,但是我的透视图转换不起作用。粗线不会显示在图像中。虽然我的cv2.drawMatches正在显示。这是示例代码:

 bfm = cv2.BFMatcher(normType=cv2.NORM_HAMMING,crossCheck=True)
 matches = bfm.match(image_1_desc,image_2_desc)

 matches = sorted(matches,key = lambda x:x.distance)
 image_1_points = np.zeros((len(matches),1,2),dtype=np.float32)
 image_2_points = np.zeros((len(matches),dtype=np.float32)

 list_kp1 = []
 list_kp2 = []
 for mat in matches:
     img1_idx = mat.queryIdx
     img2_idx = mat.trainIdx



     (x1,y1) = image_1_kp[img1_idx].pt
     (x2,y2) = image_2_kp[img2_idx].pt

     list_kp1.append((x1,y1))
     list_kp2.append((x2,y2))

   image_1_points=np.asarray(list_kp1,dtype=np.float32) 
   image_2_points=np.asarray(list_kp2,dtype=np.float32) 
   matrix,mask = cv2.findHomography(image_1_points,image_2_points,cv2.RANSAC,5.0)

   h,w,c = image_1.shape
   pts = np.float32([[0,0],[0,h],[w,0]]).reshape(-1,2)
   dst = cv2.perspectiveTransform(pts,matrix)
   homography = cv2.polylines(image_1,[np.int32(dst)],True,(255,0),3)

   plt.imshow(homography);
   plt.axis("off");

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)