def read_barcode(): vc = cv2.VideoCapture("rtsp://184.72.239.149/vod/mp4:BigBuckBunny_175k.mov"); if vc.isOpened(): # try to get the first frame dbr.initLicense("t0068MgAAABt/IBmbdOLQj2EIDtPBkg8tPVp6wuFflHU0+y14UaUt5KpXdhAxlERuDYvJy7AOB514QK4H50mznL6NZtBjITQ=") setting_file = os.path.join(os.getcwd(), 'templates', 'default.settings.json') dbr.loadSettings(setting_file) rval, frame = vc.read() else: return windowName = "Barcode Reader" formats = 0x3FF | 0x2000000 | 0x8000000 | 0x4000000; # 1D, QRCODE, PDF417, DataMatrix while True: cv2.imshow(windowName, frame) rval, frame = vc.read(); results = dbr.decodeBuffer(frame, formats, 'CUSTOM') if (len(results) > 0): print(get_time()) print("Total count: " + str(len(results))) for result in results: print("Type: " + result[0]) print("Value: " + result[1] + "\n") # 'ESC' for quit key = cv2.waitKey(20) if key == 27: dbr.destroy() break cv2.destroyWindow(windowName)
def decodeBuffer(image): results = dbr.decodeBuffer(image, config.barcodeTypes) thickness = 2 color = (0, 255, 0) for result in results: print("barcode format: " + result[0]) print("barcode value: " + bytearray.fromhex(result[1]).decode('latin-1')) x1 = result[2] y1 = result[3] x2 = result[4] y2 = result[5] x3 = result[6] y3 = result[7] x4 = result[8] y4 = result[9] cv2.line(image, (x1, y1), (x2, y2), color, thickness) cv2.line(image, (x2, y2), (x3, y3), color, thickness) cv2.line(image, (x3, y3), (x4, y4), color, thickness) cv2.line(image, (x4, y4), (x1, y1), color, thickness) cv2.imshow("Localization", image) cv2.waitKey(0)
def read_barcode(): vc = cv2.VideoCapture( "rtsp://184.72.239.149/vod/mp4:BigBuckBunny_175k.mov") if vc.isOpened(): # try to get the first frame dbr.initLicense(config.license) rval, frame = vc.read() else: return windowName = "Barcode Reader" while True: cv2.imshow(windowName, frame) rval, frame = vc.read() results = dbr.decodeBuffer(frame, config.barcodeTypes) if (len(results) > 0): print(get_time()) print("Total count: " + str(len(results))) for result in results: print("Type: " + result[0]) print("Value: " + result[1] + "\n") # 'ESC' for quit key = cv2.waitKey(20) if key == 27: dbr.destroy() break cv2.destroyWindow(windowName)
def decodeBuffer(image): formats = 0x3FF | 0x2000000 | 0x8000000 | 0x4000000 # 1D, QRCODE, PDF417, DataMatrix results = dbr.decodeBuffer(image, formats, 'CUSTOM') for result in results: print("barcode format: " + result[0]) print("barcode value: " + result[1])
def dbr_run(frame_queue, key_queue, cond, num, result_queue): conn = GattConnection() try: conn.connect() hub = MoveHub(conn) print('Robot connected') speed = 0.5 dbr.initLicense('t0126lQMAAJKX0RvMyzlh6PuQjcJyenARHjo4+sFqhwweCXfp3hAVHYasqSvCLpym3urmWpADdzSI19PIjSv4RBLR1HkSjR7O0lsOF8wumF0wu2B2wRyCOQRzCOYQzCGYKZgpmCmYKZjzW+sncrPQMG8MWRNv9W/aWNJhfgMslLDp') while num.value == 1: print('wait for event') key = key_queue.get() if key == ord('q'): break try: if key == ord('c'): inputframe = frame_queue.get() results = dbr.decodeBuffer(inputframe, 0x4000000) if (len(results) > 0): print(get_time()) print("Total count: " + str(len(results))) for result in results: print("Type: " + result[0]) print("Value: " + result[1] + "\n") result_queue.put(Result(inputframe, results)) elif key == ord('a'): # left print('left') hub.motor_AB.angled(90, speed * -1, speed) elif key == ord('d'): # right print('right') hub.motor_AB.angled(90, speed, speed * -1) elif key == ord('w'): # up print('up') hub.motor_AB.start_speed(speed) elif key == ord('s'): # down print('down') hub.motor_AB.start_speed(speed * -1) elif key == ord('p'): print('pause') hub.motor_AB.stop() except: pass dbr.destroy() print("Detection is done.") finally: conn.disconnect()
def run(self): global q while self.isRunning: # Get a frame frame = q.get(True) results = dbr.decodeBuffer(frame, config.barcodeTypes) q.task_done() if (len(results) > 0): print(get_time()) print("Total count: " + str(len(results))) for result in results: print("Type: " + result[0]) print("Value: " + result[1] + "\n") print("Quit thread")
def nextFrameSlot(self): rval, frame = self.vc.read() frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB) image = QImage(frame, frame.shape[1], frame.shape[0], QImage.Format_RGB888) pixmap = QPixmap.fromImage(image) self.label.setPixmap(pixmap) results = dbr.decodeBuffer(frame, 0x3FF | 0x2000000 | 0x4000000 | 0x8000000 | 0x10000000) out = '' index = 0 for result in results: out += "Index: " + str(index) + "\n" out += "Barcode format: " + result[0] + '\n' out += "Barcode value: " + result[1] + '\n' out += '-----------------------------------\n' index += 1 self.results.setText(out)
def run(self): global q formats = 0x3FF | 0x2000000 | 0x8000000 | 0x4000000 # 1D, QRCODE, PDF417, DataMatrix while self.isRunning: # Get a frame frame = q.get(True) results = dbr.decodeBuffer(frame, formats) q.task_done() if (len(results) > 0): print(get_time()) print("Total count: " + str(len(results))) for result in results: print("Type: " + result[0]) print("Value: " + result[1] + "\n") print("Quit thread")
def dbr_run(frame_queue, finish_queue): dbr.initLicense(config.license) while finish_queue.qsize() == 0: try: inputframe = frame_queue.get_nowait() results = dbr.decodeBuffer(inputframe, config.barcodeTypes) if (len(results) > 0): print(get_time()) print("Total count: " + str(len(results))) for result in results: print("Type: " + result[0]) print("Value: " + result[1] + "\n") except: pass dbr.destroy() print("Detection is done.") clear_queue(frame_queue) clear_queue(finish_queue)
def read_barcode(): vc = cv2.VideoCapture(0) vc.set(5, 30) #set FPS vc.set(3, 320) #set width vc.set(4, 240) #set height if vc.isOpened(): # try to get the first frame dbr.initLicense( "t0068MgAAAHtCgAPxEdCJN1bsu9n6YfnWDoaW7YZomIZZke2m9KynRnKSqsuQyd7Cdgo6razlb7VU3IFaKeBgg9Rq069Uihc=" ) rval, frame = vc.read() else: return windowName = "Barcode Reader" formats = 0x3FF | 0x2000000 | 0x8000000 | 0x4000000 # 1D, QRCODE, PDF417, DataMatrix while True: cv2.imshow(windowName, frame) rval, frame = vc.read() results = dbr.decodeBuffer(frame, formats) if (len(results) > 0): print(get_time()) print("Total count: " + str(len(results))) for result in results: print("Type: " + result[0]) print("Value: " + result[1] + "\n") # 'ESC' for quit key = cv2.waitKey(20) if key == 27: dbr.destroy() break cv2.destroyWindow(windowName)
from PIL import Image # pip install Pillow im = Image.open('qr.jpg') # im.show() import numpy import dbr import cv2 dbr.initLicense('LICENSE-LEY') opencvImage = cv2.cvtColor(numpy.array(im), cv2.COLOR_RGB2BGR) results = dbr.decodeBuffer( opencvImage, 0x3FF | 0x2000000 | 0x4000000 | 0x8000000 | 0x10000000) # 1D, PDF417, QRCODE, DataMatrix, Aztec Code for result in results: print('barcode format: ' + result[0]) print('barcode value: ' + result[1])
def decodeBuffer(image): results = dbr.decodeBuffer(image, config.barcodeTypes) for result in results: print("barcode format: " + result[0]) print("barcode value: " + result[1])
capturetime = time.strftime("%Y%m%d%H%M%S", localtime) return capturetime # Get the license of Dynamsoft Barcode Reader from https://www.dynamsoft.com/CustomerPortal/Portal/Triallicense.aspx dbr.initLicense('LICENSE KEY') npSocket = NumpySocket() npSocket.startServer(9999) # Receive frames for barcode detection while (True): try: frame = npSocket.recieveNumpy() # cv2.imshow('PC Reader', frame) results = dbr.decodeBuffer( frame, 0x3FF | 0x2000000 | 0x4000000 | 0x8000000 | 0x10000000) out = {} out['results'] = results # Send barcode results to Raspberry Pi npSocket.sendJSON({'results': results}) except: break # Press ESC to exit key = cv2.waitKey(20) if key == 27 or key == ord('q'): break npSocket.endServer() print('Closed')