gpt4 book ai didi

python - 从像素坐标计算以厘米为单位的 x 和 y 坐标

转载 作者:太空宇宙 更新时间:2023-11-03 22:51:07 27 4
gpt4 key购买 nike

嘿嘿!
我有一个平面的图像(从上方拍摄,角度为 30°),我想要特定像素的 x 和 y 坐标,但以厘米为单位(坐标系在表面中)。
有办法存档吗?
我正在使用 python,但感谢任何帮助! :)

编辑:我从下面尝试了单应法,但是我并没有安静地设法让它发挥作用。她就是我所做的:

#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))))

Actual Photo of the setup
正方形是(400px*460px)图片上可见的区域。相机位于右侧的黑框中。 X 和 Y 是我的像素坐标。
只要您留在 x 轴上,两组数字的结果都很好。一旦我向下移动 y 轴,数字就会出错。

最佳答案

一种方法是估计平面平面与图像平面之间的单应性。估计单应性的一种简单方法:

  1. 获取平面上四个(非共线)点的坐标(以厘米为单位);
  2. 找到图像中相同的四个点,并得到它们的像素坐标;
  3. cv::findHomography估计单应性;
  4. 在图像中找到您感兴趣的点并获取其坐标(以像素为单位);
  5. 使用单应性计算以厘米为单位的点坐标。

有关使用 OpenCV 使用 C++ 编写的示例,请参阅我的回答 https://stackoverflow.com/a/36388035/15485

如果您需要更高的精度,您还需要补偿镜头的失真,因为您说您有一个覆盆子 pi 相机,失真可能是不可忽略的……但这取决于您需要的精度。单应性不能补偿失真。

关于python - 从像素坐标计算以厘米为单位的 x 和 y 坐标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37462484/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com