jonasfj / zbar-sharp

.Net/Mono bindings for zbar
http://jonasfj.github.io/zbar-sharp/
GNU Lesser General Public License v2.1
41 stars 25 forks source link

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

Open yamazaki-summit opened 6 years ago

yamazaki-summit commented 6 years ago

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 commented 6 years ago

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 commented 6 years ago

@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 commented 6 years ago

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

blauertee commented 4 months ago

Seems to be fixed in this fork which is also available as a NuGet called zbar-cli-all

jonasfj commented 4 months ago

Honestly, I haven't done C# in years.

So if there is a few people that want to maintain a fork, perhaps it's better to contribute to the fork.

It's a little unwise to have me merge PRs for a thing I'm not using, and haven't touched in close to a decade.