I got the following problem, that I got image files in (supposed to be RGB888) but I'm not sure if it realy is this kind of data. (I only know the supposed format (e.g. 400 * 600) of the data, that's why I made a sample data of a picture, where I exactly know which format the hex data has.)
The Data I created looks something like this:
0xf3, 0x8d, 0x4c, 0xff, 0xf2, 0x8f, 0x4b, 0xff, 0xef, ...
I'm in this case sure, that this is RGB888 because I converted it. So the first step I did was, to load the file and stream the data to a char array.
std::ifstream infile;
char *array;
uint8_t *pixelValues;
infile.exceptions ( std::ifstream::failbit );
try {
infile.open(filename, std::ios_base::binary);
infile >> std::hex >> std::setw(2) >> std::setfill('0');
int length;
if (!infile.bad()) {
length = infile.rdbuf()->pubseekoff(0, std::ios_base::end);
array = new char[length];
infile.rdbuf()->pubseekoff(0, std::ios_base::beg);
infile.read(array, length);
infile.close();
}
uint8_t value;
pixelValues = new uint8_t[length/5];
std::size_t counter = 0;
std::size_t valueCounter = 0;
while (true) {
value = strtol(&array[counter], NULL, 0);
pixelValues[valueCounter++] = value;
while ((array[counter] != ',')) counter++;
counter++;
if (counter >= length) break;
}
}
After this step, the data in uint8_t pixelValues should be a Bitarray of the Data in the File.
My question now is, how to go on... am I doing things right or are there 'smarter' ways of getting an image out of this hex data?
My kolleague told me, that I should go on with the next step by using openCV but I can't get it running at all.
If anybody of you guys has a smart idea, please let me know ;-)