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..

 





Wednesday, June 29, 2011

bootable usb for window or How to install window 7 using USB

hi all it is very simple to do that..

First download this file.

install it.

Make an ISO file of window 7 DVD.

And make sure u have a pen drive of minimum 4GB.

after that run the Windows7-USB-DVD-tool, which you have downloaded and installed, from your desktop icon and follow the steps.

it will take some time.

after completing this. make USB 1st priority for booting in BIOS then restart

it will work enjoy....

Saturday, June 18, 2011

How to control a Motor Using Parallel port.

Parallel port gives a continuos 0 volt(as 0) or continuous 3 volt(as 1).

For controlling a motor in both direction, we can use L293D IC which simple to connect and we can controll two motor with the help of one IC, and the maximum current it can provide to motor is 1A. So if we are using motor controlling in a small robot or something else where no much load and motor can be drive by only 1A current then it is the best IC.



This IC takes only four inputs, which can be 0 or 1,and combination of 0, 1 decide how will motor rotate. And parallel port output is sufficient to give the input in this IC. So we can directly add parallel port outputs to the L293D IC inputs, and can control motor in both direction usning programming, and how to control parallel port output using programming i have discussed this in my earlier post.

But in L293D IC there is a problem we can not give more than 1A current for driving the motor so if we want to drive a motor which takes more current we can use L298 IC it can provide about 2A current. But again if you want more than this current then u have to use relay.

relay is much better solution it can switch 220V AC supply also.

for energizing the realy using parallel port, we can use ULN2803, because parallel port is not able to switch the relay, so it is better option.

Parallel port programming in Linux (Ubuntu)

Hello Every one.

It is very simple to control the parallel port in linux in c. Just run this c program. Make sure you are logged in as a root.
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/io.h>
#define pport 0x378

main(int argc,char **argv)
{
unsigned long int i;
if (ioperm(pport,1,1))
    printf("Error: Couldn't get the port at %x\n", pport);

while(1){
 for(i=0;i<99999999;i++);
   outb(0xFF,pport);
   printf("\nON");
 for(i=0;i<99999999;i++);
   outb(0x00,pport);
   printf("OFF");
}
}

This program is for blinking a LED on any data bit of parallel port.

U can change the delay by changing the for loop conditions.

If some one is new to linux then here is some help, how to add root user...

type ' sudo passwd root ' on terminal then hit enter. it will ask password for root user two times, give the password and then login as a root.

enjoy...