python opencv 二值化 计算白色像素点的实例
贴部分代码
#!/usr/bin/envpython #-*-coding:utf-8-*- importcv2 importnumpyasnp fromPILimportImage area=0 defostu(img): globalarea image=cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)#转灰度 blur=cv2.GaussianBlur(image,(5,5),0)#阈值一定要设为0!高斯模糊 ret3,th3=cv2.threshold(blur,0,255,cv2.THRESH_BINARY+cv2.THRESH_OTSU)#二值化0=black;1=white #cv2.imshow('image',th3) #a=cv2.waitKey(0) #printa height,width=th3.shape foriinrange(height): forjinrange(width): ifth3[i,j]==255: area+=1 returnarea
以上这篇pythonopencv二值化计算白色像素点的实例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持毛票票。