私は(x、y)ピクセル座標を乗算して(x、y)実世界座標を得ることができるように変換行列Hを見つけようとしています。私のコードは以下の通りです:Opencvホモグラフィでピクセルxy座標からグローバルxy座標を見つける
import cv2
import numpy as np
from numpy.linalg import inv
if __name__ == '__main__' :
D=[159.1,34.2]
I=[497.3,37.5]
G=[639.3,479.7]
A=[0,478.2]
# Read source image.
im_src = cv2.imread('/home/vivek/june_14.png')
# Four corners of the book in source image
pts_src = np.array([D,I,G,A])
# Read destination image.
im_dst = cv2.imread('/home/vivek/june_14.png')
# Four corners of the book in destination image.
print "img1 shape:",im_dst.shape
scale=1
O=[0.0,0.0]
X=[134.0*scale,0]
Y=[0.0,184.0*scale]
P=[134.0*scale,184.0*scale]
# lx = 75.5 * scale
# ly = 154.0 * scale
pts_dst = np.array([O,X,P,Y])
# Calculate Homography
h, status = cv2.findHomography(pts_src, pts_dst)
print "homography:",h
print "inv of H:",inv(h)
print "position of the blob on the ground xy plane:",np.dot(np.dot(h,np.array([[323.0],[120.0],[1.0]])),scale)
# Warp source image to destination based on homography
im_out = cv2.warpPerspective(im_src, h, (im_dst.shape[1],im_dst.shape[0]))
# Display images
cv2.imshow("Source Image", im_src)
cv2.imshow("Destination Image", im_dst)
cv2.imshow("Warped Source Image", im_out)
cv2.imwrite("im_out.jpg", im_out)
cv2.waitKey(0)
グローバルなxyは非常にオフです。私はどこかで何か間違っていますか?
申し訳ありませんが、変数 'D、I、G、A、O、X、P、Yは何ですか?これらは何を表すはずですか?とにかく、 "実世界"(x、y)の座標を計算する場所では、均等な*点が得られます。これらの点は、スケーリングされたときに等価です---換言すれば、同じ点。しかし、あなたはスケールされたものではなく、 'x、y'ポイントが必要なので、スケールで分割する必要があります。 3つのベクトルはすべて同じ量でスケーリングされるため、スケーリング係数の最後のエントリを使用できます。 'pts = scale * np.dot(h、np.array([323.0]、[120.0]、[1.0]]))' 'と' 'pts = pts/pts [-1]'を実行する必要があります。 –
OXPYは実際のワードポイントです(O原点、右にX-134インチ、右にP-134インチ、Y-184インチ下にY-184インチ)、DIGAは画像平面上のそれぞれのピクセル座標です。 –
すみません。私はスケーリングの部分をかなり得ていませんでした。 –