identify color sequence with OpenCV
import numpy as np
import cv2
img = cv2.imread('sofqn.png')
gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
hsv = cv2.cvtColor(gray,cv2.COLOR_BGR2HSV)
identify color sequence with OpenCV
import numpy as np
import cv2
img = cv2.imread('sofqn.png')
gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
hsv = cv2.cvtColor(gray,cv2.COLOR_BGR2HSV)
identify color sequence with OpenCV
res = []
for cnt in contours:
if cv2.contourArea(cnt) > 100:
x,y,w,h = cv2.boundingRect(cnt)
cx,cy = x+w/2, y+h/2
color = hsv[cy,cx,0]
if (color < 10 or color > 170):
res.append([cx,cy,'R'])
elif(50 < color < 70):
res.append([cx,cy,'G'])
elif(20 < color <40):
res.append([cx,cy,'Y'])
elif(110 < color < 130):
res.append([cx,cy,'B'])
res = sorted(res,key = lambda res : res[0])
colors = [x[2] for x in res]
print colors
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us