![](/img/trans.png)
[英]Wrong slope direction while calculating line equation with X and y coordinates
[英]Calculating the x & y coordinates in cm from the pixelcoordinates
嘿嘿!
我有一個平面的圖像(從上方拍攝,角度為 30°),我想要特定像素的 x 和 y 坐標,但以厘米為單位(坐標系在表面中)。
有沒有辦法存檔這個?
我正在使用 python 但任何幫助表示贊賞! :)
編輯:我從下面嘗試了 homographie 方法,但是我並沒有安靜地設法使它起作用。 她是我所做的:
#two sets of points I used
#src: corners + center of my 400px*460px image
#dst: coordinate system being outside the image
src = np.matrix(((1, 1, 1),(400, 1, 1),(1, 460, 1),(400, 460, 1),(200,230,1)))
dst= np.matrix(((31.6, 7, 1),(14.5, 7, 1),(28.4, 26.3, 1),(17, 26.3, 1),(22.6,18.6,1 )))
#src: random points from the image of my 400px*460px image
#dst: coordinate system being in the actual image
src = np.matrix(((1, 1, 1),(400, 460, 1),(200,1,1), (100, 170, 1), (280, 320, 1),(300, 50, 1)))
dst= np.matrix(((0, 0, 1),(14.6, 19.3, 1),(17.1/2,0,1), (5.0, 9.2, 1), (11.65, 15.3, 1), (12.9, 2.9, 1) ))
H = cv2.findHomography(src,dst,0)[0]
print (H)
for c in range(0,5):
x= c*100
y = 1
print(x,y,np.dot(H,np.array((x,y,1))))
設置的實際照片
正方形是(400px*460px)圖片上可見的區域。 相機位於右側的黑框中。 X & Y 是我的像素坐標。
只要您保持在 x 軸上,兩組數字的結果都很好。 一旦我沿着 y 軸向下移動,數字就會出錯。
一種方法是估計平面和圖像平面之間的單應性。 估計單應性的簡單方法:
cv::findHomography
估計單應性;對於使用 OpenCV 用 C++ 編寫的示例,請參閱我的答案https://stackoverflow.com/a/36388035/15485
如果您需要更高的精度,您還需要補償鏡頭的失真,並且既然您說您有一個樹莓派相機,那么失真可能是不可忽略的……但這取決於您需要的精度。 單應性不能補償失真。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.