代码:
#include <opencv2/opencv.hpp> #include <string> using namespace std; using namespace cv; int main(){ string img_dir = "/home/sensetime/000000_10.png"; cv::Mat img = cv::imread(img_dir,-1); int col = img.cols; //1242 int row = img.rows; //375 for(int i = 0;i < row;i++){ for(int j = 0;j < col;j++){ cout << "i: " << i << " j: " << j << " pixel: " << int(img.at<uchar>(i,j)) << endl; } } return 0; }
https://www.cnblogs.com/Crysaty/p/6638152.html
如果直接使用g++ *.cpp进行编译,是错误的,需要加载opencv的库进行编译才行,当然你也可以使用cmake来编译
博客里面写的c代码,c++代码是g++ gt_disp.cpp -o Test `pkg-config --cflags --libs opencv`