Hello I am trying to convert a Mat image in RRGGBB format. According to my knowledge , RRGGBB information should have 4 channels and type should be CV_8UC4. However, I am not getting the correct number of channels after conversion in rrggbb format.
cv::Mat fin_img;
fin_img = cv::imread("/home/laddu/pattern_dataset/221.png");
Mat rgb_img;
cvtColor(fin_img,rgb_img,COLOR_BGR2RGB);
Mat rrggbb_img(rgb_img.rows, rgb_img.cols, CV_8UC4);
// Define color channel mapping
int from_to[] = {0, 1, 1, 2, 2, 3, -1, 0}; // RRGGBB format: R -> B0, G -> B1, B -> B2
// Rearrange color channel values using mixChannels()
mixChannels(&rgb_img, 1, &rrggbb_img, 1, from_to, 4);
// Save image in RRGGBB format
imwrite("/home/laddu/rrggbb_image.png", rrggbb_img);
Mat ex_img = cv::imread("/home/laddu/rrggbb_image.png");
if(ex_img.channels()==4 && ex_img.type()==CV_8UC4)
{
cout<<"IMAGE IS IN RRGGBB FORMAT";
}
else{
cout<<"IMgae is not in RRGGBB format";
}
I might be wrong too. I remember reading it somewhere but I may be completely wrong too. I am just looking for a way to convert a grayscale image (mat format) in hex 0xRGB888 format. This is my current code for trying to convert in hex rgb888 format. However, the conversion i am getting is wrong. To give more information, so I am trying to use this recent Deep Learning model named “FOMO” for object detection. However, to make my input data compatible with their code, I need to get the input in hex format 0xRRGGBB This is my updated code `cv::Mat fin_img;
fin_img = cv::imread(“/home/laddu/pattern_dataset/360.png”,0);
resize(fin_img, fin_img, Size(350,350));
// imshow(“hii”,fin_img);
// waitKey(0);
cv::cvtColor(fin_img, fin_img, cv::COLOR_BGR2RGB);
Mat img_flat = fin_img.reshape(1,fin_img.total()) ;
your heuristic should be to ASK about every thing you read, and get someone to confirm or correct your understanding, before you base anything on that understanding and carry on.
you found a library that is intended for embedded programming. it is C/C++. that is not for beginners. you should learn C first, and gain experience, before you have the necessary background to deal with that library competently.
I peeked into this “edgeimpulse” thing. all they say is that a 6-nibble hex string contains the 24 bits that are customarily used to hold the RGB data of a pixel.
“0xRRGGBB”, first, is not a valid numeral in any programming language, because R and G aren’t hex digits.
it’s a pattern for humans to understand, which says that the lowest two nibbles (one byte) hold the blue value, the next higher bytes holds the green value, and then comes the red value. one could say:
pixel = (red << 16) | (green << 8) | (blue)
such a compound value is useless to neural networks because it’s code, not a scalar value.
neural networks need the values separated, i.e. red, green, blue values individually.