def decode_webcam(self, callback=lambda s: None, device='/dev/video0'): # create a Processor proc = zbar.Processor() # configure the Processor proc.parse_config('enable') # initialize the Processor proc.init(device) # setup a callback def my_handler(proc, image, closure): # extract results for symbol in image: if not symbol.count: self.data = symbol.data self.data_type = self.data_recognise() callback(symbol.data) proc.set_data_handler(my_handler) # enable the preview window proc.visible = True # initiate scanning proc.active = True # process one image and exit, otherwise wait indefinetely proc.process_one()
def read_one_qrcode(): # create a Processor proc = zbar.Processor() # configure the Processor proc.parse_config('enable') # initialize the Processor device = '/dev/video0' if len(argv) > 1: device = argv[1] proc.init(device) # enable the preview window proc.visible = True # read at least one barcode (or until window closed) proc.process_one() # hide the preview window proc.visible = False # extract results for symbol in proc.results: # do something useful with results print 'decoded', symbol.type, 'symbol', '"%s"' % symbol.data
def train(keyid): all_bars = {} if os.path.exists('dataset_bar.dat'): with open('dataset_bar.dat', 'rb') as rf: all_bars = pickle.load(rf) print "Please place the ID card near the camera:" proc = zbar.Processor() proc.parse_config('enable') device = '/dev/video0' proc.init(device) proc.visible = True proc.process_one() result = '' for symbol in proc.results: #print 'decoded', symbol.type, 'symbol', '"%s"' % symbol.data result = symbol.data all_bars[str(keyid)] = result with open('dataset_bar.dat', 'wb') as wf: pickle.dump(all_bars, wf) print 'Successfully added', keyid, 'to the database!'
def scan_qr(config): global proc if not zbar: raise BaseException("\n".join([ _("Cannot start QR scanner."), _("The zbar package is not available."), _("On Linux, try 'sudo apt-get install python-zbar'") ])) if proc is None: device = config.get_above_chain("video_device", "default") if device == 'default': device = '' proc = zbar.Processor() proc.init(video_device=device) proc.visible = True while True: try: proc.process_one() except Exception: # User closed the preview window return "" for r in proc.results: if str(r.type) != 'QRCODE': continue # hiding the preview window stops the camera proc.visible = False return r.data
def decodecam(dev=None): state = {} number = -1 proc = zbar.Processor() if dev is not None: proc.init(dev) else: proc.init() proc.visible = True missing = set() while True: proc.process_one() dats, new_number = handle_decode(proc.results) if (new_number < 0): continue elif number < 0: number = new_number elif new_number != number: raise Exception("Mismatched QR codes") state.update(dats) missing = {i for i in range(number + 1)} - set(state.keys()) if missing: print(" ".join([str(i) for i in missing])) else: break res = "".join([state[i] for i in range(number + 1)]) res = res.ljust(((len(res) + 7) // 8) * 8, '=') res = base64.b32decode(res) return base64.b16encode(res[:64]).decode(), bz2.decompress(res[64:])
def read(challenge_code, motor_num): # create a Processor proc = zbar.Processor() # configure the Processor proc.parse_config('enable') # initialize the Processor device = '/dev/video0' if len(argv) > 1: device = argv[1] proc.init(device) # setup a callback def my_handler(proc, image, closure): # extract results for symbol in image: if not symbol.count: # do something useful with results process_code(symbol.data, challenge_code, motor_num) proc.set_data_handler(my_handler) # enable the preview window proc.visible = True # initiate scanning proc.active = True try: proc.process_one() #proc.user_wait() except zbar.WindowClosed: pass
def output(): global a a = 26 print a # create a Processor proc = zbar.Processor() # configure the Processor proc.parse_config('enable') # initialize the Processor device = '/dev/video1' proc.init(device) # setup a callback proc.set_data_handler(jiema) #print 'time2',time # enable the preview window proc.visible = True # initiate scanning proc.active = True try: proc.user_wait() except zbar.WindowClosed: pass
def decode_webcam(device='/dev/video0'): # create a Processor proc = zbar.Processor() # configure the Processor proc.parse_config('enable') # initialize the Processor proc.init(device) # setup a callback def my_handler(proc, image, closure): # extract results for symbol in image: if not symbol.count: data = symbol.data data_type = data_recognise(data) callback(symbol.data) proc.set_data_handler(my_handler) # enable the preview window proc.visible = False # initiate scanning proc.active = True try: proc.user_wait(20) except zbar.WindowClosed: pass
def recog(): all_bars = {} if os.path.exists('dataset_bar.dat'): with open('dataset_bar.dat', 'rb') as rf: all_bars = pickle.load(rf) if len(all_bars) == 0: return 'No Data' all_keys = all_bars.keys() all_values = all_bars.values() print "Please place the ID card near the camera:" proc = zbar.Processor() proc.parse_config('enable') device = '/dev/video0' proc.init(device) proc.visible = True proc.process_one() result = '' for symbol in proc.results: #print 'decoded', symbol.type, 'symbol', '"%s"' % symbol.data result = symbol.data for i in range(len(all_keys)): if all_values[i] == result: return all_keys[i] return 'Not Found'
def scan_qr(config): global proc if not zbar: raise RuntimeError("\n".join([ _("Cannot start QR scanner."), _("The zbar package is not available."), _("On Linux, try 'sudo pip install zbar'") ])) if proc is None: device = config.get("video_device", "default") if device == 'default': device = '' _proc = zbar.Processor() _proc.init(video_device=device) # set global only if init did not raise an exception proc = _proc proc.visible = True while True: try: proc.process_one() except Exception: # User closed the preview window return "" for r in proc.results: if str(r.type) != 'QRCODE': continue # hiding the preview window stops the camera proc.visible = False return r.data
def __init__(self,source=0): # create a Processor self.proc = zbar.Processor() # configure the Processor self.proc.parse_config('enable') # initialize the Processor device = '/dev/video'+str(source) self.proc.init(device)
def startZbar(self): self.zbarProc = zbar.Processor() self.zbarProc.parse_config('enable') self.zbarProc.init('/dev/video1') self.zbarProc.set_data_handler(BarcodeScanner.barcodeFoundHandler, self) self.zbarProc.visible = False self.zbarProc.active = True
def __init__(self): self.proc = zbar.Processor() self.scanner = zbar.ImageScanner() self.scanner.parse_config('enable') self.proc.init("/dev/video0") self.proc.set_data_handler(self.qr_handler) self.proc.visible = True #display cam window if True, hide if False self.proc.active = True
def _init(self): if not zbar: return False try: proc = zbar.Processor() proc.init() except zbar.SystemError: # Cannot open video device return False return True
def on_button_scan_clicked(self, widget): ''' Do the scan, query the database and store the results. TODO: Need to find better way to enumerate cameras. TODO: Need to find how to do this on Windoze, gstreamer for both? TODO: If we already have a book display its location. ''' ## Is there a real scanner attached? if self.dev: self.real_scanner() return proc = None db_query = sql() device = None buff = self.text_view.get_buffer() buff.set_text(_("To begin press scan.")) self.text_view.set_buffer(buff) if system == "Linux": try: for i in self.getVideoDevices(): # Get the first found device. device = i[1] except: buff.set_text (_("Cannot find camera on this Operating system.")) self.text_view.set_buffer(buff) del buff,proc return ## No video device elif system == "Windows": # TODO: Windows camera stuff. pass else: # TODO: Write code for other systems. Others can do this perhaps. buff.set_text (_("Cannot find camera on this Operating system.")) self.text_view.set_buffer(buff) del buff,proc return # create a Processor proc = zbar.Processor() # configure the Processor proc.parse_config('enable') buff = self.text_view.get_buffer() # enable the preview window try: proc.init(device) except: buff.set_text (_("No camera present!")) self.text_view.set_buffer(buff) del buff,proc return proc.visible = True # Read one barcode (or until window closed) if proc.process_one(): logging.info(proc.results) for symbol in proc.results: bar = symbol.data self.add_book(proc, bar)
def func(): proc = zbar.Processor() proc.parse_config('enable') device = '/dev/video0' proc.init(device) # proc.visible = True proc.process_one() proc.visible = False for symbol in proc.results: print(symbol.data)
def zbar_decode(): proc = zbar.Processor() proc.parse_config('enable') device = '/dev/video0' # if len(argv) > 1: # device = argv[1] proc.init(device) proc.set_data_handler(my_handler) proc.visible = 0 proc.active = True try: proc.process_one() except zbar_flag: pass
def configura_scanner(): prints("configura_scanner") global scanner, isRasp, msg msg.put(["Configurando", "Camera"]) # cria um "Processor" do zbar scanner = zbar.Processor() scanner.parse_config('enable') # Processor em video'i' disp = "/dev/video1" scanner.init(disp) if isRasp: scanner.visible = False else: scanner.visible = True
def scan_qr(self): proc = zbar.Processor() proc.init() proc.visible = True while True: try: proc.process_one() except: # User closed the preview window return {} for r in proc.results: if str(r.type) != 'QRCODE': continue return r.data
def scan_qr(config): if not zbar: return device = config.get("video_device", "default") if device == 'default': device = '' proc = zbar.Processor() proc.init(video_device=device) proc.visible = True while True: try: proc.process_one() except Exception: # User closed the preview window return {} for r in proc.results: if str(r.type) != 'QRCODE': continue return r.data
def rollCall(): try: f = io.open('lista-' + str(date.today()) + '.csv', 'rt') linea = f.readline() while linea != "": num, lastname, firstname = linea.split(',') asistanceList.append((num, lastname, firstname)) linea = f.readline() except IOError: pass proc = zbar.Processor() proc.parse_config('enable') # initialize the Processor device = '/dev/video0' if len(argv) > 1: device = argv[1] proc.init(device) # setup a callback def my_handler(proc, image, closure): for symbol in image: if not symbol.count: # do something useful with results #print ('decoded', symbol.type, 'symbol', '"%s"' % symbol.data) #try: logReadedCode(symbol.data) #except ValueError: #print ("QR incorrecto") proc.set_data_handler(my_handler) # enable the preview window proc.visible = True # initiate scanning proc.active = True try: proc.user_wait() except zbar.WindowClosed: pass
def readQR(password): results = 'fail' scanner = zbar.Processor() scanner.parse_config('enable') device = '/dev/video0' if len(argv) > 1: device = argv[1] scanner.init(device, False) # scanner.visible = True scanner.active = True try: scanner.process_one(15) for symbol in scanner.results: results = symbol.data print 'resuls %s' % results if password == results: return True except (zbar.WindowClosed, zbar.SystemError) as e: pass return False return False
def read_barcode(): ''' Read barcode from sorce and return barcode data Still neds optimization. try:, ''' try: proc = zbar.Processor() proc.parse_config('enable') device = '/dev/video0' if len(argv) > 1: device = argv[1] proc.init(device) proc.visible = True proc.process_one() proc.visible = False except: print "reading barcode:" + bcolors.F + " FAIL " + bcolors.E return False #returns False, that means error for symbol in proc.results: print 'decoded', symbol.type, 'symbol', '"%s"' % symbol.data #just for debuging return symbol.data
def init_zbar(data_handle, device=r'/dev/video0', show_preview=False): # create a Processor proc = zbar.Processor() # configure the Processor proc.parse_config('enable') # configure the prescale proc.set_prescale(210, 210) # initialize the Processor, with no display proc.init(device, show_preview) # setup a callback proc.set_data_handler(data_handle) # disable the preview window proc.visible = show_preview return proc
def __init__(self, device='/dev/video0'): # create a Processor self.proc = zbar.Processor() self.data = '' self.device = device self.scanner = zbar.Scanner() # configure the Processor self.proc.parse_config('enable') # initialize the Processor if len(argv) > 1: self.device = argv[1] self.proc.init(self.device) self.proc.set_data_handler(self.my_handler) # enable the preview window self.proc.visible = True # initiate scanning self.proc.active = True
def qr_code(): #sys.stdout = open ("data.txt", "a") # create a Processor proc = zbar.Processor() # configure the Processor proc.parse_config('enable') # initialize the Processor device = '/dev/video0' if len(argv) > 1: device = argv[1] proc.init(device) # enable the preview window proc.visible = True # read at least one barcode (or until window closed) proc.process_one() # hide the preview window proc.visible = False # extract results for symbol in proc.results: # do something useful with results # print 'decoded', symbol.type, 'symbol', '"%s"' % symbol.data # print ('%s' % symbol.data) #mylcd.lcd_display_string("%s %%" % symbol.data) data = symbol.data if data is not None: return data else: print('QRcode não existe')
def leer_qr_desde_video(callback=lambda s: None, device='/dev/video0'): # create a Processor proc = zbar.Processor() # configure the Processor proc.parse_config('enable') # initialize the Processor proc.init(device) # setup a callback def my_handler(proc, image, closure): # extract results for symbol in image: if not symbol.count: callback(symbol.data) proc.set_data_handler(my_handler) # enable the preview window proc.visible = True # initiate scanning proc.active = True try: proc.user_wait() except zbar.WindowClosed: pass
def __init__(self, notify_window, *args, **kwargs): Thread.__init__(self, *args, **kwargs) self.proc = zbar.Processor() # self.loop = False self.notify_window = notify_window
def setUp(self): self.proc = zbar.Processor()
from sys import argv import zbar import paho.mqtt.client as mqtt import datetime import time mqtt = mqtt.Client("python_pub") mqtt.connect("192.168.1.111", 1883) ts = time.time() st = datetime.datetime.fromtimestamp(ts).strftime('%H:%M:%S') # create a Processor proc = zbar.Processor() # configure the Processor proc.parse_config('enable') # initialize the Processor device = '/dev/video0' if len(argv) > 1: device = argv[1] proc.init(device) # setup a callback #def my_handler(proc, image, closure): # extract results for symbol in proc.results: # do something useful with results print 'DATA', symbol.type, '=', '"%s"' % symbol.data, st