LibRaw with OpenCV

Hello

I use a Canon EOS 1200D.
This camera creates JPEG files with a resolution of 5184 x 3456.
The camera creates also CR2 files.

I use LibRaw to open this file.

LibRaw processor;
processor.open_file("test1.CR2");

If i debug my program i can see:
processor.imgdata.sizes.raw_height = 3516
processor.imgdata.sizes.raw_width = 5344
processor.imgdata.sizes.height = 3465
processor.imgdata.sizes.width = 5202
processor.imgdata.sizes.top_margin = 51
processor.imgdata.sizes.left_margin = 142
processor.imgdata.sizes.iheight = 3465
processor.imgdata.sizes.iwidth = 5202

1/ Why the resolution of 5184 x 3456 does not appeared?

I see also four objects in:
processor.tiff_ifd like this:

[0] {t_width=5184 t_height=3456 bps=8 ...}
[1] {t_width=160 t_height=120 bps=8 ...}
[2] {t_width=668 t_height=432 bps=16 ...}
[3] {t_width=5344 t_height=3516 bps=14 ...}

2/ What does these four objects?

3/ I do not understand what the statement:

processor.unpack();

do.
Does it convert from RGBG format to RGB format?

Now, i would like create an cv::Mat with the resolution of 5184 x 3456 and without losing accuracy.
4/ So how i can convert my CR2 file to a cv::Mat with format CV_16UC3?

From several CR2 files, i would like create a new image wich is the average.
5/ So, when i have a cv::Mat with format CV_16UC3, how i can save it in a file without losing accuracy?

Thank you.

Forums: 

1. Canon's RAW visible area

1. Canon's RAW visible area is slightly larger than in-camera JPEG
2. Jpeg preview, two smaller previews (to show on camera screen), RAW image.
3. unpack() just unpacks opened file to unprocessed bayer data array. Use dcraw_process to convert to RGB (internally) and dcraw_mem_image() to export 3-channel RGB bitmap.
4-5. know nothing about OpenCV, sorry.

-- Alex Tutubalin @LibRaw LLC

Thank you for your quick

Thank you for your quick answer.

Ok, so I have to use:

processor.imgdata.params.output_bps = 16;
processor.open_file("test1.CR2");
processor.unpack();
processor.dcraw_process();
libraw_processed_image_t* output = processor.dcraw_make_mem_image();

But how i can specify to use the JPEG resolution?
I think it is with:

processor.imgdata.params.cropbox

but how specify the JPEG resolution without hard coding?

In-camera crops are specific

In-camera crops are specific to camera (and camera crop mode). LibRaw does not read this data.

Use full image instead.

-- Alex Tutubalin @LibRaw LLC

I really need to get a

I really need to get a picture that is aligned on the JPEG picture.

In the private object:

processor.tiff_ifd[0]

i can see the good resolution but not the margin.

Sorry, LibRaw does not

Sorry, LibRaw does not provide any data to perform this alignment (yet).

-- Alex Tutubalin @LibRaw LLC

Ok.

Ok.

Perhaps, there is another solution.
If i do not use the JPEG file from camera but I use the JPEG file converted with LibRaw from the CR2 file.

Now, my 16 bits image will be aligned with the JPEG file.
All my image will have a resolution of 5202 x 3465.

What are the parameters to convert a CR2 file to a JPEG image so that it is similar to a JPEG image of a Canon camera?