#include<iostream>
#include<opencv2/highgui.hpp>
#include<opencv2/core/core.hpp>
using namespace cv;
using namespace std;
int main(int argc,char**argv)
{
cv::Mat color,depth;
color=imread("/home/finer/Desktop/images/1.png",IMREAD_COLOR);
depth=imread("/home/finer/Desktop/images/1_depth.png",-1);
imshow("color image",color);
imshow("depth image",depth);
Mat depth1;
depth.convertTo(depth1,CV_16U,1.0/500);
waitKey(0);
for(int i = 0; i<10;++i)
{
unsigned short*d = depth1.ptr<unsigned short>(i+100);
cout<<d[188]<<endl;
}
}
上面是指針訪問圖像像素點的方法,相應的還有指針讀取以及迭代器讀取。
convertTo 用於將對象圖像像素格式轉換爲指定像素格式。 第三個參數爲縮放因子,即每對象圖像像素每個值除以500,注意爲double類型。