Saturday, December 29, 2012

Using OpenCV in GTK sample program "Inverting an image on Image Processing"

In this article I want to show you How we can use the OpenCV on GTK (GIMP toolkit) on fedora.Although GTK+ is a GNU project like the GMP, it is released under the terms of the more liberal LGPL(lesser general public license) that permits software (including closed source proprietary software) to be written using GTK+ without payment of fees, royalties, or other restirictions. The freedom offered by the GTK+ license is in contrast to its competitor QT(you must instead purchase a commercial Qt license in that case).
This program is compile using gcc compiler on fedora. At first you need to install the gtk and gnome on your machine.
In fedra that use RPM packages, you should have at least install the following RPM package.
$  su

$  yum install gtk2
$  yum install gtk2-devel
$  yum install gtk2-engines
$  yum install libgnome-
$  yum install libgnome-devel
$  yum install libgnomeui
$  yum install libgnomeui-devel

Now its time to install OpenCV package.

Using semaphore to synchronize the multiple thread using c on linux/fedora

Semaphore is a new type of variable introduced by E. W. Dijkstra. You may learn about semaphores in university. It is used to solve the Producer-Consumer Problem in Operation system design which I have learn in books "Modern Operating Systems " (second edition) by Andrew S. Tanenbaum. In that books the algorithm for semaphore is clearly defined and easy to understand. But I was always curious about that "Does this type of problem occur on our program?" rather than operating system design and "Where can I use it?". When I begin to learn linux programming I found the semaphore function under <semaphore.h> header and example program where semaphore is used to synchronize the thread.
In this article we look at the simplest type of semaphore, a binary semaphore that takes only values 0 or 1. There is also a more general semaphore that takes a wider range of values. Normally, semaphores are used to protect a piece of code so that only one thread of execution can run it at any one time.The semaphore functions do not start with pthread_,as most thread-specific functions do,but with sem_. Four basic semaphore functions are used in threads. They are all quite simple.

Friday, December 28, 2012

Threads Program using c on linux/fedora


This program creates a single extra thread, shows that it is sharing variables with the original thread, and gets the new thread to return a result to the original thread. Multithreaded programs don't get much simpler than this.
Lets look the function which create the thread. pthread_create creates a new thread,much as fork creates a new process.
#include<pthread.h>
int pthread_create(pthread_t *thread, pthread_attr_t *attr, void(*start_routine)(void *), void *arg);
The first argument is a pointer to pthread_t . When a thread is created, an identifier is written to the memory location to which this variable points.This identifier enables you to refer to the thread . The next argument sets the thread attributes. You do not usually need any special attributes, and you can simply pass NULL as this argument. Later is the chapter you will see how to use these attributes. The final two arguments tell the thread the function that it is to start executing and the arguments that are to be passed to this function.

Tuesday, December 25, 2012

Bash Shell Scripting example project "library management"



This program is a sample shell script. To understand this project you must know the basic syntax of shell programming. In this article I tried to show an example how we can use a shell as a programming language. I have build the very simple shell script for managing a library books. If you are completely new to shell programming in Linux then at search the following topic on Google about their syntax and uses before proceeding this article. List of topic are:
  1. variables
  2. if condition
  3. switch case
  4. printf ,read , echo command
  5. while loop, for loop
  6. grep command
  7. function declaration
Now if you have learn above topic in shell programming then you can understand this project library management. In this project simple features are included like adding books, editing books information,remove and search books and view all books. Lets start the project.

Saturday, December 1, 2012

Creating Static Libraries using c on linux Fedora.

You have seen the library file  ".lib" extension on Windows and a ".a" on LINUX/UNIX.If you are unknown about what are they and how to create them then you will get answer here.
These are Static Library files, also known as archives, which are simply a collection of ordinary object files. It is a set of routines, external functions and variables which are resolved in a caller at compile-time and copied into a target application by a compiler, linker, or binder, producing an object file and a stand-alone executable. Simply we can say it permit users to link to programs without having to recompile its code, saving recompilation time.
There are several advantages of static libraries:
1.The most significant is that the application can be certain that all its
    libraries are present and that they are the correct version. This avoids
    dependency problems.
2. Result in a significant performance improvement.
3. Can be shared between many applications leading to space savings.
4. It also allows the library to be updated to fix bugs and security flaws
    without updating the applications that use the library.