Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

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)
Comment

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
Comment

PREVIOUS NEXT
Code Example
Python :: stitch two dictionary python 
Python :: without using sum add item in list python 
Python :: python get all items from generator 
Python :: response.url SSL warning python 
Python :: Math expressions with matplotlib 
Python :: Escala, Translação e Rotação em Vídeos - Python 
Python :: Start Openvino Python Application at Boot Time using System Service on ubunut 
Python :: turn off subplot 
Python :: how i rwrite conditon to create 1 or 0 label from two probability column python 
Python :: drop values based on type pandas 
Python :: djb2 hash function c explained 
Python :: user_info = user_info.save(commit=False) 
Python :: run python script with admin rights 
Python :: java to python conversion 
Python :: exercise of python loops 
Python :: eeetimetable 
Python :: https://practice.geeksforgeeks.org/problems/coin-change2448/1 
Python :: find and flag duplicates pandas 
Python :: append to a ldictionary value list 
Python :: python get portion of dictionary 
Python :: Classical Cryptography: Using Classical Ciphers with pycipher. 
Python :: custom auth django channels 
Python :: list the contents of a package python 
Python :: how to import autpy 
Python :: mumtiply to matrices python 
Python :: cant access a dataframe imported using pickle 
Python :: python urlopen parameters 
Python :: delete row by index pandas 
Python :: ladnha; 
Python :: argmax change dafault value for multiple maxima 
ADD CONTENT
Topic
Content
Source link
Name
6+2 =