OpenCV入門 - 調整圖片尺寸

OpenCV入門 - 調整圖片尺寸(image resize)


   通過Mat::size()方法得到關於圖像大小的Size實例,通過resize方法調整圖像大小。代碼如下:
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/nonfree/features2d.hpp> //
#include <opencv2/imgproc/imgproc.hpp> // resize()


#include <iostream>
using namespace cv;
using namespace std;


int main(int argc, const char *argv[]){
    Mat big = imread("imgs/linux.jpg",-1);//CV_LOAD_IMAGE_ANYDEPTH);// the big pic
    Mat dst = imread("imgs/200X200.jpg", -1);


    cout << "Mat info:" << endl;
    cout << "Original pic," << big.rows << " : "<< big.cols << endl;
    cout << "dst pic, " << dst.rows << " : "<< dst.cols << endl;
    
    Size s = big.size();
    cout << "Pic Size info:" << endl;
    cout << "Original pic," << s.width << " : "<< s.height << endl;
    s = dst.size();
    cout << "dst  pic," << s.width << " : "<< s.height << endl;
    // resize big to dst 
    cv::resize(big, dst, dst.size());






    // show it on an image
    imshow("big", big);
    imshow("test", dst);
    waitKey(0);


    return 0;
}





效果:
















參考:
1.cv::resize()
http://docs.opencv.org/2.4.10/modules/imgproc/doc/geometric_transformations.html#resize
2.cv::Size
http://docs.opencv.org/modules/core/doc/basic_structures.html#mat-size



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章