David Kachlon
David Kachlon

Reputation: 619

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

Upvotes: 4

Views: 2317

Answers (1)

psaboia
psaboia

Reputation: 41

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

Upvotes: 3

Related Questions