Code Monkey home page Code Monkey logo

gozbar's Introduction

GoZBar

Fork of https://github.com/PeterCxy/gozbar due to API breaking changes.

ZBar bindings for golang. Only scanner supported.

Read the ZBar documentations for explanations on constants and arguments.

The ZBar library must be installed for this to compile.

Example JPEG Scan.

func TestPhoto(t *testing.T) {
	const expectedStr = "http://www.searchenginestrategies.com/sanfrancisco/share.html"

	f, err := os.Open("./testdata/photo.jpg")
	if err != nil {
		t.Fatal(err)
	}

	i, err := jpeg.Decode(f)
	if err != nil {
		t.Fatal(err)
	}

	img := FromImage(i)

	s := NewScanner()
	err = s.SetConfig(0, CFG_ENABLE, 1)
	if err != nil {
		t.Fatal("error setting config", err)
	}

	err = s.Scan(img)
	if err != nil {
		t.Fatal("error scanning", err)
	}

	defer s.Destroy()

	img.First().Each(func(str string) {
		if str != expectedStr {
			t.Fatalf("expected [%s] got [%s]", expectedStr, str)
		}
	})
}

gozbar's People

Contributors

mordfustang21 avatar

Stargazers

 avatar Mathieu Chauvet avatar Julan Zander (ZanderCodes) avatar  avatar محمّد avatar

Watchers

James Cloos avatar  avatar  avatar

gozbar's Issues

[signal SIGSEGV: segmentation violation code=0x1 addr=0x48 pc=0x50631bb]

Hi @MordFustang21 I'm developing a qrcode detect api, when I do stress test, some time the it will panic at two line
one is panic at s := C.zbar_image_first_symbol(i.image),
the other one is at below

func (s *Symbol) Each(f func(string)) {
	t := s
       // some time t is nil
	for {
		f(t.Data())

		t = t.Next()

		if t == nil {
			break
		}
	}
}

here is my test code

package main

import (
	"bytes"
	"fmt"
	"github.com/MordFustang21/gozbar"
	"image"
	_ "image/gif"
	_ "image/jpeg"
	_ "image/png"
	"io/ioutil"
	"sync"
)

func main() {
	var wg sync.WaitGroup
	wg.Add(2000)
	for i :=0; i < 2000; i++ {
		go func() {
			defer wg.Done()
			b, err := ioutil.ReadFile("img.png")
			if err != nil {
				panic(err)
			}
			img, _, err := image.Decode(bytes.NewReader(b))
			if err != nil {
				panic(err)
			}

			barcodeImg := gozbar.FromImage(img)
			scanner := gozbar.NewScanner()
			scanner.SetConfig(gozbar.NONE, gozbar.CFG_ENABLE, 1)

			err = scanner.Scan(barcodeImg)
			if err != nil {
				panic(err)
			}

			defer scanner.Destroy()
	
			barcodeImg.First().Each(func(str string) {
				fmt.Println(str)
			})

		}()
	}
	wg.Wait()

}

here is the image
image

Do you have any suggestion?

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.