Thursday, January 8, 2009

Interfacing Parallel Port Using Visual C++

I've been searching around a lot to find some straight forward solution to deal with parallel port using Visual C, but after around a week of searching and wasting time got the solution still in a quite indirect way...so thought of writing it here...
Tools Required for Interfacing Parallel Port in Visual C++
1. Microsoft Visual Studio
2. inpout32.dll (www.logix4u.net)
3. inpout32.lib (www.logix4u.net)

Step and Code for Parallel Port Interfacing.
1. Creat a new Visual C++ Project using Visual Studio
2. Copy the inpout32.dll and inpout32.lib into your project directory
3. Goto project properties (Alt+F7), Expand Configuration Properties, Expand Linker, Click on Input, and type inpout32.lib in Additional Dependencies row and click Ok
4. Open the C source file of the project and code
#include "stdafx.h"
#include "stdio.h"
#include "conio.h"
#include "string.h"
#include "stdlib.h"
/* ----Prototypes of Inp and Outp--- */

short _stdcall Inp32(short PortAddress);
void _stdcall Out32(short PortAddress, short data);

/*--------------------------------*/

void main(void)
{
int Data; //Data to be sent on parallel port
Out32(0X378,Data); //if Inp32(0x378); used then it will take input from parallel port

}

now to check the working of the program execute LPT.exe it will start monitoring your prarallel power status, and you may check the code you just compiled.

Best of Luck

Thursday, January 1, 2009

OpenCV Image Processing - Template Matching

Matching an external file with video optained

//Standard Header
#include "stdafx.h"
//OpenCV header
#include "cv.h"
#include "highgui.h"

//Start of main function
int main( int argc, char** argv )
{
//Enable camera input
CvCapture* capture = cvCreateCameraCapture(0);
//Terminate Program if camera feed is not available
assert( capture != NULL );
//Create Window named Output
cvNamedWindow( "Output", CV_WINDOW_AUTOSIZE );

//Pointers for tracker
double m,M;
IplImage* image; IplImage* icon;
CvPoint point1;
CvPoint point2;

//continuous loop to obtain frames from the cam and display at output window
while(1)
{
//Bring each frame to image variable
image = cvQueryFrame( capture );
//If no input then terminate
if( !image )
break;
//Tracking Procedures
//Load tracking image
icon=cvLoadImage("a.jpg",1);
int resultW = image->width - icon->width + 1;
int resultH = image->height - icon->height +1;
IplImage* result = cvCreateImage(cvSize(resultW, resultH), IPL_DEPTH_32F, 1);
cvMatchTemplate(image, icon, result, CV_TM_SQDIFF);
cvMinMaxLoc(result, &m, &M, &point2, &point1, NULL);
cvRectangle( image, point2, cvPoint( point2.x + icon->width, point2.y + icon->height ), cvScalar( 0, 0, 255, 0 ), 1, 0, 0 );

cvShowImage( "Output", image );
//Delay to wait before returning to the loop to get next frame
char c = cvWaitKey(33);
//If escape ket pressed then terminate
if( c == 27 )
break;
}
//During program end release camera so it could be used by another application
cvReleaseCapture( &capture );
//Close the Output Window created earlier
cvDestroyWindow( "Output" );
}

OpenCV Image Processing - Video Acquisition

To Capture Video using a Webcam

//Standard Header
#include "stdafx.h"
//OpenCV header
#include "cv.h"
#include "highgui.h"

//Start of main function
int main( int argc, char** argv )
{
//Enable camera input
CvCapture* capture = cvCreateCameraCapture(0);
//Terminate Program if camera feed is not available
assert( capture != NULL );
//Create Window named Output
cvNamedWindow( "Output", CV_WINDOW_AUTOSIZE );
//Frames pointer
IplImage* image;

//continuous loop to obtain frames from the cam and display at output window
while(1)
{
//Bring each frame to image variable
image = cvQueryFrame( capture );
//If no input then terminate
if( !image )
break;

cvShowImage( "Output", image );
//Delay to wait before returning to the loop to get next frame
char c = cvWaitKey(33);
//If escape ket pressed then terminate
if( c == 27 )
break;
}
//During program end release camera so it could be used by another application
cvReleaseCapture( &capture );
//Close the Output Window created earlier
cvDestroyWindow( "Output" );
}