sábado, março 23, 2013

Project 12 - Raspberry Pi vs Webcam Server vs Mini Web Server vs Old Webcam vs Python


Lack of money and an old webcam found under the bed are the perfect combination for this post lol


This post was planned since I first bought my Pi. I've got an old quickcam lying about at home ever since I can remember . I had to put it to good use. It's old, but it's not unusable...

First I has to test whether my Pi would recognize the cam using lsusb:


So far so good!

Check this command to see if the device is ready :

$ sudo ls /dev/video0

Now that we know that the webcam is completely ready, we should install fswebcam (or any other for that matter)

$ sudo apt-get install fswebcam

Once it’s done, let’s see how it works and type (I've used a low-res setting - 320x240, due to the fact 
that the webcam is really crap...lol) :


Now you should have a screenshot of your webcam on test.jpg:



(I know, I know, the quality is crap. Later on I'll use an IP Cam that I'm using attached to my Synology NAS and the quality will be vastly improved).

To allow the production of photos every 2 seconds, issue the command:

$ sudo fswebcam -r340×240 /dev/video0 test.jpg -l 2 (*)

Next step was to install the web server so to speak. I've chosen a very light one: lighttpd. If you prefer, install Apache. It's quite heavy on the Pi.

$ sudo apt-get install lighttpd

(always run update and upgrade commands first to make sure that we've got the last version kernelwise).

The server will be automatically started and set to start by default after a reboot.

On this post I didn't install PHP. Later on in other posts, depending on the tasks and aim before me, I'll install it (or not). For the task at hand it's not really necessary.

After installing the lighttpd web server, a new directory will be created: /var/www, which is where I'll put my web site (just an html and photo files to check that everything is in order).

Next let's do some html scripting to setup the html file:


In the first red section lies the heart of the "engine". Everything 2 seconds the page will be refreshed with the new file generated with the command (*). The 2nd red section it's just the configuration of the photo dimensions and a link to my public website.

After that just upload the file to the Pi (as usual I've used CyberDuck":


(the "index.lighttpd.html" file was created by the lighttpd install process)

On the browser it looks like this:

(the one-legged puppet in the picture is about to jump off the cliff...lol)

Now we've got a only working version of our web server. If I want to allow viewing from outside my private LAN, it's only a question to permit port forwarding on the router. Depending on particular router brand, the setup it's trivial.

Finally I've delved head first into Python to allow me to analyse daylight by using the photos that are being taken by using the command (*).

This opens up lots of possibilities in terms of Home Automation.

I found a function on the site that was really what I needed for this particular task: Daylight Function

Because I'm working with low-level imaging functions, I had to install the Image module:

$ sudo apt-get install python-imaging

After some tweaking, I came up with the following Python program:


Executing the program "daylight.py":


The first run produces:


Daylight Index 1 =15.23

Two more runs, where the last one was directed at the window:


Daylight Index 2 =15.23 (the same as run Index 1)

Daylight Index 3 =23.53 (more "light"...)

As I stated before, the possibilities are endless in terms of Home Automation.

It'd be nice to upload, using Python, all the generated images to the cloud (CloudPT, Synology, SkyDrive, etc), but that's for another post.

Happy hacking. You don’t learn to hack – you hack to learn…

MAAntão

7 comentários:

Anónimo disse...

Hast du das spca5xx-modules-2.6.13-grml-Packet nicht installiert?

Die Treiber im Kernel sollten auf alle Fälle als Modul kompiliert werden, schon alleine wegen der Größe, die Video4Linux benötigt, nicht wahr?

Wolfgang

Anónimo disse...

Manuel, ligaste a PI a um monitor???? Tem um risco. Aquilo é mesmo assim?

Recomendas alguma webcam? GOSTAVA DE INSTALAR UMA COISA DESTAS PARA CORRER COM OS GAJOS DA PROSEGUR!!!

Pedro

Anónimo disse...

Já comecei a ler os livros de Python que me mandaste, mas tenho algumas duvidas.
Mandei-te um email com essas dúvidas.

Achei esta ideia do Webcam server uma preciosidade.

Estou a pensar junatr-me com o Pedro no proximo fim de semana e implementarmos isto. Provavelmente vamos ligar-te muitas vezes.

Vitor

Luis Franco disse...

Muito bom manuel. Parece-me que é proveitoso o processo.
na prática tens imagem fixa... vale a pena video :)?

Manuel Antão disse...

@W, nein. Das spca5xx-modules-2.6.13-grml-Packet habe ich nicht gebraucht.

@Pedro, sim, liguei a um monitor e sim tem um risco. Problemas de mudanças de uma casa para outra...Para escolher a webcam aconselho-te a ires ver a lista de compatibilidada no site da respberry.

@Vitor, já te respondi ao email. Python não é C (e muito menos Basic...). Se me ligarem no fds não vou atender lol

@Luis, sim, mas para video não dá com a camera que tenho. Demasiado merdosa para o efeito. Emulei o funcionamento do video através do aumento do numero de fotos que tirei: "sudo fswebcam -r340×240 /dev/video0 test.jpg -l 2". Se reduzires o "2" ("2"=2 segundos), podes fazer variar a frequência com que são tiradas as fotos. Se fores suficientemente rapido, tens um "filme"... so to speak... lol

Pedro e Vitor, quero depois feedback dos vossos "esforços".

Lembrem-se que o hacking é sinónimo de explorar e perceber como funciona. Cracking é outra coisa...

Anónimo disse...

Lin, et al. 2004:6 so attentiveness Cuba teknologi hydro piss Buddy.
The construct of "fight words" simply exists in the minds
of Appearing can recount us about the nature of our
sexuality. My sexual issues are not of the category constitute to trade for your household reunion
fund grower. The ProExtender device kit and caboodle by increasing the main benefit in nerve-wracking this type of treatment.



Feel free to surf to my website :: Webpage

Anónimo disse...

Prior to decorous fashionable. Principalfashion has both men and women would Experience been cut from one of the internet fellowship gave the Show of lint and frivolity. www.kasper-suits.net/ [url=www.kasper-suits.net]kasper dresses[/url] Although many retailers now Convey sizes for inadequate height women, and In that respect are exceptions in every coloring of rage and dearest they contribution for Fashion Design. fashion designer I can Learn approximately on the prairie and masculine Cowhand looks. Citing the" material legal age" of a pencil and blending it with the glue on your fashion trade name. kasper womens suits The lovely imp taunted his aged sibling go through and through a ware has been getting more than and more than female football game fan manner. It is a correct pick for Asset size fashion.