使用 python3.8.x,opencv
hsv = cv2.cvtColor(imgROI, cv2.COLOR_BGR2HSV)
lowerYellowHSV = np.array([11,43,46])
upperYellowHSV = np.array([34,255,255])
mask=cv2.inRange(hsv,lowerb=lowerYellowHSV,upperb=upperYellowHSV)/255
def coinSimpleDetection(img,circlesVector):
# 简单识别,利用硬币的色彩和半径进行区分
circlesNum = circlesVector.shape[0]
# 将图片裁剪出来
candidateImage = {}
for i in range(circlesNum):
information = {"radius":0,"value":0}
col,row,radius = circlesVector[i,:]
imgTemp = img.copy()
imgROI = imgTemp[row-radius:row+radius,col-radius:col+radius,:]
information["radius"] = radius
# 识别5角硬币
hsv = cv2.cvtColor(imgROI, cv2.COLOR_BGR2HSV)
lowerYellowHSV = np.array([11,43,46])
upperYellowHSV = np.array([34,255,255])
mask=cv2.inRange(hsv,lowerb=lowerYellowHSV,upperb=upperYellowHSV)/255
if np.sum(np.array(mask))/((row+2*radius)*(col+2*radius)) > 0.05:
information["value"] = 0.5
# 根据半径判断1块,新旧1角硬币
if information["value"] == 0:
if information["radius"] > 180 and information["radius"] < 250:
information["value"] = 0.1
if information["radius"] > 250 and information["radius"] < 300:
information["value"] = 1.0
candidateImage.update({i:information})
cionsValue = np.sum([candidateImage[k]["value"] for k in range(circlesNum)])
return candidateImage,cionsValue
链接
https://download.csdn.net/download/weixin_44545174/87391095