问题描述
在执行下面代码的时候
# Read image
img = cv2.imread("imori.jpg").astype(np.float)
#img = cv2.imread("imori.jpg").astype(np.float32)
# grayscale
#gray = BGR2GRAY(img)
gray=cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
运行报错:
gray=cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
cv2.error: OpenCV(4.1.1) /io/opencv/modules/imgproc/src/color.simd_helpers.hpp:94: error: (-2:Unspecified error) in function 'cv::impl::{anonymous}::CvtHelper<VScn, VDcn, VDepth, sizePolicy>::CvtHelper(cv::InputArray, cv::OutputArray, int) [with VScn = cv::impl::{anonymous}::Set<3, 4>; VDcn = cv::impl::{anonymous}::Set<1>; VDepth = cv::impl::{anonymous}::Set<0, 2, 5>; cv::impl::{anonymous}::SizePolicy sizePolicy = (cv::impl::<unnamed>::SizePolicy)2u; cv::InputArray = const cv::_InputArray&; cv::OutputArray = const cv::_OutputArray&]'
> Unsupported depth of input image:
> 'VDepth::contains(depth)'
> where
> 'depth' is 6 (CV_64F)
解决方法
opencv只支持float32的图像显示和操作,然后float64是numpy的数据类型,opencv中不支持。
改成np.float32即可