-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvision_tools.py
52 lines (39 loc) · 1.86 KB
/
vision_tools.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import cv2
import json
import os
import dotenv
import openai
import asyncio
dotenv.load_dotenv()
openai.api_key = os.getenv("OPEN_AI_API")
path = 'output.json'
def what_am_i_holding():
visual_input = None
#image = cv2.imread('current.jpg')
with open(path , 'r') as f:
visual_input = json.load(f)
if visual_input :
if visual_input['left_hand_object'] :
xmin = visual_input['left_hand_object']['xmin']
ymin = visual_input['left_hand_object']['ymin']
xmax = visual_input['left_hand_object']['xmax']
ymax = visual_input['left_hand_object']['ymax']
#roi = image[int(ymin):int(ymax), int(xmin):int(xmax)]
#cv2.imwrite('left_hand_object.jpg', roi)
if visual_input['right_hand_object'] :
xmin = visual_input['right_hand_object']['xmin']
ymin = visual_input['right_hand_object']['ymin']
xmax = visual_input['right_hand_object']['xmax']
ymax = visual_input['right_hand_object']['ymax']
#roi = image[int(ymin):int(ymax), int(xmin):int(xmax)]
#cv2.imwrite('right_hand_object.jpg', roi)
chat_response = None
if visual_input['left_hand_object'] and visual_input['right_hand_object'] :
chat_response = f'You are holding a {visual_input["left_hand_object"]["name"]} in your left hand and a {visual_input["right_hand_object"]["name"]} in your right hand'
elif visual_input['left_hand_object'] :
chat_response = f'You are holding a {visual_input["left_hand_object"]["name"]} in your left hand'
elif visual_input['right_hand_object'] :
chat_response = f'You are holding a {visual_input["right_hand_object"]["name"]} in your right hand'
else :
chat_response = 'You are not holding anything'
return chat_response