Note for English Readers

If I write the articles in Indonesian, I will write a summary in English so that you can read my articles too. After you read the summary and you feel that you need more information about that, please do not hesitate to contact me via e-mail that can be found in my profile.

Thank you for reading my blogs.

Monday, September 24, 2007

How to Set Extra Keys on Laptop

Laptop usually has some extra keys for particular purposes such as volume control, brightness control, sleep button, etc. If you are lucky, you will get all extra keys are working nicely. On my laptop, only brightness control can working.
From Arman Idris' blog, I got an explanation in Indonesian about how to set extra keys on laptop that have Slackware installed and KDE as desktop manager. I think all Linux distros can adopt it if they are using KDE as desktop manager. If you use GNOME, I'm sorry ... I do not know how to set ... please googling :)

The software that we need to activate the extra keys are xmodmap and xbindkeys. Xmodmap are commonly used in X system, so that, we do not need to install it. Xbindkey usually does not included. We need to install it. Get it from then compile and install it. After finishing install xbindkeys, there are some steps to follow:

First, we have to know the keycode of extra keys that we want to activate. From console, type xev then press the desired extra key. On screen we will see some texts like this:
KeyPress event, serial 32, synthetic NO, window 0x2a00001,
root 0x66, subw 0x0, time 335922971, (1083,351), root:(1093,377),
state 0x0, keycode 160 (keysym 0x0, NoSymbol), same_screen YES,
XLookupString gives 0 bytes:
XmbLookupString gives 0 bytes:
XFilterEvent returns: False

Pay attention on the bold texts. That is the keycode for extra key that we just pressed, on my laptop, that is extra key for muting volume. Using the same procedure, on my laptop, I found keycode 174 and 176 for volume down and volume up, respectively.

Second, we write 2 configuration files: .xmodmaprc and .xbindkeysrc, place them in the home directory. Here is my .xmodmaprc:
keycode 160 = F14
keycode 174 = F15
keycode 176 = F16
The name of F14, F15, and F16 are alias names of extra keys that have keycode of respectively 160, 174, and 176. For standard naming in xmodmap, please refer to xmodmap manual.
My .xbindkeysrc can be found here:
#Volume Mute
#Volume decrease
"dcop kmix Mixer0 decreaseVolume 0"
#Volume increase
"dcop kmix Mixer0 increaseVolume 0"
Note that dcop can be found only in KDE.
Since we do not have script file, we have to write it then place it to /usr/local/bin. Do not forget to change file permission using: chmod 0755 /usr/local/bin/ -- of course, you must have root permission to execute this command --
Here is the script of
MUTE=`dcop kmix Mixer0 mute 0`
if $MUTE -eq "true" ; then
dcop kmix Mixer0 setMute 0 off
dcop kmix Mixer0 setMute 0 on
This script will toggle the mute status when we press the mute key. For instance, if the last status is "mute", the status will change to "unmute" when we press the mute key.

Third, we edit the .xinitrc (you can found it in your home directory) to run configuration files that have been written. Here is my .xinitrc:
# $XConsortium: xinitrc.cpp,v 1.4 91/08/22 11:41:34 rws Exp $


# merge in defaults and keymaps

if [ -f $sysresources ]; then
xrdb -merge $sysresources

if [ -f $sysmodmap ]; then
xmodmap $sysmodmap

if [ -f $userresources ]; then
xrdb -merge $userresources

if [ -f $usermodmap ]; then
xmodmap $usermodmap

/usr/local/bin/xbindkeys -f $HOME/.xbindkeysrc

# Start the window manager:

The bold lines are the lines that have been added by me.

Last step, restart X, then enjoy your extra keys :)


Wednesday, September 19, 2007

Capturing Frames from a USB Camera using OpenCV on Linux

Next step after loading image and manipulating it, I try to access a Linux-USB-registered USB Camera using a simple camera capture framework written in C with OpenCV Library. Here is the code:

// trialcam1a.cpp
// A Simple Camera Capture Framework
// This program will connect to a camera then
// show the frames in a window

#include <stdio.h>
#include <cv.h>
#include <highgui.h>

int main()
IplImage *frame = NULL; //Preparing frame pointer
int key;

//Allocates and initializes cvCapture structure

// for reading a video stream from the camera.
//Index of camera is -1 since only one camera

// connected to the computer or it does not
// matter what camera to use.
CvCapture *input_camera = cvCaptureFromCAM(-1);

//Grabs and returns a frame from camera

frame = cvQueryFrame

//Creates window for displaying the frames
//Flag is reset (0) --> change window size
// manually

cvNamedWindow("Capturing Image ...", 0);

//Change to the appropriate size. In GTK, the
// inappropriate size will return a segmentation
// fault. I don't know why ...
//Gets the appropriate size using cvGetCaptureProperty
// as property_id
cvResizeWindow("Capturing Image ...",
(int) cvGetCaptureProperty(input_camera, CV_CAP_PROP_FRAME_HEIGHT),

(int) cvGetCaptureProperty(input_camera, CV_CAP_PROP_FRAME_WIDTH));

while(frame != NULL)
//Shows a frame
cvShowImage("Capturing Image ...", frame);

//Checks if ESC is pressed and gives a delay
// so that the frame can be displayed properly

key = cvWaitKey(10);
if(key == 27)

//Grabs and returns the next frame
frame = cvQueryFrame(input_camera);

//Release cvCapture structure

//Destroy the window
cvDestroyWindow("Capturing Image ...");

return 0;

Compiling (in the working directory):
$ g++ -Wall trialcam1a.cpp -o trialcam1a `pkg-config --cflags --libs opencv`

Running (in the working directory):
$ ./trialcam1a


dmesg when I plugged USB Camera:
usb 3-1: new full speed USB device using uhci_hcd and address 2
usb 3-1: configuration #1 chosen from 1 choice
Linux video capture interface: v2.00
pwc: Philips webcam module version 10.0.13 loaded.
pwc: Supports Philips PCA645/646, PCVC675/680/690, PCVC720[40]/730/740/750 & PCVC830/840.
pwc: Also supports the Askey VC010, various Logitech Quickcams, Samsung MPC-C10 and MPC-C30,
pwc: the Creative WebCam 5 & Pro Ex, SOTEC Afina Eye and Visionite VCS-UC300 and VCS-UM100.
pwc: Logitech QuickCam 4000 Pro USB webcam detected.
pwc: Registered as /dev/video0.
usbcore: registered new interface driver Philips webcam
usbcore: registered new interface driver snd-usb-audio

Camera driver: pwc.
Camera interface: v4l (Video for Linux).

  • OpenCV wiki (
  • Introduction to programming with OpenCV, by Gady Agam (
  • Linux-uvc-devel mailing list, January 2007 archieve, e-mail posting by Jose Luis Landabaso

Monday, September 17, 2007

Compiling OpenCV Program on Linux

After OpenCV installation, I try to make a simple OpenCV program that loads an image from file, clones it, inverts it, and displays it at monitor, then, compile it on Linux. Here is the code:

// trial1a.cpp
// This is a simple, introductory OpenCV Program. The program will
// read an image from a file, clone it, invert it, and display the
// result.

#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <cv.h>
#include <highgui.h>

int main(int argc, char *argv[])
IplImage* img = 0;
IplImage* img1 = 0;
int height,width,step,channels;
uchar *data;
int i,j,k;

printf("Usage: main \n\7");

//load an image
printf("Could not load image file: %s\n",argv[1]);

//clonning the image before processing

//get the image data
data=(uchar *)img->imageData;
printf("Processing a %dx%d image with %d channels\n",height,width,channels);

//create a window
cvNamedWindow("Image Window",CV_WINDOW_AUTOSIZE);
cvMoveWindow("Image Window",0,0);

//show the original image
cvShowImage("Image Window",img1);
//wait for input any key

//invert the image

//create another window
cvNamedWindow("Invert Image Window",CV_WINDOW_AUTOSIZE);
cvMoveWindow("Invert Image Window",500,0);

//show the inverted image
cvShowImage("Invert Image Window",img);
//wait for input any key

//release the image
return 0;

After typing and saving it using Kate Editor, I compile using gcc with command (in the working directory):
$ g++ -Wall trial1a.cpp -o trial1a `pkg-config --cflags --libs opencv`
Note that the option `pkg-config --cflags --libs opencv` will inserts -I/usr/local/include/opencv -L/usr/local/lib -lcxcore -lcv -lhighgui -lcvaux -lml automatically to the command. If that is not working, you can try this:
$ g++ -Wall trial1a.cpp -o trial1a -I/usr/local/include/opencv -L/usr/local/lib -lcxcore -lcv -lhighgui -lcvaux -lml

Next, if there are no errors, I type (in the working directory):
$ ./trial1a foto.jpg
Then ... (see screenshots)

  • OpenCV wiki (
  • Introduction to programming with OpenCV, by Gady Agam (

Installing OpenCV from source, especially on x86_64 Linux system that has multilib support

Yesterday, I spent many hours to find out why I could not use OpenCV in Slamd64 after compiling and installing from the source. Finally, I found the problem: something related to multilib support in Slamd64, especially when I configured OpenCV to use GTK+-2.0. In Slamd64 system that has multilib support, it has two version of GTK+-2.0, i.e. 32-bit version and 64-bit version. Until now, I don't understand, when in the configuring process of OpenCV source, why that process "choose" the 32-bit version of GTK+-2.0 instead of 64-bit version, so that, I got error in compiling process and if didn't get error, ld could not link the OpenCV library to my program when I run gcc. I will check later if I have time :)

How to Compile OpenCV from source, especially on x86_64 Linux system that has multilib support
Note for user that doesn't use x86_64 Linux OS: after first step, you can skip the second.
First, make sure ffmpeg has been installed. Read the INSTALL documentation in OpenCV source tree. Other libraries that may be needed such as xine-lib, ieee1394 library (libraw1394 and libdc1394), video for linux (usually already included in kernel), libjpeg, zlib, libpng, libtiff, libjasper, libIlmImf are optional. Make sure to install those libraries before configuring/compiling OpenCV if it's necessary.
Second, to make sure the configuring process of OpenCV source "choose" the 64-bit version of GTK+-2.0, you have to edit 2 lines from the configure file in OpenCV source tree because you cannot add them as options when you type ./configure on bash prompt :(

  • find this line: GTK_LIBS=`$PKG_CONFIG --libs ""gtk+-2.0 gdk-pixbuf-2.0""`
  • change to this (NOTE THAT THE CODE MAY VARY IN YOUR SYSTEM!): GTK_LIBS="-L/usr/lib64 -lgtk-x11-2.0 -lgdk-x11-2.0 -latk-1.0 -lpangocairo-1.0 -lpango-1.0 -lcairo -lgdk_pixbuf-2.0 -lm -lgobject-2.0 -lgmodule-2.0 -ldl -lglib-2.0"
How to get "-L/usr/lib64 ..."?
$ pkg-config --libs ""gtk+-2.0 gdk-pixbuf-2.0""
You will get: -L/usr/lib -lgtk-x11-2.0 -lgdk-x11-2.0 -latk-1.0 -lpangocairo-1.0 -lpango-1.0 -lcairo -lgdk_pixbuf-2.0 -lm -lgobject-2.0 -lgmodule-2.0 -ldl -lglib-2.0
Copy that line to configure file and change /usr/lib to /usr/lib64.

  • find this line: GTK_CFLAGS=`$PKG_CONFIG --cflags ""gtk+-2.0 gdk-pixbuf-2.0""`
  • change to this (NOTE THAT THE CODE MAY VARY IN YOUR SYSTEM!): GTK_CFLAGS="-DPNG_NO_MMX_CODE -I/usr/include/gtk-2.0 -I/usr/lib64/gtk-2.0/include -I/usr/include/atk-1.0 -I/usr/include/cairo -I/usr/include/pango-1.0 -I/usr/include/glib-2.0 -I/usr/lib64/glib-2.0/include -I/usr/include/freetype2 -I/usr/include/libpng12"
How to get "-DPNG_NO_MMX_CODE -I/usr/include/gtk-2.0 ..."?
$ pkg-config --cflags ""gtk+-2.0 gdk-pixbuf-2.0""
You will get: -DPNG_NO_MMX_CODE -I/usr/include/gtk-2.0 -I/usr/lib/gtk-2.0/include -I/usr/include/atk-1.0 -I/usr/include/cairo -I/usr/include/pango-1.0 -I/usr/include/glib-2.0 -I/usr/lib64/glib-2.0/include -I/usr/include/freetype2 -I/usr/include/libpng12
Copy that line to configure file and change /usr/lib/gtk-2.0/include to /usr/lib64/gtk-2.0/include

  • find this line: GTHREAD_LIBS=`$PKG_CONFIG --libs ""gthread-2.0""`
  • change to this: GTHREAD_LIBS="-L/usr/lib64 "`$PKG_CONFIG --libs ""gthread-2.0""`

$ ./configure --with-xine --with-ffmpeg --with-1394libs --with-v4l --with-gtk --without-quicktime
It indicates that OpenCV uses xine, ffmpeg, ieee1394, video for linux, and GTK+-2.0 libraries but disables quicktime library. OpenCV will be installed in default prefix (/usr/local) For detailed options, type ./configure --help
Here is some results of the configure in my laptop:
checking build system type... x86_64-unknown-linux-gnu
checking host system type... x86_64-unknown-linux-gnu
checking target system type... x86_64-unknown-linux-gnu
checking Carbon/Carbon.h usability... no
checking Carbon/Carbon.h presence... no
checking for Carbon/Carbon.h... no
checking for pkg-config... /usr/bin/pkg-config
checking for "gtk+-2.0 gdk-pixbuf-2.0"... yes
checking GTK_CFLAGS... -DPNG_NO_MMX_CODE -I/usr/include/gtk-2.0 -I/usr/lib64/gtk-2.0/include -I/usr/include/atk-1.0 -I/usr/include/cairo -I/usr/include/pango-1.0 -I/usr/include/glib-2.0 -I/usr/lib64/glib-2.0/include -I/usr/include/freetype2 -I/usr/include/libpng12
checking GTK_LIBS... -L/usr/lib64 -lgtk-x11-2.0 -lgdk-x11-2.0 -latk-1.0 -lpangocairo-1.0 -lpango-1.0 -lcairo -lgdk_pixbuf-2.0 -lm -lgobject-2.0 -lgmodule-2.0 -ldl -lglib-2.0
checking for "gthread-2.0"... yes
checking GTHREAD_CFLAGS... -pthread -I/usr/include/glib-2.0 -I/usr/lib64/glib-2.0/include
checking GTHREAD_LIBS... -L/usr/lib64 -pthread -lgthread-2.0 -lglib-2.0
checking xine.h usability... yes
checking xine.h presence... yes
checking for xine.h... yes
checking for xine_init in -lxine... yes
checking ffmpeg/avcodec.h usability... yes
checking ffmpeg/avcodec.h presence... yes
checking for ffmpeg/avcodec.h... yes
checking for avcodec_decode_video in -lavcodec... yes
checking for av_open_input_file in -lavformat... yes
checking libraw1394/raw1394.h usability... yes
checking libraw1394/raw1394.h presence... yes
checking for libraw1394/raw1394.h... yes
checking for raw1394_new_handle in -lraw1394... yes
checking libdc1394/dc1394_control.h usability... yes
checking libdc1394/dc1394_control.h presence... yes
checking for libdc1394/dc1394_control.h... yes
checking for dc1394_camera_on in -ldc1394_control... yes
checking linux/videodev.h usability... yes
checking linux/videodev.h presence... yes
checking for linux/videodev.h... yes
checking for linux/videodev2.h... yes
checking jpeglib.h usability... yes
checking jpeglib.h presence... yes
checking for jpeglib.h... yes
checking for jpeg_destroy_decompress in -ljpeg... yes
checking zlib.h usability... yes
checking zlib.h presence... yes
checking for zlib.h... yes
checking for gzopen in -lz... yes
checking png.h usability... yes
checking png.h presence... yes
checking for png.h... yes
checking libpng/png.h usability... yes
checking libpng/png.h presence... yes
checking for libpng/png.h... yes
checking for png_read_image in -lpng12... yes
checking for png_get_valid... yes
checking for png_set_tRNS_to_alpha... yes
checking tiff.h usability... yes
checking tiff.h presence... yes
checking for tiff.h... yes
checking for TIFFReadRGBAStrip in -ltiff... yes
checking jasper/jasper.h usability... yes
checking jasper/jasper.h presence... yes
checking for jasper/jasper.h... yes
checking for jas_image_readcmpt in -ljasper... yes
checking ImfCRgbaFile.h usability... no
checking ImfCRgbaFile.h presence... no
checking for ImfCRgbaFile.h... no
configure: Checking for necessary tools to build python wrappers
checking for python... /usr/bin/python
checking for python version... 2.5
checking for python platform... linux2
checking for python script directory... ${prefix}/lib64/python2.5/site-packages
checking for python extension module directory... ${exec_prefix}/lib64/python2.5/site-packages
configure: PYTHON_CSPEC=-fPIC -I/usr/include/python2.5
configure: PYTHON_LSPEC= -L/usr/lib64/python2.5/config -lm -lpthread -ldl -lutil -lpython2.5 -Xlinker -export-dynamic
checking Python.h usability... yes
checking Python.h presence... yes
checking for Python.h... yes
configure: creating ./config.status
config.status: creating Makefile
config.status: creating opencv.pc
config.status: creating opencv.spec
config.status: creating docs/Makefile
config.status: creating data/Makefile
config.status: creating cxcore/Makefile
config.status: creating cxcore/include/Makefile
config.status: creating cxcore/src/Makefile
config.status: creating cv/Makefile
config.status: creating cv/include/Makefile
config.status: creating cv/src/Makefile
config.status: creating cvaux/Makefile
config.status: creating cvaux/include/Makefile
config.status: creating cvaux/src/Makefile
config.status: creating ml/Makefile
config.status: creating ml/include/Makefile
config.status: creating ml/src/Makefile
config.status: creating otherlibs/Makefile
config.status: creating otherlibs/highgui/Makefile
config.status: creating apps/Makefile
config.status: creating apps/haartraining/Makefile
config.status: creating apps/haartraining/include/Makefile
config.status: creating apps/haartraining/src/Makefile
config.status: creating interfaces/Makefile
config.status: creating interfaces/swig/Makefile
config.status: creating interfaces/swig/filtered/Makefile
config.status: creating interfaces/swig/general/Makefile
config.status: creating interfaces/swig/python/Makefile
config.status: creating tests/Makefile
config.status: creating tests/python/Makefile
config.status: creating tests/cv/Makefile
config.status: creating tests/cv/src/Makefile
config.status: creating tests/cxts/Makefile
config.status: creating tests/cxcore/Makefile
config.status: creating tests/cxcore/src/Makefile
config.status: creating utils/Makefile
config.status: creating samples/Makefile
config.status: creating samples/c/Makefile
config.status: creating samples/python/Makefile
config.status: creating cvconfig.h
config.status: cvconfig.h is unchanged
config.status: executing depfiles commands

General configuration ================================================
Compiler: g++
CXXFLAGS: -Wall -fno-rtti -pipe -O3 -fomit-frame-pointer

Install path: /usr/local

HighGUI configuration ================================================

Windowing system --------------
Use Carbon / Mac OS X: no
Use gtk+ 2.x: yes
Use gthread: yes

Image I/O ---------------------
Use libjpeg: yes
Use zlib: yes
Use libpng: yes
Use libtiff: yes
Use libjasper: yes
Use libIlmImf: no

Video I/O ---------------------
Use QuickTime / Mac OS X: no
Use xine: yes
Use ffmpeg: yes
Use dc1394 & raw1394: yes
Use v4l: yes
Use v4l2: yes

Wrappers for other languages =========================================
Python yes

Additional build settings ============================================
Build demo apps yes

Now run make ...

ATTENTION: highgui will be built with xine support,
thus it will be a subject to GNU Public License

Fourth and next ..., if there are no errors, then
$ make
# make install
Make sure you have root privilege to run make install.

Wednesday, September 12, 2007

Installing digikam from source on Slamd64/Slackware

Last year, I bought digital camera, Canon Powershot A430, but, I never used my camera (read: download the images to PC) in Linux because Slamd64/Slackware could not detect it automatically. Today, finally .... the camera can be detected automatically so that I can download the images from that camera to PC using digikam. The software, digikam, and its dependencies has been installed by compiling them from source. I don't use Slackware's tgz because my system is x86_64 and, also, I prefer to install from source rather than install using any package management.

First step, I downloaded all sources that I needed:
  • exiv2-0.15
  • jasper-1.900.1
  • libgphoto2-2.4.0
  • libkdcraw-0.1.1
  • libkipi-0.1.5
  • libkexiv2-0.1.5
  • sqlite-3.4.2
  • digikam-0.9.2

Second step, I compiled and installed them one by one with the order same as that of I downloaded. There're some notes:
  • I added the option "--enable-shared" (the default is static). If not being added, digikam could not detect libjasper.
  • people can use specific driver when compiling libgphoto2 using option "--with-driver= ...." in configure. The default is all. I chose same as the default.
  • I used the option "--with-tcl=/usr/lib64" in configure before compiling sqlite. Without that option, the configure script could not find tcl in my system.
After installing digikam, I got a problem that the digikam could not detect my camera. There is an answer from denic's blog ( that I have to edit file /etc/udev/rules.d/50-udev.rules in section # libusb device access; add , MODE="0666" after the text SUBSYSTEM=="usb_device", PROGRAM="/bin/sh -c 'X=%k X=$${X#usbdev}; B=$${X%%%%.*}; D=$${X#*.}; echo bus/usb/$$B/$$D'", SYMLINK+="%c"
Next step, I stopped HAL, messagebus, and udev services, then, I started those service again.

After all step ... digikam can detect my camera and download the images easily in PTP mode.

Note that, by default, Slackware/slamd64 is not activating HAL service. If you activate HAL service, you will see the window below:

Thursday, September 6, 2007

I fall in love with Slackware

That is true ... I fall in love with Slackware. First time I used Linux in the end of 2003, I installed Mandrake 9.1 (now Mandriva) on my PC, but, in the third month after installed, I was boring with that distro. I wanted something that gave me a big challenge. Then, I chose Slackware 9.1 in the beginning of 2004. First time using Slackware ... very stressful ... but ... I didn't give up ... then ... I was surprised, I became know about many processes related to how to operating system works ... and the most important thing ... I got "my own desktop" so that I can said "what do you see on screen is me" :) Thank's to Patrick Volkerding and the Slackware team for the BEST Linux distribution (your mileage may vary).

In October 2006, I bought my first laptop (thank's to Ubaya and Mr. Yohanes G. Yusuf that help me financially to buy that laptop), a local trademark laptop: Relion TW12KM (AMD Turion64 1.8GHz, 1GB RAM, 60GB HDD, DVD-RW, 12.1" XGA TFT). When I was going to install Linux, I rather disappointed cause Slackware didn't have a x86_64 version (Until now, AFAIK, Pat don't have plan to release x86_64 version) ... oh .. no ... Did I had to "divorce" with Slackware? In the next few days, I got a good news from internet after searching using Google (thank's to Google for a wonderful search engine), there was a unofficial port of Slackware for x86_64 machine, that is, Slamd64 ( Thank's to Fred Emmott for this project, so that, until now, I can "live" with Slackware.

Here is the screenshot of Slamd64-current that running in my laptop:

I have changed the default icons using nuvoX 0.4. Also, I use Plastik as KDE Manager. The color of the desktop is contrast with the white case of my laptop.

Monday, August 27, 2007

First Posting

Hi ...
This is my first posting in my blog. I've never use blog, so, this is also the first time for me to write blog. I hope, I can share something to all of my reader's blog regularly :)