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.

62 lines
1.9 KiB

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