openCV tutorials

Tutorial 1

How to compile

g++ prog.c -o prog -I /usr/local/include/opencv -L /usr/local/lib

-lm -lcv -lhighgui -lcvaux

You may omit

-lcvaux

Sample program (to load an image)

/*filename prog.c*/
/* usage: prog <image_name> */
#include “cv.h”
#include “highgui.h”

int main( int argc, char** argv )
{
IplImage* img;
if( argc == 2 && (img = cvLoadImage( argv[1], 1)) != 0 )
{
cvNamedWindow( “Image view”, 1 );
cvShowImage( “Image view”, img );
cvWaitKey(0); // very important, contains event processing loop inside
cvDestroyWindow( “Image view” );
cvReleaseImage( &img );
return 0;
}
return -1;
}

How to use

./hello filename.jpg

Tutorial 2

Controlling parallel port and loading image

The code will make the pin2 of parallel port high.Then after 2 seconds the
pin2-pin9 of parallel port high and also load the image.These kind of
codes are applicable where we need robots using image processing.

Consider a fire fighting robot.The robot is controlled through parallel port
by the RF transmitter.The USB cam overhead can see the robot and controll it direction

This is the code

/*filename prog.c*/
/* usage: prog <image_name> */
#include “cv.h”
#include “highgui.h”
#include<stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <asm/io.h>

#define base 0x378 /* printer port base address */
int main( int argc, char** argv )
{

IplImage* img;
if( argc == 2 && (img = cvLoadImage( argv[1], 1)) != 0 )
{
/* set parellel port */
if (ioperm(base,1,1))
fprintf(stderr, “Couldn’t get the port at %x\n”, base), exit(1);/* parallel port error message */
outb(1, base);/* outputing value through parallel port */
sleep(2);
outb(255, base);

/* load image */

cvNamedWindow( “Image view”, 1 );
cvShowImage( “Image view”, img );
cvWaitKey(0); // very important, contains event processing loop inside
cvDestroyWindow( “Image view” );
cvReleaseImage( &img );

return 0;
}
return -1;
}

Compiling the program

Here we have to use gcc for compiling

gcc prog.c -o prog -I /usr/local/include/opencv -L /usr/local/lib
-lm -lcv -lhighgui

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s