So, I'm trying to show a binary picture with only black and white using this code:
import cv2
import numpy as np
x_img = cv2.imread("lenac.tif")
x_img_g = cv2.cvtColor(x_img, cv2.COLOR_BGR2GRAY)
y = x_img_g > 128
cv2.imshow("", y*1.0)
cv2.waitKey(0)
cv2.destroyAllWindows()
But I'm getting this error:
>Traceback (most recent call last):
File "ex5.py", line 11, in <module>
cv2.imshow("", y*1.0)
cv2.error: OpenCV(4.0.0) c:projectsopencv-
pythonopencvmodulesimgprocsrccolor.hpp:261: error: (-2:Unspecified
error) >in function '__cdecl cv::CvtHelper<struct
cv::Set<1,-1,-1>,struct cv::Set<3,4,-1>,struct
cv::Set<0,2,5>,2>::CvtHelper(const class cv::_InputArray &,const class
cv::_OutputArray &,int)'
>Unsupported depth of input image:
> 'VDepth::contains(depth)'
> where
> 'depth' is 6 (CV_64F).
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…