Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python wrapper - Multiple decode barcodes #131

Closed
as3nsi0 opened this issue Jun 18, 2020 · 18 comments
Closed

Python wrapper - Multiple decode barcodes #131

as3nsi0 opened this issue Jun 18, 2020 · 18 comments

Comments

@as3nsi0
Copy link

as3nsi0 commented Jun 18, 2020

Hi everybody,

I was testing your Python wrapper and it works very well, for this reason, I would like to ask if is there any plan to add in the future the possibility to read multiple barcodes from the same image?

maxresdefault

For example here, in this picture, I would like to obtain both readings but I only received one.

If I test the same in the original ZXing it works well and returns the two barcodes.

Thanks in advance for your help.

Cheers,

Víctor

@axxel
Copy link
Collaborator

axxel commented Jun 18, 2020

This is related to #105. And as in that case, the best approach depends on your application. Allow me to ask 3 questions:

  1. There are 3 different "MultipleBarcodeReader" implementations incorporating different strategies. I assume you tested the GenericMultipleBarcodeReader?

  2. Are you generally only interested in 1D barcodes?

  3. Is your input always as 'clean' as in this example, meaning the codes are laid out nicely aligned in a grid pattern?

@as3nsi0
Copy link
Author

as3nsi0 commented Jun 19, 2020

Hi axxel,

Thank you very much for your quick answer.

Regarding the questions you asked me:

  1. Honestly, I've tested only the following application 'https://zxing.org/w/decode.jspx' from the original ZXing code. I don't really know if here they are using GenericMultipleBarcodeReader or another one.

  2. I want to detect all kinds of barcodes (1D and 2D).

  3. Not, in fact, this is an example I found on Google images. My examples are more in the wild, like for example in a shop or it can be in a factory.

I want to clarify that as I put on the topic I am using right now the Python wrapper so, after install it I use:

import zxing
zxing.decode(img)

Additionally, I want to say that I saw the #105 issue but the idea is a bit different, because as I understood they want to read a grid of barcodes in "always" the same position more or less. As I said in my case the barcodes can be in any part of the image and the background is not white.

Thank you very much.

Cheers,

Víctor

@axxel
Copy link
Collaborator

axxel commented Jun 19, 2020

Now I have more questions: :)

  1. Could you provide a real-world and realistic example of the 'worst case' kind of image you'd like to process?

  2. Are you sure you'll need to detect a mix of 1D and 2D codes in one image?

Note: the example python you showed, uses the original interface. That has been deprecated recently and made more consistent with the rest of the pubic API. If possible, please use the latest code directly from github.

@as3nsi0
Copy link
Author

as3nsi0 commented Jun 19, 2020

As you said, you are right. I was on the v1.0.8 instead of master. I have just updated to the last code of master and I reinstalled it.
Instead of decode function, right now I can use read_barcode function.

Regarding your questions:

  1. Maybe it is not the worst-case scenario that I can have, but right now I only have this example:
    example1

  2. I can find any type of barcode and any combination of them. And this can be a possibility, to find 1D and 2D barcodes in the same image. For sure, it won't be something habitual but it is a possibility that I contemplate.

Thank you very much for your answer.

Cheers,

Víctor

@axxel
Copy link
Collaborator

axxel commented Jun 19, 2020

ad 1: If your codes are far enough apart from one another (like in your example) then the approach implemented in GenericMultipleBarcodeReader.java should work well. Maybe you can try to port that code over to c++ and we can see how to integrate it? Alternatively, you should be able to implement that in python on top of the currently available API.

ad 2: The thing is, if the codes start to come close to each other and then possibly also be rotated arbitrarily, then the above approach will fail. And making that work then will need more knowledge about the type of codes you can simultaneously encounter and be more work to implement.

axxel added a commit that referenced this issue Jul 20, 2021
This can be considered a fix for #131 as it provides a solution and works
for both presented examples.
@axxel
Copy link
Collaborator

axxel commented Jul 20, 2021

Here is a demo_reader.py showing of the currently working code to decode the two samples provided above:

import sys, zxingcpp
from PIL import Image

img = Image.open(sys.argv[1])
results = zxingcpp.read_barcodes(img, zxingcpp.BarcodeFormat.OneDCodes)
if len(results) > 0:
        for result in results:
                print("Found barcode:\n Text:    '{}'\n Format:   {}\n Position: {}"
                        .format(result.text, result.format, result.position))
else:
        print("Could not find any barcode")

Feedback would be welcome (also from @antoinehumbert @TransparentLC @urishab?). Note that the 'backend' currently does not support multiple 2D symbols of the same format, yet.

@as3nsi0
Copy link
Author

as3nsi0 commented Jul 22, 2021

Hi axxel,

Thank you very much to inform us and show us this example.

Cheers,

Víctor

@as3nsi0
Copy link
Author

as3nsi0 commented Jul 22, 2021

Hi again axxel,

I am trying to run the code that you provided here but the library does not have this read_barcodes function. I installed the last version of master.

The error that appears is:
AttributeError: module 'zxingcpp' has no attribute 'read_barcodes'

I have version 1.2.0 installed and I made the python setup.py install inside the repository.

Could you please give me some feedback related to this?

Thank you again.

Cheers,

Víctor

@axxel
Copy link
Collaborator

axxel commented Jul 22, 2021

@as3nsi0 The 1.2.0 release does not have this function, yet. You need to checkout HEAD (the latest).
EDIT: to make sure you test the right version, please uninstall 1.2.0 first...

@as3nsi0
Copy link
Author

as3nsi0 commented Jul 22, 2021

Yes, axxel you were right, I think that the problem was that I had not uninstalled the package.

I uninstalled the package, pull master (just in case), and installed it again. Now it works without any problem.

I guess that the thread can be closed.

Thank you again axxel.

Cheers,

@pearlmary
Copy link

In the new python wrapper release zxing-cpp 1.4.0, still we could not detect multiple datamatrix codes and also unable to detect single datamatrix codes also

@pearlmary
Copy link

Any workarounds to make it happen for datamatrix detection like QR detection which works perfectly fine

@axxel
Copy link
Collaborator

axxel commented Sep 21, 2022

You have to build the wrapper yourself with c++20 support enabled. Replace the "17" with "20" in the line set(CMAKE_CXX_STANDARD 17) in both the top-level CMakeLists.txt as well as the wrappers/python/CMakeLists.txt. That should do the trick.

@pearlmary
Copy link

Atleast I have noticed multiple times, it fails to detect even single datamatrix images. Why does it happen?

@axxel
Copy link
Collaborator

axxel commented Sep 21, 2022

Without the c++20 support it currently only detects symbols that intersect with the horizontal center-line (or if tryRotate is enabled also the vertical center-line). You can change that even with only c++17 available as described in this comment.

@pearlmary
Copy link

I saw that comment. Is there any way to set tryHarder = True as an argument in the python wrapper release zxing-cpp 1.4.0 or any other versions

@axxel
Copy link
Collaborator

axxel commented Sep 21, 2022

Is there any way to set tryHarder = True as an argument in the python wrapper release zxing-cpp 1.4.0 or any other versions

No there is not. You have to build the wrapper yourself.

@pearlmary
Copy link

okay. Thank you so much for the quick reply

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants