makiuchi-d / gozxing

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

NotFoundException using MultiFormatUPCEANReader #68

Open lnds opened 6 months ago

lnds commented 6 months ago

When trying to decode this image I get NotFoundException.

Here's my code:

func scanBarCode(fileName string) {
file,  _ := os.Open(fileName)
img, _,_ := image.Decode(file)
bmp, err := gozxing.NewBinaryBitmapFromImage(img)
if err != nil {
    fmt.Println("error: could not get bmp from image", err)
   return
}
reader := oned.NewMultiFormatUPCEANReader(nil)

result, err := reader.DecodeWithoutHints(bmp)
if err != nil {
   fmt.Println("error: no barcode found in image", err)
  return
}
fmt.Println("success:", result)
}

7

makiuchi-d commented 6 months ago

It seems that there is not enough white space on both sides. I got the result by adding white space.

img, _,_ := image.Decode(file)

img2 := image.NewRGBA(image.Rect(0, 0, 3000, 2500))
draw.Draw(img2, img2.Bounds(), image.White, image.Pt(0, 0), draw.Over)
draw.Draw(img2, image.Rect(250, 0, 2750, 2500), img, image.Pt(0, 0), draw.Over)

bmp, err := gozxing.NewBinaryBitmapFromImage(img2)