0% found this document useful (0 votes)
69 views1 page

Geometry Trans

This document discusses geometry transformations in OpenCV. It provides code examples to resize and rotate an image. The resize function changes the size of an image using interpolation. The warpAffine function rotates an image by generating a rotation matrix specifying the center point, angle, and scale of rotation. It uses interpolation for pixel values between coordinates. A trackbar is implemented to dynamically control the degree and size of transformations.

Uploaded by

api-303634380
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
69 views1 page

Geometry Trans

This document discusses geometry transformations in OpenCV. It provides code examples to resize and rotate an image. The resize function changes the size of an image using interpolation. The warpAffine function rotates an image by generating a rotation matrix specifying the center point, angle, and scale of rotation. It uses interpolation for pixel values between coordinates. A trackbar is implemented to dynamically control the degree and size of transformations.

Uploaded by

api-303634380
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

Geometry Tranform

Geometry Tranform
Li Yicheng
LIACS
[email protected]
Abstract
Here we discuss how to do the geometry transformation in opencv. We will get the operations like
resize , rotate, and we would learn how interpolation plays in this part. Furthermore, a Trackbar would be
implemented according to the previous tutorial to change how much degree and howmuch size would the
image transformed.

I.

Code and API

1
2 void processImage ( )
3 {
4 i n t i n t e r p o l a t i o n = INTER_AREA ; / /
INTER_CUBIC ; / / INTER_LANCZOS4 ; / /
INTER_LINEAR ; / / INTER_NEAREST ;
5 r e s i z e ( image , processedImage , S i z e ( 2 0 0 ,
200) , 0 , 0 , interpolation ) ;
6 imshow ( " Resized Image " , processedImage ) ;
7
8 double angle = 3 0 . 0 ;
9 double s c a l e = 0 . 7 ;
10 P o i n t 2 f imageCenter = P o i n t 2 f ( image . c o l s
/ 2 . , image . rows / 2 . ) ;
11 Mat r o t a t i o n M a t = g e t R o t a t i o n M a t r i x 2 D (
imageCenter , angle , s c a l e ) ;
12 warpAffine ( image , processedImage ,
r o t a t i o n M a t , image . s i z e ( ) ) ;
13 imshow ( " Rotated Image " , processedImage ) ;
14 }
15
16 API :
17 void r e s i z e ( InputArray s r c , OutputArray
dst , S i z e dsiz e , double f x =0 , double
f y =0 , i n t i n t e r p o l a t i o n =INTER_LINEAR )
18
19 void warpAffine ( InputArray s r c ,
OutputArray dst , InputArray M, S i z e
ds ize , i n t f l a g s =INTER_LINEAR , i n t
borderMode=BORDER_CONSTANT, c o n s t
S c a l a r& borderValue= S c a l a r ( ) )

tutorial

20
21 Mat g e t R o t a t i o n M a t r i x 2 D ( P o i n t 2 f c e n t e r ,
double angle , double s c a l e )

Ifunction resize
fx is the scale factor along the Horizontal
axis; when it equals 0, it is computed as :
(double)dsize.width/src.cols
fy is the scale factor along the vertical axis;
when it equals 0, it is computed as :
(double)dsize.height/src.rows
dsize explicitly show the size of the output
image.
IwarpAffine
M is a 2 3trans f ormationmatrix
operation: dst( x, y) = src( M11 x + M12 Y +
M13 , M21 x, + M22 y + M23 )
in the code we use the rotation matrix as the
M here.
Irotation
matrix


(1 ) center.x .center.y
M=
center.x + (1 ) center.y
= scale. cos( angle)
= scale. sin( angle)

referred to sebastians work check his work in PACKT.com

You might also like