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.

41 lines
1.2 KiB

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