Tuesday, July 12, 2011

First Program using opencv in Visual Studio 2008

Before you can start programming you will need to set environment. Follow the steps below.

1) Install opencv. Refer http://opencv.willowgarage.com/wiki/InstallGuide. After installing a directory will be created. In my installation it is C:\OpenCV2.1.

2) Start VS2008. Go to File->new->project. Select Visual C++->Win32->Win32 Console Application.

3) Give a name. Click next and then finish. A new project will be created.

4) Go to Project-> Properties.

5) In ‘Property’ dialog go to Config properties->c/c++. In ‘Additional Directories’ option add directory of opencv include files.( C:\OpenCV2.1\include\opencv)

6) Again in same dialog go to Config properties->Linker->General. In ‘Additional Libraries’ option add directory of opencv libraries.( C:\OpenCV2.1\lib)

7) Go to Config properties->Linker->Input. In ‘Additional Dependacies’ option add files ‘cv210d.lib’ ‘highgui210.lib’. These files are library files for respective header files. In this example we are using two header files ‘cv.h’ and ‘highgui.h’.

Now you are set with all requirements. So get ready to start with your first opencv program. In this example we are going to show feed from a video camera.

You will need a camera attached to your computer. It will act as image source. You can use a video file also. Opencv has data structure ‘CvCapture’ representing this image source. Opencv has built in function to create ‘CvCapture’ from camera. Its prototype is

CvCapture * cvCreateCameraCapture(int index)

‘index’ is index of camera. Use -1 for default.

Another data structure is ‘IplImage’. It represents an image.

Following lines captures an image from camera.

CvCapture *c=cvCreateCameraCapture(-1);

IplImage *frame;

frame=cvQueryFrame(c);

cvReleaseCapture( &capture );

‘cvQueryFrame’ function retrieves an image from ‘CvCapture’ and returns an ‘IplImage’. Memory of capture is released by ‘CvReleaseCapture’ function.

To show the captured image we need a user interface. Opencv has provided windows library in ‘highgui.h’ file. Following are basic functions of windows

int cvNamedWindow(const char * name, int flag=1)

It creates a new window with ‘name’.

void cvShowImage(const char * name, const CvArr * image)

It displays image in window named ‘name’. If window is not already created using ‘cvNamedWindow’ function, it creates a window.

void cvDestroyWindow( const char * name)

Using above functions we can write our first program.

#include "cv.h"

#include "highgui.h"

int main(int argc, char* argv[])

{

CvCapture *c=cvCreateCameraCapture(-1);

IplImage *frame;

while(true)

{

frame=cvQueryFrame(c);

cvShowImage("Window",frame);

char ch=cvWaitKey(15);

if(ch==27)

break;

}

return 0;

}

Here we have used ‘cvWaitkey’. It waits 15 msec for any key press. If a key is pressed it returns its ASCII else returns 0. We then compare it with ASCII value of ‘Esc’ and break the while loop. This delay is important otherwise the program will stuck in infinite loop and nothing will be displayed in window.

Cross your fingers and press F5. If you are lucky your program will run without error.

Monday, May 16, 2011

How to prepare for GATE (CS)


Overview:
GATE is an all India examination administered and conducted jointly by the Indian Institute of Science and seven Indian Institutes of Technology on behalf of the National Coordination Board - GATE, Department of Higher Education, Ministry of Human Resource Development (MHRD), Government of India.
Admission to postgraduate programmes with MHRD and some other Government scholarships/assistantships in engineering colleges/institutes is open to those who qualify in GATE examination. GATE qualified candidates with Bachelor's degree in Engineering/Technology/Architecture or Master's degree in any branch of Science/Mathematics/Statistics/Computer Applications are eligible for admission to Master's degree programmes in Engineering/Technology/Architecture as well as for Doctoral programmes in relevant branches of Science with MHRD or other government scholarships/assistantships. To avail the scholarship, the candidate must secure admission to such a postgraduate programme, as per the prevailing procedure of the admitting institution. However, candidates with Master's degree in Engineering/Technology/Architecture may seek admission to relevant Doctoral programmes with scholarship/assistantship without appearing in the GATE examination.
For more information visit-http://www.gate.iitb.ac.in/gate2013/
My View:
GATE is not that much tough if you are strong in academics. It tests your logical thinking and applications of subjects that you have learned in the last three years. But according to me it is easier to get admission in IITs for post-graduation than graduation. You should give extra time and adopt new way to study, because the way we study for university exams is very bad. So you should be willing to give more effort, read more and solve more.
Time to start:
As it is always said, it is better late than never. Good time to start for study is when examination for third year finishes. As it is last year you will be very busy. You will have your final year project, company placements and other extra-curricular activities (as it is last year to do so). In the first sem you can revise subjects up to 3rd year. While doing so use reference books as given in syllabus book. I have uploaded some of them. Many times we have wrong concepts or have fear of some subjects (like TOC, PCD). These books will help you to in both cases. While revising make your own notes. So these can be referred in days before exam. In second sem you need to study extensively.
But if you have less time then it is okay to start with that little time and give a try. Prepare a plan and follow it. In my case I started in January and exam was on 13th feb.
Syllabus:
Syllabus for CS includes following
Mathematical Logic, Probability, Set Theory & Algebra, Combinatorics, Graph Theory, Linear Algebra, Numerical Methods, Calculus
Digital Logic, Computer Organization and Architecture, Programming and Data Structures, Algorithms, Theory of Computation, Compiler Design, Operating System, Databases, Information Systems and Software Engineering, Computer Networks, Web Technologies.
Worried……?
Don’t worry. When you will start studying it from reference books you will enjoy it, believe me.
You should have look at detailed syllabus--
Planning:
Get all books according to syllabus.
Mathematical Logic
Any book will work including text books.
Probability
Set Theory and Algebra
combinatorics
Graph Theory
Linear Algebra
Numerical Methods
Refer any book for mechanical (they have in their syllabus).
Calculus
Refer text book.
Digital Logic
Computer Organization and Architecture
Programming and Data Structures
Algorithms
Theory of Computation
Compiler Design
Operating System
Databases
Information Systems and Software Engineering
Computer Networks
Computer Networks -Tanenbaum A, Data Communications and Networking -Fourauzan B.
Web Technologies
Any book from library.
Now you have all books.
So before you start you should plan for your study. See the syllabus book and mark the points those you should study. You may not want to study the whole book as only part of it will be enough for GATE.
Make a table for yourself with columns such as ‘subject’, ‘reading started’, ‘reading complete’, ‘Questions solved’. Tick the columns as appropriate. It will help you to follow your study and assign the time.
Question Paper:
If you see the question paper pattern, you will notice that you have sufficient time to solve the problems. As each question gets around 2.5 minutes. So give enough time for each question.
The most important thing after you study is solving the question papers. Refer previous years question papers. Various publications have set of previous years question papers with answers and explanation. Answer of some questions may not be correct. But it will give you the idea as what types of questions are asked. Also solve some online question papers with time limit. Various institutes like Vani offer online test series for free. It will help you solving variety of problems.

Few days before exam:
Get an official leave of 10 days before exam. Complete the reading and solving the previous papers. Two days before exam revise all what you have studied from your notes. If you need any books try to use hard copy as it will help to revise faster than soft copy.

!!!!!!!!!!!!!BEST LUCK!!!!!!!!!!!!!!!