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

How to detect the 2D position of a QR code with zbar-sharp #8

Open
yamazaki-summit opened this issue Sep 6, 2018 · 3 comments
Open

Comments

@yamazaki-summit
Copy link

yamazaki-summit commented Sep 6, 2018

Now I'm trying to detect a QR code with ZBar in both python and C#.

In python, I succeeded in detecting both string data and the 2D position of the QR code in the following way.

from pyzbar.pyzbar import decode
from pyzbar.pyzbar import ZBarSymbol

def __pyzbarDetect(self, image):
    allCodes = decode(image)
    data, x, y = "", 0, 0
    for code in allCodes:
        data = code.data.decode()
        left, top, width, height = code.rect
        x = left+round(width/2)
        y = top +round(height/2)
    return data, x, y

In C#, however, I succeeded only in detecting string data, but not in detecting the 2D position. My C# code is the following.

using ZBar;

private static string zbarDetect(Mat image)
{
    using (var scanner = new ImageScanner { Cache = false })
    {
        var scanned = scanner.Scan(image.ToBitmap());
        var symbol = scanned.LastOrDefault();
        var data = symbol?.Data ?? string.Empty;
        return data;
    }  
}

Is is possible to detect the 2D position of the QR code with C# (zbar-sharp) in a similar way to python (or in a totally different way)?

@the-vindicar
Copy link

I have this problem too. @yamazaki-summit have you been able to solve it? Or did you have to write your own wrapper instead of zbar-sharp?

@yamazaki-summit
Copy link
Author

@the-vindicar Thank you for your comment. I wrote my own wrapper methods to detect the 2D position by using original zlib methods as extern. In other aspects such as decoding of the string data, I used zbar-sharp methods as shown above.

@the-vindicar
Copy link

I did that too. Also, I sent a pull request - hopefully, @jonasfj will accept it.

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

2 participants