Skip to content

Instantly share code, notes, and snippets.

@ashwin
Created September 3, 2014 06:34
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ashwin/565a6f8f09ce69367aab to your computer and use it in GitHub Desktop.
Save ashwin/565a6f8f09ce69367aab to your computer and use it in GitHub Desktop.
Resize or rescale image in OpenCV
const int kNewWidth = 200;
const int kNewHeight = 400;
const float kRescaleFactor = 0.75;
/**
* Resize mat
*/
Mat mat; // Input
Mat new_mat;
resize(mat, new_mat, cvSize(kNewWidth, kNewHeight));
/**
* Rescale mat
*/
Mat mat; // Input
Mat new_mat;
resize(mat, new_mat, cvSize(0, 0), kScaleFactor, kScaleFactor);
/**
* Resize IplImage
*/
IplImage* img; // Input
IplImage* new_img = cvCreateImage(cvSize(kNewWidth, kNewHeight), img->depth, img->nChannels);
cvResize(img, new_img);
/**
* Rescale IplImage
*/
IplImage* img; // Input
const int new_width = (int) ((float) img->width * kRescaleFactor);
const int new_height = (int) ((float) img->height * kRescaleFactor);
IplImage* new_img = cvCreateImage(cvSize(new_width, new_height), img->depth, img->nChannels);
cvResize(img, new_img);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment