学OpenCV
=========================================================
原书代码有问题,这里我改了下。
=========================================================
啊
1 #include <iostream> 2 #include <opencv2/opencv.hpp> 3 4 using namespace std; 5 using namespace cv; 6 7 int Test1() 8 { 9 Mat img = imread(R"(C:\testNoGit\learnOpenCV4-master\data\lena.png)"/*,IMREAD_GRAYSCALE*/); 10 if (img.empty()) 11 { 12 cout << "bad file" << endl; 13 return 1; 14 } 15 16 Mat imgSmall, imgBig1, imgBig2, imgBig3; 17 18 int rows = img.rows; 19 int cols = img.cols; 20 resize(img, imgSmall, Size(cols/2,rows/2), 0, 0, INTER_AREA);//变为原图的1/2*1/2=1/4大小 21 imshow("imgSmall", imgSmall); 22 23 resize(img, imgBig1, Size(), 3.0, 3.0, INTER_NEAREST);//颗粒感 24 imshow("imgBig1", imgBig1); 25 26 resize(img, imgBig2, Size(), 3.0, 3.0, INTER_LINEAR);//模糊,虚,看着晕 27 imshow("imgBig2", imgBig2); 28 29 resize(img, imgBig3, Size(), 3.0, 3.0, INTER_CUBIC);//效果好 30 imshow("imgBig3", imgBig3); 31 32 return 0; 33 } 34 35 int main() 36 { 37 Test1(); 38 waitKey(0); 39 40 return 0; 41 }
效果
这里用的1.5的缩放,3.0的太大了,没法截图