2011-12-17 125 views
3

我想为JPEG图像(其坐标(X,Y))转换为圆柱坐标..图像变换坐标,圆柱坐标系

是否有OpenCV的一个功能,可以直接做到这一点?或者我可以使用opencv中的哪些函数创建自己的?

我有2d坐标,三维坐标和圆柱坐标之间的混淆..有人可以简要讨论一下吗?

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

我阅读了有关这个话题以前的帖子,但不明白它..

我还没有采取图像处理的过程,但我在赶时间看书.. 我学习的经验,通过研究其他程序员的代码..所以源代码将非常感激..

感谢大家和对不起我的小学后,,

+0

我想JPEG图像的二维坐标转换成圆柱坐标..我将使用转换后的coordina稍后再测试图像拼接功能.. – njm 2011-12-17 02:45:11

回答

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

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

+0

是的,你是对的我对图像拼接感兴趣.. 我能成功地运行你的第一个程序,但在你的第二个源代码中有问题,用>> magAngleZ.push_back (像素); – njm 2011-12-17 15:32:42