2011-12-17 127 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