You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

65 lines
1.8 KiB

  1. from imutils.video import VideoStream
  2. from pyzbar import pyzbar
  3. import imutils
  4. import time
  5. import cv2
  6. import generate_moves
  7. print("[INFO] starting video stream...")
  8. vs = VideoStream().start()
  9. time.sleep(2.0)
  10. dates = []
  11. reps = 0
  12. barcodes = None
  13. prevcode = None
  14. exp_date = []
  15. def main():
  16. global vs
  17. global dates
  18. global reps
  19. global barcodes
  20. global prevcode
  21. global exp_date
  22. global current_date
  23. while True:
  24. try:
  25. while (barcodes == None or barcodes == []):
  26. frame = vs.read()
  27. frame = imutils.resize(frame, width=400)
  28. barcodes = pyzbar.decode(frame)
  29. cv2.imshow("Image", frame)
  30. if cv2.waitKey(1) & 0xFF == ord('q'):
  31. break
  32. barcodes = pyzbar.decode(frame)
  33. # loop over the detected barcodes
  34. for barcode in barcodes:
  35. (x, y, w, h) = barcode.rect
  36. cv2.rectangle(frame, (x, y), (x + w, y + h), (0, 0, 255), 2)
  37. barcodeData = barcode.data.decode("utf-8")
  38. barcodeType = barcode.type
  39. if (barcodeData != prevcode):
  40. text = "{} ({})".format(barcodeData, barcodeType)
  41. cv2.putText(frame, text, (x, y - 10), cv2.FONT_HERSHEY_SIMPLEX,
  42. 0.5, (0, 0, 255), 2)
  43. print("[INFO] Found {} barcode: {}".format(barcodeType, barcodeData))
  44. reps += 1
  45. prevcode = barcodeData
  46. barcodes = None
  47. cv2.imshow("Image", frame)
  48. if cv2.waitKey(1) & 0xFF == ord('q'):
  49. break
  50. except KeyboardInterrupt:
  51. break
  52. main()
  53. print("[INFO] cleaning up...")
  54. moves = generate_moves.generate(dates,current_date)
  55. cv2.destroyAllWindows()
  56. vs.stop()