OpenCv C++透视变换

发布于 2024-11-07 13:44:05 字数 184 浏览 4 评论 0原文

我正在尝试使用 OpenCv 校正图像的失真,然后计算给定像素坐标的真实世界坐标。我在网上或 OpenCv 书中找不到任何关于如何执行此操作的示例。

我已经用棋盘图像完成了相机校准。现在,我只需要一个基本函数,我可以为其提供像素坐标,该函数将根据相机矩阵、畸变系数、旋转和平移向量为我提供真实世界坐标。

有谁知道该怎么做?

I am trying to use OpenCv to correct an image for distortion and then calculate the real world coordinates given a pixel coordinate. I can not find any examples online or in the OpenCv book of how to do this.

I have done the camera calibration with the chess board image. Now, I just need a basic function that I can give pixel coordinates to that will give me real world coordinates based off of the camera matrix, the distortion coefficients, rotational and translation vectors.

Does anyone know how to do this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

箜明 2024-11-14 13:44:05

看一下 findHomography() 函数。如果您知道一组点在现实世界中的位置,则可以使用此函数创建可与函数 perspectiveTransform() 一起使用的变换矩阵。

std::vector<Point2f> worldPoints;
std::vector<Point2f> cameraPoints;

//insert somepoints in both vectors

Mat perspectiveMat_= findHomography(cameraPoints, worldPoints, CV_RANSAC);

//use perspective transform to translate other points to real word coordinates

std::vector<Point2f> camera_corners;
//insert points from your camera image here

std::vector<Point2f> world_corners;
perspectiveTransform(camera_corners, world_corners, perspectiveMat_);

您可以找到有关函数 此处

Take a look at the findHomography() function. If you know the location in the real world of a set of points you can use this function to create transformation matrix that you can use with the function perspectiveTransform()

std::vector<Point2f> worldPoints;
std::vector<Point2f> cameraPoints;

//insert somepoints in both vectors

Mat perspectiveMat_= findHomography(cameraPoints, worldPoints, CV_RANSAC);

//use perspective transform to translate other points to real word coordinates

std::vector<Point2f> camera_corners;
//insert points from your camera image here

std::vector<Point2f> world_corners;
perspectiveTransform(camera_corners, world_corners, perspectiveMat_);

You can find more information about the function here

金橙橙 2024-11-14 13:44:05

据我正确理解,你需要一个来自图像点的世界点。对于单目相机来说这个问题是无法解决的。您无法确定现实世界点到相机的深度(距离)。

有些视觉同步定位与建图 (SLAM) 算法可以创建世界地图并根据视频计算摄像机的轨迹,但它们完全是另一回事。

As I understand correctly you need a world point from image point. With a monocular camera this problem is unsolvable. You can not determine the depth (distance) of the real world point to the camera.

There are visual simultaneous localization and mapping (SLAM) algorithms that create a map of the world and compute the trajectory of the camera from a video, but they are a whole other thing.

我们的影子 2024-11-14 13:44:05

给定一个图像及其上的一个点(以 2D 像素坐标表示),现实世界中存在无限多个 3D 点,所有这些点都属于一条线,映射到图像中的点...而不仅仅是一个观点。

Given a single image and a point on it, expressed in terms of 2D pixel coordinates, there is an infinity of 3D points in the real world, all belonging to a line, which map to your point in your image... not just one point.

素罗衫 2024-11-14 13:44:05

但是,如果您知道物体距相机的距离(以像素 (x,y) 为单位),则可以计算其 3D 位置。

But, if you know the distance of the object in pixel (x,y) from the camera then you can calculate its location in 3D.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文