使用opencv拉伸圖像擴大分辨率示例
使用OPENCV圖像處理庫,拉伸圖像擴大分辨率
//縮放圖像文件
#include <opencv2/opencv.hpp>
using namespace std;
//隱藏控制臺窗口
#pragma comment(linker, "/subsystem:\"windows\" /entry:\"mainCRTStartup\"")
int main()
{
const char *pstrImageName = "airplane.jpg";
const char *pstrSaveImageName = "airplane縮放圖.jpg";
const char *pstrWindowsSrcTitle = "原圖";
const char *pstrWindowsDstTitle = "縮放圖";
double fScale = 2;//縮放倍數(shù)
CvSize czSize; //目標圖像尺寸
//從文件中讀取圖像
IplImage *pSrcImage = cvLoadImage(pstrImageName, CV_LOAD_IMAGE_UNCHANGED);
IplImage *pDstImage = NULL;
//計算目標圖像大小
czSize.width = pSrcImage->width * fScale;
czSize.height = pSrcImage->height * fScale;
//創(chuàng)建圖像并縮放
pDstImage = cvCreateImage(czSize, pSrcImage->depth, pSrcImage->nChannels);
cvResize(pSrcImage, pDstImage, CV_INTER_AREA);
//創(chuàng)建窗口
cvNamedWindow(pstrWindowsSrcTitle, CV_WINDOW_AUTOSIZE);
cvNamedWindow(pstrWindowsDstTitle, CV_WINDOW_AUTOSIZE);
//在指定窗口中顯示圖像
cvShowImage(pstrWindowsSrcTitle, pSrcImage);
cvShowImage(pstrWindowsDstTitle, pDstImage);
//等待按鍵事件
cvWaitKey();
//保存圖片
cvSaveImage(pstrSaveImageName, pDstImage);
cvDestroyWindow(pstrWindowsSrcTitle);
cvDestroyWindow(pstrWindowsDstTitle);
cvReleaseImage(&pSrcImage);
cvReleaseImage(&pDstImage);
return 0;
}
相關文章
C語言的可變參數(shù)函數(shù)實現(xiàn)詳解
某些情況下我們希望函數(shù)的參數(shù)個數(shù)可以根據(jù)需要確定,因此c語言引入可變參數(shù)函數(shù)。典型的可變參數(shù)函數(shù)的例子有printf()、scanf()等,下面我就開始講解2021-08-08C語言三種函數(shù)調(diào)用約定_cdecl與_stdcall及_fastcall詳細講解
本篇文章使用的工具是vs2010,內(nèi)容可能涉及到匯編的知識,建議有一些匯編基礎的再來看,不過沒有匯編基礎也沒有關系,了解一下這三種調(diào)用約定即可2022-10-10