Giter Site home page Giter Site logo

goqr's Introduction

goqr

GoDoc Go Report Card Build Status Coverall License Example

This is a QR Code recognition and decoding library in pure go. It can recognize most of images into QR Code string.

Example

package main

import (
	"bytes"
	"fmt"
	"github.com/liyue201/goqr"
	"image"
	_ "image/jpeg"
	_ "image/png"
	"io/ioutil"
)

func recognizeFile(path string) {
	fmt.Printf("recognize file: %v\n", path)
	imgdata, err := ioutil.ReadFile(path)
	if err != nil {
		fmt.Printf("%v\n", err)
		return
	}

	img, _, err := image.Decode(bytes.NewReader(imgdata))
	if err != nil {
		fmt.Printf("image.Decode error: %v\n", err)
		return
	}
	qrCodes, err := goqr.Recognize(img)
	if err != nil {
		fmt.Printf("Recognize failed: %v\n", err)
		return
	}
	for _, qrCode := range qrCodes {
		fmt.Printf("qrCode text: %s\n", qrCode.Payload)
	}
}

func main() {
	recognizeFile("testdata/008.png")
}

goqr's People

Contributors

liyue201 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

goqr's Issues

采用go modules

go modules 现在是golang官方包管理工具,可以的话请加上go.mod和go.sum。

Input device

Thanks for this nice go-library. What is your recommendation regarding to use your library with an input device like a webcam to have "realtime" scanning...should it periodically take images (every second) or somehow read directly from the videostream?

panic: runtime error: index out of range [3] with length 2

https://play.golang.org/p/huk3FeEAEot

package main

import (
	"log"
	"bytes"
	"image"
	"io/ioutil"
	_ "image/jpeg"
	_ "image/png"

  	"github.com/liyue201/goqr"
  	qrcode "github.com/skip2/go-qrcode"
)

func main() {
	p := "/tmp/test-goqr.png"

  	err := qrcode.WriteFile(`-----BEGIN PGP MESSAGE-----

wy4ECQMIlEOR6t1Wvp1guIRRXN87HQ3UOlSurE3gyiQslGraKi8kZYypMiygs0R8
0uAB5GzHuQ8nkg6uGv3tZ6/sdTDh+WTga+Dc4Yk34JTiRWqEv+DW5TllSJSMPjw6
YPpzIAwihrjG+cpfuF1OhrJwy8duwSR54DfkiHu7ymylwCw9lCejbU1OHODP4ogk
4CPgDuS/gfaOnv6Rb4MzV7/CnFeS4neA2yfhUWoA
=mD6l
-----END PGP MESSAGE-----`, qrcode.Medium, 256, p)
  	if err != nil {
    		log.Fatal(err)
  	}
  
	imgdata, err := ioutil.ReadFile(p)
	if err != nil {
		log.Fatal(err)
	}

	img, _, err := image.Decode(bytes.NewReader(imgdata))
	if err != nil {
		log.Fatal(err)
	}

	_, err = goqr.Recognize(img)
	if err != nil {
		log.Fatal(err)
	}
}
panic: runtime error: index out of range [3] with length 2

goroutine 1 [running]:
github.com/liyue201/goqr.alphaTuple(0xc0000161c0, 0xc0003c9818, 0xb, 0x2, 0xfd)
	/tmp/gopath044694003/pkg/mod/github.com/liyue201/[email protected]/decoding.go:580 +0x1fa
github.com/liyue201/goqr.decodeAlpha(0xc0000161c0, 0xc0003c9818, 0x2, 0xc0003c97b0)
	/tmp/gopath044694003/pkg/mod/github.com/liyue201/[email protected]/decoding.go:598 +0xad
github.com/liyue201/goqr.decodePayload(0xc0000161c0, 0xc0003c9818, 0x0, 0x0)
	/tmp/gopath044694003/pkg/mod/github.com/liyue201/[email protected]/decoding.go:695 +0x8e
github.com/liyue201/goqr.decode(0xc0003d3000, 0xc0000161c0, 0x0, 0x629290)
	/tmp/gopath044694003/pkg/mod/github.com/liyue201/[email protected]/qrcode.go:141 +0x16d
github.com/liyue201/goqr.(*recognizer).Decode(0xc0002fc000, 0x0, 0x0, 0x629290, 0xc0001bf42c)
	/tmp/gopath044694003/pkg/mod/github.com/liyue201/[email protected]/recognizer.go:106 +0xb9
github.com/liyue201/goqr.Recognize(0x53daa0, 0xc000052420, 0x53daa0, 0xc000052420, 0x518e4d, 0x3, 0x0)
	/tmp/gopath044694003/pkg/mod/github.com/liyue201/[email protected]/recognition.go:54 +0x2e2
main.main()
	/tmp/sandbox177494500/prog.go:40 +0x1fa

QR code location in large images seems to prevent qr code detection

I'm using goqr to look for AWS MFA QR codes on screenshots. Using the same qr code but located in different areas of the screen seems to change if goqr can find the qrcode or if it returns "no QR code in image"

The images I'm using are being captured with github.com/kbinani/screenshot and feeding the screen images into goqr. Depending on the location of the image on screen the recognizer.

The image size is a 1920x1080 screen shot and it seems that there is an issue if the qr code is not in the upper left quadrant of the image. I have moved the testing image I am using as little as one line down and see it not be recognized.

After much testing whatever is going on appear to be related to the number of different colors encountered in the image. When I had failures I was using a background screen image "Catalina Day" and by changing the background on the screen to black and leaving the QR code on the screen in the exact same position goqr was able to find the QR Code. This was done with the QR located in the lower right portion of the screen.

This seem to be a bug in the recognizer when it has a lot of color noise from the background.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.