#include "mainwindow.h" #include <QApplication> #include <opencv2/imgproc.hpp> #include <opencv2/highgui.hpp> #include <opencv2/opencv.hpp> using namespace cv; using namespace std; #define WINDOW_NAME "[圖像]" int main(int argc, char *argv[]) { QApplication a(argc, argv); system("chcp 65001"); String imgpath = "F:\\MyCode\\dcq.jpg"; Mat srcImage = imread(imgpath, 1); // Mat tmpImage = srcImage; if(!srcImage.data){printf("讀取失敗");return -1;} resize(srcImage, srcImage, Size(250, 125)); namedWindow(WINDOW_NAME, WINDOW_AUTOSIZE); imshow(WINDOW_NAME, srcImage); int key = 0; Mat dstImage1 ; while(1) { key = waitKey(9); //讀取鍵值到key種 switch(key) { case 27: //ESC return 0; break; case 'q': //鍵值Q return 0; break; case 'a': pyrUp(srcImage, dstImage1, Size(srcImage.cols*2, srcImage.rows*2)); printf("pyrUp圖像尺寸*2"); imshow("pyrUp", dstImage1); break; case 'w': resize(srcImage, dstImage1, Size(srcImage.cols*2, srcImage.rows*2), INTER_LINEAR); printf("pyrUp圖像尺寸*2"); imshow("pyrUp", dstImage1); break; case '1': resize(dstImage1, dstImage1, Size(dstImage1.cols*1.2, dstImage1.rows*1.2), INTER_LINEAR); printf("pyrUp圖像尺寸*2"); imshow("resize", dstImage1); break; case 'd': resize(srcImage, dstImage1, Size(dstImage1.cols/2, dstImage1.rows/2)); imshow("sXresize", dstImage1); break; case 's': pyrDown(dstImage1, dstImage1, Size(dstImage1.cols/2, dstImage1.rows/2)); imshow("sXresize", dstImage1); break; } } pyrDown(srcImage, dstImage1, Size(srcImage.cols/2, srcImage.rows/2)); imshow("pyrDown", dstImage1); return a.exec(); }