How to map x,y pixel to world cordinates

末鹿安然 提交于 2020-08-05 11:47:11

问题


In my project I am calculating x,y in pixel and Z the distance from the camera in mm. So I want to make use of the depth and calculate the x,y,z.

Can any one tell me how I can do that?

I have the following information:

  1. x,y pixel obtained from the image
  2. Distance from the camera and the object distance from camera and object keep varying, since am making image from different distances

回答1:


If you have x,y in image coordinates, a camera matrix, and z in world coordinates then you need to put your image coordinates into a homogenous vector, multiply by the inverse of the camera matrix, and then by your z_world coordinate. Something that might not be intuitive at first is that your units in world coordinates do not matter. After multiplying by the inverse of the camera matrix you have defined the ratio x/z which is unitless. You give the result units by multiplying by z_world. You can measure it in mm, inches, miles, whatever and your resulting vector will have the same units.

cv::Matx31f world_cord(x_im,y_im,1);         //here measured in pixels
world_cord = camera_matrix.inv()*world_cord; //representing a ratio x/z,y/z
world_cord *= z_world;                       //now x,y,z are measured in units of z_world

world_cord now contains x_world,y_world,z_world.



来源:https://stackoverflow.com/questions/13419605/how-to-map-x-y-pixel-to-world-cordinates

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!