Skip to main content

Ralsina.Me — Roberto Alsina's website

Goodreads+webcam+python+zbar == hackfun!

I am a big fan of GoodReads a so­cial net­work for peo­ple who read book­s.

I read a lot, and I like that I can see what oth­er peo­ple think be­fore start­ing a book, and I can put my short re­views, and I can see what I have been read­ing, and lots more.

In fac­t, goodreads is go­ing to be a big part of a project I am start­ing with some PyAr guys.

One thing I have been lazy about is adding my book list to goodread­s, be­cause it's a bit of a chore.

Well, chore no more!

Here's how to do it, the hack­er way...

  1. Get zbar

  2. Get a cheap we­b­­cam

  3. Get a book

  4. Get a 7-­­line python pro­­gram (in­­clud­ed be­low)

Now watch the video...

Cute, is­n't it?

Here's the code:

import os

p=os.popen('/usr/bin/zbarcam','r')
while True:
    code = p.readline()
    print 'Got barcode:', code
    isbn = code.split(':')[1]
    os.system('chromium http://www.goodreads.com/search/search?q=%s'%isbn)
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/v4l1compat.so zbarcam /dev/video1','r')
while True:
    code = p.readline()
    print 'Got barcode:', code
    isbn = code.split(':')[1]
    os.system('firefox http://www.goodreads.com/se...

In order to use my Creative WebCam Plus, I had to add the line:
"LD_PRELOAD=/usr/lib/libv4l/v4l1compat.so" 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:
http://www.youtube.com/watc...

I got the info from here:
http://www.tuxbrain.com/con...

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: http://aranduka.googlecode.com

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
kriskrimson@ymail.com


Contents © 2000-2024 Roberto Alsina