載入影象和遍歷畫素(OpenCV)
阿新 • • 發佈:2018-11-24
#include <iostream> using namespace std; #include <opencv2\opencv.hpp> using namespace cv; void main() { Mat imgMat = imread("0_depth.png"); imshow("原圖", imgMat); cout << imgMat.channels() << endl; Mat imgGray; cvtColor(imgMat, imgGray, CV_RGB2GRAY); cout << imgGray.channels() << endl; int nRows = imgGray.rows; int nCols = imgGray.cols * imgGray.channels(); cout << nRows << endl; cout << nCols << endl; for (int j = 0; j < nRows; j++) { uchar* data = imgGray.ptr<uchar>(j); for (int i = 0; i < nCols; i++) { if (data[i]!=0) { cout << data[i] << endl; } } } imshow("處理後的影象", imgGray); waitKey(0); system("pause"); }