def test_write_read_cycle_pil(self): from PIL import Image format = BF.QRCode text = "I have the best words." img = zxingcpp.write_barcode(format, text) img = Image.fromarray(img, "L") self.check_res(zxingcpp.read_barcode(img), format, text) self.check_res(zxingcpp.read_barcode(img.convert("RGB")), format, text) self.check_res(zxingcpp.read_barcode(img.convert("RGBA")), format, text) self.check_res(zxingcpp.read_barcode(img.convert("1")), format, text) self.check_res(zxingcpp.read_barcode(img.convert("CMYK")), format, text)
def test_write_read_cycle(self): format = BF.QRCode text = "I have the best words." img = zxingcpp.write_barcode(format, text) res = zxingcpp.read_barcode(img) self.check_res(res, format, text) self.assertEqual(res.symbology_identifier, "]Q1") self.assertEqual(res.position.top_left.x, 4) res = zxingcpp.read_barcode(img, formats=format) self.check_res(res, format, text)
def test_failed_read(self): import numpy as np res = zxingcpp.read_barcode( np.zeros((100, 100), np.uint8), formats=BF.EAN8 | BF.Aztec, binarizer=zxingcpp.Binarizer.BoolCast ) self.assertEqual(res, None)
def test_failed_read(self): import numpy as np res = zxingcpp.read_barcode(np.zeros((100, 100), np.uint8), formats=BF.EAN8 | BF.Aztec, binarizer=zxingcpp.Binarizer.BoolCast) self.assertFalse(res.valid) self.assertEqual(res.format, BF.NONE) self.assertEqual(res.text, '')
def test_write_read_oned_cycle(self): format = BF.Code128 text = "I have the best words." height = 80 width = 400 img = zxingcpp.write_barcode(format, text, width=width, height=height) self.assertEqual(img.shape[0], height) self.assertEqual(img.shape[1], width) res = zxingcpp.read_barcode(img) self.check_res(res, format, text) self.assertEqual(res.position.top_left.x, 61)
import sys, zxingcpp from PIL import Image img = Image.open(sys.argv[1]) result = zxingcpp.read_barcode(img) if result.valid: print( "Found barcode:\n Text: '{}'\n Format: {}\n Position: {}".format( result.text, result.format, result.position)) else: print("Could not read barcode")