3

我想将 Jpeg 图像(其坐标 (x,y))转换为圆柱坐标。

opencv中是否有可以直接执行此操作的函数?或者我可以使用 opencv 中的哪些函数来创建自己的函数?

我在 2d 坐标、3d 坐标和圆柱坐标之间感到困惑。有人可以简要讨论一下吗?

是否有可用于将 2d 转换为 3d 的数学算法?二维到圆柱坐标?3d到圆柱坐标?

我阅读了有关此主题的上一篇文章,但不明白它..

我没有上过图像处理课程,但我急于看书。我通过经验和学习其他程序员的代码来学习。所以源代码将不胜感激。

谢谢大家,很抱歉我的基本帖子,,

4

1 回答 1

7

在 2D 领域,您有极坐标。OpenCV 有两个很好的函数用于在笛卡尔坐标和极坐标之间进行转换cartToPolarpolarToCart。似乎没有使用这些函数的好例子,所以我为您制作了一个使用该cartToPolar函数的例子:

#include <opencv2/core/core.hpp>
#include <iostream>

#include <vector>

using namespace cv;
using namespace std;

int main(int argc, char** argv)
{
    vector<double> vX;
    vector<double> vY;

    for(int y = 0; y < 3; y++)
    {
        for(int x = 0; x < 3; x++)
        {
            vY.push_back(y);
            vX.push_back(x);
        }
    }

    vector<double> mag;
    vector<double> angle;

    cartToPolar(vX, vY, mag, angle, true);

    for(size_t i = 0; i < mag.size(); i++)
    {
        cout << "Cartesian (" << vX[i] << ", " << vY[i] << ") " << "<-> Polar (" << mag[i] << ", " << angle[i] << ")" << endl;
    }

    return 0;
}

圆柱坐标是极坐标的 3D 版本。下面是一个小示例,展示了如何实现柱坐标。我不确定你会在哪里得到你的 3D z 坐标,所以我只是让它变得任意(例如,x + y):

Mat_<Vec3f> magAngleZ;

for(int y = 0; y < 3; y++)
{
    for(int x = 0; x < 3; x++)
    {
        Vec3f pixel;
        pixel[0] = cv::sqrt((double)x*x + (double)y*y); // magnitude
        pixel[1] = cv::fastAtan2(y, x);                 // angle
        pixel[2] = x + y;                               // z
        magAngleZ.push_back(pixel);
    }
}

for(int i = 0; i < magAngleZ.rows; i++)
{
    Vec3f pixel = magAngleZ.at<Vec3f>(i, 0);
    cout << "Cylindrical (" << pixel[0] << ", " << pixel[1] << ", " << pixel[2] << ")" << endl;
}

如果您对图像拼接感兴趣,请查看 OpenCV 提供的stitching.cppstitching_detailed.cpp示例。

编辑:
您可能会发现这些关于圆柱投影的资源很有帮助:

计算机视觉:马赛克
为什么选择马赛克?
使用不变特征的自动全景图像拼接
创建全景全景图像马赛克和环境地图

于 2011-12-17T05:08:57.710 回答