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