Ask Your Question
0

Provide shape like cylindrical image to UIImage with OpenCV?

asked 2016-04-06 01:06:28 -0600

Ankit C gravatar image

updated 2016-04-08 01:31:00 -0600

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?

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
2

answered 2016-04-07 05:17:19 -0600

LBerger gravatar image

I hope it will help you

#include "opencv2/stitching/detail/util.hpp"
#include "opencv2/stitching/detail/warpers.hpp"
#include "opencv2/stitching/warpers.hpp"

#include <iostream>
#include <fstream>
#include <algorithm>
#include <ctype.h>

using namespace cv;
using namespace std;

int main(int argc, char* argv[])
{

Mat im=imread("f:/lib/opencv/samples/data/lena.jpg",CV_LOAD_IMAGE_GRAYSCALE);
Mat dst,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(im, k, r, INTER_LINEAR, BORDER_REFLECT, dst);
warper->warpBackward(dst, k, r, INTER_LINEAR, BORDER_REFLECT, im.size(),dstback);
imshow("src",im);
imshow("cylinder warp ",dst);
imshow("cylinder backward(warp)",dstback);
waitKey();
return 0;
}
edit flag offensive delete link more

Comments

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?

Ankit C gravatar imageAnkit C ( 2016-04-08 00:59:35 -0600 )edit

Original image is src and project it on a cylinder (dst) using warp function. After you can unwarp this image using unwarp method result is then dstback

LBerger gravatar imageLBerger ( 2016-04-08 02:30:27 -0600 )edit

Try using CIImage Class. It has many preprogrammed effects and you can write your own as well. Seems you could take some base code from opencv classes and modify it to work. CIImage is much more lightweight than opencv due to the lack of the file conversion until the end of the process. Dont get me wrong I really like opencv for some things, but for image processing for OS, iOS CIImage is a better way to go, imo. Core Image Class works with the 'recipe' of the image and does no acutal pixel conversion until all the processing is done, unlike opencv where you need to convert the file to Mat, then back to UIImage. Just a thought. If you are handy with graphics algorithms it should be a piece of cake.

jmbapps gravatar imagejmbapps ( 2016-04-09 09:34:13 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2016-04-06 01:06:28 -0600

Seen: 1,173 times

Last updated: Apr 08 '16