一目标
当我们把bayer partten demosic后,我们通常需要把rgb三个通道的值导出来以便分析
我这里是把value值保存到txt文件,然后把txt文件导入到excel以便分析
二代码
#include <opencv2/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/imgproc/imgproc_c.h>
#include <math.h>
#include < fstream>
#include < iostream>
/将下列代码带入到我上一篇文章的函数里*/
//查看每个channel的值
cv::Vec3f pixel = rgbImage_rg.atcv::Vec3w(0, 0);
float blue = pixel[0];
float green = pixel[1];
float red = pixel[2];
std::cout << "Blue: " << blue << std::endl;
std::cout << "Green: " << green << std::endl;
std::cout << "Red: " << red << std::endl;
std::ofstream file_raw_value_R("E:/test/PixelValues_R.txt");
std::ofstream file_raw_value_G("E:/test/PixelValues_G.txt");
std::ofstream file_raw_value_B("E:/test/PixelValues_B.txt");
for (int i = 0; i < rgbImage_gb.rows; ++i)
{
for (int j = 0; j < rgbImage_gb.cols; ++j)
{
// 获取像素值
cv::Vec3w pixel = rgbImage_rg.at<cv::Vec3w>(i, j);
ushort blue = pixel[0];
ushort green = pixel[1];
ushort red = pixel[2];
// 将像素值写入文本文件
file_raw_value_R << " " << red << ", ";
file_raw_value_G << " " << green << ", ";
file_raw_value_B << " " << blue << ", ";
}
file_raw_value_R << std::endl;
file_raw_value_G << std::endl;
file_raw_value_B << std::endl;
}
// 关闭文件
file.close();
注意事项
1.这里是经过bayer partten demosic后的一张图像所有的值,所以在excel当中可能不太好分析出来
所以最好把它变成1625个大块,每个大块当中再分成55或者44的小块,已10801920为例每个小块估计有207个像素值,把这个207个像素值通过加权平均或者乘上高斯核,需要看具体要求了。
-
ushort blue = pixel[0]; ushort green = pixel[1]; ushort red = pixel[2]; 不一定pixel[0];就是b通道,的看sensor的具体型号, B G G R G B R G G R B G R G G B 应该就分这几种格式,所以当调用cv::cvtColor(bayerImage, rgbImage_rg, cv::COLOR_BayerRG2BGR);如果不知道的用哪种模式,只能一遍遍试了
时间
2023.10.22-10.24
本文介绍如何使用OpenCV库在C++中处理Bayer图像格式,提取RGB通道值并保存到文本文件,以便后续分析。涉及BayertoRGB转换、像素操作和数据处理方法。
bayer partten demosic后piexl中 r,g,b保存到txt文件中&spm=1001.2101.3001.5002&articleId=134013443&d=1&t=3&u=8bac132d9e0847268054c2c2b5a91d78)
6230

被折叠的 条评论
为什么被折叠?



