Sunday, June 20, 2010

Open CV Tutorial - Basic operations for images Rotate and Scale

In this tutorials of OpenCV we will do some basic but interesting operartion on images. We rotate the image and scale it down.

For this we will use a matrix and rotate it. 

/************************************************/


#include "cv.h"
#include "highgui.h"
#include "math.h"
int main()
{
IplImage* src;
IplImage* dst;
int delta;
int angle;
src = cvLoadImage("apple.bmp", 1);
dst = cvCloneImage( src );
delta = 1; angle = 0;
cvNamedWindow( "src", 1 );
cvShowImage( "src", src );
for(;;)
{
float m[6];
double factor = (cos(angle*CV_PI/180.) + 1.1)*3;
CvMat M = cvMat( 2, 3, CV_32F, m );
int w = src->width;
int h = src->height;
m[0] = (float)(factor*cos(-angle*2*CV_PI/180.));
m[1] = (float)(factor*sin(-angle*2*CV_PI/180.));
m[2] = w*0.5f;
m[3] = -m[1];
m[4] = m[0];
m[5] = h*0.5f;
cvGetQuadrangleSubPix( src, dst, &M, 1, cvScalarAll(0));
cvNamedWindow( "dst", 1 ); cvShowImage( "dst", dst );
if( cvWaitKey(5) == 27 )
break;
angle = (angle + delta) % 360;
}
return 0;
}

OUTPUT:- 

ALSO READ :- 


1 comment:

  1. A FREE VIDEO TUTORIAL Website which contains tutorials of -
    Computer Science,
    Competitive exams
    Engineering
    Management
    Economic
    Astronomy
    Psychology
    Communication Skills
    Languages
    Art and Music
    www.openvideotutorial.com
    Click Here Video Tutorials Collection

    ReplyDelete