python - OpenCV python拜耳转换错误

标签 python image opencv image-processing

以下代码:

filePath = os.path.join(root,file)
image = cv2.imread(filePath)
convertedImage = cv2.cvtColor(image, cv2.COLOR_BAYER_GR2RGB)

产生这个错误:

opencv\modules\imgproc\src\color.cpp:4196: error: (-215) scn == 1 && dcn == 3 in function cv::cvtColor

这个错误是什么意思(除了说明源和目标中的 channel 数)?我怎样才能解决这个问题?这与我加载图像的方式有关吗?

最佳答案

您忘记指定要读取的输入图像的类型。默认情况下,cv2.imread 将读取带有标志 cv2.IMREAD_COLOR 的图像(如 their documentation 中所示)。您可以将代码更改为以下内容:

filePath = os.path.join(root,file)
#Load the image as grayscale image
image = cv2.imread(filePath,0)
convertedImage = cv2.cvtColor(image, cv2.COLOR_BAYER_GR2RGB)

关于python - OpenCV python拜耳转换错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28677320/

相关文章:

Python 模块 xml.etree.ElementTree 自动修改 xml 命名空间键

javascript - RNFetchBlob - 无法在生成的图像文件中获取 API 数据

android - 线上/线下形象管理策略

Python OpenCV 2.4 写入半完整的PNG视频帧

c++ - CMake:编译 OpenCV 时找不到 CUDA 库

python - 比较两个 csv 文件中的内容

python - TensorFlow Estimator ServingInputReceiver 功能与 receiver_tensors : when and why?

python - typing.List<~T>[typing.Tuple[int]] 在 Python 类型库中是什么意思?

php - 复制后损坏的图像

c++ - 如何将opencv图像(IplImage)写入V4L2环回设备?