Monday, July 25, 2011

Configure OpenCV2.2 with Dev-C++ in windows.

In the earlier post i have configured the opencv2.1 with dev-c++ now opencv2.2 is there and it has many more library including all the library in previous vrsion opencv2.1. So it will be good to use OpenCV2.2.

For configuring the opencv2.2 with dev-c++, first you have to install opencv2.2.

You can download OpenCV2.2 from here.

After downloading install OpenCV2.2

and do some changes in the Dev-C++ compiler.

go to Tools->Compiler options then follow these steps as shown in image below.



In this image all the linker text is not visible so just copy this:

-lopencv_calib3d220 -lopencv_contrib220 -lopencv_core220 -lopencv_features2d220 -lopencv_ffmpeg220 -lopencv_flann220 -lopencv_gpu220 -lopencv_highgui220 -lopencv_imgproc220 -lopencv_legacy220 -lopencv_ml220 -lopencv_objdetect220 -lopencv_ts220 -lopencv_video220

and click ok.

Now goto directories and add some directories of OpenCV2.2.










A simple example for capture an image from camera


#include 
#include 
#include 
#include 
int main(int argc,char *argv[])
{
IplImage *frame=0,*grayimg=0;
CvCapture* video=0;
video = cvCreateCameraCapture(1);
if(!video)
{
printf("\nCamera Initialization Failed.............");
}
cvNamedWindow("Display",CV_WINDOW_AUTOSIZE);

while(1)
{
frame=cvQueryFrame(video);
if(!frame) break;
cvSaveImage("image.jpg",frame);
cvShowImage("Display",frame);
char ch=cvWaitKey(30);
if(ch==27) break;
cvReleaseImage(&frame);
}
cvReleaseCapture(&video);
cvDestroyWindow("Display");
getch();
return 0;
} 

Friday, July 15, 2011

Parallel port programming in Windows XP or Windows Vista

Hello friends, this is very much exciting to control the parallel port, because using parallel port we can control many types of robot from small to very large, there is no limitation we can think beyond the expectation, all the programming can be done on today's fastest computer or laptop and we can place laptop or a CPU in any robot if it is capable of and we can provide vision by camera using vision processing, so lots of ideas can come in picture, here I am giving one simple example that how to control parallel port in windows.

We have two solutions that I know to control parallel port in windows operating system

  1. First method

    Using Turbo C for coding and in a C program include dos.h header file as shown in program below.
  • This program is for blinking a led at all the data pins of parallel port
#include <stdio.h>
#include <conio.h>
#include <dos.h>
#define PORTID 0x378

void main()
{
long int i;
while(1){
   outportb(PORTID,0xFF); //0xFF will enable all the eight data pin of parallel port
   for(i=0;i<999999;i++); // for delay
   outportb(PORTID,ox00); //0x00 will disable all the data pins of port
   for(i=0;i<999999;i++); // for delay
}
}

  • Similarly we can take input from  a parallel port  with the help of inportb(PORTID) function.
  • First declare an integer variable
         For Example:
                             int a;
                             a=inportb(PORTID);
  • Using above statement, status of data pins of parallel port will be stored in variable a, and then we can use this variable for comparison or any other use.
  1. Second method for controlling the parallel port:

  • If you want to integrate your parallel port controlling part in vision processing then you need a good IDE for development like Dev-C++, things those are difficult to implement in Turbo C can be easily done in IDE like Dev-C++. Using inpout32.dll library we can achieve parallel port controlling in Dev-C++
  • I have done this in Dev-C++ while I was using OpenCV2.2 for real time vision processing, it works very well
  • You can download inpout32.dll file
  • Unzip the downloaded folder 
  • Then go to binaries->DLL and copy inpout32.dll file
  • Paste it in 'C:/window/system32/' where all the dll files has been placed
  • After pasting this file now you can use this library in your C program in Dev-C++ IDE
  • Example is shown below:
#include <stdio.h>
#include <conio.h>
#include <windows.h>
#define p 0x378

typedef short _stdcall (*inpfuncPtr)(short portaddr);
typedef void _stdcall (*oupfuncPtr)(short portaddr, short datum);

int main(void)
{
HINSTANCE hLib;
inpfuncPtr in;
oupfuncPtr out;
long int i;
char c;
hLib = LoadLibrary("inpout32.dll");
if (hLib == NULL) {
printf("LoadLibrary Failed.\n");
getch();
return -1;
}
in = (inpfuncPtr) GetProcAddress(hLib, "Inp32");
if (in == NULL) {
printf("GetProcAddress for Inp32 Failed.\n");
getch();
return -1;
}
out = (oupfuncPtr) GetProcAddress(hLib, "Out32");
if (out == NULL) {
printf("GetProcAddress for Oup32 Failed.\n");
getch();
return -1;
}
out(p,0x00);
printf("OFF\n");
while(1){

while(kbhit()){
c=getch();
if(c=='p'){
printf("ON\n");
out(p,0xFF);
}
else if(c=='o'){
printf("OFF\n");

out(p,0x00);
}

}
FreeLibrary(hLib);
out(p,0x00);
return 0;
}

To know how to control Parallel Port in Linux, see my blog: Parallel port programming in Linux

..........Enjoy...:)

Friday, July 1, 2011

Configure OpenCV2.1 with Dev-C++

download OpenCV2.1 form this link, install it in C drive.

now open dev-cpp and open compiler options from tool menu, and link the files as shown in figure.

Click on image to see inlarge..