python颜色识别_毕业设计 python opencv实现车牌识别 颜色判断

defimg_color(card_imgs):

colors=[]for card_index, card_img inenumerate(card_imgs):

green= yello = blue = black = white =0

card_img_hsv=cv2.cvtColor(card_img, cv2.COLOR_BGR2HSV)#有转换失败的可能,原因来自于上面矫正矩形出错

if card_img_hsv isNone:continuerow_num, col_num= card_img_hsv.shape[:2]

card_img_count= row_num *col_numfor i inrange(row_num):for j inrange(col_num):

H=card_img_hsv.item(i, j, 0)

S= card_img_hsv.item(i, j, 1)

V= card_img_hsv.item(i, j, 2)if 11 < H <= 34 and S > 34:

yello+= 1

elif 35 < H <= 99 and S > 34:

green+= 1

elif 99 < H <= 124 and S > 34:

blue+= 1

if 0 < H < 180 and 0 < S < 255 and 0 < V < 46:

black+= 1

elif 0 < H < 180 and 0 < S < 43 and 221 < V < 225:

white+= 1color= "no"limit1= limit2 =0if yello * 2 >=card_img_count:

color= "yello"limit1= 11limit2= 34 #有的图片有色偏偏绿

elif green * 2 >=card_img_count:

color= "green"limit1= 35limit2= 99

elif blue * 2 >=card_img_count:

color= "blue"limit1= 100limit2= 124 #有的图片有色偏偏紫

elif black + white >= card_img_count * 0.7:

color= "bw"colors.append(color)

card_imgs[card_index]=card_imgif limit1 ==0:continuexl, xr, yh, yl=accurate_place(card_img_hsv, limit1, limit2, color)if yl == yh and xl ==xr:continueneed_accurate=Falseif yl >=yh:

yl=0

yh=row_num

need_accurate=Trueif xl >=xr:

xl=0

xr=col_num

need_accurate=Trueif color =="green":

card_imgs[card_index]=card_imgelse:

card_imgs[card_index]= card_img[yl:yh, xl:xr] if color != "green" or yl < (yh - yl) // 4 elsecard_img[

yl-(

yh- yl) // 4:yh,

xl:xr]ifneed_accurate:

card_img=card_imgs[card_index]

card_img_hsv=cv2.cvtColor(card_img, cv2.COLOR_BGR2HSV)

xl, xr, yh, yl=accurate_place(card_img_hsv, limit1, limit2, color)if yl == yh and xl ==xr:continue

if yl >=yh:

yl=0

yh=row_numif xl >=xr:

xl=0

xr=col_numif color =="green":

card_imgs[card_index]=card_imgelse:

card_imgs[card_index]= card_img[yl:yh, xl:xr] if color != "green" or yl < (yh - yl) // 4 elsecard_img[

yl-(

yh- yl) // 4:yh,

xl:xr]return colors,card_imgs

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值