How to handle Canon EOS RAW images in C++/Qt

RAW, or to put it in terms of file extension, CR2 and CRW files are the images produced using Canon EOS cameras. A RAW photo, as it appears from it’s name, is the raw format of the image, meaning it contains the exact binary data that was recorded by a specific camera when the photo was taken.

It is not easy to read or convert raw files because there are numerous types of them. Almost all camera models have different types of raw files. So the best way, and the way I am going to describe here, is to use the SDK provided by Canon. I have seen people trying to write their own raw handlers using OpenCV and other methods but it’s just pointless.

The first step to acquire Canon EOS SDK is applying for Canon Developer Program. If your application is successful, you will get to benefit from the latest release and updates to EOS SDK.

Canon EOS SDK is pretty well documented but I am going to share here what I do to be able to read CR2 and CRW images in my Qt applications.

Make sure you download the latest version of EDSDK (at the time of writing this article the latest version is EDSDK v3.4)

Add *.LIB and include files to your Qt project:


The idea is that you need to create an EdsStreamRef for input and another one for output. With this approach you’ll be able to convert RAW files to JPG.

So first read the RAW file like this:

EdsStreamRef input_stream;
EdsCreateFileStream(rawfile, kEdsFileCreateDisposition_OpenExisting, kEdsAccess_Read, &input_stream);

EdsImageRef input_image;
EdsCreateImageRef(input_stream, &input_image);

Next, you have to create your output file. It should obviously have a JPG extension.

EdsStreamRef output_stream;
EdsCreateFileStream(jpgfile, kEdsFileCreateDisposition_CreateAlways, kEdsAccess_Write, &output_stream);

EdsSaveImageSetting settings;

EdsSaveImage(input_image, kEdsTargetImageType_Jpeg, settings, output_stream);

Finally, you need to release all the resources you have used in your program.


Let me know if you face any problems trying to implement codes shared in this tutorial.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.