使用 OpenCV 将云数据转换为二维图像 [英] Conversion of cloud data into 2d image using OpenCV

查看:88
本文介绍了使用 OpenCV 将云数据转换为二维图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 IDE VS2013 中使用 OpenCV2(3.0.0).我的要求是我们有一个 3D 点云数据(带有参数 XYZ),我可以将该 3D 点云转换为 2d 图像吗,我们可以使用 Opencv 将云数据转换为图像而不链接 PCL.

I am using OpenCV2(3.0.0) with IDE VS2013. My requirement is we are having a 3D point cloud data (with parameters XYZ), can i convert that 3d point point cloud into a 2d image and can we convert the cloud data to image using Opencv without linking PCL.

有可能吗???

如果可能,任何人都可以通过 OpenCV 的示例代码建议我如何转换.

If possible can anyone suggest me how to convert, with a sample code of OpenCV.

任何建议都会有所帮助提前致谢

Any suggestions will be helpful Thanks in advance

推荐答案

问题不是很清楚.将点云转换"为二维图像是什么意思?
我假设转换"是指项目.
在 opencv 中,可以使用 projectpoints 将点云或任何 3d 点投影到 2d 图像上:http://docs.opencv.org/2.4/modules/calib3d/doc/camera_calibration_and_3d_reconstruction.html>#projectpoint.

The question is not really clear. What do you mean by "convert" a point cloud to a 2d image?
I will assume that by "convert" you mean project.
In opencv a point cloud, or any 3d point for that matter can be projected onto a 2d image using projectpoints: http://docs.opencv.org/2.4/modules/calib3d/doc/camera_calibration_and_3d_reconstruction.html#projectpoints.

这是基于针孔相机模型,看这里的例子:http://homepages.inf.ed.ac.uk/rbf/CVonline/LOCAL_COPIES/FUSIELLO4/tutorial.html

This is based on the pinhole camera model, take a look here for example: http://homepages.inf.ed.ac.uk/rbf/CVonline/LOCAL_COPIES/FUSIELLO4/tutorial.html

你也看不到这个问题:OpenCV的projectPoints函数

请记住,您将无法重建原始 3d 数据(因为在投影过程中丢失了深度信息)

Bare in mind that you will not be able to reconstruct you original 3d data (since the depth info was lost in the projection process)

为简化起见,我们可以使用具有任意焦距的完美"投影模型(无相机镜头失真)(如果您希望显示图像,则需要根据您的数据调整焦距,使得投影点的值不会太高,例如不超过 2048,即 2k 分辨率图像的宽度).

To simplify things, we can use a "perfect" projection model (no camera lens distortions) with an arbitrary focal length (if you wish to display the image, you need to play around with the focal length according to your data, such that the projected points' values are in not too high, for example not above 2048, which is the width of a 2k resolution image).

这是一个例子:

#include <string>
#include "opencv2/opencv.hpp"
using namespace cv;
using namespace std;


std::vector<cv::Point3d> Generate3DPoints();

int main(int argc, char* argv[])
{
    // Read 3D points
    std::vector<cv::Point3d> objectPoints = Generate3DPoints();
    std::vector<cv::Point2d> imagePoints;

    int f = 5;  //focal length

    for (unsigned int i = 0; i < objectPoints.size(); i++)
    {
        cv::Point3d orig_point = objectPoints[i];
        imagePoints.push_back(cv::Point2d(
            f*orig_point.x / orig_point.z,  //x' = f*x/z
            f*orig_point.y / orig_point.z)  //y' = f*y/z
            );
    }
}

std::vector<cv::Point3d> Generate3DPoints()
{
    std::vector<cv::Point3d> points;

    double x, y, z;

    x = .5; y = .5; z = -.5;
    points.push_back(cv::Point3d(x, y, z));

    x = .5; y = .5; z = .5;
    points.push_back(cv::Point3d(x, y, z));

    x = -.5; y = .5; z = .5;
    points.push_back(cv::Point3d(x, y, z));

    x = -.5; y = .5; z = -.5;
    points.push_back(cv::Point3d(x, y, z));

    x = .5; y = -.5; z = -.5;
    points.push_back(cv::Point3d(x, y, z));

    x = -.5; y = -.5; z = -.5;
    points.push_back(cv::Point3d(x, y, z));

    x = -.5; y = -.5; z = .5;
    points.push_back(cv::Point3d(x, y, z));

    for (unsigned int i = 0; i < points.size(); ++i)
    {
        std::cout << points[i] << std::endl << std::endl;
    }

    return points;
}

这篇关于使用 OpenCV 将云数据转换为二维图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆