пятница, 18 октября 2019 г.

OpenCV : colorpicker from video pixel

● OpenCV приложение1 (2016г)
– Входные данные: поток web-камеры
– Вывод: Графическое окно с текущем кадром потока. На на кадре
текстом выведен код цвета под курсором.

#laba1
import numpy as np
import cv2
capture=cv2.VideoCapture(0)
global r,b,y
global im,location
strings = "q"xi=100yi=100
def showcolor(event,x,y,flags,param):
    global xi, yi
    xi=x
    yi=y

while True:
    b,frame=capture.read()
    im=frame
    msg = strings
    fontface = cv2.FONT_HERSHEY_SIMPLEX
    fontscale = 1.0    location = (xi, yi)
    b = im[yi, xi][0]
    g = im[yi, xi][1]
    r = im[yi, xi][2]
    strings = r.astype(str) + " " + g.astype(str) + " " + b.astype(str)
    clr = np.array([r.astype(int), g.astype(int), b.astype(int)])
    color = (r.astype(int), 190, 0)
    cv2.putText(frame, msg, location, fontface, fontscale,  color=(clr[0], clr[1], clr[2]))
    cv2.imshow("image", frame)
    cv2.setMouseCallback('image', showcolor)
    if cv2.waitKey(1) & 0xFF == ord('q'):
        break
capture.release()
cv2.destroyAllWindows()