isp处理流程(2)bayer partten demosic后piexl中 r,g,b保存到txt文件中

本文介绍如何使用OpenCV库在C++中处理Bayer图像格式,提取RGB通道值并保存到文本文件,以便后续分析。涉及BayertoRGB转换、像素操作和数据处理方法。

一目标

当我们把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个像素值通过加权平均或者乘上高斯核,需要看具体要求了。

  1.      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

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值