This repository was archived by the owner on Aug 4, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcamera.py
63 lines (51 loc) · 1.79 KB
/
camera.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
import os
import time
from threading import Thread
from queue import Queue
from picamera import PiCamera
from keras.models import load_model, Sequential
import numpy as np
from PIL import Image
camera = PiCamera()
class Camera(Thread):
def __init__(self, q_write):
Thread.__init__(self)
self.name = "camera_thread"
self.q_write = q_write
def run(self):
while True:
time.sleep(1)
self.take_photo()
# Process your photo, do everything you want here
os.system("zbarimg " + "pic.jpg > code.txt")
with open('code.txt', "r") as text_file:
data = text_file.readline()
if not data:
print("not QR code")
print("the fruit is...")
img = Image.open("pic.jpg")
img = img.resize((100,100), Image.ANTIALIAS)
img = np.array(img).astype(np.uint8)
img = np.expand_dims(img,axis=0)
model = load_model("fruit_model.h5")
print(model.predict_classes(img))
cooking_time = 0
else:
data = data.split(':')
cooking_time = int(data[1])
print(cooking_time)
#According to the image, put the required cooking time here. If no cooking is required, put 0
if cooking_time != 0:
self.q_write.put(str(cooking_time))
def take_photo(self):
camera.capture('pic.jpg')
if __name__ == "__main__":
camera.capture('pic.jpg')
os.system("zbarimg " + "pic.jpg > code.txt")
with open('code.txt', "r") as text_file:
data = text_file.readline()
if not data:
print("not QR code")
else:
data = data.split(':')
print(int(data[1]))