代码如下: #include<opencv2/highgui/highgui.hpp> #include<stdio.h> using namespace cv; using namespace std; int main() { Mat img = imread("/home/jay/Pictures/python.jpg",CV_LOAD_IMAGE_COLOR); unsigned char *input = (unsigned char*)(img.data); int i,j,r,g,b; for(int i = 0;i < img.rows;i++){ for(int j = 0;j < img.cols;j++){ b = input[j + img.step * i ] ; g = input[j + img.step * i + 1]; r = input[j + img.step * i + 2]; } } Mat target_gray; cvtColor(img , target_gray, CV_RGB2GRAY); //这里需要读取target_gray的data所有数据? return 0; }
for(int i = 0;i < target_gray.rows;i++){
for(int j = 0;j < target_gray.cols;j++){
b = input[j + target_gray.step * i +0] ;
}
}