python - How to detect color in opencv? -


as salamu alaikum, want make program take input (colored paper) webcam, , output string of color of paper. ex. if hold blue paper in front of webcam it's gonna tell me "blue".

use pil library if open cv not neccessity you. here function open image , main color.

import urllib2 import imagefile  image_url = "/path of file" opener1 = urllib2.build_opener() page1=opener1.open(image_url)  p = imagefile.parser()  while 1:     s = page1.read(1024)     if not s:         break     p.feed(s)  im = p.close() r,g,b = im.getpixel((0,0)) 

from rgb values can decide color. hope helps..

edit:you can use getcolors() function. im.getcolors(maxcolors) ⇒ list of (count, color) tuples or none

it returns unsorted list of (count, color) tuples, count number of times corresponding color occurs in image.


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -