I get a Bayer image(raw data) from the Basler camera and save it in a CSV file. again I get a GBR image from the camera and convert it to raw data using the code below and save it to a CSV file. but these two CSV files are different. 70 percent of the cells are exactly the same and others have the difference between -130 up to 127 but just 4 percent of them have a difference greater than 5 or less than -5. what is the problem? and how can I fix it? or is it normal?
cv::Mat ConvertBGR2Bayer(cv::Mat BGRImage) {
cv::Mat BayerImage(BGRImage.rows, BGRImage.cols, CV_8UC1);
int channel;
for (int row = 0; row < BayerImage.rows; row++)
{
for (int col = 0; col < BayerImage.cols; col++)
{
if (row % 2 == 0)
{
//even columns and even rows = blue = channel:0
//even columns and uneven rows = green = channel:1
channel = (col % 2 == 0) ? 0 : 1;
}
else
{
//uneven columns and even rows = green = channel:1
//uneven columns and uneven rows = red = channel:2
channel = (col % 2 == 0) ? 1 : 2;
}
BayerImage.at<uchar>(row, col) = BGRImage.at<cv::Vec3b>(row, col).val[channel];
}
}
return BayerImage;
}
'''