Python 在cv2中使用略读图像
我试图用skimage和scipy来提高灰度图像的图像质量,然后在cv2中使用它们。不幸的是,当我试图用cv2转换浏览图像时,我遇到了一个错误 图片: 输出:Python 在cv2中使用略读图像,python,opencv,matplotlib,scipy,scikit-image,Python,Opencv,Matplotlib,Scipy,Scikit Image,我试图用skimage和scipy来提高灰度图像的图像质量,然后在cv2中使用它们。不幸的是,当我试图用cv2转换浏览图像时,我遇到了一个错误 图片: 输出: Traceback (most recent call last): File "/home/artur/Desktop/test.py", line 25, in <module> img_gs = cv2.cvtColor(sharp_img, cv2.COLOR_BGR2GRAY) cv2.error: O
Traceback (most recent call last):
File "/home/artur/Desktop/test.py", line 25, in <module>
img_gs = cv2.cvtColor(sharp_img, cv2.COLOR_BGR2GRAY)
cv2.error: OpenCV(3.4.3) /io/opencv/modules/imgproc/src/color.hpp:255: error: (-2:Unspecified error) in function 'cv::CvtHelper<VScn, VDcn, VDepth, sizePolicy>::CvtHelper(cv::InputArray, cv::OutputArray, int) [with VScn = cv::Set<3, 4>; VDcn = cv::Set<1>; VDepth = cv::Set<0, 2, 5>; cv::SizePolicy sizePolicy = (cv::SizePolicy)2u; cv::InputArray = const cv::_InputArray&; cv::OutputArray = const cv::_OutputArray&]'
> Invalid number of channels in input image:
> 'VScn::contains(scn)'
> where
> 'scn' is 1
Traceback (most recent call last):
File "/home/artur/Desktop/test.py", line 23, in <module>
sharp_img = skimage.img_as_ubyte(sharp_img)
File "/home/artur/.local/lib/python3.6/site-packages/skimage/util/dtype.py", line 492, in img_as_ubyte
return convert(image, np.uint8, force_copy)
File "/home/artur/.local/lib/python3.6/site-packages/skimage/util/dtype.py", line 261, in convert
raise ValueError("Images of type float must be between -1 and 1.")
ValueError: Images of type float must be between -1 and 1.
输出:
Traceback (most recent call last):
File "/home/artur/Desktop/test.py", line 25, in <module>
img_gs = cv2.cvtColor(sharp_img, cv2.COLOR_BGR2GRAY)
cv2.error: OpenCV(3.4.3) /io/opencv/modules/imgproc/src/color.hpp:255: error: (-2:Unspecified error) in function 'cv::CvtHelper<VScn, VDcn, VDepth, sizePolicy>::CvtHelper(cv::InputArray, cv::OutputArray, int) [with VScn = cv::Set<3, 4>; VDcn = cv::Set<1>; VDepth = cv::Set<0, 2, 5>; cv::SizePolicy sizePolicy = (cv::SizePolicy)2u; cv::InputArray = const cv::_InputArray&; cv::OutputArray = const cv::_OutputArray&]'
> Invalid number of channels in input image:
> 'VScn::contains(scn)'
> where
> 'scn' is 1
Traceback (most recent call last):
File "/home/artur/Desktop/test.py", line 23, in <module>
sharp_img = skimage.img_as_ubyte(sharp_img)
File "/home/artur/.local/lib/python3.6/site-packages/skimage/util/dtype.py", line 492, in img_as_ubyte
return convert(image, np.uint8, force_copy)
File "/home/artur/.local/lib/python3.6/site-packages/skimage/util/dtype.py", line 261, in convert
raise ValueError("Images of type float must be between -1 and 1.")
ValueError: Images of type float must be between -1 and 1.
我做错了什么?您已经将图像转换为行中的灰度
img_int_gray = skimage.color.rgb2gray(img_int)
它在生产线上失败了
img_gs = cv2.cvtColor(sharp_img, cv2.COLOR_BGR2GRAY)
因为它需要一个3通道BGR映像。删除该行,您只需使用plt保存sharp\u img。imsave'sharp\u img.png',sharp\u img,cmap='gray'您已经将该行中的图像转换为灰度
img_int_gray = skimage.color.rgb2gray(img_int)
它在生产线上失败了
img_gs = cv2.cvtColor(sharp_img, cv2.COLOR_BGR2GRAY)
因为它需要一个3通道BGR映像。删除该行,您就可以使用plt保存sharp\u img了。imsave'sharp\u img.png',sharp\u img,cmap='gray'