python - 函数 fastNlMeansDenoisingColored 中的 Opencv-python : Type of input image should be CV_8UC3 or CV_8UC4!

标签 python opencv ubuntu

我写了一个简单的opencv程序,可以降低图像的噪声。

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

img = cv2.imread('stream/horse.png')

dst = cv2.fastNlMeansDenoisingColored(img, None, 10, 10, 7, 21)

cv2.imshow(dst)
plt.subplot(121), plt.imshow(img)
plt.subplot(122), plt.imshow(dst)
plt.show()

horse.png

当我运行程序时出现错误。这是...

OpenCV Error: Bad argument (Type of input image should be CV_8UC3 or CV_8UC4!) in fastNlMeansDenoisingColored, file /home/govinda/github_repos/opencv/modules/photo/src/denoising.cpp, line 176
Traceback (most recent call last):
  File "/home/govinda/workspace-python/opencv/src/Smle.py", line 7, in <module>
    dst = cv2.fastNlMeansDenoisingColored(img, None, 10, 10, 7, 21)
cv2.error: /home/govinda/github_repos/opencv/modules/photo/src/denoising.cpp:176: error: (-5) Type of input image should be CV_8UC3 or CV_8UC4! in function fastNlMeansDenoisingColored

我该如何克服呢?

最佳答案

你需要像这样转换图像:

converted_img = cv2.cvtColor(img, cv2.COLOR_GRAY2BGR)

帮助你有点晚了,但我希望它能帮助别人。

干杯!

关于python - 函数 fastNlMeansDenoisingColored 中的 Opencv-python : Type of input image should be CV_8UC3 or CV_8UC4!,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44601593/

相关文章:

python - 图像处理:实时FedEx Logo 检测器的算法改进

python - Python Opencv MJPG压缩?

python - 将默认 python 版本从 2.6.6 更改为 2.7 并配置 django

regex - 使用 sed 或脚本解析、重新格式化日志文件?

python - 值错误 : Unable to configure filter 'require_debug_false' : Cannot resolve 'django.utils.log.CallbackFilter' : No module named CallbackFilter

python - 在 anaconda 上安装 kivy 时出现 PermissionError(13, 'The process cannot access the file because it is being used by another process' )

python - 如何使格式不会导致类型提示错误?

python - 新手 : writing backend code for website

python - 我怎样才能让视频在录制时暂停/继续?

django - 服务器上的 NGINX Docker 与 Ubuntu 服务器上预先存在的 NGINX