Monday, September 10, 2012

resize Image in OpenCV

This is simple. Just in case people may need it sometimes.
Here, we resize the image into 1 quarter of the original image, with half height and width comparing to original image.


#include <iostream>
#include <opencv2/opencv.hpp>

int main(int argc, const char * argv[])
{
    // Read original image into varialbe img
    cv::Mat img = cv::imread("/Users/herbert19lee/Desktop/lena1.jpg");
    // Declare variable img_resize as container for resized image
    cv::Mat img_resize;

    // resize the original img, as half size of original cols and rows
    // cv::Size2i(img.cols/2, img.rows/2) is where you specify the desired dimension for resized image
    cv::resize(img, img_resize, cv::Size2i(img.cols/2, img.rows/2));
  
    // Visualize the original and resized image in window: lena and lena_resize respectively. 
    cv::namedWindow("lena");
    cv::namedWindow("lena_resize");
    cv::imshow("lean", img);
    cv::imshow("lena_resize", img_resize);
    
    cv::waitKey();
    return 0;
}

1 comment:

prettify