Opencv读取图片(三通道和单通道)像素并保存
三通道: #include <opencv2/opencv.hpp> #include<vector> #include <fstream> using namespace std; using namespace cv; int main(int argc, char* argv[]) { const char* imagename = "1.png"; //从文件中读入图像 Mat img = imread(imagename); ofstream outfile("3chn.txt"); //如果读入图像失败 if (img.empty()) { fprintf(stderr, "Can not load image %s\n", imagename); return -1; } int i, j; int cPointR, cPointG, cPointB, cPoint;//currentPoint; { for (j = 1; j<img.cols; j++) { cPointB = img.at<Vec3b>(i, j)[0]; cPointG = img.at<Vec3b>(i, j)[1]; cPointR = img.at<Vec3b>(i, j)[2