-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
executable file
·57 lines (43 loc) · 1.16 KB
/
main.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
#! /usr/bin/python2
import RPi.GPIO as GPIO
from hx711 import HX711
from picamera import PiCamera
import os
import time
from classifier import Classifier
import food_logger
camera = PiCamera()
classifier = Classifier(
"converted_tflite/model_unquant.tflite", "converted_tflite/labels.txt"
)
IMAGES_FOLDER = "images"
if not os.path.exists(IMAGES_FOLDER):
os.mkdir(IMAGES_FOLDER)
def capture():
img_name = int(time.time())
img_path = f"images/{img_name}.jpg"
camera.capture(img_path)
return img_path
referenceUnit = 346
hx = HX711(5, 6)
hx.set_reading_format("MSB", "MSB")
hx.set_reference_unit(referenceUnit)
hx.reset()
hx.tare()
print("Tare done! Add weight now...")
while True:
try:
value = hx.get_weight()
counter = 0
print(value)
while value > 10:
img_path = capture()
label = classifier.infer(img_path)
print(f"{label} : {int(value)}gm")
counter += 1
if counter == 3:
food_logger.log(label, value)
time.sleep(0.2)
value = hx.get_weight()
except (KeyboardInterrupt, SystemExit):
GPIO.cleanup()