1

How to read image data from .cr2 (raw image format by Canon) in C++?

The only one operation I need to perform is to read pixel data of .cr2 file directly if it is possible, otherwise I would like to convert it to any loss-less image and read its pixels' data.

Any suggestions?

Thomas Matthews
  • 56,849
  • 17
  • 98
  • 154
Pavel
  • 4,912
  • 7
  • 49
  • 69
  • Did you try google? http://lclevy.free.fr/cr2/ – deviantfan Oct 12 '14 at 17:39
  • And if that is too much to read/implement: ImageMagick is said too convert cr2 fine. – deviantfan Oct 12 '14 at 17:41
  • @deviantfan I need to handle a lot of raw images using `CUDA`, so it's the last option to convert each image at first. "dcraw" is good but it's "the program that decodes any raw image from any digital camera on any computer running any operating system", so I only can use it as a guide of `.cr2` structure to write my own image data reader, but at first I'll try to find a library that can read image data directly. – Pavel Oct 12 '14 at 17:46

1 Answers1

1

I would go with ImageMagick too. You don't have to convert all your files up front, you can do them one at a time as you need them.

In your program, rather than opening the CR2 file, just open a pipe (popen() call) that is executing an ImageMagick command like

convert file.cr2 ppm:-

then you can read the extremely simple PPM format which is described here - basically just a line of ASCII text that tells you the file type, then another line of ASCII text that tells you the image dimensions, followed by a max value and then the data in binary.

Later on you can actually use the ImageMagick library and API if you need to.

Mark Setchell
  • 191,897
  • 31
  • 273
  • 432