Skip to content

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

@yamazaki-summit

Description

@yamazaki-summit

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)?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions