Archive for November, 2009

Programming a webcam in C using ‘OpenCv library’

 OpenCv library is  really a great help in programing a web-cam.I  tried to access a web-cam through a C code and was succesfull in doing it.Before the code can be executed and the web-cam can be accesed ,a library named ‘opencv’ is to be installed .
                          OpenCV (Open Source Computer Vision) is a library of programming functions for real time computer vision . OpenCV is released under a BSD license, it is free .

The library is available in debian distro cd’s and can be installed by issuing the commands

apt-get install opencv*

apt-get install libhighgui*

apt-get install libaux-dev

  •   Program in C to access web-cam, Capturing and Saving image

The web-cam can be accessed in C and the images  saved is in .jpg format

A simple program to see the video accessed by the webcam.

 My Cheese app in C.

cheese.c

#include
#include <  opencv/cv.h  >
int main(int argc,char **argv)
{
        cvNamedWindow(“rohit”,CV_WINDOW_AUTOSIZE);
        CvCapture* cap = cvCreateCameraCapture(0);
        IplImage *image1,*image2;
        while(1){
                image1  = cvQueryFrame(cap);
                if(!image1)
                        break;

                cvShowImage(“rohit”,image1);

//waiting 33 milliseconds for a key to be pressed

                char c = cvWaitKey(33);

//if the key pressed is esc
//ascii of esc is 27

                if(c==27)
                        break;
//if the key pressed is an up-arrow key
                else if(c ==’82’)
                {
                        image2 = image1;
                        cvNamedWindow(“rohit photo”,CV_WINDOW_AUTOSIZE);
                        cvShowImage(“rohit photo”,image2);
                        cvSaveImage(“my-photo.jpg”,image2);
                }
        }
        cvReleaseCapture(&cap);
        cvDestroyWindow(“rohit”);
        cvDestroyWindow(“rohit photo”);
}

Compile the above code by executing the command:

gcc -o cheese_in_c cheese.c `pkg-config opencv --cflags --libs `

 this command creates an executable named “cheese_in_c”.
Execute the executable as

 
./cheese_in_c

this program displays a window named “rohit”showing the pictures taken from the webcam,then it waits for 33 milliseconds for the user to press a key.If key pressed is ‘up-arrow’ the picture from the camera is captured and saved in the same directory in the name “my-photo.jpg”.


			

1 Comment

Internet connection through WLL BSNL in linux

I ‘m using a wireless Internet connection (BSNL WLL connction).This post may be of use to newbies in linux ,trying to connect to internet through a dial up connection.The first step to be done is

  • To install ‘wvdial’ 

In debian distro, the package is available in their distribution cd.For installation try the command

apt-get install wvdial

 the package can be downloaded from the link below

http://packages.ubuntu.com/hardy/i386/wvdial/download

the package can then be installed as

dpkg -i wvdial-xx.deb 

  •  configuring the file /etc/wvdial.conf

 now the file /etc/wvdial.conf has to be configured according to connection requirements ,the overall structure of the /etc/wvdial.conf can be obtained from link
http://ranjeethpt.wordpress.com/2009/08/27/working-with-arm-7/

my wvdial.conf file looks like the one below

[Dialer Defaults]
Init1 = ATZ
Init2 = ATQ0 V1 E1 S0=0 &C1 &D2 +FCLASS=0
Init3 = at+crm=1;+cmux=1;+cps=33;+cta=0
Stupid Mode = yes
ISDN = 0
Modem Type = USB Modem
New PPPD = yes
Phone = #777
Modem = /dev/ttyUSB0
Username = xxxxxxx
Password  = xxxxxxx
Baud = 460800

 here in the file for the users using BSNL – WLL  connection have to replace
username  and password provided to them by the service provider
Username = xxxxxxxx
Password = xxxxxxxx

now to be able to use the connection ,first we have to register the dial-up modem to their kernel.as provided in the link

 http://ranjeethpt.wordpress.com/2009/08/27/working-with-arm-7/

then the user can browse onto internet by just dialing

wvdial

in the terminal.

Leave a comment

Mounting a NTFS filesystem in read/write mode in debian (NTFS-3g)

For mounting a disk partition in linux formatted as NTFS file system  in read/write mode or any other file system in debian,  NTFS-3g can be of a great use.For using this to be used the packages are supposed to be installed onto the operating system by first adding all the debian distribution CD’s to the synaptic manager followed by using the command.

apt-get install ntfs-3g

The package ‘NTFS-3G’ can be installed either from debian lenny distribution CD’s .by first
Root previledge is needed for the below commands.

  • first make the destination folder anywhere you want (as i made my destination folder as /media/disk1)

mkdir /media/disk1

  • if you are having a sata hard-disk then try the command

mount -t ntfs-3g /dev/sda5   /media/disk1

or
       if you are having an IDE  hard disk then try the command

mount -t ntfs-3g /dev/hda5  /media/disk-1

  • Mounting disk drives at the startup

 For mounting disk drives at boot-up time. The file /etc/fstab has to be configured .In the file ,under the type bar the file system for ntfs is to mounted under ntfs-3g system.


Leave a comment

DOS in Debian ( a free DOS emulator in linux)

Next week,I am having an examination of Computer hardware lab where all we people are supposed to do
assembly level coding for X86 architecture.In our lab, we used to do coding in Ms-WindowsXp using a software “NASM.exe” (an assembler),although our staff prefers open-source over a proprietory software.
Only hardware lab was there in our college which was still having MS-windows installed on it,all other labs are having open source OS installled in their PC’s.As no awareness about  free software version of NASM and DOSEMU was there with our staff.
This was the time when one of my friend and classmate  Harikrishnan suggested them about  packages  “Dos-Emu”   in LINUX environment

Now ,govt engineering college sreekrishnapuram is one of those engineering colleges in our country where all the computer labs are having open source operating system on each of it’s computer.

The package “dosemu” is available in the latest version of almost every linux distro’s.
For Debian 5.0 lenny the package is available in the cdrom itself,otherwise can be downloaded from the link
http://packages.debian.org/lenny/i386/dosemu/download

the rpm version for redhat distros and package.tar.gz  is available at the link

http://dosemu.sourceforge.net/stable/

I installed it on one of my friend’s PC having a debian lenny distro.As the package was  available with the distro cd ,all i needed to do was to add cdrom in synaptic manager and install the package dosemu.

  • Adding a cdrom in Synaptic Package Manager

         From the
                                 System –  Administration
click open the
                               Synaptic Package Manager
this will prompt for the root password,as the procedure needs root previlege

under the edit tab there is an option “add cdrom”,this may prompt for inserting a cdrom to be added if it is not already inserted.After the cdrom is inserted all the indexes of the package will added into the package list.

  • Installation of dosemu

then package “dosemu “can be installed from the Synaptic Package Manager or it can be instatlled by
the command


sudo apt-get install dosemu

the package will be installed and the dos emulator can be accesed by typing a command

dosemu

in the shell.
This will create a  “.dosemu ” directory  in your login directory (in /home/… directory).In that directory it will create a drive_c directory where the “dosemu ” works .

I hope that this will be a bit usefull to those who are trying to switch onto open-source environment from windows environment like me

  • nasm installation in debian

The package NASM is available with debian lenny distro CD.and is available at

http://packages.debian.org/sid/nasm

can be installed from debian distro cd as

sudo apt-get install nasm

 any .asm file can be assembled by NASM as

 nasm file.asm -fbin -o file.com


which creates a file file.com
this file.com can be executed by executing the file’s name on “dosemu” prompt.

Leave a comment