Saturday, November 13, 2010

OpenCV - link libraries and compile

#the source directory would change depending on where you install it

#output errors while compiling are very useful to debug
export LD_LIBRARY_PATH=/usr/src/opencv/release/lib/:$LD_LIBRARY_PATH
ldconfig
PKG_CONFIG_PATH=/usr/src/lib/pkgconfig:${PKG_CONFIG_PATH}
export PKG_CONFIG_PATH
ldconfig

#some examples and guidelines here
linuxconfig.org/introduction-to-computer-vision-with-opencv-on-linux

#compiling
g++ `pkg-config opencv --cflags --libs` example21.cpp -o example21

Friday, November 12, 2010

Building OpenCV

#lets install some requirements
#some of them comes from
#http://opencv.willowgarage.com/wiki/InstallGuide%20:%20Debian

sudo apt-get install pkgconfig
sudo apt-get install build-essential
sudo apt-get install cmake
sudo apt-get install libgtk2.0-dev libavcodec-dev \
libavformat-dev libjpeg62-dev libtiff4-dev
sudo apt-get install libpngwriter0c2
sudo apt-get install zlib1g-dbg zlib1g zlib1g-dev
sudo apt-get install libjasper-dev libjasper-runtime libjasper1
sudo apt-get install pngtools libtiff4-dev libtiff4 libtiffxx0c2
sudo apt-get install libtiff-tools
sudo apt-get install libavcodec-dev libavcodec52
sudo apt-get install libgstreamer0.10-0-dbg libgstreamer0.10-0
sudo apt-get install libgstreamer0.10-dev
sudo apt-get install libxine1-ffmpeg libxine-dev libxine1-bin
sudo apt-get install libunicap2 libunicap2-dev
sudo apt-get install libdc1394-22-dev libdc1394-22 libdc1394-utils
sudo apt-get install swig
sudo apt-get install libv4l-0 libv4l-dev
sudo apt-get install libpython2.6 python-dev python2.6-dev
sudo apt-get install subversion
sudo apt-get install yasm

#feel free to work under /usr/src/ or /usr/local/src ..
#build ffmpeg
sudo svn checkout svn://svn.ffmpeg.org/ffmpeg/trunk ffmpeg
./configure --enable-shared
make
sudo make install

#build opencv
sudo svn checkout https://code.ros.org/svn/opencv/trunk/opencv
cd /usr/src/opencv
mkdir release
cd release
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/src \
-D BUILD_PYTHON_SUPPORT=ON -D BUILD_EXAMPLES=ON /usr/src/opencv/
make
sudo make install

#to make python work with opencv it is needed
mv /usr/src/lib/python2.6/site-packages/cv.so \
/usr/local/lib/python2.6/dist-packages/
#to test that it can read the library
# python2.6
>>> import cv
#it should work that way
#IPP librarys can be installed with license

Sunday, October 10, 2010

3 minutes news and weather information

alarm_podcast.py is a script that helps me to save some time during the morning, I can enjoy my breakfast while this program serves me the morning news and the weather forecast.

The script basically does 3 things:
1.- Connects to Yahoo weather to parse the current weather conditions and the forecast.
2.- All that information is sent to festival, who is doing the text to speech conversion and output to the speakers. This helps me a lot in order to know if I can take the bike or not that day.
3.- Finally the scripts check the national spanish television for a 2 minutes news video, that downloads, trying to bypass some obfuscation. Then the video is played with the realtime weather information, an icon showing the weather and also the time.

A cron job is taking care of running it daily from Mon to Fri. Using a bash script that is doing something like:

#!/bin/bash
pushd .
cd /home/user/weather
#lets clean the house first
find *.flv *.png -type f -mtime +3 -exec rm {} \;
python alarm_podcast.py
popd .

The script can be found on my open source github repository:

http://github.com/daniguerrero/spanish_news-weather

Sunday, September 12, 2010

Flash dd-wrt on Accton MR3201A Router

Go to the next page:
http://www.dd-wrt.com/site/support/router-database

select your model and download the linux.bin image, instead following the manual way like setting up a tftp server with the image and configuring the redboot loader...

Download from here:
http://www.gargoyle-router.com/download.php

The fonflash binarys corresponding your operating system in my case I used:
fon-flash-linux.tar.gz
untar and flash selecting the software (ddwrt in my case) using the nice gui or via command line tool:

sudo ./fon-flash -i eth0 -c ddwrt linux.bin

Once run the line above, power cycle your router and wait some time to have it flashed.

Saturday, August 28, 2010

Jugando con jquery, flot, prototype y python

Si la máquina virtual no se cae o se apaga el pc, aquí un ejemplo rápido de generación de gráficas limpias. Un script python en servidor es el encargado de generar los datos y pasarlos via json, parseando de manera muy manual los datos de Yahoo Weather. Cualquier modificación iría encaminada a utilizar un mecanismo más estandard de tratamiento xml.

El resultado:
http://dani.homeunix.org/meteo/

el código fuente en:
http://github.com/daniguerrero/meteo

Friday, August 20, 2010

Probando las bicis p'ublicas de Lyon

La verdad es que est'a muy bien montado, con estaciones de bicis por todas partes, y bastantes carriles bici, ojal'a se extendiera pronto por todo el mundo y se dejara de lado cada d'ia m'as tanto coche.

Este es el paseo que he dado con el MyTracks en el G1.


View Pista Ciclista in a larger map

Total Time: 00:26:58
Moving Time: 00:24:45
Distance: 6.09
Distance Unit: km
Average Speed: 13.58
Average Moving Speed: 14.77
Max Speed: 27.9
Speed Unit: km/h
Elevation Gain: 241
Min Elevation: 210
Max Elevation: 272
Elevation Unit: m

Sunday, August 15, 2010

Notes - Python time string to timestamp

>>> from datetime import datetime, date, time
>>> import time as _time
>>>> # Using datetime.strptime()
>>> dt = datetime.strptime("21/11/06 16:30", "%d/%m/%y %H:%M")
>>> dt
datetime.datetime(2006, 11, 21, 16, 30)
>>> tt = (dt.year, dt.month, dt.day, dt.hour, dt.minute, dt.second, dt.weekday(), 0, -1)
>>> tt
(2006, 11, 21, 16, 30, 0, 1, 0, -1)
>>> stamp = _time.mktime(tt)
>>> stamp
1164123000.0
>>> o = datetime.fromtimestamp(stamp)
>>> print o
2006-11-21 16:30:00

More info with all string codes for date/time here:
http://docs.python.org/library/time.html#time.strftime

Thursday, August 12, 2010

Notes - Run a Unix virtualbox machine during boot time

In order to save some memory and cpu on your host machine instead running virtual machines through the X system (windows like method :-p) you can use this method.
#Create a system user for VirtualBox
root@yourmachine:/imadirectory#useradd -r -m vbox
#add it to the right group (note that I'm using the same name for
#the group, not very educational)
root@yourmachine:/metoo#usermod -a -G vbox vbox
Probably you have installed Virtualbox with your user, and that installation will store the VirtualBox config files.
You need to copy all those files to the home directory of your new system user vbox and then change permissions to own the files,
by doing something like:
root@yourmachine:/home/vbox/.VirtualBox#chown -R vbox:vbox *
and make sure your virtual machine file allow write permissions to your vbox user or group:
root@yourmachine:/media/sda1# ls -l | grep openbsd
-rw-rw-r-- 1 dani vbox 1239450112 2010-08-12 21:29 openbsdserver.vdi
Once this is setup you can move to add a init script to your linux box, in my case a Ubuntu Lucid box.

#! /bin/sh 

### BEGIN INIT INFO
# Provides: Starts local virtual machines
# Required-Start: $local_fs $remote_fs $syslog $all
# Required-Stop:
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
### END INIT INFO

N=/etc/init.d/virtual_machines_local
VBOX_RUNNING=`pgrep -c VBoxHeadless`
set -e

case "$1" in
start)
if [ "$VBOX_RUNNING" = 0 ]
then
logger "trying to boot vboxheadless.."
echo "Starting headless virtual machines."
sudo -i -b -u vbox /usr/bin/VBoxHeadless -s \
openbsdserver -vrdp off
else
echo "VBoxHeadless already appears to be running"
fi
;;
stop)
if [ `pgrep -c VBoxHeadless` != 0 ]
then
echo "Sending acpipowerbutton to VMs...."
logger "Sending acpipowerbutton to VMS...."
sudo -i -b -u vbox /usr/bin/VBoxManage controlvm \
openbsdserver acpipowerbutton
I=0
echo "Waiting for successful shutdown: \
60 seconds (or less)."
while [ `pgrep -c VBoxHeadless` != 0 ] && [ $I -lt 60 ]
do
sleep 1
I=$(($I + 1))
echo -n "."
done
fi
;;
reload|restart|force-reload)
;;
*)
echo "Usage: $N {start|stop}" >&2
exit 1
;;
esac
exit 0
Make sure you add it to default start / stop scripts with the proper runlevels, and install if necessary acpid on the guest system, so it can receive the signal acpipowerbutton to shutdown gracefully.
update-rc.d virtual_machines_local defaults

Sunday, May 30, 2010

Python notes - Timestamp to Datetime

>>> import datetime
>>> import time
>>> time.time()
1275242762.4052529
>>> int(time.time())
1275242769
>>> n=int(time.time())
>>> print datetime.datetime.fromtimestamp(n)
2010-05-30 20:06:20

Syncing your music at home with Android

I was a bit tired to use always a cable for syncing music inside my home pc with my phone, even more to continue hearing the same music all the days on the tram or the bike because I forgot to plug the cable, mount and cp the files.
Using an Android G1/Dream phone, I've been able to synchronize music and other files on the fly while arriving home via wifi and an encrypted connection.

First I thought to try scp and control the access time of the files to synchronize, but then I thought that rsync would do a better job, so I went for installing CyanogenMod 5.0.7 that it is and Android 2.1 (Eclair) with our great rsync.

Once done the dirty job, I installed ASE scripting for Android, and from there I started my little one liner script.

We can also create dsa and rsa keys in our android device, for that just open a terminal and write:

$ su 

# dropbear-keygen

just in case we want to do password-less sync. If you want to show the rsa key from your phone do:
dropbearkey -y -f /data/dropbear/dropbear_rsa_host_key
More information about ssh at

Finally create a new shell script for ASE scripting with something like: (note the non default ssh port if you use something different than 22)
su -c "rsync -av --partial --stats --progress --delete --rsh='ssh -p1234' 

dani@my_ip:/media/Music/android/ /sdcard/Music"
Add a new launcher on the phone's desktop and you're all set. If apart from wifi, you also use 3G and one gps locale application, the possibilities for sync your music are almost infinite.

Saturday, May 29, 2010

Add keyboard shortcut on Ubuntu to send user defined signal

Sometimes it is needed to do a task quick and effective on linux, here is when it comes into account keyboard shortcuts.
There is several ways to make this work, but the easiest one I found is just using the default tools provided by Ubuntu.

So, lets say we want to send a user defined signal to a Unix process in our machine to do some specific task asynchronously, that is, when we press the keyboard shortcut. In Windows systems probably we would need to trap events to do something similar.

To do that just go to System - Preferences - keyboard shortcuts and add your command.
In this particular case we want to add:

bash -c -i "kill -USR1 $(pgrep -f your_proccess_name.py)"

Take into account that first we specify the Unix interpreter to be used and then the command.
Kill is sending our user defined signal to our python script, and from that python script we will capture and handle the signal.


Tuesday, May 04, 2010

Using someone else to read for you

Time is limited and that makes me try to optimize it as much as possible. There is quite a lot of blogs that I'm subscribed to and that I would like to have the time to read, even more all of those blogs or webpages contains valuable references or hyper links that I'd love to read as well.

What I really hate is have to go through all of them looking for the topics that I like, really I don't have the time, and posts and more posts goes into the cruel destiny of never-read land. Because of that reason, since some time ago I keep some "readers" on my machine, they're basically some processes that examine my preferred webs, starting the search with my Reader subscriptions and then sneaking into the first level links from them.

So basically the parent process is looking for new information in my social circle that talk about my interests.

As an example the first version of the script was doing something like:

for i in $(cat google-reader-subscriptions.xml | grep xmlUrl | sed 's/^.*xmlUrl="//g' | sed 's/".*$//g'); do echo "Checking website: " $i; curl -s $i | grep "Alicante" ; done

Then the future version include a handy mail notification as soon as my preferred news appear, or any link from my web social circle talk about it.

Oops dinner is ready, lets keep my readers doing the job, I'll see later what they have to say... ;-)

Image from: http://www.rdpl.org

Saturday, May 01, 2010

Installing Ubuntu Lucid Lynx with no CD and encrypted home

Follow steps here to setup dhcp server and tftp server:
https://wiki.koeln.ccc.de/index.php/Ubuntu_PXE_Install

Download the netboot image and place it inside the proper directory:
/var/lib/tftpboot

Use a crossover cable to connect one pc to the other, or disable home router dhcp so there is no conflicts.

Dowload iso alternate disk from Ubuntu (important must be alternate) and place it inside your local web server /var/www/ubuntu/

sudo mkdir /var/www/ubuntu/ sudo mount -o loop /path/to/.iso /mnt sudo cp -a /mnt/* /var/www/ubuntu/

Then boot from network card on your client, the pc where you want to do the installation, and instead selecting a remote repository over the internet (they could fail, your local server not :-) ) Just select your local server repository as a ubuntu mirror something like:
http://yourserver/ubuntu

Finish the installation and boot in your new system. If you have encrypted your home directory as I usually do, you may notice some issues regarding access to it, a message like "Could not update ICEauthority", you should be happy to notice it and observe that your home dir is not mounting, this is preventing that any other can read it even if they install another operating system.

So to fix it, just install the package ecryptfs-utils and run under terminal the nexts lines, so you can type your personal passphrase. First type your passphrase and then type your system password.

cd $HOME/.ecryptfs/
ecryptfs-wrap-passphrase wrapped-passphrase
tip from http://angelverde.info/tag/ubuntu/

Then reboot to go to a new login screen and log in normally, all your home settings will be there.

Sunday, April 18, 2010

Image conversions / JPG to PDF and TIFF to PDF

With ImageMagick use command
$ convert img1.jpg img2.jpg img3.jpg all_images.pdf

With libtiff-tools create multipage tiff and than convert to pdf
$ tiffcp 1.tif 2.tif ... N.tif multi.tif
$ tiff2pdf -o out.pdf multi.tif

Saturday, April 10, 2010

looping through files with spaces in the filenames in bash

I sometimes have to transfer files with spaces in the names, I like using a for loop, but the usual way doesn’t work. Usual way:

for file in `find . -type f|grep .ext$`
do
/do/something/to $file
done
To get around this I use a while loop with a read instead. Using the read will read to the end of the line, enclosing within quotes escapes the spaces. Unusual way:
find . -type f|grep .ext$ |while read file
do
/do/something/to "$file"
done

source: http://ramblings.narrabilis.com/wp/looping-through-files-with-spaces-in-the-names-in-bash/

Wednesday, April 07, 2010

Vulnerabilidad Sockstress del protocolo TCP

Muy interesante la vulnerabilidad, y también la historia de cómo se desarrollaron los acontecimientos.

http://www.kriptopolis.org/sockstress

el documento pdf original en castellano aquí:
http://gabriel.verdejo.alvarez.googlepages.com/ARTICULOS-Lavulnerabilidaddelprotoco.pdf

En la pagina de Wikipedia que habla de la vulnerabilidad informa que puede ser mitigada utilizando iptables mediante connection tracking and rate limiting.

Esta vulnerabilidad en la pila TCP/IP no tiene solución hasta el momento, todos los sistemas operativos están afectados, podríamos decir que es una vulnerabilidad del protocolo, siempre y cuando éstos tengan algún tipo de servicio que establezca conexiones tcp a la escucha.

No me gustaría dar ideas, pero por la misma regla de tres incluso los servidores dns podrían estar afectados, aquellos cuya respuesta se realizara via tcp y no udp como suele ser lo habitual.

Sunday, March 28, 2010

Editing android read-only file system

This lines also help to fix the route and ifconfig not working as expected from /system/bin/

mount -o remount,rw -t yaffs2 /dev/block/mtdblock6 /system
mkdir /system/xbin
cd /system/xbin
ln -s /data/busybox/ifconfig ifconfig
ln -s /data/busybox/route route
mount -o remount,ro -t yaffs2 /dev/block/mtdblock6 /system


Setting up SSL/TLS vpn from Android phones

I did create a client.conf file almost similar for all my clients, one of them, the android phone.
Then created a simple script to start the vpn.

#again setting right path as ASE scripting for android uses other shell
export PATH='/system/sbin:/system/xbin:/system/bin'
cd /sdcard/openvpn/
su -c "openvpn --config /sdcard/openvpn/client.conf"&

Make busybox the default for android terminal

just enter on terminal Preferences and under Command line enter /system/xbin/sh and inside the initial comand set PATH to run commands from busybox and not from the default terminal.

export PATH='/system/sbin:/system/xbin:/system/bin'

after that ifconfig and route commands for example will work like a charm :-)

Start android connection with a linux box

adb kill-server
sudo adb start-server
adb devices

Tuesday, February 23, 2010

Reading about SQLite...

An extremely reliable open source relational database used by several MP3 players, the iPhone, Android and probably iPad also.

It was first designed by D. Richard Hipp in the Spring of 2000 while working for General Dynamics on contract with the United States Navy. Hipp was designing software used on board guided missile destroyer ships...

More info here and there.

Tuesday, January 26, 2010

Installing Ubuntu through pxe boot

more notes...
https://wiki.koeln.ccc.de/index.php/Ubuntu_PXE_Install

Sunday, January 24, 2010

PS3 as mediacenter (playing MKV files)

Some notes so I don't forget the links.

Just install ffmpeg following this guide http://ubuntuforums.org/showthread.php?t=786095

I've used the ./configure inside the next link (outdated for karmic) http://juliensimon.blogspot.com/2009/01/howto-converting-mkv-files-to-play-on.html
With quite good examples and notes on troubleshooting.

By the way, I wouldn't try to stream 1080p/i or 720p through wifi, not even with 802.11n, if I have the chance I would like to try a gigabit network. Numbers are tight, but if you want to try, ps3mediacenter works well.
The way I see high definition videos with the ps3 is dowloading the files first to the ps3, for example through a web server, in my case lighthttp.