c++computer-vision

Visp library - how to resize image


I am using Visp computer vision library and now I have a problem. I want to resize my image and next display it in window. I use function resize but I get some broken image. Here is my code:

vpImageIo::read(I,"test.jpg");
vpDisplayGDI d(I);
vpDisplay::setTitle(I, "My image");

I.resize(10,10);
vpDisplay::display(I);
vpDisplay::flush(I);

Maybe someone had the same problem in the past and resolve it.


Solution

  • The code:

    I.resize(10,10);
    

    will only change the dimension of the image.

    To resize the image, you have to use vpImageTools::resize(). Be careful, the function cannot work in-place (the source and destination images must be different).

    What you want should be something like this:

      vpImage<vpRGBa> I_src, I;
      vpImageIo::read(I_src, "test.jpg");
      vpImageTools::resize(I_src, I, I_src.getWidth()/2, I_src.getHeight()/2);
    
      vpDisplayGDI d(I);
      vpDisplay::setTitle(I, "My image");
    
      vpDisplay::display(I);
      vpDisplay::flush(I);
      vpDisplay::getClick(I);