import cv2
import numpy as np

cap = cv2.VideoCapture(0)
while(1):

    _, frame = cap.read()

    #hsv or rgb
    hsv = cv2.cvtColor(frame, cv2.COLOR_BGR2HSV)
    rgb = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)

    lower_red = np.array([0,120,82])
    upper_red = np.array([15,255,249])


    mask = cv2.inRange(hsv, lower_red, upper_red)
    color_image = cv2.circle(mask, (1, 1), 1, (0, 255, 255), -1)

    res = cv2.bitwise_and(frame,frame, mask= mask)

    point_size = 4
    point_color = (0, 0, 255)  # BGR
    thickness = 4

    b = 239
    w = 0

    for i in range(32):
        w = w + 19
        coordinate = hsv[b, w]  # 輸入要取得顏色的指定座標

        point = (w, b)
        cv2.circle(color_image, point, point_size, point_color, thickness)
        if coordinate[0] == 0:
            print('Is red')
        else:
            print('Is green')
    print(w, b)
    #cv2.imshow('frame',frame)
    #cv2.imwrite('C:/Users/User/Desktop/company_files/coffee_case/opencv/1.png', color_image)
    cv2.imshow('mask',color_image)
    #cv2.imshow('res',res)
    k = cv2.waitKey(5) & 0xFF
    if k == 27:
        break
cv2.destroyAllWindows()