【问题标题】:Image transformation from 2D coordinates to Cylindrical Coordinates从二维坐标到圆柱坐标的图像转换
【发布时间】:2012-01-22 10:53:58
【问题描述】:

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

opencv中有没有可以直接做这个的函数?或者我可以使用 opencv 中的哪些函数来创建自己的函数?

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

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

我看了上一篇关于这个话题的帖子,但不明白..

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

感谢大家,对我的基本帖子感到抱歉,

【问题讨论】:

  • 我想将jpeg图像的2d坐标转换为柱坐标..我将在稍后将转换后的坐标用于图像拼接功能..

标签: image-processing opencv projection-matrix


【解决方案1】:

在 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;
}

Cylindrical coordinates 是极坐标的 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 示例。

编辑:
您可能会在 cylindrical projection 上找到这些有用的资源:

Computer Vision: Mosaics
Why Mosaic?
Automatic Panoramic Image Stitching using Invariant Features
Creating full view panoramic image mosaics and environment maps

【讨论】:

  • 是的,你说得对,我对图像拼接很感兴趣。我能够成功运行你的第一个程序,但在你的第二个源代码中遇到了问题 >>magAngleZ.push_back(pixel );
  • 感谢您的帮助.. 赞赏。我还有一个问题。图像的像素值位于每个 (x,y) 坐标中。我的问题是,如果我将 (x,y) 坐标转换为圆柱坐标,位于该坐标上的像素值会改变吗?希望你能得到我的问题..纠正我我有误解..
  • @NicoleMontecalvo 如果您在使用 Mat::push_back() 函数时遇到问题,您可能正在运行旧版本的 OpenCV。你用的是什么版本?
  • 我在 Codeblocks 10.05 中运行 opencv 2.3.0,MinGw Gnu Gcc 编译器。我已经阅读了很多文章。我需要校准我的相机吗?我将使用 casio exilim ex-z77,但我看到的例子,似乎他们正在使用网络摄像头。有没有办法校准我的相机。如果我错了,请纠正我..这可能与我最初提出的问题不同..问候并感谢您。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-07-03
  • 1970-01-01
  • 1970-01-01
  • 2013-08-05
  • 1970-01-01
相关资源
最近更新 更多