切換
舊版
前往
大廳
主題

【OpenCV】邊寫作業邊筆記 之 Mat資料型態

璇琰 | 2015-10-14 13:13:23 | 巴幣 38 | 人氣 9687

建立Mat的時候需要設定型態,例:

//C是一個3*3的矩陣,存彩色圖、數值是float
Mat C = Mat(3, 3, CV_32FC3)


最後C1是黑白圖C3是彩圖,也就是BGR,這樣的圖中,實際上column比圖片大小要展成3倍,簡單的一個測試方式是,把每個pixel都給0,如果出現全黑,表示他真的是C1,如果圖只消失1/3,表示他其實是GBR,測試的code如下:

   Mat img= imread("Fig.tif");      //讀一張圖
    for(int i=0;i<img.rows;i++)     //i是y座標
    {
        for(int j=0;j<img.cols;j++)  //j是x座標
            img.at<uchar>(i,j)=0;
    }
    namedWindow("Window");  //開一個視窗
    imshow("Window",img);       //在視窗裡show出圖


我就這樣愉快地發現,作業測資看起來是黑白的,其實是個RGB圖【


而其實我要記的重點是

CV_8U:8-bit unsigned integers ( 0~255 )
CV_8S:8-bit signed integers ( -128~127 )
CV_16U:16-bit unsigned integers ( 0~65535 )                           →大小相當於short
CV_16S:16-bit signed integers ( -32768~32767 )
                      →大小相當於short
CV_32S:32-bit signed integers ( -2147483648~2147483647 )  
→大小相當於long
CV_32F:32-bit floating-point numbers
CV_64F:64-bit floating-point numbers

另外
Mat_<uchar>對應CV_8U
Mat_<char>對應CV_8S

Mat_<short>對應CV_16S
Mat_<int>對應CV_32S
Mat_<float>對應CV_32F
Mat_<double>對應CV_64F



參考資料:http://blog.csdn.net/yang_xian521/article/details/7107786

創作回應

VODKA
整理得有夠好的 謝謝幫大忙了
2020-03-06 19:32:12
璇琰
啊能幫上忙真是太好了XD
2020-04-01 20:48:45

更多創作