-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain_testing.py
72 lines (54 loc) · 1.86 KB
/
main_testing.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import gradio as gr
import time
import cv2
import threading
from colorama import Fore, Back, Style
from utils.ml import get_material
from utils.firebase import into_firebase
from utils.webhook import webhook_signal
from utils.doors import open_door, servo_setup
from utils.misc import rn_fancy, big_fancy_title4
from dotenv import load_dotenv
load_dotenv()
"""
testing the main.py file with a static image
"""
image_path = './testing-images/bottle.jpg'
# THE SETUP
print(big_fancy_title4)
print(Fore.MAGENTA + "\n===== SETUP STARTING =====\n" + Style.RESET_ALL)
def load_server(server_loaded_event):
gr.Interface.load("models/yangy50/garbage-classification")
server_loaded_event.set()
server_loaded_event = threading.Event()
interface_thread = threading.Thread(target=load_server, args=(server_loaded_event,))
interface_thread.start()
print(Fore.YELLOW + "Waiting for server to load..." + Style.RESET_ALL)
server_loaded_event.wait()
print(Fore.GREEN + "Server has loaded successfully!\n" + Style.RESET_ALL)
# servo angles setup
servo_setup()
print(Fore.MAGENTA + "\n===== SETUP DONE =====\n" + Style.RESET_ALL)
# THE MAIN LOOP
while True:
frame = cv2.imread(image_path)
cv2.imshow('frame', frame)
key = cv2.waitKey(1)
if key == ord(' '): # pretend that pressing SPACE is like throwing the trash in
time.sleep(1) # wait 1 sec for the trash to fall in
_, img_encoded = cv2.imencode('.jpg', frame)
img_bytes = img_encoded.tobytes()
material, certainty = get_material(img_bytes)
data = {
'material': material,
'certainty': certainty,
'datetime': rn_fancy(),
'img_bytes': img_bytes
}
open_door(material)
webhook_signal(data)
into_firebase(data)
print("")
elif key == 27: # press Esc to quit
break
cv2.destroyAllWindows()