任意座標の色の抽出
2015/8/11
Python2.7.6, OpenCV3.0
import cv2
import numpy as np
img = cv2.imread('messi5.jpg')
px = img[100,100]
print px
#[157 166 200]
# accessing only blue pixel
blue = img[100,100,0]
print blue
#157
どうもimg[y,x]
のようなので注意
また、返す色も[blue, green, red]
マウスの座標位置のHSVを返すイベント
import colorsys
def onMouse(event, x, y, flags, param):
global image
color = image[y,x]
r = color[2]
g = color[1]
b = color[0]
hsv = colorsys.rgb_to_hsv(r/255.0,g/255.0,b/255.0)
h = int(hsv[0]*180)
s = int(hsv[1]*255)
v = int(hsv[2]*255)
print('HSV: %d,%d,%d' % (h,s,v))
OpenCV-Python Tutorials Basic Operations on Images
http://opencv-python-tutroals.readthedocs.org/en/latest/py_tutorials/py_core/py_basic_ops/py_basic_ops.html#basic-ops