makiuchi-d / gozxing

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

Cannot decode qr code image #31

Closed filirnd closed 4 years ago

filirnd commented 4 years ago

Hi, I have a problem with decode this image that contains qr code qr

My code is the follow and i can decode the image with online zxing web app.

func qrDecoder(localQrPath string) (*gozxing.Result,error) {
    // open and decode image file
    file, err := os.Open(localQrPath)
    if err != nil {
        return nil,err
    }
    img, _, err := image.Decode(file)
    if err != nil {
        return nil,err
    }
    src := gozxing.NewLuminanceSourceFromImage(img)
    // prepare BinaryBitmap
    bmp, err := gozxing.NewBinaryBitmap(gozxing.NewGlobalHistgramBinarizer(src))
    if err != nil {
        return nil,err
    }
    // decode image
    hints :=  map[gozxing.DecodeHintType]interface{}{
        //gozxing.EncodeHintType_ERROR_CORRECTION: decoder.ErrorCorrectionLevel_L,
        gozxing.DecodeHintType_TRY_HARDER: true,
        gozxing.DecodeHintType_POSSIBLE_FORMATS: []gozxing.BarcodeFormat{
            gozxing.BarcodeFormat_QR_CODE },
    }
    qrReader := qrcode.NewQRCodeReader()
    return qrReader.Decode(bmp, hints)
}

It return "image: unknown format" error.

filirnd commented 4 years ago

I've found the mistake. Need to import this _ "image/jpeg"