Closed Uzver123 closed 1 month ago
Hello,
I suspect that this is because your pixel type is unknown, for a PLAIN image in your ImageReader::Options
you must also provide the correct options.fileInfo.imageLayout
and/or options.fileInfo.pixelType
fields.
The error message was not meaningful because I found that the pixel type error check was after the alignment guess, however the alignment guess requires a correct pixel type, so you would end up with this alignment error in case you do not provide a pixel type. I just committed a fix to this.
Please let me know if you manage to read your image with this or if something still doesn't work.
Thanks for quick response, even though i know how to somewhat read C++ code i am not aware how to compile it and i was using the other Python lib (link) that works with your project which adds complexity in integrating latest updates. Its above my pay grade so to say. Is there way to make it work without integrating latest commit?
I already had imageLayout
specified, if i also add pixelType: bayer_bggr
it still shows same error Cannot guess relevant width alignment corresponding to file size
.
Suspect that this could problem with image itself, or some specific way android is encoding YUV420 NV12 because yesterday i have spent all evening trying to convert it using many different image libraries for Python and standalone ones (ffmpeg, gstreamer), all they failed with similar error message or produced file that consist of scaled color lines.
Could you take a look at this images (link) from Android 11 and see if you able to load them properly with your fix.
Ok thank you for the informations, my latest update only fixes the error message, it will also work with the older version used by the python bindings.
I investigated the images you attached and here what I found:
The raw image: theorical file size should be 4000 3000 2 bytes = 24000000, however you file size is 24002560. Opening it with a hex editor shows 2560 zeros at the end, just remove them ($ truncate --size=24000000 raw.RAWPLAIN16
) and then the raw is read successfully by cxx-image.
The yuv image: this one is a bit more complicated. You first need to remove the "pixelType": "bayer_bggr"
line in the json file, it is only applicable for a raw file, and will lead to a wrong pixel type for a nv12 image. Then in an hex editor we can see 32 zeros of padding at the end of each line, and 8 additional lines of padding at the end. Thus theorical file size is 4032 3008 1.5 = 18192384 but your file size is 18194432, you need to remove the 2048 trailing zeros: $ truncate --size=18192384 yuv.YUV420NV12
.
Here is the corresponding json file to use with the truncated file:
{
"fileInfo": {
"format": "plain",
"width": 4032,
"height": 3008,
"imageLayout": "nv12"
}
}
With these changes I checked that I can convert your nv12 image to a jpg image using the cxx-image convert tool and it looks ok.
In 53c56de74ac3d2a68bed963ab7c3ed2631590a79 I have added the heightAlignment
and sizeAlignment
properties in addition to the existing widthAlignment
. This allows to read your provided files as is, without manually removing the padding, using the following json:
RAW:
{
"fileInfo": {
"fileFormat": "plain",
"width": 4000,
"height": 3000,
"pixelPrecision": 16,
"imageLayout": "planar",
"pixelType": "bayer_bggr",
"sizeAlignment": 4096
}
}
YUV:
{
"fileInfo": {
"fileFormat": "plain",
"width": 4000,
"height": 3000,
"imageLayout": "nv12",
"widthAlignment": 64,
"heightAlignment": 16,
"sizeAlignment": 4096
}
}
The python bindings however are not updated because I do not own them. Maybe at some point I can create a fork so that I can maintain them updated with the latest C++ library, but I currently lack some time to do this.
Keep getting this error when trying to convert file no solution that i can find in source code, can you suggest anything?