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.

90 lines
2.5 KiB

7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
  1. from imutils.video import VideoStream
  2. from pyzbar import pyzbar
  3. import imutils
  4. import time
  5. import cv2
  6. import database_read
  7. import datetime
  8. import generate_moves
  9. import serial
  10. arduino = serial.Serial('/dev/ttyACM0', 115200, timeout=.1)
  11. def move(locations):
  12. reps = 0
  13. for i in range(0,len(locations),2):
  14. arduino.write(locations[i])
  15. while(arduino.read() == '\x00'):
  16. continue
  17. arduino.write(locations[i+1])
  18. while(arduino.read() == '\x00'):
  19. continue
  20. print("[INFO] starting video stream...")
  21. def dateStr():
  22. date_cur = ""
  23. if len(str(datetime.date.today().day)) == 1:
  24. date_cur = date_cur + "0" + str(datetime.date.today().day) + "."
  25. else:
  26. date_cur = date_cur + str(datetime.date.today().day) + "."
  27. if len(str(datetime.date.today().month)) == 1:
  28. date_cur = date_cur + "0" + str(datetime.date.today().month) + "."
  29. else:
  30. date_cur = date_cur + str(datetime.date.today().month) + "."
  31. date_cur += str(datetime.date.today().year)
  32. return date_cur
  33. vs = VideoStream().start()
  34. time.sleep(2.0)
  35. dates = []
  36. reps = 0
  37. barcodes = None
  38. prevcode = None
  39. exp_date = []
  40. current_date = dateStr()
  41. while reps<1:
  42. try:
  43. while (barcodes == None or barcodes == []):
  44. frame = vs.read()
  45. frame = imutils.resize(frame, width=400)
  46. barcodes = pyzbar.decode(frame)
  47. cv2.imshow("Image", frame)
  48. if cv2.waitKey(1) & 0xFF == ord('q'):
  49. break
  50. barcodes = pyzbar.decode(frame)
  51. # loop over the detected barcodes
  52. for barcode in barcodes:
  53. (x, y, w, h) = barcode.rect
  54. cv2.rectangle(frame, (x, y), (x + w, y + h), (0, 0, 255), 2)
  55. barcodeData = barcode.data.decode("utf-8")
  56. barcodeType = barcode.type
  57. if (barcodeData != prevcode):
  58. text = "{} ({})".format(barcodeData, barcodeType)
  59. cv2.putText(frame, text, (x, y - 10), cv2.FONT_HERSHEY_SIMPLEX,
  60. 0.5, (0, 0, 255), 2)
  61. print("[INFO] Found {} barcode: {}".format(barcodeType, barcodeData))
  62. dates.append(database_read.getDate(barcodeData))
  63. reps += 1
  64. arduino.write("1")
  65. prevcode = barcodeData
  66. barcodes = None
  67. cv2.imshow("Image", frame)
  68. if cv2.waitKey(1) & 0xFF == ord('q'):
  69. break
  70. except KeyboardInterrupt:
  71. break
  72. print("[INFO] cleaning up...")
  73. moves = generate_moves.generate(dates,current_date)
  74. #move(moves)
  75. cv2.destroyAllWindows()
  76. vs.stop()