Advertisement
orneto

Untitled

Jun 14th, 2023
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.61 KB | None | 0 0
  1. Basics.py
  2. import cv2
  3. import numpy as np
  4. from pyzbar.pyzbar import decode
  5.  
  6. #img = cv2.imread('1.png')
  7. cap = cv2.VideoCapture(0)
  8. cap.set(3,640)
  9. cap.set(4,480)
  10.  
  11. while True:
  12.  
  13. success, img = cap.read()
  14. for barcode in decode(img):
  15. myData = barcode.data.decode('utf-8')
  16. print(myData)
  17. pts = np.array([barcode.polygon],np.int32)
  18. pts = pts.reshape((-1,1,2))
  19. cv2.polylines(img,[pts],True,(255,0,255),5)
  20. pts2 = barcode.rect
  21. cv2.putText(img,myData,(pts2[0],pts2[1]),cv2.FONT_HERSHEY_SIMPLEX, 0.9,(255,0,255),2)
  22.  
  23. cv2.imshow('Result',img)
  24. cv2.waitKey(1)
  25.  
  26. /////////////////////////////////////////////////////////////////////////
  27. Project.py
  28.  
  29.  
  30.  
  31.  
  32. import cv2
  33. import numpy as np
  34. from pyzbar.pyzbar import decode
  35.  
  36. #img = cv2.imread('1.png')
  37. cap = cv2.VideoCapture(0)
  38. cap.set(3,640)
  39. cap.set(4,480)
  40.  
  41. with open('myDataFile.text') as f:
  42. myDataList = f.read().splitlines()
  43.  
  44. while True:
  45.  
  46. success, img = cap.read()
  47. for barcode in decode(img):
  48. myData = barcode.data.decode('utf-8')
  49. print(myData)
  50.  
  51. if myData in myDataList:
  52. myOutput = 'Authorized'
  53. myColor = (0,255,0)
  54. else:
  55. myOutput = 'Un-Authorized'
  56. myColor = (0, 0, 255)
  57.  
  58. pts = np.array([barcode.polygon],np.int32)
  59. pts = pts.reshape((-1,1,2))
  60. cv2.polylines(img,[pts],True,myColor,5)
  61. pts2 = barcode.rect
  62. cv2.putText(img,myOutput,(pts2[0],pts2[1]),cv2.FONT_HERSHEY_SIMPLEX,
  63. 0.9,myColor,2)
  64.  
  65. cv2.imshow('Result',img)
  66. cv2.waitKey(1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement