Pyramid-shaped image processing (image scaling)
The main use of the two functions: Pyrup and Pyrdown
Here's the code:
1#include <opencv2\opencv.hpp>2#include <iostream>3#include <string>4 5 #pragmaComment (linker, "/subsystem:\" windows\ "/entry:\" Maincrtstartup\ "")6 7 intMax_kernel_length = to;8 9 using namespacestd;Ten using namespaceCV; One A voidShow (ConstSTD::string&name,ConstMat &img) - { - Namedwindow (name, cv_window_autosize); the imshow (Name, IMG); - } - - intMainvoid) + { -Mat img = Imread ("lena.jpg"); + if(Img.empty ()) A return-1; atShow ("Source", IMG); -Mat tmp=Img.clone (); -Mat DST =tmp; - -Pyrup (TMP, DST, Size (Tmp.rows *2, Tmp.cols *2)); -Show ("bigger", DST); in -Pyrdown (TMP, DST, Size (Tmp.rows/2, Tmp.cols/2)); toShow ("Smaller", DST); + Waitkey (); - return 0; the}
Note that the third parameter of the two functions is of type size, which is an object enlarged, since the image used is 512*512, corresponding to the pyramid image magnification, the enlarged image can not be programmed other than the size of the integer multiples of 2, so for rows*1.5,rows* 7 Wait, these dimensions are going to go wrong. Can only be the original image size multiplied by or except 2 of the positive integer number of powers.
Also note that the magnification shown here is the size of the length and width are magnified, so the above results are:
This means that the original 512x512 image is magnified twice times after the 1024x1024, reduced to 1/2 is 256x256.
Above
OPENCV Official Document Learning record (10)