python openCV debayer

The problem is that OpenCV doesn't know the data type and size of the raw image that you are trying to load. You have to specify that through Numpy, since OpenCV arrays are Numpy arrays in Python. Try this:

import numpy as np
imsize = imrows*imcols
with open(infile, "rb") as rawimage:
    img = np.fromfile(rawimage, np.dtype('u1'), imsize).reshape((imrows, imcols))
    colour = cv2.cvtColor(img, cv2.COLOR_BAYER_BG2BGR)

Use np.dtype('u2') for 16 bpp images. Also note that you need cv2.COLOR_BAYER_BG2BGR instead of cv2.CV_BayerBG2BGR.

Tags:

Python

Opencv