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 <