import numpy as np
import cv2
from PARAM import *

def Fcolor():
    cap = cv2.VideoCapture(0)
    cap.set(cv2.CAP_PROP_FRAME_WIDTH, Lx)
    cap.set(cv2.CAP_PROP_FRAME_HEIGHT, Ly)
    XC=int(Lx/2); YC=int(Ly/2)
    t=0
    while t < 4:
        ret,frame = cap.read(); t+=1
        if(ret==True):
            img3=frame[YC:YC+10,XC:XC+10,:]
            a=np.arange(3)
            for n in range(3): a[n]=int(np.average(img3[:,:,n:n+1]))
            r1=round(float(a[1])/float(a[0]),2); 
            r2=round(float(a[2])/float(a[0]),2); 
            print(t,'focus:acc,r1,r2=',a,r1,r2)
            cv2.circle(frame,(XC,YC), 10, (0, 155, 255), 2)
            cv2.imshow('frame',frame)
            cv2.waitKey(0)
    cv2.destroyAllWindows()
    cap.release()
    return a,r1,r2

