由于是opencv3.0.0,所以文件夹的结构和书上说的并不一样,找opencv.sln就找不到。
因此前几题几乎没法做,直接做最后一题看看吧
因为看错题目了,以为是把静止的图像缩放,其实是把视频缩放,不过原理差不多
关键是缩放的时候只能够缩放2倍4倍和8倍,再多就不行了,缩放的方法是重复嵌套缩放多次,所以才只有3个阶段啊。
源码:
#include "cv.h"
#include "highgui.h"
int g_size = 2;
int max_size = 8;
int min_size = 2;
void onTrackbarSlide(int size) {
g_size = size;
}
IplImage* doPyrDown( IplImage* in, int filter = CV_GAUSSIAN_5x5)
{
// Best to make sure input image is divisible by two.
//
assert( in->width%2 == 0 && in->height%2 == 0 );
IplImage* out = cvCreateImage(
cvSize( in->width/2, in->height/2 ),
in->depth,
in->nChannels
);
cvPyrDown( in, out );
return( out );
};
int main( int argc, char** argv )
{
IplImage* img = cvLoadImage( argv[1] );
IplImage* img2 = cvCreateImage( cvSize( img->width,img->height ), img->depth, img->nChannels);
cvNamedWindow("Example1", CV_WINDOW_AUTOSIZE );
cvNamedWindow("Example2", CV_WINDOW_AUTOSIZE );
cvShowImage("Example1", img );
cvShowImage("Example2", img2 );
cvCreateTrackbar( "size","Example1",&g_size,max_size, onTrackbarSlide );
while(1) {
img2 = doPyrDown( img );
for(int i=2;i<g_size;i++)
{
img2 = doPyrDown( img2 );
}
cvShowImage( "Example2", img2 );
char c = (char)cvWaitKey(33);
if( c == 27 ) break;
}
cvReleaseImage( &img );
cvReleaseImage( &img2 );
cvDestroyWindow("Example1");
cvDestroyWindow("Example2");
}
难度还是有一点的,主要是自己知道的太少。