RSS Subscription
Linux Howtos & Tutorials

Enter your email:

Delivered by


NOTE:New tutorials are from LinuxCareer.com

Poll

Do you own or wish to have iPhone?
 


Linux eBooks FREE Download
A guide to programming Linux kernel modules
Introduction to Linux - A Hands on Guide
A Newbie's Getting Started Guide to Linux

Linux from Scratch - Create Your Own Linux System - Free eBook

Linux: The Hacking Solution (v.3.0)

SQLite 3 with PHP Essential Training – Free Video Training Tutorials

This guide will introduce you to the world of GNU/Linux

The GNU/Linux Advanced Administration

A Complete Beginner's Manual for Ubuntu 10.04 (Lucid Lynx)

Advanced Bash-Scripting Guide

Set up, maintain, and secure a small office email server

Partner Linux Sites:
How-To.LinuxCareer.com
Jobs.LinuxCareer.com
TuxMachines
Monsterb
LinuxBloggers
AdamsInfo
LinuxScrew
All For Linux

Resize an image with OpenCV cvResize function

This is a small code to resize an image to a desired percentage from an original. New size of width and height are calculated from a percentage supplied as a 3th argument. Supplying 100% will simply copy the original image to new image.

cvResize also accepts an interpolation argument, however in case of this small program we use the default linear interpolation.

#include <iostream>
#include "cv.h"
#include "highgui.h"

using namespace std;

int main( int argc, char** argv )

{
// Create an IplImage object *image
IplImage *source = cvLoadImage( argv[1]);
// Here we retrieve a percentage value to a integer
int percent = atoi(argv[3]);

// declare a destination IplImage object with correct size, depth and channels
IplImage *destination = cvCreateImage
( cvSize((
int)((source->width*percent)/100) , (int)((source->height*percent)/100) ),
source->depth, source->nChannels );

//use cvResize to resize source to a destination image
cvResize(source, destination);

// save image with a name supplied with a second argument
cvSaveImage( argv[2], destination );


return 0;

}


Compile:

g++ `pkg-config opencv --cflags --libs` resize_image.cpp -o resize_image


Usage:

./resize_image dsc00056.jpg new_dsc00056.jpg 65%

Share this linux post:

Submit Resize an image with OpenCV cvResize function in Delicious Submit Resize an image with OpenCV cvResize function in Digg Submit Resize an image with OpenCV cvResize function in FaceBook Submit Resize an image with OpenCV cvResize function in Google Bookmarks Submit Resize an image with OpenCV cvResize function in Stumbleupon Submit Resize an image with OpenCV cvResize function in Technorati Submit Resize an image with OpenCV cvResize function in Twitter
 
Comments for this page are closed !!!
Please visit our new Linux Forum for additional help or discussion.


Linux eBooks FREE Download