0

I am using objective c language.

I want to convert my image to cylindrical shape. Here I am using below cpp file code to convert image.

    cv::Mat CylindricalWarper2 (Mat img)
    {
        cv::Mat destImgMat(img.size(), CV_8U);

        for(int y = 0; y < img.rows; y++)
        {
            for(int x = 0; x < img.cols; x++)
            {
                cv::Point2f current_pos(x,y);

                current_pos = convert_pt1dd(current_pos, img.cols, img.rows);

                cv::Point2i top_left((int)current_pos.x,(int)current_pos.y);            

                if(top_left.x < 0 || top_left.x > img.cols-2 || top_left.y < 0 ||   
                top_left.y > img.rows-2)
                {
                   continue;
                }
                //bilinear interpolation
                float dx = current_pos.x-top_left.x;
                float dy = current_pos.y-top_left.y;

                float weight_tl = (1.0 - dx) * (1.0 - dy);
                float weight_tr = (dx)       * (1.0 - dy);
                float weight_bl = (1.0 - dx) * (dy);
                float weight_br = (dx)       * (dy);

                uchar value = weight_tl * img.at<uchar>(top_left) +
                weight_tr * img.at<uchar>(top_left.y,top_left.x+1) +
                weight_bl * img.at<uchar>(top_left.y+1,top_left.x) +
                weight_br * img.at<uchar>(top_left.y+1,top_left.x+1);

                destImgMat.at<uchar>(y,x) = value;
            }
        }
        return destImgMat;
     }


    cv::Point2f convert_pt1dd(cv::Point2f point,int w,int h)
    {
          cv::Point2f pc(point.x-w/2,point.y-h/2);

         float f = w;
         float r = w;

         float omega = w/2;
         float z0 = f - sqrt(r*r-omega*omega);

         float zc = (2*z0+sqrt(4*z0*z0-4*(pc.x*pc.x/(f*f)+1)*(z0*z0-r*r)))/(2*      
         (pc.x*pc.x/(f*f)+1));

         cv::Point2f final_point(pc.x*zc/f,pc.y*zc/f);
         final_point.x += w/2;
         final_point.y += h/2;

         return final_point;
     }

With this code I got the cylindrical shape but my image cut down. Not get the full cylindrical projection image,My image look like below,

Image link

I want to display my full image in cylindrical shape. If some source or help provided, greatly Appreciated.

Thanks in advance

Ankit
  • 1
  • 3
  • Is your input image 3 channel / RGB ? Because your destination image only has 1 channel (you're creating it as CV_8U, which has only one channel) – yhenon Apr 01 '16 at 14:45
  • Possible duplicate of [Convert image to Cylindrical shape image with OpenCV library. Call cpp class method in Objective C](http://stackoverflow.com/questions/36308994/convert-image-to-cylindrical-shape-image-with-opencv-library-call-cpp-class-met) – beaker Apr 01 '16 at 15:58
  • here is a similar question but for java https://stackoverflow.com/questions/39944635/convert-an-image-to-cylindrical-shape-in-java – Areza Aug 26 '21 at 12:26

0 Answers0