[英]OpenCV affine transformation won't perform
我正在嘗試使用樞軸點執行基本的仿射變換。
import cv2
import numpy as np
import PIL
import matplotlib.pyplot as plt
img = cv2.imread('earth.png')
img_pivots = cv2.imread('earth_keys.png')
map_img = cv2.imread('earth2.png')
map_pivots = cv2.imread('earth2_keys.png')
pts_img_R = np.transpose(np.where(img_pivots[:, :, 2] > 0 ))
pts_img_G = np.transpose(np.where(img_pivots[:, :, 1] > 0 ))
pts_img_B = np.transpose(np.where(img_pivots[:, :, 0] > 0 ))
pts_img = np.vstack([pts_img_R, pts_img_G, pts_img_B])
pts_map_R = np.transpose(np.where(map_pivots[:, :, 2] > 0 ))
pts_map_G = np.transpose(np.where(map_pivots[:, :, 1] > 0 ))
pts_map_B = np.transpose(np.where(map_pivots[:, :, 0] > 0 ))
pts_map = np.vstack([pts_map_R, pts_map_G, pts_map_B])
M = cv2.estimateRigidTransform(pts_map.astype(np.float32), pts_img.astype(np.float32), True)
dst = cv2.warpAffine(map_img,M,(img.shape[1], img.shape[0]))
plt.subplot(121),plt.imshow(img),plt.title('earth.png')
plt.subplot(122),plt.imshow(dst),plt.title('earth2.png transrofmed')
plt.show()
在兩張圖像上,我制作了3個點(R,G和B)並將它們保存在單獨的圖像中('earth_keys.png'表示'earth.png'而'earth2_keys.png'表示'earth2.png')。 我想要的是將'earth2.png'上的樞軸點與'earth.png'上的樞軸點相匹配。
我假設我錯放了一些論點或類似的東西,但我嘗試了所有組合並獲得了所有類型的錯誤結果,但仍然無法發現它。
編輯:將樞軸編號更改為6
M現在等於
array([[ 4.33809524e+00, 8.28571429e-01, -5.85633333e+02],
[ -6.22380952e+00, -1.69285714e+00, 1.03468333e+03]])
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.