python openCV debayer



我想用openCV解析一个16位RAW静态图像,但是cvtColor函数有问题。Color to Gray的正确结果如下:

import cv2
import numpy as np    
infile = '/media/rainer/IMG_2806.JPG'
img = cv2.imread(infile,1)
bw = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
resized = cv2.resize(bw, (0,0), fx=0.3, fy=0.3)
cv2.imshow('image',resized)
cv2.waitKey(0)
cv2.destroyAllWindows()

那么debayer在python 2.7中会是什么样子呢?

infile = '/media/rainer/test.raw'
img = cv2.imread(infile,0)
debayer = cv2.cvtColor(img, cv2.CV_BayerBG2BGR)
resized = cv2.resize(debayer, (0,0), fx=0.3, fy=0.3)
cv2.imshow('image',resized)
cv2.waitKey(0)
cv2.destroyAllWindows()

非常感谢您的帮助....

问题是OpenCV不知道你试图加载的原始图像的数据类型和大小。你必须通过Numpy来指定它,因为OpenCV数组在Python中是Numpy数组。试试这个:

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)

使用np.dtype('u2')为16 bpp图像。还要注意,您需要cv2。

试试这个:

import os
import cv2
imagePath = '/path/to/image'
imageRaw = cv2.imread(imagePath, cv2.IMREAD_GRAYSCALE | cv2.IMREAD_ANYDEPTH)
rgb = cv2.cvtColor(imageRaw, cv2.COLOR_BAYER_BG2BGR)
cv2.imwrite('rgb.png', rgb)

相关内容

  • 没有找到相关文章

最新更新