-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreqwocam.py
53 lines (46 loc) · 1.79 KB
/
reqwocam.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
## THIS FILE IS USED TO TEST THE ROBOFLOW API WITHOUT THE NEED OF A RASPBERRY PI
import json
from time import sleep
import send_image
# Örnek bir resim dosyasının yolu
image_path = 'battery.jpg'
# POST isteği için endpoint URL'si
command_url = 'https://classify.roboflow.com/waste-detection-yljc0/1'
trash_url = 'https://detect.roboflow.com/yolov5-garbage-detection/1'
def get_command():
trash_response = send_image.send_image(image_path, trash_url)
if trash_response is None:
return None
elif trash_response.status_code == 200:
try:
print(json.dumps(trash_response.json(), indent=4))
trash_result = json.loads(trash_response.text)
if(len(trash_result['predictions']) == 0):
print("No predictions from trash API")
return 0
trash_label = trash_result['predictions'][0]['class']
if trash_label == "trash":
print("Trash: Exiting...")
return 0
elif trash_label == "not trash":
print("Not Trash: Continue...")
except Exception as e:
print(e)
return
response = send_image.send_image(image_path, command_url)
if response is None: #TODO: Add error handling
return None
elif response.status_code == 200:
try:
result = json.loads(response.text)
if len(result['predicted_classes']) == 0:
return 0
print("Etiket: ", result['predicted_classes'][0])
predicted_class = str(result['predicted_classes'][0])
return predicted_class
except Exception as e:
print("Hata Olustu: ",str(e))
return 0
else:
print("Istek basarisiz. HTTP Hata Kodu:", response.status_code)
return 0