Convert Raw image to JPG

1.4k Views Asked by At

I have the following issues when I try to run: the input would be something like file=/Downloads/canon_eos_70d_20.CR2

with Raw(file) as raw_image:
        buffered_image = np.array(raw_image.to_buffer())
        im = Image.frombuffer('RGB', (raw_image.metadata.width, raw_image.metadata.height), buffered_image, 'raw',
                              'RGB', 0, 1)
        im.save(os.path.split(file)[1] + '.jpg')
        print('Successfully saved file as JPG.')


'Unsupported Libraw version: %s.%s.%s.' % self.version_number

ImportError: Unsupported Libraw version: 0.19.2.

Any ideas? if not did anyone tried any other way to convert RAW images to jpg?

2

There are 2 best solutions below

0
On

The front page of the rawkit documentation states this under requirements:

  • LibRaw 0.16.x (API version 10)
  • LibRaw 0.17.x (API version 11)

Should be clear then that 0.19.x is not supported.

0
On

Instead of using rawpy(had a postprocessing I could not seem to understand ) or rawkit (had complications with Libraw). Use PIL

from PIL import Image

file = r"/Downloads/canon_eos_70d_20.CR2"
im = Image.open(file)
rgb_im = im.convert('RGB')
rgb_im.save(file[:-4]+'.JPG')