The software of the image transformation of fish eyes and the method of eye-correction of fish

Source: Internet
Author: User
To do a panoramic view, of course, first look for a panoramic picture (360° fisheye lens) and then panoramic view of the conversion software, if you can do it yourself. Recommended here PANO2VR

After the picture is converted, a set of cube patches is obtained.


Reprint for Forgetting: http://blog.csdn.net/gaoleikidkidkid/article/details/22159481

The work of a panoramic picture map has recently been done by mapping a 360-degree panoramic spherical photo onto a plane so that it does not appear to be deformed. Because some fish eye photograph's correction procedure is not good to use on the net, oneself through the triangle computation of the sphere, has found the mapping effect better method. Write a blog in case you forget. Look at the effect first.

After that, a number of modifications have been made, making the program a relatively generic program of variable size and variable angle. My ability is weak, can only use the stupid method to think the question, the inadequacy asks Haihan.


The main algorithm is this. When turning from a plane to a spherical surface, you need to draw a straight line from the center of the circle, hitting the sphere with each pixel of the plane image and giving the plane a pixel to the sphere. I think the map of the plane should be the reverse process. The key is how to find the relationship between the point of the spherical surface and the point of the plane. Because although it is a spherical picture, but only visually spherical, its picture structure is still two-bit pixel points. Let's look at the specific analysis.


In the picture is a sketch that I hand-painted. When you map a sphere to a plane, you need to create a new planar picture. On the plane of the picture of the vertical left point loop, run every point, do Point and center O line, hit the sphere, the point on the sphere and the spherical image of the left and right side of the arc between the length, is the spherical picture of the horizontal axis we require. So how does the arc length count? It is obvious to use the angle of the center angle times the radius of the sphere. (Because of the center of the circle, so the circle.) The radius is the width of the picture as the circumference of the circle, the radius r to find out. Angle how to ask for it. The more straightforward approach I can think of is triangular geometry. The a point on the picture is any point on our plane, and we ask for an angle between the AO and the Red line. Then the do and the red line angle minus the angle between do and AO. Do with the red line angle of the plane picture length of the general, the assumption is LENGTH/2. The length of do can be dco this right-angled triangle, through the Pythagorean theorem, the value is sqrt (Y*Y+LENGTH/2*LENGTH/2). The red line and the intersection of the horizontal lines of a are assumed to be E, then Ed is length/2. So Doe=arctan (ed/do). Doa=arctan ((length/2-x)/do). So the AoE we seek is Doe-doa=arctan (ed/do)-arctan (length/2-x). This angle is directly multiplied by the radius r is the horizontal axis. When the point is in the right half of the plane, turn the length/2-x into X-LENGTH/2.

The ordinate is similar to this, just require AOB angle. Ask for Bo through the triangle theorem of BC and OC. Then AOB is arctan (AB/BO). The arc length of the ball is arctan (Ab/bo) *r But there is still a problem, now is only the arc length, but we require the ordinate of the spherical image, so you need to use the height of the spherical image minus the arc length. So we get the coordinates for each point. Show the picture.

This is the basic idea, procedures and algorithms are very simple, but the effect is good, but also more stable.

Because it's a 360-degree panorama, so we're going to want to show the rest, we'll want to show the angle in a vector<float>d, then change the angle in the loop, and put the picture of each angle into a vector<iplimage *>results vector, and display it. In the use of Vector<iplimage*>results vector, Push_back, encountered trouble, delay a day to solve this push_back will cover the image before the problem, worried about my death. This will be raised in another blog post. My project files can be found in the resources.

There is also a problem is to find the image pixel is approximate, so it will be blurred, need to deal with, that is, is not the point of integers, through the top and bottom around four points, the average image will be much better. The main part of the function is this:[CPP]  View Plain  copy Int comeon (iplimage* srcimg,vector<float>& directions,  Float angle, int xdim, int ydim,vector<iplimage*>& results)       {             //srcimg is the original image, Directions is the desired direction, angle is the viewing range, Xdim and Ydim are mapped picture sizes, results to store results    &NBSP;&NBSP;&NBSP;&NBSP;MAT&NBSP;SRC ( SRCIMG);        mat img (XDIM+1,YDIM+1,CV_8UC3);        float z=xdim/(2*tan (angle*3.1415926/360));       TickMeter  tm;            tm.start ();         for (Int i=0;i<directions.size (); i++)        {                       for  (Int y=0; y<ydim; y++)              {                      Uchar* p1  = img.ptr<uchar> (y);                 uchar* P0  = src.ptr<uchar> (y);                        for  (int x=0; x<xdim; x++)                   {                    float c;                    if (y<= (int) (YDIM/2))           &nBsp;             c=change1 (x,y,xDim*1.0/2.0, YDIM*1.0/2.0,Z);                    else                        c=change2 (x,y,xdim*1.0/2.0,ydim*1.0/2.0,z);                    int d= (int) C;                        P0  = src.ptr<uchar> (c);                                     float a;                    a=change (x,y,xdim*1.0/2.0,z);                    a=a+directions[i];                       int    b= (int) a;                   &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;FLOAT&NBSP;B=P0[3*B] * (1-a+b) +p0[3* (b+1)]* (a-b);                      float g=p0[3*b+1]* (1-a+b) +p0[3* (b+1) +1]* a-b (;  )                     float r=p0[3*b+2]* (1-a+b) +p0[3* (b+1) +2]* (a-b);                 &nBsp;       p0  = src.ptr<uchar> (c+1);                   float b1= p0[3*b]* (1-a+b) +p0[3* (b+1)]* (a-b);                      float g1=p0[3*b+1]* (1-a+b) +P0[3*

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.