#include<opencv2/opencv.hpp>
#include<stdio.h>
using namespace std;
using namespace cv;
int main(int argc, char* argv[])
{
Mat img = imread("C:/Users/鑫鑫/Desktop/6.jpg",-1);//正确读取照片
FILE*f1;
f1 = fopen("C:/Users/鑫鑫/Desktop/原图RGB.txt", "a");
int pixelR, pixelG, pixelB;//定义三个接收RGB的变量
for (int r = 0; r < img.rows; r++)
{
for (int c = 0; c < img.cols; c++)
{
pixelB = img.at<Vec3b>(r, c)[0];//注意opencvz中Scalar(B,G,R)不是R,G,B这个顺序
pixelG = img.at<Vec3b>(r, c)[1];
pixelR = img.at<Vec3b>(r, c)[2];
fprintf(f1, "(%d,%d,%d)\n", pixelR, pixelG, pixelB);//输出定向到文件保存
}
}
return 0;
}
Use the opencv library to view the RGB color value of a picture
Guess you like
Origin blog.csdn.net/weixin_43408595/article/details/89205423
Recommended
Ranking