Thursday, August 26, 2010
Compiling cpp with gcc
Tuesday, August 24, 2010
The Old "new"
Saturday, August 21, 2010
Dual booting on my phone
Friday, June 18, 2010
awk------ a jewel...
Its been a long time friends, since i last posted.
So what's better to reboot the posting spree than Linux.
awk is the focus today.
This post is not supposed to be an extended tutorial, but just a reference for novices and first timers.
awk is not just a simple command, its an interpreter, well atleast sort of.
you can write awk scripts, and rule the world :)
consider a condition in which you want to print the second column of every line of the input, which can be a file or even the output of some command piped through.
ls -l | awk '{print $2}'
this command does it all, takes the input from ls command and prints the 2nd column.
and its just not that you can even use if/for/while etc.
So, jump into the depths of awk.
More is coming.
Monday, May 24, 2010
N900:- absolute beauty
Am writing this post from my N900 itself. This phone has got a variant of debian on it. And with intel and nokia's Meego OS coming soon, this phone will have a multiboot options in Maemo and Meego.
Will post more about my adventures with this wonderful device incourse.
Monday, April 26, 2010
Searching 2.0 ---- new frontiers
As far as searching for a book or textual logo goes it can be easily implemented using OCR to extract the text from the image and then searching the text which was earlier extracted from the image.
OCR stands for "Optical character recognition". It is widely used to convert books and documents into electronic files, to computerize a record-keeping system in an office, or to publish the text on a website. OCR makes it possible to edit the text, search for a word or phrase, store it more compactly, display or print a copy free of scanning artifacts, and apply techniques such as machine translation, text-to-speech and text mining to it. OCR is a field of research in pattern recognition, artificial intelligence and computer vision.
In this blog post, We will be discussing how to easily extract text from images ourselves and then implement out own visual searching service.
For the purpose of extracting text from the image we will be using The "Tesseract OCR engine". The Tesseract OCR engine was one of the top 3 engines in the 1995 UNLV Accuracy test. Between 1995 and 2006 it had little work done on it, but it is probably one of the most accurate open source OCR engines available. The source code will read a binary, grey or color image and output text. A tiff reader is built in that will read uncompressed TIFF images, or libtiff can be added to read compressed images.
As a wrapper for this engine we will be writing a script in python using an opensource python project called "PyTesser".
PyTesser is an Optical Character Recognition module for Python. It takes as input an image or image file and outputs a string.
PyTesser uses the Tesseract OCR engine (an Open Source project at Google), converting images to an accepted format and calling the Tesseract executable as an external script. A Windows executable is provided along with the Python scripts. The scripts should work in Linux as well.
The example we are going to discuss here is tested on python 2.5, but it should work with newer versions barring version 3.0.
Another component which needs to be added to the python2.5 is PIL. It is required to work with images in memory. PyTesser has been tested with Python 2.5 in Windows XP.
So, now moving on to more exciting part, i.e actually getting something done. Download and extract the PyTesser into the scripts folder of python25 dir. Tesseract OCR engine's binary is included with the PyTesser archive.
We have used IDLE editor for python coding, any other can be used. Eclipse too can be used for python development with "pydev" plugin installed.
After setting up the environment paste this code in the newly initiated project/file.
from pytesser import * # import all packages from pytesser script
image = Image.open('fnord.tif') # Open image object using PIL
print image_to_string(image) # Run tesseract.exe on image
print image_file_to_string('fnord.tif')
We have used the example image provided with the PyTesser package here. Running this code will analyze the image and after extracting the text embedded in the image will print it on the console.
So, now we have to use the extracted text for searching.
This relatively simple thing can be used for multiple scenarios, one can be getting info about the latest offer for a product, or searching for different branches of a chain of stores. Lets discuss the endless possibilities and unleash our creativity here.
Download Links:
python imaging library ( PIL ) : http://www.pythonware.com/products/pil/
PyTesser : http://code.google.com/p/pytesser/
Tesseract OCR engine : http://code.google.com/p/tesseract-ocr/
Saturday, April 17, 2010
Structures and Classes in c++
But most people ignore the fact that structs have been totally reinvented in c++.
The only difference between struct and class in c++ is that by default everything is public in structs and private in classes, even the default inheritance in struct is public.
thats all the difference between structs and classes, then why in recent programming practices structs have been totally ignored.
structs can be safely initialized using constructors, they can have polymorphic nature, support late binding, in short everything you need to write good OO code.
check out the code given below.
#include
using namespace std;
struct Whatever
{
virtual void foo() { }
virtual ~Whatever() { }
};
struct Derived : Whatever
{
void foo() { cout << "value=" << value; }
Derived(int n) : Whatever(), value(n) { }
private:
int value; // private data member
};
int main()
{
Whatever *pW = new Derived(10);
pW->foo(); // virtual call
delete pW;
return 0;
}
IMHO struct are fighting a loosing battle because of the mindset of the developers, We have been taught C++ means classes, C++ even started out as "C with classes".
anything which needs an aggregate data type can be implemented using structs and anything needed as a complex data type adhering to OOPS principles, representing some real world object needs to be implemented in terms of classes.
There is no problem in using classes or structs for that matter, just need to open our minds to the realities of C++ , rather than following and believing in myths.
Saturday, March 20, 2010
const in c++ ---- storage and linkage
This is the one thing which most people are unaware of in c++. Constants do not behave like normal types, i know you must be thinking that you knew this already, they are constants.
but wait for me to finish.
1.> STORAGE POINT OF VIEW
globally declared const variables are not allocated any storage space by default, compiler makes a mere entry of it in its symbol table.
This is done for the sake of optimization, as compilers in case of const implement constant folding.
Any other global variable ( non const ) is allocated memory.
But we can force the compiler to allocate memory to a const global variable by
--> passing it to a function as an argument
--> storing its address
Its because of this, linkage for const variables are also imlemented in a different manner.
2.> LINKAGE POINT OF VIEW
const by default has internal linkage, this is due to the fact that its not allocated any memory.
Consider the expression
external int a;
This line tells the compiler that this is a mere definition and declaration for this variable is given else where. When a variable is declared it is allocated some memory, which is not the case with const variables, Hence the need of keeping the default linkage as internal.
As we have seen earlier how compiler can be forced to allocate memory to a const variable, well there is one more way
By explicitly declaring the const variable as external. Which changes its linkage and as its linkage is external now compiler allocates the memory to the variable.
Hence for making a const variable external we need to specifically declare it as
extern const int a;
Hope this make the things a bit clear.
Monday, March 15, 2010
Free Software : The Practical Perspective
And I in no way am an expert on this, its just what i see after a very short career in software field, may be my views are wrong but this i what i have understood so far. So please bear with my ignorance in case i am wrong.
The good versus evil debate has been raging since Richard Stallman started the “Free Software Movement” at the MIT lab.
Before starting off with the article i would like to make it clear that “Free Software” and “Open source Software” are two completely different things. Free software is always free, non free software is seen as a social evil, on the other hand Open source software is not always free.
As specified by RMS is his essay “Why Free Software is better than Open Source”
The fundamental difference between the two movements is in their values, their ways of looking at the world. For the Open Source movement, the issue of whether software should be open source is a practical question, not an ethical one. As one person put it, “Open source is a development methodology; free software is a social movement.” For the Open Source movement, non-free software is a suboptimal solution. For the Free Software movement, non-free software is a social problem and free software is the solution.
Now coming back to the article, RMS in an interview in the Documentary "Revolution OS" says free software is a way of living in the society,small children are taught in schools to share their lunch with others, good neighbours help each other, its a way of living in harmony with the society.
I completely agree with RMS here, but only on a philosophical level, what he suggest here is a perfect condition of a perfect society, but the society is not perfect. every thing cannot be shared. you don't share your money with others, software is a way of earning money for people, programmers earn their living with it.
Don't get me wrong , I myself use Slackware and Ubuntu on my machine, and the proprietary drivers provided by ATI for my graphics chip works better than the opensource alternative, so i use the ATI ones and have no problem in doing so.
What RMS is preaching is a world altering philosophy, but as it happens with every other radical preacher, it will not be accepted by the masses, unless until by some unseen trend in market makes software profits redundant.
And i am also staunchly opposed to the closed sourced corporation like microsoft n googles of the world, Opensource movement seems to be the correct way to go right now. We have to attain a balance and live with the necessary evil, the need to earn money.