GithubHelp home page GithubHelp logo

chenjiexu / pyzxing Goto Github PK

View Code? Open in Web Editor NEW
144.0 5.0 22.0 593 KB

Python wrapper of ZXing Java library, making qrcode decoding super easy!

License: MIT License

Python 100.00%
zxing barcode python-wrapper qrcode python

pyzxing's Introduction

pyzxing

English | 简体中文

GitHub release (latest by date including pre-releases) PyPI Conda-forge Conda

Travis (.org) Codacy grade

First GA

After a year of development, the first General Availability of pyzxing is finally released. I would like to express my gratitude to all the developers for their suggestions and issue, which helped the development of this project to a great extent. This project will continue to be open source and updated regularly.

Introduction

A Python wrapper of ZXing library. python-zxing does not work properly and is out of maintenance. So I decide to create this repository so that Pythoneers can take advantage of ZXing library with minimum effort.

Features

  • Super easy to get hands on decoding qrcode with Python
  • Structured outputs
  • Scan multiple barcodes in one picture
  • Scan multiple pictures in parallel, which speeds up 77%

Installation

Installing from Github source is recommended :

git clone https://github.com/ChenjieXu/pyzxing.git
cd pyzxing
python setup.py install

It is also possible to install from PyPI:

pip install pyzxing

Install from Anaconda. Now available on the public channel, conda-forge:

conda install pyzxing # conda-forge channel
conda install -c chenjiexu pyzxing # private channel

Build ZXing Library

A ready-to-go jar file is available with release, but I can not guarantee that this file will work properly on your PC. You may run test script before building ZXing. Pyzxing will download compiled Jar file automatically and call unit test. For those who haven't installed Java, I strongly recommend you to install openjdk8.

python -m unittest tests.test_decode

If failed, build ZXing using following commands.

git submodule init
git submodule update
cd zxing
mvn install -DskipTests
cd javase
mvn -DskipTests package assembly:single

Quick Start

from pyzxing import BarCodeReader

reader = BarCodeReader()
results = reader.decode('/PATH/TO/FILE')
# Or file pattern for multiple files
results = reader.decode('/PATH/TO/FILES/*.png')
print(results)
# Or a numpy array
# Requires additional installation of opencv
# pip install opencv-python
results = reader.decode_array(img)

Or you may simply call it from command line

python scripts/scanner.py -f /PATH/TO/FILE

TODO

  • Fix setup.py

  • Add multi and pure_barcode into parameters to resolve #25

  • Change Travis CI to GitHub Action

Sponsor

Logo
Open Source Support Program

pyzxing's People

Contributors

chenjiexu avatar komugisama avatar xiyaowong avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

pyzxing's Issues

Error in Python 3.9

I'm getting an error when running the scanner.py script on the back of my ID card. Here's the traceback:

python scanner.py -f dl_back.jpg 
Use local jar file.
Traceback (most recent call last):
  File "/Users/vlsd/projects/my_project/scanner.py", line 27, in <module>
    main(args)
  File "/Users/vlsd/projects/my_project/scanner.py", line 13, in main
    results = reader.decode(args.file)
  File "/Users/vlsd/projects/my_project/.venv/lib/python3.9/site-packages/pyzxing/reader.py", line 45, in decode
    results = self._decode(filenames[0].replace('\\', '/'))
  File "/Users/vlsd/projects/my_project/.venv/lib/python3.9/site-packages/pyzxing/reader.py", line 61, in _decode
    result = [self._parse_single(
  File "/Users/vlsd/projects/my_project/.venv/lib/python3.9/site-packages/pyzxing/reader.py", line 61, in <listcomp>
    result = [self._parse_single(
  File "/Users/vlsd/projects/my_project/.venv/lib/python3.9/site-packages/pyzxing/reader.py", line 90, in _parse_single
    result['points'] = [ast.literal_eval(
  File "/Users/vlsd/projects/my_project/.venv/lib/python3.9/site-packages/pyzxing/reader.py", line 90, in <listcomp>
    result['points'] = [ast.literal_eval(
  File "/Users/vlsd/.pyenv/versions/3.9.0/lib/python3.9/ast.py", line 105, in literal_eval
    return _convert(node_or_string)
  File "/Users/vlsd/.pyenv/versions/3.9.0/lib/python3.9/ast.py", line 104, in _convert
    return _convert_signed_num(node)
  File "/Users/vlsd/.pyenv/versions/3.9.0/lib/python3.9/ast.py", line 78, in _convert_signed_num
    return _convert_num(node)
  File "/Users/vlsd/.pyenv/versions/3.9.0/lib/python3.9/ast.py", line 69, in _convert_num
    _raise_malformed_node(node)
  File "/Users/vlsd/.pyenv/versions/3.9.0/lib/python3.9/ast.py", line 66, in _raise_malformed_node
    raise ValueError(f'malformed node or string: {node!r}')
ValueError: malformed node or string: <ast.Name object at 0x109b54a00>

I wonder if Python 3.9 introduced some breaking changes to how ast behaves?

reader.decode fails for a certain QR code

For this spicific QR_CODE reader.decode() fails with error :

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/arion/.local/lib/python3.8/site-packages/pyzxing/reader.py", line 45, in decode
    results = self._decode(filenames[0].replace('\\', '/'))
  File "/home/arion/.local/lib/python3.8/site-packages/pyzxing/reader.py", line 61, in _decode
    result = [self._parse_single(
  File "/home/arion/.local/lib/python3.8/site-packages/pyzxing/reader.py", line 61, in <listcomp>
    result = [self._parse_single(
  File "/home/arion/.local/lib/python3.8/site-packages/pyzxing/reader.py", line 90, in _parse_single
    result['points'] = [ast.literal_eval(
  File "/home/arion/.local/lib/python3.8/site-packages/pyzxing/reader.py", line 90, in <listcomp>
    result['points'] = [ast.literal_eval(
  File "/usr/lib/python3.8/ast.py", line 59, in literal_eval
    if isinstance(node_or_string, Expression):
  File "/usr/lib/python3.8/ast.py", line 47, in parse
    return compile(source, filename, mode, flags, _feature_version=feature_version)
  File "<unknown>", line 1
    param1):
          ^
SyntaxError: unmatched ')'

Here's my code -

>>> from pyzxing import BarCodeReader
>>> reader = BarCodeReader()
Use local jar file.
>>> reader.decode('8RXzm7LJ.png')

/* Errors */

Here's the decoded output, decoded in the xzing website -

param0 = "2XEY1jQ1gZv8f03Y8juNiXOHgXTymJtO"
param1 = "XRrI4mjQvdrfCRPsleVI2jK7ySHp1EXa"
param2 = 690
output = ""
o = False
i = 0
for c0, c1 in zip(param0, param1):
  if i % 2 == 0:
    cc = c0 + c1
    if cc.isnumeric() and o is False:
      o = True
      meh = param0 + str(param2) + param1
      for j in range(0, i * param2):
        x = 13
        if j % 2 == 0:
          x = 77
        output += meh[(j + x) % len(meh)]
        output = output[::-1]
    else:
      output += cc
      output = output[::-1]
  else:
    if ord(c0) == ord(c1):
      output += c1 + c0
    elif ord(c0) > ord(c1):
      output += c0
    else:
      output += c1
  i += 1
output = output[0:32]
print(output)

It works in the xzing website. and pyzxing works fine for the other 10 or so QR_CODEs I've tested it for.


  • Python version : 3.8.6

build失败和一个小问题,感谢

  1. 在windows上python -m unittest src.test_decode这行命令一直下不下来包Downloading data from https://github.com/ChenjieXu/pyzxing/releases/download/v0.1/javase-3.4.1-SNAPSHOT-jar-with-dependencies.jar
    EDownloading data from https://github.com/ChenjieXu/pyzxing/releases/download/v0.1/javase-3.4.1-SNAPSHOT-jar-with-dependencies.jar 在ubuntu上failed了 - ImportError: Failed to import test module: test_decode

于是我尝试第二种方式,我在pyzxing目录下执行git submodule init,git submodule update第二条命令又失败了,fatal: 无法克隆 'https://github.com/zxing/zxing' 到子模组路径 '/home/jayjia/桌面/demo/zxing/javase/python-zxing/pyzxing/zxing'
第二次尝试克隆 'zxing' 失败,退出

  1. 我想请问您的这个识别率怎么样,如果和libdmtx比呢?哪个识别的更多一些

For file format QR code.

I made a simple wrapper to handle the file format QR code:

def _decode(self, filename):
    try:
        # the origin code
        cmd = ' '.join([self.command, self.lib_path, 'file:///' + filename, '--multi'])
        (stdout, _) = subprocess.Popen(cmd,
                                        stdout=subprocess.PIPE,
                                        universal_newlines=True,
                                        shell=True).communicate()
        lines = stdout.splitlines()
        separator_idx = [
            i for i in range(len(lines)) if lines[i][:4] == 'file'
        ] + [len(lines)]

        result = [
            self._parse_single(lines[separator_idx[i]:separator_idx[i + 1]])
            for i in range(len(separator_idx) - 1)
        ]
    except:
        # my add-in code
        cmd = ' '.join([self.command, self.lib_path, 'file:///' + filename, '--multi'])
        (lines, _) = subprocess.Popen(cmd,
                                    stdout=subprocess.PIPE,
                                    stderr=subprocess.PIPE).communicate()
        result = lines[lines.index(b'Raw result:\n')+len(b'Raw result:\n'):lines.index(b'\nFound')]
    return result

This will return the 'Raw result' bytes while the result can't be decoded with the default character set.

性能不如微信

有的二维码微信可以识别但是用pyzxing识别不出来,这样下去什么时候能打破鹅厂的垄断,客户很不满,让我来发issue,理解一下

URI is not hierarchical

1.run in python get errot result:
Use local jar file.
'java' �����ڲ����ⲿ���Ҳ���ǿ����еij���
���������ļ���
2.use CMD:C:\Users\XXX>java -jar C:\Users\XXX\.local\javase-3.4.1-SNAPSHOT-jar-with-dependencies.jar C:\Users\XXX\.local\test\*.png:
Exception in thread "main" java.lang.IllegalArgumentException: URI is not hierarchical
at java.base/sun.nio.fs.WindowsUriSupport.fromUri(WindowsUriSupport.java:122)
at java.base/sun.nio.fs.WindowsFileSystemProvider.getPath(WindowsFileSystemProvider.java:97)
at java.base/java.nio.file.Path.of(Path.java:203)
at java.base/java.nio.file.Paths.get(Paths.java:98)
at com.google.zxing.client.j2se.CommandLineRunner.expand(CommandLineRunner.java:112)
at com.google.zxing.client.j2se.CommandLineRunner.main(CommandLineRunner.java:76)

recognition is slow on mac

thanks for your great work!
when I ran pyzxing for one image and it cost more than two seconds on mac os.
Although multiple pictures parallel computing is very fast . (55pictures / 20s)

How much time do you spend on a single picture?
Is there something wrong with my environment?

Unable to detect QR codes with particular data values

System Information

Operating System: Ubuntu 22.04
Python version: 3.10.6

.venv dump (pip freeze) - also contains other QR detection libraries which were tested:

joblib==1.2.0
numpy==1.24.3
opencv-python==4.7.0.72
py4j==0.10.9.7
PyBoof==0.41
pyzbar==0.1.9
pyzxing==1.0.2
segno==1.5.2
six==1.16.0
transforms3d==0.4.1

Detailed description

I was testing the performance of various QR code detection libraries using "perfect" version 1-H QR codes generated by segno, and I noticed that some of these codes could not be detected. In particular, the following 192 values failed to be detected when testing exhaustively in the range $[0, 10^6]$:

1982, 2189, 2429, 4041, 4135, 4598, 4608, 4705, 5468, 6310, 6466, 6620, 6904, 7418, 9983, 10279, 11066, 11561, 13451, 14861, 14940, 15105, 16171, 16697, 17199, 17237,  17367, 18125, 18249, 18251, 18331, 19198, 19295, 19485, 20451, 21842, 22820, 22975, 23030, 23110, 23389, 23502, 23577, 24380, 24403, 24537, 24836, 25114, 25393, 25481, 26545, 26668, 26783, 26872, 27075, 27649, 29342, 29744, 29759, 30473, 31283, 32182, 33687, 33982, 34427, 35288, 36713, 36731, 37872, 38155, 38630, 39141, 39892, 40506, 41855, 42022, 42536, 42918, 43036, 43452, 44255, 44300, 47121, 47681, 48830, 48942, 49808, 49992, 50922, 52182, 53588, 54099, 54441, 54635, 55294, 55540, 55802, 56831, 57003, 57950, 58161, 58240, 58815, 60599, 60826, 60915, 61078, 61569, 61612, 62202, 62457, 62710, 63392, 64002, 64632, 65289, 65742, 66070, 66175, 66495, 67268, 67345, 67861, 68142, 69169, 69772, 69991, 70558, 70585, 72597, 72769, 73250, 73726, 74664, 74729, 75836, 76625, 77483, 77574, 77762, 77906, 78091, 78339, 78350, 78626, 78678, 78889, 78922, 79267, 79726, 79889, 80122, 80483, 80615, 80680, 80886, 80930, 81243, 81315, 81862, 82485, 82509, 82600, 84801, 85762, 86122, 87319, 87729, 89386, 89478, 89996, 90458, 90709, 90938, 91397, 91541, 92479, 93120, 93287, 94030, 94865, 95290, 95342, 95377, 95700, 95815, 96620, 97158, 98549, 98665, 99579, 99794

This issue was not exclusive to pyzxing, and other tested libraries such as OpenCV and BoofCV also had issues with some payloads (although for different values), which are confirmed as a bug due to false positives in the finder pattern (which may or may not be the same issue in this case) - see lessthanoptimal/PyBoof#23. Please note that there is also an identified bug in segno in which the padding is malformed for 4-digit payloads - see heuer/segno#123, although this does not seem to affect pyzxing as I'm assuming you ignore the padding bits (which seems to be a strategy employed by many detector libraries).

Steps to reproduce

import cv2
import segno
from pyzxing import BarCodeReader

TEST_FILE = 'qr_test.png'

reader = BarCodeReader()
bad_detections = []

for i in range(0, 100000):
    qrcode = segno.make(i, version=1)
    assert qrcode.error == 'H'
    qrcode.save(TEST_FILE, scale = 5)

    img = cv2.imread(TEST_FILE)
    img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
    img = cv2.resize(img, (88, 88))

    barcodes = reader.decode_array(img)
    assert len(barcodes) == 1
    if 'raw' not in barcodes[0]:
        print(f"Unable to detect {i}")
        bad_detections.append(i)
    else:
        assert barcodes[0]['raw'].decode("utf-8") == str(i), f"Mismatch between detected value {barcodes[0]['raw'].decode("utf-8")} and input {x}"

print(f"Unable to detect the following data payloads:\n{bad_detections}")

Data matrix generator

Do you have an example of how to generate a data matrix and configure image height and width (number of pixels)?

条码识别性能问题

作者您好,我发现有些条码pyzxing无法识别,但zxing的online版本可以识别出来,不知为啥。

How to get detected codewords before error correction?

Hi,
I'm working on code-words error correction algorithm as part of my thesis. I need to show a demo but didn't find any good pure python qrcode reader and my understanding with this library is limited. I just want to quickly know how to get detected code words. Can somebody point me in this library to get detected codewords, preferably as an array, before feeding them for error correction.
Thanks!

QR Code Generation

Hello,
Thanks for your contribution, is it also possible to generate QR codes?

How to interpret points in result dictionary?

Hello i have simple but annoying question that i couldn't found answer for. I got result in a form like '{filename': ''filename.jpg, 'format': b'QR_CODE', 'type': b'URI', 'raw': b'raw_data', 'parsed': b'parsed_data', 'points': [(435.0, 378.5), (433.0, 271.0), (545.5, 267.66666), (527.25, 359.5)]}

I need to draw border around found barcode so how do i know what these numbers inside 'points' list means?

绝对路径报错

您好,我想请教使用pyzxing进行开发时遇到的问题,使用绝对路径会报错/找不到文件,使用绝对路径则能正常识别,具体情况如下:

执行python scanner.py -f D:/pyzxing/images/codabar.png报错:

        at java.net.URL.<init>(Unknown Source)
        at java.net.URL.<init>(Unknown Source)
        at java.net.URL.<init>(Unknown Source)
        at com.google.zxing.client.j2se.ImageReader.readImage(ImageReader.java:44)
        at com.google.zxing.client.j2se.DecodeWorker.decode(DecodeWorker.java:125)
        at com.google.zxing.client.j2se.DecodeWorker.call(DecodeWorker.java:76)

执行python scanner.py -f file:///D:/pyzxing/images/codabar.png输出:File not found!
执行python scanner.py -f images/codabar.png则能正常识别

Error when does not detect any barcode

Hello ! Thank you for your work.

I am testing your wrapper with some images and for a image with no barcode I got this error:

Traceback (most recent call last):
File "pyzxing/scanner.py", line 27, in
main(args)
File "pyzxing/scanner.py", line 16, in main
results_string = [result['parsed'] for result in results]
File "pyzxing/scanner.py", line 16, in
results_string = [result['parsed'] for result in results]
KeyError: 'parsed'

Installing pyzxing using pip raises FileNotFoundError because of missing requirements.txt

Collecting pyzxing
  Downloading pyzxing-0.3.1.tar.gz (6.7 kB)

DEPRECATION: The -b/--build/--build-dir/--build-directory option is deprecated. pip 20.3 will remove support for this functionality. A possible replacement is use the TMPDIR/TEMP/TMP environment variable, possibly combined with --no-clean. You can find discussion regarding this at https://github.com/pypa/pip/issues/8333.
    ERROR: Command errored out with exit status 1:
     command: /home/dinko/Projects/python-exercises/venv/bin/python -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pycharm-packaging/pyzxing/setup.py'"'"'; __file__='"'"'/tmp/pycharm-packaging/pyzxing/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base /tmp/pip-pip-egg-info-g_75g7jf
         cwd: /tmp/pycharm-packaging/pyzxing/
    Complete output (5 lines):
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/tmp/pycharm-packaging/pyzxing/setup.py", line 5, in <module>
        with open('requirements.txt') as f:
    FileNotFoundError: [Errno 2] No such file or directory: 'requirements.txt'
    ----------------------------------------
ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.

Can't install using pip because requirements.txt is not included in source.

Is there a way to get the result points at the moment?

I'm not sure if I'm worng, but is there a reason why i can´t get the resultpoints at the moment? Because it
looks like result['points'] = [ast.literal_eval(line[12:]) for line in lines[points_index+1:-1]] it is not working

安装成功但测试运行失败

``你好,我在按README.md安装pyzxing的时候遇到了一些问题。
首先是运行测试脚本
python -m unittest tests.test_decode
得到了如下结果: FAILED (failures=2, errors=6)

Exception in thread "main" java.lang.IllegalArgumentException: Bad escape
	at sun.nio.fs.UnixUriUtils.fromUri(UnixUriUtils.java:87)
	at sun.nio.fs.UnixFileSystemProvider.getPath(UnixFileSystemProvider.java:98)
	at java.nio.file.Paths.get(Paths.java:138)
	at com.google.zxing.client.j2se.CommandLineRunner.expand(CommandLineRunner.java:112)
	at com.google.zxing.client.j2se.CommandLineRunner.main(CommandLineRunner.java:76)
EException in thread "main" java.lang.IllegalArgumentException: Bad escape
	at sun.nio.fs.UnixUriUtils.fromUri(UnixUriUtils.java:87)
	at sun.nio.fs.UnixFileSystemProvider.getPath(UnixFileSystemProvider.java:98)
	at java.nio.file.Paths.get(Paths.java:138)
	at com.google.zxing.client.j2se.CommandLineRunner.expand(CommandLineRunner.java:112)
	at com.google.zxing.client.j2se.CommandLineRunner.main(CommandLineRunner.java:76)
EException in thread "main" java.lang.IllegalArgumentException: Bad escape
	at sun.nio.fs.UnixUriUtils.fromUri(UnixUriUtils.java:87)
	at sun.nio.fs.UnixFileSystemProvider.getPath(UnixFileSystemProvider.java:98)
	at java.nio.file.Paths.get(Paths.java:138)
	at com.google.zxing.client.j2se.CommandLineRunner.expand(CommandLineRunner.java:112)
	at com.google.zxing.client.j2se.CommandLineRunner.main(CommandLineRunner.java:76)
EException in thread "main" java.lang.IllegalArgumentException: Bad escape
	at sun.nio.fs.UnixUriUtils.fromUri(UnixUriUtils.java:87)
	at sun.nio.fs.UnixFileSystemProvider.getPath(UnixFileSystemProvider.java:98)
	at java.nio.file.Paths.get(Paths.java:138)
	at com.google.zxing.client.j2se.CommandLineRunner.expand(CommandLineRunner.java:112)
	at com.google.zxing.client.j2se.CommandLineRunner.main(CommandLineRunner.java:76)
FException in thread "main" java.lang.IllegalArgumentException: Bad escape
	at sun.nio.fs.UnixUriUtils.fromUri(UnixUriUtils.java:87)
	at sun.nio.fs.UnixFileSystemProvider.getPath(UnixFileSystemProvider.java:98)
	at java.nio.file.Paths.get(Paths.java:138)
	at com.google.zxing.client.j2se.CommandLineRunner.expand(CommandLineRunner.java:112)
	at com.google.zxing.client.j2se.CommandLineRunner.main(CommandLineRunner.java:76)
Exception in thread "main" java.lang.IllegalArgumentException: Bad escape
	at sun.nio.fs.UnixUriUtils.fromUri(UnixUriUtils.java:87)
	at sun.nio.fs.UnixFileSystemProvider.getPath(UnixFileSystemProvider.java:98)
	at java.nio.file.Paths.get(Paths.java:138)
	at com.google.zxing.client.j2se.CommandLineRunner.expand(CommandLineRunner.java:112)
	at com.google.zxing.client.j2se.CommandLineRunner.main(CommandLineRunner.java:76)
Exception in thread "main" java.lang.IllegalArgumentException: Bad escape
	at sun.nio.fs.UnixUriUtils.fromUri(UnixUriUtils.java:87)
	at sun.nio.fs.UnixFileSystemProvider.getPath(UnixFileSystemProvider.java:98)
	at java.nio.file.Paths.get(Paths.java:138)
	at com.google.zxing.client.j2se.CommandLineRunner.expand(CommandLineRunner.java:112)
	at com.google.zxing.client.j2se.CommandLineRunner.main(CommandLineRunner.java:76)
Exception in thread "main" java.lang.IllegalArgumentException: Bad escape
	at sun.nio.fs.UnixUriUtils.fromUri(UnixUriUtils.java:87)
	at sun.nio.fs.UnixFileSystemProvider.getPath(UnixFileSystemProvider.java:98)
	at java.nio.file.Paths.get(Paths.java:138)
	at com.google.zxing.client.j2se.CommandLineRunner.expand(CommandLineRunner.java:112)
	at com.google.zxing.client.j2se.CommandLineRunner.main(CommandLineRunner.java:76)
Exception in thread "main" java.lang.IllegalArgumentException: Bad escape
	at sun.nio.fs.UnixUriUtils.fromUri(UnixUriUtils.java:87)
	at sun.nio.fs.UnixFileSystemProvider.getPath(UnixFileSystemProvider.java:98)
	at java.nio.file.Paths.get(Paths.java:138)
	at com.google.zxing.client.j2se.CommandLineRunner.expand(CommandLineRunner.java:112)
	at com.google.zxing.client.j2se.CommandLineRunner.main(CommandLineRunner.java:76)
Exception in thread "main" java.lang.IllegalArgumentException: Bad escape
	at sun.nio.fs.UnixUriUtils.fromUri(UnixUriUtils.java:87)
	at sun.nio.fs.UnixFileSystemProvider.getPath(UnixFileSystemProvider.java:98)
	at java.nio.file.Paths.get(Paths.java:138)
	at com.google.zxing.client.j2se.CommandLineRunner.expand(CommandLineRunner.java:112)
	at com.google.zxing.client.j2se.CommandLineRunner.main(CommandLineRunner.java:76)
FException in thread "main" java.lang.IllegalArgumentException: Bad escape
	at sun.nio.fs.UnixUriUtils.fromUri(UnixUriUtils.java:87)
	at sun.nio.fs.UnixFileSystemProvider.getPath(UnixFileSystemProvider.java:98)
	at java.nio.file.Paths.get(Paths.java:138)
	at com.google.zxing.client.j2se.CommandLineRunner.expand(CommandLineRunner.java:112)
	at com.google.zxing.client.j2se.CommandLineRunner.main(CommandLineRunner.java:76)
E.Exception in thread "main" java.lang.IllegalArgumentException: Bad escape
	at sun.nio.fs.UnixUriUtils.fromUri(UnixUriUtils.java:87)
	at sun.nio.fs.UnixFileSystemProvider.getPath(UnixFileSystemProvider.java:98)
	at java.nio.file.Paths.get(Paths.java:138)
	at com.google.zxing.client.j2se.CommandLineRunner.expand(CommandLineRunner.java:112)
	at com.google.zxing.client.j2se.CommandLineRunner.main(CommandLineRunner.java:76)
EException in thread "main" java.lang.IllegalArgumentException: Bad escape
	at sun.nio.fs.UnixUriUtils.fromUri(UnixUriUtils.java:87)
	at sun.nio.fs.UnixFileSystemProvider.getPath(UnixFileSystemProvider.java:98)
	at java.nio.file.Paths.get(Paths.java:138)
	at com.google.zxing.client.j2se.CommandLineRunner.expand(CommandLineRunner.java:112)
	at com.google.zxing.client.j2se.CommandLineRunner.main(CommandLineRunner.java:76)
E
======================================================================
ERROR: test_codabar (tests.test_decode.TestBarCodeReaderDecode)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/media/lappy/文档/cv-practice/ZXing/pyzxing/tests/test_decode.py", line 16, in test_codabar
    self.assertEqual(result[0]['parsed'], gt)
IndexError: list index out of range

======================================================================
ERROR: test_code128 (tests.test_decode.TestBarCodeReaderDecode)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/media/lappy/文档/cv-practice/ZXing/pyzxing/tests/test_decode.py", line 30, in test_code128
    self.assertEqual(result[0]['parsed'], gt)
IndexError: list index out of range

======================================================================
ERROR: test_code39 (tests.test_decode.TestBarCodeReaderDecode)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/media/lappy/文档/cv-practice/ZXing/pyzxing/tests/test_decode.py", line 23, in test_code39
    self.assertEqual(result[0]['parsed'], gt)
IndexError: list index out of range

======================================================================
ERROR: test_nobarcodefile (tests.test_decode.TestBarCodeReaderDecode)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/media/lappy/文档/cv-practice/ZXing/pyzxing/tests/test_decode.py", line 59, in test_nobarcodefile
    self.assertEqual(result[0].get('parsed', None), None)
IndexError: list index out of range

======================================================================
ERROR: test_pdf417 (tests.test_decode.TestBarCodeReaderDecode)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/media/lappy/文档/cv-practice/ZXing/pyzxing/tests/test_decode.py", line 37, in test_pdf417
    self.assertEqual(result[0]['parsed'], gt)
IndexError: list index out of range

======================================================================
ERROR: test_qrcode (tests.test_decode.TestBarCodeReaderDecode)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/media/lappy/文档/cv-practice/ZXing/pyzxing/tests/test_decode.py", line 44, in test_qrcode
    self.assertEqual(result[0]['parsed'], gt)
IndexError: list index out of range

======================================================================
FAIL: test_multibarcodes (tests.test_decode.TestBarCodeReaderDecode)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/media/lappy/文档/cv-practice/ZXing/pyzxing/tests/test_decode.py", line 69, in test_multibarcodes
    self.assertEqual(set(result_string), set(gt))
AssertionError: Items in the second set but not the first:
b'201541368446'
b'201541371885'
b'201541332863'
b'201541332768'
b'201541395223'
b'201541350294'
b'201541393029'

======================================================================
FAIL: test_multifiles (tests.test_decode.TestBarCodeReaderDecode)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/media/lappy/文档/cv-practice/ZXing/pyzxing/tests/test_decode.py", line 86, in test_multifiles
    self.assertEqual(set(results_string), set(gt))
AssertionError: Items in the second set but not the first:
b'31117013206375'
b'[)>\x1e01\x1d96123450000\x1d222\x1d111\x1dMODE2'
b'-ActiveBarcode-ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890-ActiveBarcode-ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890-ActiveBarcode-ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890-ActiveBarcode-ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890-ActiveBarcode-ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890-ActiveBarcode-ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890'
b'When we at WRT talk about \\"text,\\" we are generally talking about a particular kind of readable information encoding - and readable is a complex proposition. Text may be stylized in a way we are unfamiliar with, as in blackletter - it may be interspersed with some markup we don\\\'t understand, such as HTML - it may be be a substitution system we aren\\\'t familiar with, such as braille or morse code - or it may be a system that, while technically human-readable, isn\\\'t particularly optimized for reading by humans, as with barcodes (although barcodes can be read).'
b'TEST-SHEET'
b'8101054321120021123456'

----------------------------------------------------------------------
Ran 9 tests in 5.651s

FAILED (failures=2, errors=6)

之后我运行了如下指令


git submodule init
git submodule update
cd zxing
mvn install -DskipTests

得到输出


……

[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary for ZXing 3.4.1-SNAPSHOT:
[INFO] 
[INFO] ZXing .............................................. SUCCESS [ 21.216 s]
[INFO] ZXing Core ......................................... SUCCESS [ 43.372 s]
[INFO] ZXing Java SE extensions ........................... FAILURE [  4.195 s]
[INFO] ZXing zxing.org web app ............................ SKIPPED
[INFO] ZXing Appspot-based encoder ........................ SKIPPED
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  01:09 min
[INFO] Finished at: 2022-03-02T16:20:19+08:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.rat:apache-rat-plugin:0.13:check (default) on project javase: Too many files with unapproved license: 1 See RAT report in: /media/lappy/文档/cv-practice/ZXing/pyzxing/zxing/javase/target/rat.txt -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException
[ERROR] 
[ERROR] After correcting the problems, you can resume the build with the command
[ERROR]   mvn <args> -rf :javase


再接着运行


cd javase
mvn -DskipTests package assembly:single

得到输出

……

[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  6.526 s
[INFO] Finished at: 2022-03-02T16:21:33+08:00
[INFO] ------------------------------------------------------------------------

运行示例代码,报错


Exception in thread "main" java.lang.IllegalArgumentException: Bad escape
	at sun.nio.fs.UnixUriUtils.fromUri(UnixUriUtils.java:87)
	at sun.nio.fs.UnixFileSystemProvider.getPath(UnixFileSystemProvider.java:98)
	at java.nio.file.Paths.get(Paths.java:138)
	at com.google.zxing.client.j2se.CommandLineRunner.expand(CommandLineRunner.java:112)
	at com.google.zxing.client.j2se.CommandLineRunner.main(CommandLineRunner.java:76)
[]


我对没有了解过Java和maven,请问我该如何解决遇到的问题?

not scanning codes properly

i have tried lib but its not scanning codes properly so is it possible to improve results. thanks

sample images
new1
P3111 00KHRTRND__20220313_14_4945_1

Decode doesn't work with spaces in the path

My code:

        codes = reader.decode(r"C:\\Users\\oscar\\Projects\\Camera Project\\captures\\barcode_Color.png")

The error message:

Exception in thread "main" java.util.concurrent.ExecutionException: javax.imageio.IIOException: Can't get input stream from URL!
        at java.util.concurrent.FutureTask.report(Unknown Source)
        at java.util.concurrent.FutureTask.get(Unknown Source)
        at com.google.zxing.client.j2se.CommandLineRunner.main(CommandLineRunner.java:96)
Caused by: javax.imageio.IIOException: Can't get input stream from URL!
        at javax.imageio.ImageIO.read(Unknown Source)
        at com.google.zxing.client.j2se.ImageReader.readImage(ImageReader.java:44)
        at com.google.zxing.client.j2se.DecodeWorker.decode(DecodeWorker.java:125)
        at com.google.zxing.client.j2se.DecodeWorker.call(DecodeWorker.java:76)
        at com.google.zxing.client.j2se.DecodeWorker.call(DecodeWorker.java:56)
        at java.util.concurrent.FutureTask.run(Unknown Source)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
        at java.lang.Thread.run(Unknown Source)
Caused by: java.io.FileNotFoundException: C:\Users\oscar\Projects\Camera (The system cannot find the file specified)
        at java.io.FileInputStream.open0(Native Method)
        at java.io.FileInputStream.open(Unknown Source)
        at java.io.FileInputStream.<init>(Unknown Source)
        at java.io.FileInputStream.<init>(Unknown Source)
        at sun.net.www.protocol.file.FileURLConnection.connect(Unknown Source)
        at sun.net.www.protocol.file.FileURLConnection.getInputStream(Unknown Source)
        at java.net.URL.openStream(Unknown Source)
        ... 9 more

Specifically this line:

Caused by: java.io.FileNotFoundException: C:\Users\oscar\Projects\Camera (The system cannot find the file specified)

批量识别速度太慢

识别一张图片要1秒,而zbar是150毫秒。我看了下代码,是不是每次识别不同的图片都要重新用java -jar运行zxing,这样每次重新加载下zxing会影响速度。是不是可以建一个zxing的进程,然后和这个进程通讯(比如用zeromq)来解码。

No barcode found

hi there, why this image detection failed? this picture is quite clear!
1152

Decode maxicode Error

Hi , I have tried pyzxing0.3.5 and it's very good! Thanks!
But it seems there are some little errors in it.
When i used [maxicode] picture for test, both of decode[array] and decode [filename], will get this error.
image

But pyzxing0.3.3 can recognize maxicode successfully! (0.3.4 also❌ )

Originally posted by @zhaozhen1002 in #17 (comment)

Thank you! It seems that points information can't be parsed successfully. I will look into it.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.