forked from mqzpt/smartsortr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsmartSortr.py
62 lines (42 loc) · 1.38 KB
/
smartSortr.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
import requests
url = "https://mantis-object-detection.p.rapidapi.com/rest/v1/public/detectObjects/base64/json"
import base64
from io import BytesIO
from PIL import Image
import RPi.GPIO as GPIO
import time
import cv2 as cv
import RPi.GPIO as GPIO
import numpy as np
cam = cv.VideoCapture(0)
font = cv.FONT_HERSHEY_SIMPLEX
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
GPIO.setup(14, GPIO.OUT)
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BCM)
GPIO.setup(23, GPIO.OUT)
GPIO.setup(18, GPIO.OUT)
ret, frame = cam.read()
numpy_array = frame
cv.imwrite('output.jpg', numpy_array)
image_path = "/home/jeyoung7/raspberry-camera-object-recognition/output1.jpg"
image = Image.open(image_path)
buffered = BytesIO()
image.save(buffered, format="JPEG")
img_str = base64.b64encode(buffered.getvalue())
headers = {
"content-type": "text/plain",
"X-RapidAPI-Key": "",
"X-RapidAPI-Host": "mantis-object-detection.p.rapidapi.com"
}
image = Image.open('/home/jeyoung7/raspberry-camera-object-recognition/output1.jpg')
image.show()
response = requests.post(url, data=img_str, headers=headers)
print(response.json())
recycle = {'bottle', 'glass bottle', 'plastic bottle', 'can', 'cup', 'plastic cup','utensil', 'paper', 'newspaper', 'shredded paper', 'paper bags', 'box'}
label = response['detected-objects'][0]['label']
if label in recycle:
GPIO.output(18, True)
else:
GPIO.output(23, False)