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.

45 lines
1.2 KiB

7 years ago
  1. from pyzbar import pyzbar
  2. import argparse
  3. import cv2
  4. import time
  5. import database_actions
  6. dates = []
  7. reps = 0
  8. barcodes = None
  9. prevcode = None
  10. exp_date = []
  11. cam = cv2.VideoCapture(0)
  12. while(reps<2):
  13. while(barcodes == None or barcodes == []):
  14. ret , image = cam.read()
  15. barcodes = pyzbar.decode(image)
  16. cv2.imshow("Image", image)
  17. if cv2.waitKey(1) & 0xFF == ord('q'):
  18. break
  19. for barcode in barcodes:
  20. (x, y, w, h) = barcode.rect
  21. cv2.rectangle(image, (x, y), (x + w, y + h), (0, 0, 255), 2)
  22. barcodeData = barcode.data.decode("utf-8")
  23. barcodeType = barcode.type
  24. if(barcodeData != prevcode):
  25. text = "{} ({})".format(barcodeData, barcodeType)
  26. cv2.putText(image, text, (x, y - 10), cv2.FONT_HERSHEY_SIMPLEX,
  27. 0.5, (0, 0, 255), 2)
  28. print("[INFO] Found {} barcode: {}".format(barcodeType, barcodeData))
  29. dates.append(database_actions.getDate(barcodeData))
  30. exp_date.append(int(barcodeData))
  31. reps += 1
  32. prevcode = barcodeData
  33. barcodes = None
  34. cv2.imshow("Image", image)
  35. if cv2.waitKey(1) & 0xFF == ord('q'):
  36. break
  37. print dates