Monday, February 25, 2008

Accesing a veriable defined in another file in C++

This might be a very simple thing to most of the programmers. But I thought of writing this in my blog as I spent half a day finding a way to access a variable in .cpp from another .cpp(without importing the .h or defining as public inside a class.)

suppose the variable we want to access is defined as follows in the original file,

bool flag;

if you want to access this from another .cpp simply you have to do is define it with extern key word in that file,

i.e extern bool flag;

both declarations refer to the same variable "flag".

Friday, February 22, 2008

C++ threading in windows

Any one had trouble in implementing threading in C++(well, I had, as C++ directly not providing threading) . We have to use the treading support in the windows API. But it is bit difficult to directly code to the windows API using "windows.h". while I 'm searching I found the article "C++ And Threads, by Randy Charles Morin" which has implemented the threading in C++ very effectively. If you are interested I recommend you to go through it. here is the link

http://www.kbcafe.com/articles/HowTo.Thread.pdf

Thursday, February 21, 2008

Bug in OpenCV

I wanted to capture an image from the web cam and convert that to gray scale in my application. I use openCV to do that. But when I directly convert the captured image to gray scale it returned a horizontally flip gray image of the original. but if I load an image using cvLoadImage() and then convert it to gray scale there was no problem. No flipping is involved. I think this was a bug in openCV. Correct me if I am wrong.

here is the code that cause the flipping,

CvCapture* capture = cvCaptureFromCAM( CV_CAP_ANY );
IplImage* frame = cvQueryFrame( capture );

IplImage* gray = cvCreateImage( cvGetSize(frame), 8, 1 );
cvCvtColor( frame, gray, CV_BGR2GRAY );

Sunday, February 3, 2008

Einstein's Challenge

Would you like some brainstorming challenge. Here it is. It is often called "Einstein's Puzzle" or "Einstein's Riddle" because it is said to have been invented by Albert Einstein as a boy. Some claim that Einstein said "only 2 percent of the world's population can solve it". But I believe it should be more than 2% if they given sufficient time. so here it is, ENJOY !!!!!!!!!!!!!!!

There are 5 houses in 5 different colors. In each house lives a person with a different nationality. The 5 owners drink a certain type of beverage, smoke a certain brand of cigar, and keep a certain pet. No owners have the same pet, smoke the same brand of cigar, or drink the same beverage.
  • The British lives in the red house.
  • The Swedish keeps dogs as pets.
  • The Danish drinks tea.
  • The green house is on the left of the white house.
  • The green homeowner drinks coffee.
  • The person who smokes Pall Mall rears birds.
  • The owner of the yellow house smokes Dunhill.
  • The man living in the center house drinks milk.
  • The Norwegian lives in the first house.
  • The man who smokes Blend lives next to the one who keeps cats.
  • The man who keeps the horse lives next to the man who smokes Dunhill.
  • The owner who smokes Bluemaster drinks beer.
  • The German smokes prince.
  • The Norwegian lives next to the blue house.
  • The man who smokes Blend has a neighbor who drinks water.
the question is , Who owns the fish?


try it your self, it's fun. Here is the answer..........................

But don't look at it till you finished.




House 1

House 2

House 3

House 4

House 5

Nationality

Norwegian

Dane

Brit

German

Swede

Color

Yellow

Blue

Red

Green

White

Pet

Cats

Horses

Birds

Fish

Dog

Beverage

Water

Tea

Milk

Coffee

Beer

Cigarettes

Dunhill

Blend

Pall Mall.

Prince

Blue Mstr