def test_one_qr_code(self): raw, (width, height) = self.get_image('one_qr_code') code = zbarlight.qr_code_scanner(raw, width, height) self.assertEqual(code, b"zbarlight test qr code")
def scan(self): """ Looks through camera once; if there's a QR code, returns it. Otherwise, returns -1. """ stream = io.BytesIO() self.cam.capture(stream, format="jpeg", use_video_port=True) stream.seek(0) img = Image.open(stream) img.load() grayscale_img = img.convert('L') img.close() raw = grayscale_img.tobytes() width, height = grayscale_img.size scan_results = zbarlight.qr_code_scanner(raw, width, height) try: code = scan_results.decode() print("QR: ", code) # print "Truncating now" stream.truncate(0) return code except: print("QR: N/A") stream.truncate(0) # print "truncating" return -1
def qrCheck(arg): """ Check an image for a QR code, return as string """ image_string = arg.tostring() try: code = zbarlight.qr_code_scanner(image_string, 400, 300) return code except: return
def decodeImage(self, image): """ Check an image for a QR code, return as string """ image_string = image.tostring() try: code = zbarlight.qr_code_scanner(image_string, self.camera.resolution[0], self.camera.resolution[1]) return code except: return
def qr_decode(img): file_path = img with open(file_path, 'rb') as image_file: image = Image.open(image_file) image.load() converted_image = image.convert( 'L') # Convert image to gray scale (8 bits per pixel). image.close() raw = converted_image.tobytes() # Get image data. width, height = converted_image.size # Get image size. code = zbarlight.qr_code_scanner(raw, width, height) return img + ' QR code: %s' % code.decode()
def ocr_qrcode_zbarlight(filename): img = Image.open(filename) width, height = img.size raw = img.tobytes() #把图像装换成数据 data = zbarlight.qr_code_scanner(raw, width, height) if data: logger.debug(u'识别二维码:%s,内容: %s' % (filename, data)) else: logger.error(u'识别zbarlight二维码出错:%s' % (filename)) img.save('%s-zbar.jpg' % filename) return data
def read_qrcode(pic_name): with open(pic_name, 'rb') as image_file: image = Image.open(image_file) image.load() converted_image = image.convert('L') # Convert image to gray scale (8 bits per pixel). image.close() raw = converted_image.tobytes() # Get image data. width, height = converted_image.size # Get image size. code = zbarlight.qr_code_scanner(raw, width, height) print code if code != None: pic_id = get_pic_id(code) return pic_id # way_2 : chose the number and ab else: print '[No Need to Rename] pic_name: ' + pic_name return ''
def read_qrcode(pic_name): with open(pic_name, 'rb') as image_file: image = Image.open(image_file) image.load() converted_image = image.convert( 'L') # Convert image to gray scale (8 bits per pixel). image.close() raw = converted_image.tobytes() # Get image data. width, height = converted_image.size # Get image size. code = zbarlight.qr_code_scanner(raw, width, height) print code if code != None: pic_id = get_pic_id(code) return pic_id # way_2 : chose the number and ab else: print '[No Need to Rename] pic_name: ' + pic_name return ''
import fastzbarlight import numpy as np import zbarlight img = np.load('trial.npy') import timeit num = 1000 duration = timeit.timeit( lambda: zbarlight.qr_code_scanner(img.tobytes(), 100, 100), number=num) print('Average call time with zbarlight: %sms (%d tries)' % (duration / num * 1000, num)) duration = timeit.timeit( lambda: fastzbarlight.qr_code_scanner(img.tobytes(), 100, 100), number=num) print('Average call time with fastzbarlight: %sms (%d tries)' % (duration / num * 1000, num)) # from PIL import Image # img = Image.fromarray(img.reshape((100, 100))) # img.save('trial.png') # duration = timeit.timeit(lambda: zbarlight.scan_codes('qrcode', img), number=num) # print('Average call time with image 2.0: %sms' % (duration/num*1000))
height = 480 cap.set(cv2.cv.CV_CAP_PROP_FRAME_WIDTH, width) cap.set(cv2.cv.CV_CAP_PROP_FRAME_HEIGHT, height) # quick+dirty function to get an image from the camera def getImage(): retval, image = cap.read() return image # get the image from the camera, write it to a file image = getImage() cv2.imwrite('test_py.jpg', image) # load the image file, convert to grayscale frame = cv2.imread('test_py.jpg', cv2.cv.CV_LOAD_IMAGE_GRAYSCALE) # convert the image file to string so zbarlight can read it image_string = frame.tostring() # scan the image code = zbarlight.qr_code_scanner(image_string, width, height) # if there's a single qr code in the frame, its value is set # if not, an exception is thrown try: value = code.decode() except: value = "No code or multiple codes detected" print value
def test_two_qr_code(self): raw, (width, height) = self.get_image('two_qr_codes') self.assertIsNone(zbarlight.qr_code_scanner(raw, width, height))
#from PIL import Image #import zbarlight #file_path = 'i:/jpcxxoo.png' #with open(file_path, 'rb') as image_file: # image = Image.open(image_file) # image.load() #codes = zbarlight.scan_codes('qrcode', image) #print('QR codes: %s' % codes) from PIL import Image import zbarlight file_path = 'i:/jpcxxoo.png' with open(file_path, 'rb') as image_file: image = Image.open(image_file) image.load() converted_image = image.convert( 'L') # Convert image to gray scale (8 bits per pixel). image.close() raw = converted_image.tobytes() # Get image data. print(raw) width, height = converted_image.size # Get image size. code = zbarlight.qr_code_scanner(raw, width, height) print('QR code: %s' % code.decode())