Reputation: 51
I would like to convert a Jpeg image (its coordinates (x,y)) into a Cylindrical coordinates..
Is there a function in opencv that can do this directly? or what functions in opencv can I use to create my own??
I am having confusion between 2d coordinates, 3d coordinates and cylindrical coordinates.. can someone briefly discuss this?
Is there a mathematical algorithms available to convert 2d to 3d? 2d to cylindrical coordinates? 3d to cylindrical coordinates?
I read the previous post regarding this topic but does not understand it..
I have not take a course on image processing but I'm in a rush to read books.. I learn by experience and by studying other programmers code.. so source code will be much appreciated..
thanks to everyone and sorry for my elementary post,,
Upvotes: 3
Views: 8491
Reputation: 14021
In the 2D realm, you have Polar coordinates. OpenCV has two nice functions for converting between Cartesian and Polar coordinates cartToPolar and polarToCart. There doesn't seem to be a good example of using these functions, so I made one for you using the cartToPolar
function:
#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 are the 3D version of Polar coordinates. Below is a small sample to show how you could implement cylindrical coordinates. I'm not sure where you'll be getting your 3D z-coordinate, so I just made it arbitrary (e.g., 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;
}
If you're interested in image stitching, have a look at the stitching.cpp and stitching_detailed.cpp samples provided by OpenCV.
EDIT :
You may find these resources on cylindrical projection helpful:
Computer Vision: Mosaics
Why Mosaic?
Automatic Panoramic Image Stitching using Invariant Features
Creating full view panoramic image mosaics and environment maps
Upvotes: 7