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