-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEscale.cpp
51 lines (42 loc) · 1.05 KB
/
Escale.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include "opencv2/core/core.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/imgproc/imgproc_c.h"
#include <iostream>
#include <cmath>
#include <string>
int ScaleX;
int ScaleY;
IplImage * src;
IplImage * res;
IplImage * ScaleImage( )
{
float dw = ((float)ScaleX)/100;
float dh = ((float)ScaleY)/100;
cvSet( res, CV_RGB(0,0,0) );
float a[] = { dw, 0, 0,
0, dh, 0
};
CvMat * M = cvCreateMat(2,3,CV_32F);
cvSetData(M, a, sizeof(float)*3);
cvWarpAffine(src, res, M, CV_INTER_LINEAR);
cvReleaseMat(&M);
return res;
}
void onChange( int )
{
cvShowImage("Lena", ScaleImage() );
}
int main(int argc, const char* argv[])
{
src = cvLoadImage("lena.jpg", 1);
res = cvCreateImage( cvSize(src->width, src->height), src->depth, src->nChannels );
ScaleX = 100;
ScaleY = 100;
cvNamedWindow("Lena", CV_WINDOW_AUTOSIZE);
cvShowImage("Lena", src);
cvCreateTrackbar("Escala X", "Lena", &ScaleX, 200, onChange );
cvCreateTrackbar("Escala Y", "Lena", &ScaleY, 200, onChange );
cvWaitKey();
return 0;
}