Use the opencv stretch image to expand the resolution sample
- 2020-04-02 02:19:46
- OfStack
Using OPENCV image processing library, stretch the image to expand the resolution
//Zoom image file
#include <opencv2/opencv.hpp>
using namespace std;
//Hide console window
#pragma comment(linker, "/subsystem:"windows" /entry:"mainCRTStartup"")
int main()
{
const char *pstrImageName = "airplane.jpg";
const char *pstrSaveImageName = "airplane Scaling figure .jpg";
const char *pstrWindowsSrcTitle = " The original image ";
const char *pstrWindowsDstTitle = " Scaling figure ";
double fScale = 2;//Zoom multiples
CvSize czSize; //Target image size
//Reading an image from a file & NBSP;
IplImage *pSrcImage = cvLoadImage(pstrImageName, CV_LOAD_IMAGE_UNCHANGED);
IplImage *pDstImage = NULL;
//Calculate the target image size
czSize.width = pSrcImage->width * fScale;
czSize.height = pSrcImage->height * fScale;
//Create the image and scale it
pDstImage = cvCreateImage(czSize, pSrcImage->depth, pSrcImage->nChannels);
cvResize(pSrcImage, pDstImage, CV_INTER_AREA);
//Create a window
cvNamedWindow(pstrWindowsSrcTitle, CV_WINDOW_AUTOSIZE);
cvNamedWindow(pstrWindowsDstTitle, CV_WINDOW_AUTOSIZE);
//Displays an image in the specified window
cvShowImage(pstrWindowsSrcTitle, pSrcImage);
cvShowImage(pstrWindowsDstTitle, pDstImage);
//Waiting for key events
cvWaitKey();
//Save the picture
cvSaveImage(pstrSaveImageName, pDstImage);
cvDestroyWindow(pstrWindowsSrcTitle);
cvDestroyWindow(pstrWindowsDstTitle);
cvReleaseImage(&pSrcImage);
cvReleaseImage(&pDstImage);
return 0;
}