Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to open a CR2 file in python OpenCV

I've managed to come very far on a program I'm writing. I don't know how to load CR2 files into an OpenCV Image. I've tried the following:

raw = rawpy.imread(sys.argv[1])
rgb = raw.postprocess()
PILrgb = scipy.misc.toimage(rgb)
image = cv2.imdecode(PILrgb, 1)

It was an attempt at converting the numpyarray returned by Postprocess the currently loaded RAW image and return the new resulting image as numpy array. Then calling spicy.misc.toimage to Takes a numpy array and returns a PIL image..

I get the following msg though TypeError: buf is not a numpy array, neither a scalar

like image 583
David Kachlon Avatar asked Sep 02 '25 02:09

David Kachlon


1 Answers

It may be easier if you only rawpy

import rawpy
import cv2

raw = rawpy.imread(sys.argv[1]) # access to the RAW image
rgb = raw.postprocess() # a numpy RGB array
image = cv2.cvtColor(rgb, cv2.COLOR_RGB2BGR) # the OpenCV image
like image 162
psaboia Avatar answered Sep 07 '25 13:09

psaboia