当前位置:   article > 正文

Python实例:通过摄像头实时识别一维条形码

python 一维码识别
  1. #coding:utf-8
  2. '''
  3. 通过摄像头识别一维条形码
  4. '''
  5. import cv2
  6. from pyzbar.pyzbar import decode
  7. # results = decode(cv2.imread('datas/images/barcode-3.jpg'))
  8. # for result in results:
  9. # print('barcode = %s'% str(result.data))
  10. cap = cv2.VideoCapture(0)
  11. if not cap.isOpened():
  12. print('cannot open camera 0')
  13. exit(0)
  14. while True:
  15. ret,frame = cap.read()
  16. if not ret:
  17. print('cannot grab frame from camera')
  18. continue
  19. results = decode(frame)
  20. for result in results:
  21. print('barcode = %s' % result.data)
  22. barcode_roi = frame[result.rect.left:result.rect.width,result.rect.top:result.rect.height]
  23. cv2.imshow('barcode:%s' % result.data,barcode_roi)
  24. cv2.imshow('camera',frame)
  25. key = cv2.waitKey(10)
  26. if key == 27:
  27. break
  28. cv2.destroyAllWindows()

 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/繁依Fanyi0/article/detail/649382
推荐阅读
相关标签
  

闽ICP备14008679号