我的python opencv2不知道出错在哪里?
"C:\ProgramFiles\Python36\python.exe"C:/Users/Administrator/.PyCharmCE2018.2/config/s...
"C:\Program Files\Python36\python.exe" C:/Users/Administrator/.PyCharmCE2018.2/config/scratches/scratch_8.pyTraceback (most recent call last): File "C:/Users/Administrator/.PyCharmCE2018.2/config/scratches/scratch_8.py", line 17, in <module> mat= cv2.cvtColor(mat, cv2.COLOR_YCrCb2RGB)[:,:,2]cv2.error: OpenCV(3.4.3) C:\projects\opencv-python\opencv\modules\imgproc\src\color.cpp:181: error: (-215:Assertion failed) !_src.empty() in function 'cv::cvtColor'
展开
2018-09-17 · 知道合伙人互联网行家
关注
展开全部
我没用过Python的Opencv的库,只是用过Python的Image的库;Image库已经可以结果这个问题了我试着做一下:你先得安装PIL库得到rgb三个通道,然后转到HSV通道,其中H表示0-255的颜色,V表示强度,你大概先知道紫色的范围是多少from PIL import Imageimport colorsysdef CalculateH(img): if len(img.getbands()) == 4: ir,ig,ib,ia = img.split() else: ir, ig, ib = img.split() Hdat = [] Sdat = [] Vdat = [] for rd,gn,bl in zip(ir.getdata(),ig.getdata(),ib.getdata()): h,l,s = colorsys.rgb_to_hsv(rd/255.,gn/255.,bl/255.) Hdat.append(h) Sdat.append(l) Vdat.append(s) meanV = mean(Vdat) return Hdat, meanV def myreadim(filename): im = Image.open(filename) H,V = CalculateH(im)后面我就懒得写了,应该思路都清楚了吧,要转到其他的颜色通道上,不要在rgb通道上
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询