cvtColor返回异常

时间:2014-11-12 13:33:21

标签: python opencv colors spyder

我正在尝试使用cv2.cvtColor(image,cv.COLOR_RGB2LAB)执行RGB到L a b *颜色转换,但Spyder会返回以下错误:

OpenCV Error: Assertion failed (src.dims <= 2 && esz <= (size_t)32) in transpose,
file /tmp/buildd/opencv-2.3.1/modules/core/src/matrix.cpp, line 1680 terminate called after throwing an instance of 'cv::Exception'
what():  /tmp/buildd/opencv-2.3.1/modules/core/src/matrix.cpp:1680: error: (-215) src.dims <= 2 && esz <= (size_t)32 in function transpose

这是相关的我的代码,我正在使用3个通道为R,G和B创建一个numpy数组,它们都是(300,400)大小的float64类型。这给了我一个(300,400,3)float 64数组,叫做small_wbcorrect_lab

import numpy as np
from matplotlib import pyplot as plt
import cv2 as cv


width=400
height=300

small_wbcorrect_lab=np.zeros((np.size(range(0,width)),np.size(range(0,height)),3),dtype=np.float64) # create an array which will contain the converted l*a*b* image

# I skip the part of the code which fills the arrays redchannel_wbcorrect,greenchann... for more clarity. 
# They are all three (300,400) float64 array filled with values from 0 to 255

small_wbcorrect=np.transpose(np.array([np.transpose(redchannel_wbcorrect),np.transpose(greenchannel_wbcorrect),np.transpose(bluechannel_wbcorrect)])/255)

plt.imshow(small_wbcorrect)
plt.title('Photo White Balanced') # displaying works fine

small_wbcorrect_lab=cv.cvtColor(small_wbcorrect,cv.COLOR_RGB2LAB)

有趣的是:cv.cvtColor可以很好地工作,如果我用它来转换导入的图像,用

导入
image=cv.imread('image.jpg')

感谢您的帮助

0 个答案:

没有答案
相关问题