Ask Your Question

Ankit C's profile - activity

2016-04-08 01:20:12 -0500 asked a question Convert image to cylindrical shape.

Hi,

I will try to convert my image to cylindrical shape,I am using objective c,

Here I am using below code, but getting same image without curved,

 cv::Mat cylindricalimg (Mat img)
 {
   //with img object i got the original image
   cv::Mat dst;
   cv::Mat dstback;

   Ptr<WarperCreator> warper_creator;
   warper_creator = makePtr<CylindricalWarper>();

   Mat k=(Mat_<float>(3,3) <<2, 0, 0,  0, 1, -0,   0,0,0.001);
   Mat r=(Mat_<float>(3,3) << 1, 0, 0,    0,  1, 0,    0, 0,1);

   Ptr<detail::RotationWarper> warper=warper_creator->create(static_cast<float>(1000));
   warper->warp(img, k, r, INTER_LINEAR, BORDER_REFLECT, dst);
   warper->warpBackward(dst, k, r, INTER_LINEAR, BORDER_REFLECT, img.size(),dstback);

   return dstback;
 }

Please let me know where I have done mistake?

Thanks, In advance.

2016-04-08 01:15:12 -0500 received badge  Editor (source)
2016-04-08 00:59:35 -0500 commented answer Provide shape like cylindrical image to UIImage with OpenCV?

Hi @LBerger thank you for Answer,But it's not working for me,I got the same image without curve, I have update code with question, Please let me know where I have done mistake?

2016-04-08 00:46:49 -0500 received badge  Enthusiast
2016-04-06 01:06:28 -0500 asked a question Provide shape like cylindrical image to UIImage with OpenCV?

Hello,

I want to give shape like cyndrical image to my UIImage. I am using objective c and opencv library.

With stitcher class we are able to provide shape for the images with below code,

 cv::Mat stitch (vector<Mat>& images)
 {
   imgs = images;
   Mat pano;
   Stitcher stitcher = Stitcher::createDefault(try_use_gpu);
   Stitcher.setWarper( new cv::CylindricalWarper);

   Stitcher::Status status = stitcher.stitch(imgs, pano);

    if (status != Stitcher::OK)
    {
    cout << "Can't stitch images, error code = " << int(status) << endl;
        //return 0;
    }
    return pano;
 }

sticher works with more than one image. It's not work with one image.

opencv provide cylindrical method link, But how we can use this method for warping Image? If any one provide some source or code or give some idea, How i can use this, It's help me a lot.

Thank in advance.

As per the @LBerger Answer, Here i have updated code,

Here I am using below code, but getting same image without curved,

 cv::Mat cylindricalimg (Mat img)
 {
   //with img object i got the original image
   cv::Mat dst;
   cv::Mat dstback;

   Ptr<WarperCreator> warper_creator;
   warper_creator = makePtr<CylindricalWarper>();

   Mat k=(Mat_<float>(3,3) <<2, 0, 0,  0, 1, -0,   0,0,0.001);
   Mat r=(Mat_<float>(3,3) << 1, 0, 0,    0,  1, 0,    0, 0,1);

   Ptr<detail::RotationWarper> warper=warper_creator->create(static_cast<float>(1000));
   warper->warp(img, k, r, INTER_LINEAR, BORDER_REFLECT, dst);
   warper->warpBackward(dst, k, r, INTER_LINEAR, BORDER_REFLECT, img.size(),dstback);

   return dstback;
 }

Please let me know where i have done mistake?

2016-04-01 04:30:42 -0500 asked a question How to convert image to cylindrical shape?

Hello,

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 description

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

Thanks in advance