Thursday 12 December 2013

How to install Opencv in Visual Studio 2010 in windows 64 bit

Many of us ofcourse Programmers facing problem in OpenCv with Visual Studio 2010. Problem encounter at the beginning. Means installation of OpenCv in VS_2010 specially in windows 7 64bit computer. I have created a video in which this type of installation problem has solved. Here you can see the video click here.
Also I am describing here all the steps for installation. You may watch video or go step by step process to install.

Step-1: 

software requirement : 

1. Microsoft Visual Studio 2010 express


2. OpenCv Latest Version

Step-2:

After downloading vs2010 install it and when you run OpenCv .exe file it will extract all data to a directory in your computer. 
 It will look like this (for opencv)
Step-3:

Now you have done installing vs2010 and opencv. Now you have to configure property sheet in vs2010 project to properly run your c++ image-processing code. In property sheet configuration we just import opencv and it functions to visual studio to perform image-processing action. So get ready for that. step 4 explain how to configure property sheet.


Step-4:

Open visual Studio 2010 and create new project. Select win32 and console application as shown in figure below and click Ok.

Then click next.
Then check on empty project and click finish.
 Next go to property manager which is below right side in window.
Now right click on debug |win32 and select last option property. Then it will look like as image below
and
  

In above image there are three points.
      4a. VC++ directories
      4b. c/c++
      4c. Linker


4a.  VC++ directories :

   There are two field.
   include directory and library directory
In "include directory" you have to add include folder of opencv
in my case it is in folder "C:\Users\Krishna\Downloads\Programs\opencv\build\include"
In "Library directory" you have to add library folder of opencv as like "C:\Users\Krishna\Downloads\Programs\opencv\build\x86\vc10\lib"
this tutorial only describe for windows 64 bit users.
4b. C/C++ :

go to general  ->  additional include directory.
and add the include folder of opencv


4c. Linker :

There will be two tab "general" and "input"
In general tab add in additional library directories

 now go to the input tab. 
It is serious part of step 4 and you need to mare care about this part.
go to directory "C:\Users\Krishna\Downloads\Programs\opencv\build\x86\vc10\lib" and copy the name of all debug dll file and paste it in input part as in figure below
how to identify debug dll file? 
simple way is that if a file contains atleast one 'd' letter then it will be debug dll file. I am using opencv 4.6 so in my case it is

opencv_calib3d246d.lib
opencv_contrib246d.lib
opencv_core246d.lib
opencv_features2d246d.lib
opencv_highgui246d.lib
opencv_imgproc246d.lib
opencv_legacy246d.lib
opencv_nonfree246d.lib
opencv_objdetect246d.lib
opencv_photo246d.lib
opencv_stitching246d.lib
opencv_video246d.lib
opencv_videostab246d.lib


after that click Ok and again Ok to close property sheet.
Now you have done.

Step-5: 

Now go to solution explorer and right click on source -> add new source file and add c++ file
build and run your code.
Here is sample code just copy and paste.

#include <opencv\cv.h>
#include <opencv\highgui.h>

using namespace std;
using namespace cv;

int main()
{
IplImage* img =  cvLoadImage("c:\\p.jpg");
cvNamedWindow("Input_Image");
cvShowImage("Input_Image",img);
waitKey(300);
system("pause");

return 0;
}

I hope you run your code successfully. For any help regarding to this topic please comment I will help you always.
Thank You.

Friday 6 December 2013

Face Detection in OpenCv and Visual Studio 2010

Face detection was one of the my hobby project. I did it successfully. At the same time I learned OpenCv and its uses and various function. I am still learning. Here I will describe whatever i did in my face detection project. Here is my project result click here.

Sunday 1 December 2013

Access smartphone's webcam in opencv in c++

This post  describe you how to access ipwebcam from your smartphone to your project in opencv. I faced very difficulty to find solution of this problem on internet. Now I have solved this problem and decide to share it for helping others who is seeking with this problem.
First you need to download ip-webcam in your smartphone. I am using android v3.6 . You can download ipwebcam from google play store. Now when you start server it generate ip address based on your network. If you are using internet then it provide your isp address. If you connected to wifi then it will generate your device ip-address and If you are using tethering hotspot then it will generate gateway ip-address. Whatever when you get the ip-address you need to open it in your computer in any browser. I am supposing your ip-address is http://192.168.100.1:8080
Now come to second part ...
In Visual Studio 2010 and opencv I am using c++ programming. The only way to access webcam from mobile is write a code to download image from ip-address to your computer and you can use that image for further processing. Here is code.

//Code:

#include <math.h>
#include <opencv\cv.h>
#include <opencv\highgui.h>
#include <stdlib.h>
#include <iostream>
#include <stdio.h>
#include<UrlMon.h>
#include<tchar.h>
#pragma comment(lib,"urlmon.lib")


using namespace cv;
using namespace std;


int main()
{
    Mat capf;
    for(;;)
    {
HRESULT hr = URLDownloadToFile(NULL,
        _T("http://192.168.43.1:8080/shot.jpg"),
        _T("e:/ptest.jpg"),0,NULL);

    //IplImage *test=cvLoadImage("e:/ptest.jpg");
    capf=imread("e:\\ptest.jpg");
    imshow("test",capf);
    cvWaitKey(30);
    }
    system("pause");
    return 0;
}


This program grab an image from your mobile webcam and store it in particular location (any drive) and next line in code open that image in your opencv window for further processing. This process is slow but very usefull in various application.
I am not a professional so my explaination is rough type. All you need to grab information from this post. Further any query leave a comment. Thank You.