import cv2
import numpy as np
from matplotlib import pyplot as plt
def colorList(imagepath):
img = cv2.imread(imagepath,cv2.IMREAD_COLOR)
##print img
h = img.shape[0]
w = img.shape[1]
dic = {}
for x,y in enumerate(img):
for i,j in enumerate(y):
s = str(j[0]) + '_' + str(j[1]) + '_' +str(j[2])
###print x,i,s
if dic.has_key(s):
dic[s] = dic[s] + 1
else:
dic[s]=1
ret = sorted(dic.items(), lambda x, y: cmp(x[1], y[1]), reverse=True)
print ret
yarr = np.zeros(h)
xarr = np.zeros(w)
color = (255,255,255)
for x,y in enumerate(img):
for i,j in enumerate(y):
s = str(j[0]) + '_' + str(j[1]) + '_' +str(j[2])
if(dic[s]<2000 and dic[s]>300):
##print x,i,s,color
yarr[x] = yarr[x] + 1
xarr[i] = xarr[i] + 1
continue
else:
img[x][i] = color
##print x,i,s,color
print xarr,yarr
isword = 0
for i in range(0,h):
if(yarr[i]>0 and isword==0):
y1=i
isword=1
if(yarr[i]==0 and isword==1):
y2=i
break
isword = 0
for i in range(0,w):
if(xarr[i]>0 and isword==0):
x1=i
isword=1
if(xarr[i]==0 and isword==1):
x2=i
isword=0
cv2.rectangle(img,(x1,y1),(x2,y2),(255,0,0))
plt.imshow(img)
plt.show()
##print img
return ret
t = colorList('./10028_3565.png')
opencv学习1 数字分割
需积分: 10 111 浏览量
2017-10-26
14:20:24
上传
评论
收藏 21KB RAR 举报
fengfangfang
- 粉丝: 30
- 资源: 7
最新资源
- VR开发的概要介绍与分析
- 自动驾驶定位系列教程七:点云畸变补偿.pdf
- HM2302D-VB一款N-Channel沟道SOT23的MOSFET晶体管参数介绍与应用说明
- HM2302B-VB一款N-Channel沟道SOT23的MOSFET晶体管参数介绍与应用说明
- springboot学生考勤管理系统
- HM2302A-VB一款N-Channel沟道SOT23的MOSFET晶体管参数介绍与应用说明
- HM2301-VB一款P-Channel沟道SOT23的MOSFET晶体管参数介绍与应用说明
- 数据可视化的概要介绍与分析
- HM2301E-VB一款P-Channel沟道SOT23的MOSFET晶体管参数介绍与应用说明
- HM2301D-VB一款P-Channel沟道SOT23的MOSFET晶体管参数介绍与应用说明
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈