updates to quality

This commit is contained in:
Charlie Holtz 2023-11-07 10:50:50 -05:00
parent 899bb437d8
commit 1dd40a7499
2 changed files with 27 additions and 2 deletions

View File

@ -1,5 +1,7 @@
import cv2
import time
from PIL import Image
import numpy as np
# Folder
folder = "frames"
@ -17,6 +19,18 @@ time.sleep(2)
while True:
ret, frame = cap.read()
if ret:
# Convert the frame to a PIL image
pil_img = Image.fromarray(cv2.cvtColor(frame, cv2.COLOR_BGR2RGB))
# Resize the image
max_size = 250
ratio = max_size / max(pil_img.size)
new_size = tuple([int(x*ratio) for x in pil_img.size])
resized_img = pil_img.resize(new_size, Image.LANCZOS)
# Convert the PIL image back to an OpenCV image
frame = cv2.cvtColor(np.array(resized_img), cv2.COLOR_RGB2BGR)
# Save the frame as an image file
print("📸 Say cheese! Saving frame.")
path = f"{folder}/frame.jpg"

View File

@ -4,12 +4,22 @@ import base64
import json
import time
import simpleaudio as sa
import errno
client = OpenAI()
def encode_image(image_path):
with open(image_path, "rb") as image_file:
return base64.b64encode(image_file.read()).decode('utf-8')
while True:
try:
with open(image_path, "rb") as image_file:
return base64.b64encode(image_file.read()).decode('utf-8')
except IOError as e:
if e.errno != errno.EACCES:
# Not a "file in use" error, re-raise
raise
# File is being written to, wait a bit and retry
time.sleep(0.1)
def play_audio(file_path):
@ -37,6 +47,7 @@ def analyze_posture(base64_image):
{
"type": "image_url",
"image_url": f"data:image/jpeg;base64,{base64_image}",
# "image_url": "https://upload.wikimedia.org/wikipedia/commons/thumb/d/dd/Gfp-wisconsin-madison-the-nature-boardwalk.jpg/2560px-Gfp-wisconsin-madison-the-nature-boardwalk.jpg"
},
],
}