makiuchi-d / gozxing Goto Github PK
View Code? Open in Web Editor NEWPort of ZXing (https://github.com/zxing/zxing) core to pure Go.
License: Other
Port of ZXing (https://github.com/zxing/zxing) core to pure Go.
License: Other
IMG: https://i.imgur.com/UoRQWJE.jpg
I got this error from result, err := qrReader.Decode(bmp, nil)
dependencies:
Could you please check, why qrReader.Decode(img, nil) returns error "NotFoundException: startSize = 0"?
File is attached, QR-code looks normal.
Online version doesn't decode it too.
Give an example of reading ENA from a file please...
this is my code, the error occur in the last row:
func helloworld(c *gin.Context) {
file, _ := c.FormFile("file")
log.Println(file.Filename)
fileDetail, err := file.Open()
if err != nil {
c.JSON(http.StatusBadRequest, PostScanSettlementReply{
Status: http.StatusBadRequest,
Msg: "error: i" + err.Error(),
})
return
}
img, _, err := image.Decode(fileDetail)
if err != nil {
logcat.Log().Sugar().Error("image decode error, the error is ", err.Error())
c.JSON(http.StatusBadRequest, PostScanSettlementReply{
Status: http.StatusBadRequest,
Msg: "error: " + err.Error(),
})
return
}
// prepare BinaryBitmap
bmp, _ := gozxing.NewBinaryBitmapFromImage(img)
// decode image
qrReader := qrcode.NewQRCodeReader()
result, err := qrReader.Decode(bmp, nil)
//...... more code
}
How to add FNC1 character to the beginning of datamatrix code?
Hint gozxing.EncodeHintType_GS1_FORMAT not work in datamatrix writer
I try to decode a qrcode, but I cannot decode it.
it give me a error
NotFoundException
but actully it is a normal qrcode, this is my pic.
that my code:
func DecodeFile(fi string)(string, error) {
file, _ := os.Open(fi)
img, _, _:= image.Decode(file)
// prepare BinaryBitmap
bmp, _:= gozxing.NewBinaryBitmapFromImage(img)
// decode image
result, err := qrcode.NewQRCodeReader().Decode(bmp, nil)
if err != nil {
return "", err
}
return result.String(), nil
}
Hi @makiuchi-d,
First off, thank you for such a great library!
I have a question. In a scenario of scanning documents, where the content area is large and barcode presence percentage is relatively small, what might be a recommended approach? Using scanned pages' images as is doesn't work, no barcodes are found on a page. As a workaround, I used cropping the image leaving only top-right area (a potential place of a barcode) for example. That worked, but I'm not sure, probably there is some more robust approach embedded to the library which I just missed?
Hi
Thanks for the library first. It's working well. However for some QR codes it doesn't able to find QR codes. I've also tried some hints e.g. Try harder. But it doesn't work. The code I've been trying with is;
`bmp, err := gozxing.NewBinaryBitmap(gozxing.NewGlobalHistgramBinarizer(gozxing.NewLuminanceSourceFromImage(img)))
hints := map[gozxing.DecodeHintType]interface{}{
gozxing.DecodeHintType_TRY_HARDER: true,
gozxing.DecodeHintType_POSSIBLE_FORMATS: []gozxing.BarcodeFormat{
gozxing.BarcodeFormat_QR_CODE},
}
// decode image
qrReader := qrcode.NewQRCodeReader()
result, err := qrReader.Decode(bmp, hints)`
And the QR codes, which doesn't decode/detected are the following.
Hello! Is there any way to decrease the white border?
Hey makiuchi,
Thank you for the great and active development!
I am currently trying to generate and read qr codes within Go.
The only kinda fast encoding library I found was at github.com/chai2010/qrcode. However, the decoding from the wrapped libqrencode is unable to read the codes generated by itself, as can be seen here: chai2010/qrcode#2
I generated a sample file with the maximum bytes:
As the online version of Zxing was able to read it (it's just "Hello World. " repeatedly), I hoped that this library can read it. Sadly, it doesn't.
Do you know
RSS14Reader
The file to decode: https://pyds.oss-cn-beijing.aliyuncs.com/uploads/test-data/2019-11-13/deskewed/09e0789b-8ada-4ff4-bc81-3339c805eedf.png
My cellphone can scan it.
This issue related to #1
Dependencies of qrcode.detector.Detector:
Dependencies:
"errVerbose":"NotFoundException: startSize = 0:
qukan-ugc/vendor/github.com/makiuchi-d/gozxing/qrcode/detector.(*FinderPatternFinder).SelectBestPatterns
/data/jenkins/home/workspace/techcenter_content_server-ugc-api/src/qukan-ugc/vendor/github.com/makiuchi-d/gozxing/qrcode/detector/finder_pattern_finder.go:459
Is there plans to port PDF417?
First of all, thanks for this great pure go port.
I'm having a problem with a qr extracted from a pdf, I'm saving it to a jpg before trying to decode
The code I'm using is this
qrImage := args[0]
qrFile, _ := os.Open(qrImage)
img, _, _ := image.Decode(qrFile)
bmp, err := gozxing.NewBinaryBitmapFromImage(img)
handleError(err) // this only print the error
qrReader := qrcode.NewQRCodeReader()
result, err := qrReader.Decode(bmp, nil)
handleError(err)
fmt.Println(result)
This code is showing not found exception, but zxing online shows the following
I try also with hints (maybe I'm doing it wrong)
hints := map[gozxing.DecodeHintType]interface{}{
gozxing.DecodeHintType_PURE_BARCODE: true,
gozxing.DecodeHintType_POSSIBLE_FORMATS: []gozxing.BarcodeFormat{
gozxing.BarcodeFormat_DATA_MATRIX },
}
result, err := qrReader.Decode(bmp, hints)
with format exception.
Need some help, because the users will be loading the pdf dynamically
A vote for aztec code decoding support
I am getting error while trying to parse qr code png image.
"NotFoundException: (w, h) = (492, 492), (x, y) = (63, -7)"
is the error message I am getting.
I am sorry, I cant attach the sample QR code with you.
f, _ = ioutils.ReadFile(filepath)
require.NoError(t, err)
img, _, err := image.Decode(f)
require.NoError(t, err)
bmp, err := gozxing.NewBinaryBitmapFromImage(img)
require.NoError(t, err)
// decode image
qrReader := qrcode.NewQRCodeReader()
result, err := qrReader.Decode(bmp, nil)
require.NoError(t, err) // Error is thrown here.
panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xc0000005 code=0x0 addr=0x20 pc=0xbf0648]
goroutine 1 [running]:
github.com/makiuchi-d/gozxing.NewLuminanceSourceFromImage({0x0, 0x0})
D:/Program Files/GOPATH/pkg/mod/github.com/makiuchi-d/[email protected]/go_image_luminance_source.go:19 +0x28
github.com/makiuchi-d/gozxing.NewBinaryBitmapFromImage({0x0?, 0x0?})
D:/Program Files/GOPATH/pkg/mod/github.com/makiuchi-d/[email protected]/go_image_luminance_source.go:10 +0x27
here is my code
func main() {
// open and decode image file
file, _ := os.Open("D:\\AppData\\Local\\Temp\\123.jpg")
img, _, _ := image.Decode(file)
// prepare BinaryBitmap
bmp, _ := gozxing.NewBinaryBitmapFromImage(img)
// decode image
qrReader := qrcode.NewQRCodeReader()
result, _ := qrReader.Decode(bmp, nil)
fmt.Println(result)
}
Could you add version tags to this module to indicate release stability? I'd be happy to help you out with setting this up, as well as some GitHub Actions automation for releases when a new tag is pushed.
The attached PNG file cannot be detected by the lib. What am I doing wrong?
func Decode(data []byte) (string, error) {
img, err := png.Decode(bytes.NewReader(data))
if err != nil {
return "", ErrNotPNG
}
// prepare BinaryBitmap
bmp, err := gozxing.NewBinaryBitmapFromImage(img)
if err != nil {
return "", ErrNotPNG
}
// decode image
qrReader := qr1.NewQRCodeReader()
result, err := qrReader.Decode(bmp, nil)
if err != nil {
return "", ErrNotQRCode
}
return result.GetText(), nil
}```
![qr](https://user-images.githubusercontent.com/39924160/227664064-a9c716f0-1907-49da-8f15-3a60cb2a0150.png)
Hello
Is there anything planned for Datamatrix encoding ?
In the original library, there is an extra step for "data encodation": Zxing DataMatrixWriter
It looks like that all the code is already there in golang, the only missing part is to use EncodeHintType (for instance FORCE_C40 is missing)
Hello! I'm trying to make datamatrix code for Cyrillic
text := "Mосква"
datamatrixWriter := datamatrix.NewDataMatrixWriter()
datamatrixCode, _ := datamatrixWriter.Encode(text, gozxing.BarcodeFormat_DATA_MATRIX, 648, 648, nil)
and Windows1251 ("Ìîñêâà"):
text := "Mосква"
enc := charmap.Windows1251.NewEncoder()
win1251text, _ := enc.String(text)
datamatrixWriter := datamatrix.NewDataMatrixWriter()
datamatrixCode, _ := datamatrixWriter.Encode(win1251text, gozxing.BarcodeFormat_DATA_MATRIX, 648, 648, nil)
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x18 pc=0x12f2e63]
github.com/makiuchi-d/gozxing/datamatrix/encoder.(*EncoderContext).SetSymbolShape(...)
/go/src/github.com/makiuchi-d/gozxing/datamatrix/encoder/encoder_context.go:42
github.com/makiuchi-d/gozxing/datamatrix/encoder.EncodeHighLevel(0x13ed327, 0x4, 0x0, 0x0, 0x0, 0xc0001024b0, 0x34, 0xc000000076, 0xc0000b4078, 0x10c2240)
/go/src/github.com/makiuchi-d/gozxing/datamatrix/encoder/high_level_encoder.go:116 +0x1a3
github.com/makiuchi-d/gozxing/datamatrix.(*DataMatrixWriter).Encode(0x172ad30, 0x13ed327, 0x4, 0x5, 0x288, 0x288, 0x0, 0x0, 0x0, 0x140695a)
/go/src/github.com/makiuchi-d/gozxing/datamatrix/datamatrix_writer.go:61 +0x2ac
main.createRPImageContext(0x13ef3bd, 0x9, 0x0, 0x829749600, 0x0, 0x140695a, 0x60, 0x140695a, 0x60, 0x140695a, ...)
Dependencies:
when i use to scan barcode , it show err : NotFoundException: startSize = 0
can it scan barcode ?
but i can use online scan the result, https://zxing.org/w/decode.jspx, below is my picture,, thks
This issue related to #1
Dependencies of qrcode.decoder.Decoder:
I need to play with Code128 and FNC3, but ... facing some troubles...
From the sources, I understand my code should look like :
...
data := "\u00f3FOO"
writer := oned.NewCode128Writer()
bmx, err := writer.Encode(data, gozxing.BarcodeFormat_CODE_128, w, h, nil)
if err != nil {
fmt.Printf("Encoder error : %s\n", err)
return err
}
...
With the code above, I get an error like : Bad character in input: 195
I had deeper look to code128 encoder and I suspect a bug in this area:
for i := 0; i < length; i++ {
c := contents[i]
switch c {
case code128ESCAPE_FNC_1, code128ESCAPE_FNC_2, code128ESCAPE_FNC_3, code128ESCAPE_FNC_4:
break
default:
if c > 127 {
// support for FNC4 isn't implemented, no full Latin-1 character set available at the moment
return nil, gozxing.NewWriterException(
"IllegalArgumentException: Bad character in input: %v", c)
}
}
}
With traces inserted, none of the case code128ESCAPE_FNC_x are hit.
I suspect a kind of problem like in the playground : https://play.golang.org/p/cfPXCJsBN3a
dependencies:
Hi, I have a problem with decode this image that contains qr code
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.
panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xc0000005 code=0x0 addr=0x20 pc=0x4b60be]
goroutine 1 [running]:
github.com/makiuchi-d/gozxing.NewLuminanceSourceFromImage(0x0, 0x0, 0xc00007e070, 0x0)
C:/src/go_work/src/github.com/makiuchi-d/gozxing/go_image_luminance_source.go:19 +0x3e
github.com/makiuchi-d/gozxing.NewBinaryBitmapFromImage(0x0, 0x0, 0x0, 0x0, 0x0)
C:/src/go_work/src/github.com/makiuchi-d/gozxing/go_image_luminance_source.go:10 +0x40
main.main()
C:/src/go_work/src/learning/qrcode.go:36 +0x85
exit status 2
package main
import (
"fmt"
"image"
_ "image/jpeg"
"os"
"github.com/makiuchi-d/gozxing"
"github.com/makiuchi-d/gozxing/qrcode"
)
func main() {
// open and decode image file
file, _ := os.Open("qr.png")
img, _, _ := image.Decode(file)
// prepare BinaryBitmap
bmp, _ := gozxing.NewBinaryBitmapFromImage(img)
// decode image
qrReader := qrcode.NewQRCodeReader()
result, _ := qrReader.Decode(bmp, nil)
fmt.Println(result)
}
The QRCodeReader fails to extract the QR code from the attached image:
It responds with a NotFoundException
Go snippet:
...
img, _, _ := image.Decode(file)
bmp, _ := gozxing.NewBinaryBitmapFromImage(img)
qrReader := qrcode.NewQRCodeReader()
result, err := qrReader.Decode(bmp, nil)
...
The Java equivalent (https://github.com/zxing/zxing) on the other hand is able to do it
Java snippet:
...
LuminanceSource source = new BufferedImageLuminanceSource(image);
BinaryBitmap bitmap = new BinaryBitmap(new GlobalHistogramBinarizer(source));
Reader reader = new QRCodeReader();
Result theResult = reader.decode(bitmap, null);
...
Dependencies of qrcode.QRCodeReader:
Is there a plan to implement "reader programming" support with Datamatrix ?
Got something, working with Datalogic scanners ...
in case ...
Usage:
ctx
is a web server response context, just ignore it.
encoder := qrcode.NewQRCodeWriter()
btmtrx, err := encoder.Encode(yearInt+"|"+nanoId, gozxing.BarcodeFormat_QR_CODE, 300, 300, nil)
finalBuf := bytes.NewBuffer(nil)
_ = png.Encode(finalBuf, btmtrx)
ctx.SetStatusCode(200)
ctx.Response.Header.Set("Content-disposition", "attachment; filename=qrcode.png")
ctx.SetContentType("application/octet-stream")
ctx.SetBody(finalBuf.Bytes())
After downloaded, the file cannot be open.
One extra byte here:
00000000: c289 504e 470d 0a1a 0a00 0000 0d49 4844 ..PNG........IHD
The binwalk result is:
mypc% binwalk /tmp/h1.png
DECIMAL HEXADECIMAL DESCRIPTION
--------------------------------------------------------------------------------
1 0x1 PNG image, 300 x 300, 8-bit grayscale, non-interlaced
After stripped the first extra byte, the file is attached here.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.