hi, malik_cisse,
I followed your advise and captured a 12bit image successfully with gstreamer.
Since the image is in big-endian, I performed 'BSWAP' first, then debayering with `cv::cvtColor(img_bayer, img_result, cv::COLOR_BayerRG2BGR)`, a debayering function in OpenCV.
#define BSWAP_16(x) (uint16_t)((((uint16_t)(x)&0x00ff) << | (((uint16_t)(x)&0xff00) >> 8))
void Bayer2ImageNXPTest() {
std::string file_name = "test_12bit_bayer.raw";
FILE *fp1 = fopen(file_name.c_str(), "rb");
int size = GetFileSize(file_name);
char *buf = new char[size];
for (int i = 0; i < size; i++) {
buf[i] = getc(fp1);
}
fclose(fp1);
int width = 4000;
int height = 3000;
std::cout << "file size is " << size << std::endl;
cv::Mat img_bayer = cv::Mat(height, width, CV_16UC1);
memcpy(img_bayer.data, buf, size);
delete buf;
for (int i = 0; i < height; i++) {
for (int j = 0; j < width; j++) {
img_bayer.at<uint16_t>(i, j) = BSWAP_16(img_bayer.at<uint16_t>(i, j)) - 256;
}
}
cv::Mat img_result;
cv::cvtColor(img_bayer, img_result, cv::COLOR_BayerRG2BGR);
cv::Mat img_show;
img_result.convertTo(img_show, CV_8UC3, 1.0f / 256.0f);
cv::resize(img_show, img_show, cv::Size(800, 600));
cv::imshow("show", img_show);
cv::waitKey(0);
}
But I found the image is gray. The debayering process had been proved functional well in another program.
Would you please help me find out the problem, is there some thing special with this debyering process? I confirm that my sensor is a colorful sensor.