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.

77 lines
2.5 KiB

7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
  1. # import the necessary packages
  2. from imutils.video import VideoStream
  3. from pyzbar import pyzbar
  4. import imutils
  5. import time
  6. import cv2
  7. import database_actions
  8. import datetime
  9. import generate_moves
  10. # initialize the video stream and allow the camera sensor to warm up
  11. print("[INFO] starting video stream...")
  12. def dateStr():
  13. date_cur = ""
  14. if len(str(datetime.date.today().day)) == 1:
  15. date_cur = date_cur + "0" + str(datetime.date.today().day) + "."
  16. else:
  17. date_cur = date_cur + str(datetime.date.today().day) + "."
  18. if len(str(datetime.date.today().month)) == 1:
  19. date_cur = date_cur + "0" + str(datetime.date.today().month) + "."
  20. else:
  21. date_cur = date_cur + str(datetime.date.today().month) + "."
  22. date_cur += str(datetime.date.today().year)
  23. return date_cur
  24. # vs = VideoStream(src=0).start()
  25. vs = VideoStream().start()
  26. time.sleep(2.0)
  27. dates = []
  28. reps = 0
  29. barcodes = None
  30. prevcode = None
  31. exp_date = []
  32. current_date = dateStr()
  33. print current_date
  34. # loop over the frames from the video stream
  35. while reps<1:
  36. # grab the frame from the threaded video stream and resize it to
  37. try:
  38. while (barcodes == None or barcodes == []):
  39. frame = vs.read()
  40. frame = imutils.resize(frame, width=400)
  41. barcodes = pyzbar.decode(frame)
  42. cv2.imshow("Image", frame)
  43. if cv2.waitKey(1) & 0xFF == ord('q'):
  44. break
  45. barcodes = pyzbar.decode(frame)
  46. # loop over the detected barcodes
  47. for barcode in barcodes:
  48. (x, y, w, h) = barcode.rect
  49. cv2.rectangle(frame, (x, y), (x + w, y + h), (0, 0, 255), 2)
  50. barcodeData = barcode.data.decode("utf-8")
  51. barcodeType = barcode.type
  52. if (barcodeData != prevcode):
  53. text = "{} ({})".format(barcodeData, barcodeType)
  54. cv2.putText(frame, text, (x, y - 10), cv2.FONT_HERSHEY_SIMPLEX,
  55. 0.5, (0, 0, 255), 2)
  56. print("[INFO] Found {} barcode: {}".format(barcodeType, barcodeData))
  57. dates.append(database_actions.getDate(barcodeData))
  58. reps += 1
  59. prevcode = barcodeData
  60. barcodes = None
  61. cv2.imshow("Image", frame)
  62. if cv2.waitKey(1) & 0xFF == ord('q'):
  63. break
  64. except KeyboardInterrupt:
  65. break
  66. # close the output CSV file do a bit of cleanup
  67. print("[INFO] cleaning up...")
  68. print dates
  69. generate_moves.generate(dates,current_date)
  70. cv2.destroyAllWindows()
  71. vs.stop()