• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            隨筆 - 46  文章 - 39  trackbacks - 0
            <2021年6月>
            303112345
            6789101112
            13141516171819
            20212223242526
            27282930123
            45678910

            常用鏈接

            留言簿(2)

            隨筆分類

            隨筆檔案

            友情鏈接

            搜索

            •  

            最新評論

            閱讀排行榜

            評論排行榜

            目標
            學習:1、使用imread載入圖像。
                     2、使用namedWindow創建命名OpenCV窗口。
                     3、使用imshow在OpenCV窗口中顯示圖像。

            源碼
             1 #include <opencv2/core/core.hpp>
             2 #include <opencv2/highgui/highgui.hpp>
             3 #include <iostream>
             4 
             5 using namespace cv;
             6 using namespace std;
             7 
             8 int main(int argc, char ** argv)
             9 {
            10     if (2 != argc)
            11     {
            12         cout << " Usage: display_image ImageToLoadAndDisplay" << endl;
            13         return -1;
            14     }
            15 
            16     Mat image;
            17     image = imread(argv[1], CV_LOAD_IMAGE_COLOR);          // Read the file
            18 
            19     if (!image.data)                                                                 // Check for invalid input
            20     {
            21         cout << "Could not open or find the image" << std::endl;
            22         return -1;
            23     }
            24 
            25     namedWindow("Display window", WINDOW_AUTOSIZE);      // Create a window for display
            26     imshow("Display window", image);                                     // Show our image inside it.
            27 
            28     waitKey(0);                                                                       // wait for a keystroke in the window
            29     return 0;
            30 }

            說明
            在使用OpenCV 2 的功能之前,幾乎總是要包含
            1、core 部分,定義庫的基本構建塊
            2、highgui模塊,包含輸入輸出操作函數。

             #include <opencv2/core/core.hpp>
             #include <opencv2/highgui/highgui.hpp>
             #include <iostream>

            還需要include<iostream>這樣更容易在console上輸出輸入。為了避免數據結構和函數名稱與其他庫沖突,OpenCV有自己的命名空間cv。當然為了避免在每個關鍵字前都加cv::keyword,可以在頭部導入該命名空間。
            using namespace cv;
            using namespace std;

            需要在命令行輸入有效的圖像名稱。
            if (2 != argc)
            {
                  cout << " Usage: display_image ImageToLoadAndDisplay" << endl;
                  return -1;
            }
            然后創建Mat對象用于存儲載入的圖像數據。
            Mat image;

            調用imread函數載入圖像(圖像名稱為argv[1]指定的)。第二個參數指定圖像格式。
            1、CV_LOAD_IMAGE_UNCHANGED (<0) loads the image as is(including the alpha channel if present)
            2、CV_LOAD_IMAGE_GRAYSCALE (0) loads the image as an intensity one
            3、CV_LOAD_IMAGE_COLOR (>0) loads the image in the BGR format

            image = imread(argv[1], CV_LOAD_IMAGE_COLOR);      // Read the file
            如果第二個參數未指定,那么默認為CV_LOAD_IMAGE_COLOR

            為了檢查圖像是否正常載入,我們用namedWindow函數創建一個OpenCV窗口來顯示圖像。需要指定窗口名稱和大小。
            第二個參數默認為:WINDOW_AUTOSIZE
            1、WINDOW_AUTOSIZE    只支持QT平臺。
            2、WINDOW_NORMAL       QT上支持窗口調整大小。

            最后在創建的窗口中顯示圖像
            imshow("Display window", image);   
                                         
                 

            結果
            編譯執行程序。
            ./DisplayImage d:\apple.jpg
            posted on 2016-07-11 07:58 canaan 閱讀(972) 評論(0)  編輯 收藏 引用 所屬分類: OPenCV學習
            国产精品美女久久久久| 国产69精品久久久久观看软件| 亚洲AV无一区二区三区久久| 久久WWW免费人成一看片| 久久午夜羞羞影院免费观看| 久久久国产精品福利免费 | 亚洲日本va午夜中文字幕久久| 香蕉久久影院| 精品无码久久久久久午夜| 久久er国产精品免费观看8| 乱亲女H秽乱长久久久| 久久精品女人天堂AV麻| 久久人人妻人人爽人人爽| 大香网伊人久久综合网2020| 国产激情久久久久久熟女老人| 一本伊大人香蕉久久网手机| 伊人久久久AV老熟妇色| 久久精品国产一区二区电影| 日韩精品久久无码人妻中文字幕| 亚洲国产成人久久综合区| 国产69精品久久久久777| 久久精品国产99国产精品亚洲| 精品久久久久久亚洲| 东方aⅴ免费观看久久av| 久久国产欧美日韩精品免费| 久久综合九色综合97_久久久| 亚洲国产另类久久久精品黑人| 色综合久久天天综线观看| 91精品国产91久久久久久| 国产精品岛国久久久久| 久久久无码精品亚洲日韩蜜臀浪潮 | 国内精品久久久久久久亚洲| 久久99国产精一区二区三区| 久久久久久夜精品精品免费啦| 伊人久久大香线蕉av不卡| 亚洲欧美一区二区三区久久| 久久本道久久综合伊人| 久久久久国产视频电影| 久久久久国产精品嫩草影院| 日韩欧美亚洲国产精品字幕久久久| 久久精品亚洲精品国产欧美|