makiuchi-d / gozxing

Port of ZXing (https://github.com/zxing/zxing) core to pure Go.
Other
565 stars 65 forks source link

qr is not recognized #62

Closed nechel11 closed 11 months ago

nechel11 commented 1 year ago

Greetings guys. there is problem with some qrs. example below test

makiuchi-d commented 1 year ago

Your image is a little distorted and blurry. Also, there is not enough white space (quiet zone).

I tried transform the image a bit, and got a result: D3D4E88916F1743F2142328E928369FEFFD87D6198F949081CFD8FC30D56340640E0EBD2A15CB16088BCEC1D051D14D9EFB54A94C80E9C594FDD6CE3C440EF06E2FFD424F1D8598F9CD0446CC715D7A8570BCA5E307F033039D440308BA5F0C0AB5905C5673F4DA2BCB12CC2424ABB5F

The program is:

package main

import (
        "fmt"
        "image"
        _ "image/png"
        "os"

        "golang.org/x/image/draw"
        "golang.org/x/image/math/f64"

        "github.com/makiuchi-d/gozxing"
        "github.com/makiuchi-d/gozxing/qrcode"
)

func must(err error) {
        if err != nil {
                panic(err)
        }
}

func main() {
        file, err := os.Open("/home/makki/Desktop/qr.png")
        must(err)
        defer file.Close()
        src, _, err := image.Decode(file)
        must(err)

        max := src.Bounds().Max
        img := image.NewRGBA(src.Bounds())
        aff := f64.Aff3{0.7, -0.1, float64(max.X) * 0.2, 0.1, 0.7, float64(max.Y) * 0.1}
        draw.CatmullRom.Transform(img, aff, src, src.Bounds(), draw.Over, nil)

        bmp, err := gozxing.NewBinaryBitmapFromImage(img)
        must(err)

        qrReader := qrcode.NewQRCodeReader()
        result, err := qrReader.Decode(bmp, nil)
        must(err)

        fmt.Println(result)
}