Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

You are almost there. Use the rectangle to cut the part of the image as the player.

x,y,w,h = cv2.boundingRect(contour)
player = frame[x:x+w,y:y+h] # the sub-image containing the player
meancolor = np.mean(2) # get the mean R,G,B for the ROI, I think that's what you want
cv2.rectangle(frame, (x,y), (x+w,y+h), (0,0,255), 2) # no need to check if area>0, this should be always the case
cv2.putText(frame, 'Player '+str(meancolor[0]+' '+str(meancolor[1]+' '+str(meancolor[2]+' ', (x, y), cv2.FONT_HERSHEY_SIMPLEX, 0.8, (255,0,0), 2, cv2.LINE_AA)

This will display the mean color of the rectangle above the player. If you want to identify the team based on the shirt color, it will be probably more complicated, but you are on the right track.

You are almost there. Use the rectangle to cut the part of the image as the player.

x,y,w,h = cv2.boundingRect(contour)
player = frame[x:x+w,y:y+h] # the sub-image containing the player
meancolor = np.mean(2) player.mean(2) # get the mean R,G,B for the ROI, I think that's what you want
cv2.rectangle(frame, (x,y), (x+w,y+h), (0,0,255), 2) # no need to check if area>0, this should be always the case
cv2.putText(frame, 'Player '+str(meancolor[0]+' '+str(meancolor[1]+' '+str(meancolor[2]+' ', (x, y), cv2.FONT_HERSHEY_SIMPLEX, 0.8, (255,0,0), 2, cv2.LINE_AA)

This will display the mean color of the rectangle above the player. If you want to identify the team based on the shirt color, it will be probably more complicated, but you are on the right track.