opencv - 输入图像类型上的 opencv 错误应为 CV_8UC3 或 CV_8UC4
问题描述
我尝试了opencv 示例中的以下代码段,
import numpy as np
import cv2 as cv
from matplotlib import pyplot as plt
img = cv.imread('die.png')
dst = cv.fastNlMeansDenoisingColored(img,None,10,10,7,21)
plt.subplot(121),plt.imshow(img)
plt.subplot(122),plt.imshow(dst)
plt.show()
但是我收到以下错误,他的根本原因是什么以及如何解决?
错误 Traceback (last last call last) in 3 from matplotlib import pyplot as plt 4 img = cv.imread('die.png') ----> 5 dst = cv.fastNlMeansDenoisingColored(img,None,10,10,7 ,21) 6 plt.subplot(121),plt.imshow(img) 7 plt.subplot(122),plt.imshow(dst)
error: OpenCV(4.1.1) ..\modules\photo\src\denoising.cpp:178: error: (-5:Bad argument) Type of input image should be CV_8UC3 or CV_8UC4! in function 'cv::fastNlMeansDenoisingColored'
解决方案
cv::fastNlMeansDenoisingColored期望 3 或 4 个通道的 8 位图像。在调用 fastNlMeansDenoisingColored 函数之前尝试将图像转换为 uint8
img=np.uint8(img)
推荐阅读
- perl - 如何在解析Excel工作表时按列查找行数
- html - 如何修复未正确应用的 CSS?
- sql-server - 无法在 SQL Server 2014 中导出数据层应用程序?
- angular - 如何在垫工具提示 div 下放置一个三角形?
- java - 如何设置一个视图,当用户单击手机的后退按钮时,它会返回到同一个 java 类中的视图
- mongodb - 用于高效连接的 MongoDB 建模
- node.js - 插入后无法重定向
- android - 用户卸载 App 时清除 OneSignal 标签
- c# - 如何在失去焦点时保持 C# 命令行程序仍在运行
- python-3.x - 如何从 numpy.random.normal() 中获取特定的范围值?