<commit_before>import io
import picamera
import time
import numpy 
import cv2
import onlineCoffee
import twitter

def detectCoffee():
    stream = io.BytesIO()
    
        #Get the picture (low resolution, so it should be quite fast)
        #Here you can also specify other parameters (e.g.:rotate the image)
    with picamera.PiCamera() as camera:
        camera.resolution = (350, 262)
        camera.capture(stream, format='jpeg')
    
    buff = numpy.fromstring(stream.getvalue(), dtype=numpy.uint8)
    
    #Now creates an OpenCV image
    img = cv2.imdecode(buff, 1)
    
    #img = cv2.imread('coffee.jpg')
    face_cascade = cv2.CascadeClassifier('/home/pi/Documents/OpenCV_Projects/XML_Files/coffeePot.xml')
    eye_cascade = cv2.CascadeClassifier('/home/pi/Documents/OpenCV_Projects/XML_Files/liquid.xml')
    
    gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
    rgb_val = 0
    faces = face_cascade.detectMultiScale(gray, 1.2, 200, minSize=(30,50))
    for (x,y,w,h) in faces:
        img = cv2.rectangle(img,(x,y),(x+w,y+h),(255,0,0),2)
        roi_gray = gray[y:y+h, x:x+w]
        roi_color = img[y:y+h, x:x+w]
        eyes = eye_cascade.detectMultiScale(roi_gray, 1.2, 10, minSize=(25,25))
        rgb_val = 0
        numPots = 0
        for (ex,ey,ew,eh) in eyes:
            cv2.rectangle(roi_color,(ex,ey),(ex+ew,ey+eh),(0,255,0),2)
            roi_liquid_color = img[ey:ey+eh, ex:ex+ew]
            mean = cv2.mean(roi_liquid_color)
            rgb_val += mean[0] +mean[1] +mean[2]
            numPots += 1
        if(numPots == 0):
            numPots += 1
        rgb_val /= numPots
        print(rgb_val)
    return rgb_val
    
def getAVGcoffee(numPics):
    if(numPics > 0):
        avg_rgb_val = 0
        good_vals = 0
        for i in range(numPics):
            next_rgb_val = 0
            next_rgb_val = detectCoffee()
            if(next_rgb_val > 0):
                avg_rgb_val += next_rgb_val
                good_vals += 1
            time.sleep(1)
        avg_rgb_val /= good_vals
        return avg_rgb_val
    
#Main Prog Loop
loops = 0
constant_empty_rgb_val = 0
while(True):
    if(loops < 2):
        if(loops == 0):
            print("Calibrating, please ensure pot is EMPTY,")
            raw_input("Press ENTER when pot is EMPTY...")
            constant_empty_rgb_val += getAVGcoffee(4)
        else:
            constant_empty_rgb_val += getAVGcoffee(4)
            constant_empty_rgb_val /= 2
    else:
        print("Checking for coffee... ")
        currentCoffeeLevel = getAVGcoffee(4)
        percentDiff = (abs(constant_empty_rgb_val - currentCoffeeLevel)/float(constant_empty_rgb_val))*100.0
        print("RGB val of pot is: " + str(currentCoffeeLevel))
        print("There is approximately %d% coffee in the pot"(percentDiff))
        time.sleep(3)
    loops += 1<commit_msg>camera settings and width settings<commit_after>import io
import picamera
import time
import numpy 
import cv2
import onlineCoffee
import Twitter

def detectCoffee():
    stream = io.BytesIO()
    
        #Get the picture (low resolution, so it should be quite fast)
        #Here you can also specify other parameters (e.g.:rotate the image)
    with picamera.PiCamera() as camera:
        camera.start_preview()
        camera.resolution = (700, 525)
        camera.awb_mode = "auto"
        camera.iso = 800
        camera.capture(stream, format='jpeg')
    
    buff = numpy.fromstring(stream.getvalue(), dtype=numpy.uint8)
    
    #Now creates an OpenCV image
    img = cv2.imdecode(buff, 1)
    
    #img = cv2.imread('coffee.jpg')
    face_cascade = cv2.CascadeClassifier('/home/pi/Documents/OpenCV_Projects/XML_Files/coffeePot.xml')
    eye_cascade = cv2.CascadeClassifier('/home/pi/Documents/OpenCV_Projects/XML_Files/liquid.xml')
    
    gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
    rgb_val = 0
    faces = face_cascade.detectMultiScale(gray, 1.2, 200, minSize=(30, 50))
    for (x,y,w,h) in faces:
        img = cv2.rectangle(img,(x,y),(x+w,y+h),(255,0,0),2)
        roi_gray = gray[y:y+h, x:x+w]
        roi_color = img[y:y+h, x:x+w]
        minPotWidth,minPotHeight = w*0.8
        eyes = eye_cascade.detectMultiScale(roi_gray, 1.2, 10, minSize=(minPotWidth, minPotHeight))
        rgb_val = 0
        numPots = 0
        for (ex,ey,ew,eh) in eyes:
            cv2.rectangle(roi_color,(ex,ey),(ex+ew,ey+eh),(0,255,0),2)
            roi_liquid_color = img[ey:ey+eh, ex:ex+ew]
            mean = cv2.mean(roi_liquid_color)
            rgb_val += mean[0] +mean[1] +mean[2]
            numPots += 1
        if(numPots == 0):
            numPots += 1
        rgb_val /= numPots
        print(rgb_val)
    return rgb_val
    
def getAVGcoffee(numPics):
    if(numPics > 0):
        avg_rgb_val = 0
        good_vals = 0
        for i in range(numPics):
            next_rgb_val = 0
            next_rgb_val = detectCoffee()
            if(next_rgb_val > 0):
                avg_rgb_val += next_rgb_val
                good_vals += 1
            time.sleep(1)
        avg_rgb_val /= good_vals
        return avg_rgb_val
    
#Main Prog Loop
loops = 0
constant_empty_rgb_val = 0
while(True):
    if(loops < 2):
        if(loops == 0):
            print("Calibrating, please ensure pot is EMPTY,")
            raw_input("Press ENTER when pot is EMPTY...")
            constant_empty_rgb_val += getAVGcoffee(4)
        else:
            constant_empty_rgb_val += getAVGcoffee(4)
            constant_empty_rgb_val /= 2
    else:
        print("Checking for coffee... ")
        currentCoffeeLevel = getAVGcoffee(4)
        percentDiff = (abs(constant_empty_rgb_val - currentCoffeeLevel)/float(constant_empty_rgb_val))*100.0
        print("RGB val of pot is: " + str(currentCoffeeLevel))
        print("There is approximately %d% coffee in the pot {}".format(percentDiff))
        time.sleep(3)
    loops += 1
{'fraction_non_alphanumeric': 0.11615989067304407, 'fraction_numerical': 0.026819268875982235, 'mean_word_length': 2.3981427742309926, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 4}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '463487', 'n_tokens_mistral': 2198, 'n_tokens_neox': 2039, 'n_words': 423}