Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

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
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #identify #color #sequence #OpenCV
ADD COMMENT
Topic
Name
1+7 =