Ir al contenido principal

Ralsina.Me — El sitio web de Roberto Alsina

Goodreads+webcam+python+zbar == hackfun!

Leo mu­cho, y me gus­ta que pue­do ver las opi­nio­nes de otra gen­te an­tes de em­pe­zar un li­bro, y pue­do po­ner co­men­ta­rio­s, y que an­du­ve le­yen­do, y otras co­sas.

De he­cho, goodrea­ds va a ser una par­te im­por­tan­te de un pro­yec­to que es­ta­mos em­pe­zan­do con gen­te de PyA­r.

Una co­sa que no ven­go ha­cien­do es agre­gar los li­bros que ten­go en goodrea­d­s, por­que es mu­cho la­bu­ro.

Bue­no, ya no tan­to!

Así se ha­ce, al es­ti­lo ha­cke­r...

  1. In­s­­ta­­lá zbar

  2. Co­n­se­­gui­­te una we­­b­­cam ba­­ra­­ta

  3. Aga­­rrá un li­­bro

  4. Un pro­­­gra­­mi­­ta py­­thon de 7 lí­­neas (ver aba­­jo)

Y mi­rá el vi­deo­...

¿No es lin­do?

El pro­gra­ma:

import os

while True:
    code = p.readline()
    print 'Got barcode:', code
    isbn = code.split(':')[1]
Holger / 2010-09-02 08:00:

A good idea. I am acutally en route to sell some of my old books on the internet and thought about buying a barcode scanner. But this is so obviously a better idea as all my computers have a camera build in. Thanks for the idea!

Roberto Alsina / 2010-09-02 14:01:

Glad it was useful :-)

Mr.Fmft71 / 2011-12-19 17:53:

Hi, there Robert!

I've tried your 7-line python script, but I had to do some changes. so your code is working for me now, like this:

import os

p=os.popen('LD_PRELOAD=/usr/lib/libv4l/ zbarcam /dev/video1','r')
while True:
    code = p.readline()
    print 'Got barcode:', code
    isbn = code.split(':')[1]

In order to use my Creative WebCam Plus, I had to add the line:
"LD_PRELOAD=/usr/lib/libv4l/" before "zbarcam" and after it. "/dev/video1" because I'm using the script on a laptop with a built-in webcam, but that's the one I don't want to use, because isn't in focus. The one I want to use is the Creative one, plugged via USB with a ring to focus it.

The other change is the browser.
I don't use Chrome, so I changed "chrome" for "firefox" and everything works like a charm.

Thanks for your script.

I also want to share with you a video I uploaded to YouTube, using Zbar to search any item with a barcode using Google, or another program. I used another tiny program called "crikey" that allow me to use the read barcode anywhere I want....

Here is the videoclip:

I got the info from here:

Now I've got a question. How can I do the same on Windows? I mean, how can I use the read barcode from Zbar, anywhere I want? Is there a way to redirect the output of the webcam to any open search box, active window (NotePad, for example) or search box on any application?

If you've got any idea, please, contact me at fmft71 at yahoo dot es

También hablo y entiendo Español, sin ningún problema.... OK?

swheatley / 2010-09-02 13:58:

Very cool! I'm curious to see if zbar works on Windows or (preferably) OS X. Nice hack!

Roberto Alsina / 2010-09-02 14:00:

It seems the webcam support is not available for windows, and the scanner that uses images is much harder to get working right.

When working with video, you just move it around until it clicks, with snapshots it's a pin in the neck.

Kumar Chetan / 2010-09-08 06:58:

Thanks a ton, am also reading your PyQT tutorials. There are some typos in tutorials.

sheep12 / 2011-02-05 14:20:

do you know how to connect zbar to a database eg google and search and print the deatails found

Roberto Alsina / 2011-02-05 20:50:

Actually, yes, we ahve implemented that in Aranduka:

You want the google_guesser and barcode plugins (integrate branch) for the sample code. Of course, some glue will be required to make them work outside Aranduka.

Kriskrimson / 2011-10-10 20:14:

is there a way of getting this to work on a win box. I copied the code and defined the location of zbar. why am I not able to scan the code. It just does not start the zbar program

Contents © 2000-2023 Roberto Alsina