How to install OpenCV with Python for Windows?

What is OpenCV?

OpenCV stands for Open Source Computer Vision. It is a library of programming functions mainly aimed at real-time computer vision, developed by Intel Russia research center. As the name suggests, it is free for use under the open source BSD license. The library is cross platform i.e. it can  be used & merged along with the other programming languages. It focuses mainly on real-time image processing. At the time of development, it is written in C/C++.
Python is highly compatible with OpenCV, this is the reason for the selection of Python with OpenCV by most of the developers working on Image Processing.
For further information about OpenCV, one can refer the official website www.opencv.org

Installation guide for OpenCV with Python:

Step I: Download & Install Python

First download Python from www.python.org/download/windows for Windows & install Python 2.7. Leave all settings as default. In that case, Python will be installed in default folder C:\Python27\

Step II: Download & Install Numpy

Now download Numpy from www.scipy.org/scipylib/download.html . Again leave everything default. Numpy will find Python directory and will be installed to most appropriate folder.

Step III: Download & Install OpenCV

Download OpenCV from www.opencv.org/downloads.html & double-click OpenCV.exe. It will ask for the extraction folder. Let it as  just C:\. It will extract all files to C:\opencv\  . Wait until everything is extracted.

Step IV: Copy files to Python from OpenCV

Now copy everything from the folder C:\opencv\build\python\x86\2.7\ ( most probably, there will be only one file i.e. cv2.pyd ) and paste it in the folder C:\Python27\Lib\site-packages\

Step V: Run Python IDLE

Now open “Python IDLE” ( from Start > All Programmes > Python 2.7 > Python IDLE ) and just type following :
import cv2
This will import the cv2 module.

P.S. You can also run the sample files from the folder C:\opencv\samples\python2 by just double-clicking on it.

About these ads

KJSCE Canteen | Android App + HTML5 App

In every college, Canteen is one such place where you find more number of students than you find in a Lecture Hall. People come here to chit-chat, time-pass, eat, treat and hang around. But since the Canteen is crowded most of the times, one can’t get his/her hands on the Menu Card of the Canteen.

I stay in a Hostel & have to visit Canteen most of the times for Lunch. Finding the Menu Card each time, going through it & then deciding what to have & what not was too hectic for me & my friend Sanga. This forced me to think of some solution & I thought of building an Android or a native app. But then building an app is not that easy when you’re not so good at Android Programming. Then I thought of a CMS solution to this and built it in a few days of time.

Here’s the screenshot of the Application & its published page on the Monkey Market.
KJSCE Canteen Logo

Click Here to download the application.
Or visit http://www.fanapp.mobi/kjsce_canteen from any of the Browser which is currently in use on your Device.

Once you’ve installed the application and are well-versed with the functioning of it, please make sure that you fill the Feedback Form which is available under the About section.
Your appreciation & suggestions will help me make it better for me & you both.

P.S. Application also works when you’re disconnected to the internet. Only some links in the About tab won’t function without an active Internet connection.Also this app belongs to only those who eat in K. J. Somaiya College of Engineering, Vidyavihar’s Canteen.

Who will win the ICC World T20, 2014 ?

ICC-T20-World-Cup-2014 LogoThis is the question of the millennium for most of the Cricket Lovers all around the World. People have been guessing, predicting & visualizing their favorite teams as the Winners of the ICC World T20, 2014 which is gonna be played in Bangladesh this year. Due to the introduction of the various domestic T20 leagues like IPL in India, Big Bash League in Australia, BPL in Bangladesh & similar leagues in other Cricket playing nations, the capabilities of both Bowlers & Batsmen have been developed drastically. Improvisation in the fielding was a cause of too much T20 Cricket which made it mandatory to perform exceptionally well in this sector of the Game. Also the better performances by the Associate countries over the past few years have made the game even more competitive. In such a scenario, people have the license to expect some real close shaves during this World T20.

Here’s a list of countries participating in this major Tournament & their probable winning chances based on their Current Form , X-factor & 1 Key Player:

My Predictions for Test Playing Nations
World T20 Predictions for Test Playing Nations

My Predictions for Associate Nations
World T20 Predictions for Associate Nations

 Though I’ve made the predictions based on their mettle, current form & other Cricketing aspects, the predictions remain personal. Result can always be astonishing in Cricket, since “Cricket is a funny Game“. If even you do possess some knowledge about Cricket & take interests in such tournaments, try your luck in Fantasy Games by ESPN Cricinfo or ICC Fantasy League & keep your fingers crossed for the Results.

How to earn Free Recharge ?

Internet is flooded with false & fake tricks about “How to earn Free Recharge?”. But, unfortunately none of them works fine. There Tricks & Treats about the referral network or some or the other hacks to some applications or websites. All of these are certainly to increase the traffic on a particular network. People are misguided on the lines of Free Recharge most of the times in such cases.

Enough of such false practices, finally here’s a technique/treat to earn some extra brownie points :p
An application called hike Messenger for Smart Phone devices gives a simple yet effective solution to this Free Recharge tragedy.

Steps to earn Free Recharge:

  • Download & Install hike Messenger on your Smart Phone.
    P.S. hike is available for iPhone, Android, Windows Phone, BlackBerry, Nokia S40, S60 for Free.
  • You get a Joining Bonus of ₹.15 on installing it on your device.
  • Move towards the Rewards section in the app.
  • Invite your Contacts via Free hike messages.
  • For each successful invite, you’re rewarded by ₹.20. This means ₹.100  Free Recharge just for inviting 5 people.
    Successful Invite refers to getting a Contact to join to hike messsenger.
  • As soon as a Contact joins hike, a pop up notifies you of your Reward.
  • You can redeem the Reward Bonus by entering your Recharge details within the app itself.
    hike messenger uses PayTM for the Mobile Recharge.

hike Rewards screenshot

P.S. In case of multiple invites to a single user, the person who sends the latest invite before the users’ joining will be rewarded with a Recharge Bonus of ₹.20.

Here’s a screenshot of my Recharge Earnings by just using hike messenger. Yes I know you’re amazed  looking at this screenshot, but trust me even you can earn it by simply following the above mentioned steps.

More over hike messenger has some interesting features like 2-way Chat Themes, Offline messaging for Free, Stickers & Graphical Smileys, Media attachment enabled & many more are being added regularly.
So dude & dudettes, rush for your Free Recharges. Happy hiking! ;)

Bezier Curve Algorithm (C++)

Problem Definition: Write a program to analyse and interpret the implementation of Bezier Curves.

#include<iostream.h>
#include<conio.h>
#include<dos.h>
#include<graphics.h>
void main(){
int gd=DETECT,gm;
initgraph(&gd,&gm,”C:\\TC\\BGI”);
int x[4],y[4],px,py,i;
cout<<”Enter four control points of bezier curve: “;
for(i=0;i<4;i++) cin>>x[i]>>y[i];
double t;
for(t=0.0;t<=1.0;t+=0.001){
px=(1-t)*(1-t)*(1-t)*x[0]+3*t*(1-t)*(1-t)*x[1]+3*t*t*(1-t)*x[2]+t*t*t*x[3];
py=(1-t)*(1-t)*(1-t)*y[0]+3*t*(1-t)*(1-t)*y[1]+3*t*t*(1-t)*y[2]+t*t*t*y[3];
putpixel(px,py,WHITE);
delay(2);
}
getch();
closegraph();
}

Sutherland-Hodgeman Polygon Clipping Algorithm (C++)

#include <iostream.h>
#include <conio.h>
#include <graphics.h>
int xl,yl,xh,yh,poly[100],n;
void left_clip(){
int temp[100],i,j=0,count=0,x1,y1,x2,y2;
for(i=0;i<2*n;i+=2){
x1 = poly[i];
y1 = poly[i+1];
x2 = poly[i+2];
y2 = poly[i+3];
if(x1<xl && x2<xl){
//both points outside. Do not store any vertices
}else if(x1>xl && x2>xl){
//both points inside. Store second vertex
temp[j] = x2;
temp[j+1] = y2;
j+=2;
count++;
}else if(x1<xl && x2>xl){
//outside to inside. Store intersection n second vertex
int x=xl;
int y= y1 + (xl-x1)*(float)(y2-y1)/(x2-x1);
temp[j]=x;
temp[j+1]=y;
temp[j+2]=x2;
temp[j+3]=y2;
j+=4;
count+=2;
}else{
//inside to outside. Store intersection only
int x=xl;
int y= y1 + (xl-x1)*(float)(y2-y1)/(x2-x1);
temp[j] = x;
temp[j+1] = y;
j+=2;
count++;
}
}
n=count;
//store 1st vertex as last
temp[j]=temp[0];
temp[j+1]=temp[1];

for(i=0;i<2*(n+1);i++)
poly[i]=temp[i];
}
void right_clip(){
int temp[100],i,j=0,count=0,x1,y1,x2,y2;
for(i=0;i<2*n;i+=2){
x1 = poly[i];
y1 = poly[i+1];
x2 = poly[i+2];
y2 = poly[i+3];
if(x1>xh && x2>xh){
//both points outside. Do not store any vertices
}else if(x1<xh && x2<xh){
//both points inside. Store second vertex
temp[j] = x2;
temp[j+1] = y2;
j+=2;
count++;
}else if(x1>xh && x2<xh){
//outside to inside. Store intersection n second vertex
int x=xh;
int y= y1 + (xh-x1)*(float)(y2-y1)/(x2-x1);
temp[j]=x;
temp[j+1]=y;
temp[j+2]=x2;
temp[j+3]=y2;
j+=4;
count+=2;
}else{
//inside to outside. Store intersection only
int x=xh;
int y= y1 + (xh-x1)*(float)(y2-y1)/(x2-x1);
temp[j] = x;
temp[j+1] = y;
j+=2;
count++;
}
}
n=count;
//store 1st vertex as last
temp[j]=temp[0];
temp[j+1]=temp[1];

for(i=0;i<2*(n+1);i++)
poly[i]=temp[i];
}
void bottom_clip(){
int temp[100],i,j=0,count=0,x1,y1,x2,y2;
for(i=0;i<2*n;i+=2){
x1 = poly[i];
y1 = poly[i+1];
x2 = poly[i+2];
y2 = poly[i+3];
if(y1>yl && y2>yl){
//both points outside. Do not store any vertices
}else if(y1<yl && y2<yl){
//both points inside. Store second vertex
temp[j] = x2;
temp[j+1] = y2;
j+=2;
count++;
}else if(y1>yl && y2<yl){
//outside to inside. Store intersection n second vertex
int x= x1 + (yl-y1)/((float)(y2-y1)/(x2-x1));
int y= yl;
temp[j]=x;
temp[j+1]=y;
temp[j+2]=x2;
temp[j+3]=y2;
j+=4;
count+=2;
}else{
//inside to outside. Store intersection only
int x= x1 + (yl-y1)/((float)(y2-y1)/(x2-x1));
int y= yl;
temp[j] = x;
temp[j+1] = y;
j+=2;
count++;
}
}
n=count;
//store 1st vertex as last
temp[j]=temp[0];
temp[j+1]=temp[1];

for(i=0;i<2*(n+1);i++)
poly[i]=temp[i];
}
void top_clip(){
int temp[100],i,j=0,count=0,x1,y1,x2,y2;
for(i=0;i<2*n;i+=2){
x1 = poly[i];
y1 = poly[i+1];
x2 = poly[i+2];
y2 = poly[i+3];
if(y1<yh && y2<yh){
//both points outside. Do not store any vertices
}else if(y1>yh && y2>yh){
//both points inside. Store second vertex
temp[j] = x2;
temp[j+1] = y2;
j+=2;
count++;
}else if(y1<yh && y2>yh){
//outside to inside. Store intersection n second vertex
int x= x1 + (yh-y1)/((float)(y2-y1)/(x2-x1));
int y= yh;
temp[j]=x;
temp[j+1]=y;
temp[j+2]=x2;
temp[j+3]=y2;
j+=4;
count+=2;
}else{
//inside to outside. Store intersection only
int x= x1 + (yh-y1)/((float)(y2-y1)/(x2-x1));
int y= yh;
temp[j] = x;
temp[j+1] = y;
j+=2;
count++;
}
}
n=count;
//store 1st vertex as last
temp[j]=temp[0];
temp[j+1]=temp[1];

for(i=0;i<2*(n+1);i++)
poly[i]=temp[i];
}
void main(){
int gdriver = DETECT,gmode;
initgraph(&gdriver,&gmode,”C:\TC\BGI”);
int i;
setcolor(BLUE);
cout<<”Enter bottom left and top right co-ordinates of window: “;
cin>>xl>>yl>>xh>>yh;
rectangle(xl,yl,xh,yh);
cout<<”Enter the no. of vertices: “;
cin>>n;
for(i=0;i<2*n;i+=2){
cout<<”Enter co-ordinates of vertex “<<(i/2+1)<<”: “;
cin>>poly[i]>>poly[i+1];
}
//store 1st vertex as last
poly[2*n] = poly[0];
poly[2*n+1] = poly[1];
drawpoly(n+1,poly);
getch();

left_clip();
right_clip();
bottom_clip();
top_clip();
cout<<”After clipping:”;
setcolor(WHITE);
drawpoly(n+1,poly);

getch();
closegraph();
}