structure cleanup and led inclusion in rfid test

This commit is contained in:
2023-01-17 10:52:43 +00:00
parent 22bb578913
commit 0ce89fab9e
5 changed files with 32 additions and 12 deletions

View File

@@ -0,0 +1,49 @@
from imutils.video import VideoStream
from pyzbar import pyzbar
import argparse
import datetime
import imutils
import time
import cv2
ap = argparse.ArgumentParser()
ap.add_argument("-o", "--output", type=str, default="barcodes.csv",
help="path to output CSV file containing barcodes")
args = vars(ap.parse_args())
vs = VideoStream(src=0).start() #Uncomment this if you are using Webcam
#vs = VideoStream(usePiCamera=True).start() # For Pi Camera
time.sleep(2.0)
csv = open(args["output"], "w")
found = set()
while True:
frame = vs.read()
frame = imutils.resize(frame, width=400)
barcodes = pyzbar.decode(frame)
for barcode in barcodes:
(x, y, w, h) = barcode.rect
cv2.rectangle(frame, (x, y), (x + w, y + h), (0, 0, 255), 2)
barcodeData = barcode.data.decode("utf-8")
barcodeType = barcode.type
text = "{} ({})".format(barcodeData, barcodeType)
print (text)
cv2.putText(frame, text, (x, y - 10),
cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0, 0, 255), 2)
# if the barcode text is currently not in our CSV file, write
# the timestamp + barcode to disk and update the set
if barcodeData not in found:
csv.write("{},{}\n".format(datetime.datetime.now(),
barcodeData))
csv.flush()
found.add(barcodeData)
# cv2.imshow("Barcode Reader", frame)
key = cv2.waitKey(1) & 0xFF
# if the `s` key is pressed, break from the loop
if key == ord("s"):
break
print("[INFO] cleaning up...")
csv.close()
cv2.destroyAllWindows()
vs.stop()

17
test_scripts/led_test.py Normal file
View File

@@ -0,0 +1,17 @@
from indication_driver import IndicationDriver
from time import sleep
import asyncio
async def __main__():
task = asyncio.create_task(indication_driver.indicate_async("BOTTLE"))
await asyncio.sleep(5)
indication_driver.stop_loop()
await task
indication_driver.clear()
indication_driver = IndicationDriver()
asyncio.run(__main__())
sleep(2)
indication_driver.indicate("CAN")
sleep(2)
indication_driver.clear()

23
test_scripts/rfid_test.py Normal file
View File

@@ -0,0 +1,23 @@
from time import sleep
import RPi.GPIO as GPIO
from mfrc522 import SimpleMFRC522
import sys
sys.path.append('..')
import TREx.config as config
from TREx.indication_driver import IndicationDriver
reader = SimpleMFRC522()
indication_driver = IndicationDriver()
while True:
id, _ = reader.read()
if id in config.RFID_LOOKUP_TABLE.keys():
trash_category = config.RFID_LOOKUP_TABLE[id]
print(f"{id}: {trash_category}")
indication_driver.indicate(trash_category)
else:
print(id)
sleep(1)
GPIO.cleanup()