Anda di halaman 1dari 9

CARA INSTALL OPENCV PADA WINDOWS XP

Initial Condition:
Pada Komputer telah terinstal Visual C++.net (Visual studio 2003 atau visual studio
2008)
Langkah 1 :
Click dua kali pada file OpenCV_1.0

Langkah 2 :
Proses instalasi berjalan. Pilih pada tombol yang di tandai hingga Finish.

5
Konfigurasi OpenCV dengan Visual C++.net.
Langkah 1.
Create New Project pada menu Visual C++.net.

C:\Program Files\OpenCV\cvaux\include\
C:\Program Files\OpenCV\cxcore\include\
C:\Program Files\OpenCV\cv\include\
C:\Program Files\OpenCV\otherlibs\highgui\
C:\Program
Files\OpenCV\otherlibs\cvcam\include\
"C:\Program
"C:\Program
"C:\Program
"C:\Program
"C:\Program

Files\OpenCV\lib\cv.lib"
Files\OpenCV\lib\cvaux.lib"
Files\OpenCV\lib\cxcore.lib"
Files\OpenCV\lib\cvcam.lib"
Files\OpenCV\lib\highgui.lib"

Contoh 1.
Menulis Hello Word pada Layar.
#include <cv.h>
#include <highgui.h>
int main( int argc, char** argv )
{
//declare for the height and width of the image
int height = 320;
int width = 240;
//specify the point to place the text
CvPoint pt = cvPoint( height/4, width/2 );
//Create an 8 bit, 3 plane image
IplImage* hw = cvCreateImage(cvSize(height, width), 8, 3);
//initialize the font
CvFont font;
cvInitFont( &font, CV_FONT_HERSHEY_COMPLEX,
1.0, 1.0, 0, 1, CV_AA);
//place the text on the image using the font
cvPutText(hw, "Hello World", pt, &font, CV_RGB(150, 0, 0) );
//create the window container
cvNamedWindow("Hello World", 0);
//display the image in the container
cvShowImage("Hello World", hw);
//hold the output windows
cvWaitKey(0);
return 0;
}

Dengan Cara yang sama


#include <cv.h>
#include <highgui.h>
int main( int argc, char** argv )
{
char* imageName = "lena.jpg"; //Gambar yang akan di tampilkan
IplImage *image2 = 0;//1
// Membuat Window dengan nama "Test2"
cvNamedWindow("Test2", 1);
//Ambil Gambar
image2 = cvLoadImage(imageName, -1);
// Tampilkan gambar ke window
cvShowImage("Test2",image2);
//Tahan tampilan
cvWaitKey(0);
return 0;
}

#include <cv.h>
#include <highgui.h>
void main(int argc,char *argv[])
{
int c;
IplImage* color_img;
CvCapture* cv_cap = cvCaptureFromCAM(-1); // -1 = only one cam or
doesn't matter
cvNamedWindow("Video",1); // create window
for(;;)
{
color_img = cvQueryFrame(cv_cap); // get frame
if(color_img != 0)
cvShowImage("Video", color_img); // show frame
c = cvWaitKey(10); // wait 10 ms or for key stroke
if(c == 27)
break; // if ESC, break and quit
}
/* clean up */
cvReleaseCapture( &cv_cap );
cvDestroyWindow("Video");
}

#include <conio.h>
#include <stdio.h>
#include <ctype.h>
#include <cv.h>
#include <highgui.h>
char f[100];
char* imageName = "lena.jpg"; //Gambar yang akan di tampilkan
IplImage *image2 = 0;//1
int main( int argc, char** argv )
{
// Membuat Window dengan nama "Test2"
cvNamedWindow("Test2", 1);
sprintf(f,"D:\\Open CV Project\\Tes1\\Test3.jpg");
//Ambil Gambar
image2 = cvLoadImage(imageName, -1);
cvSaveImage(f, image2);
// Tampilkan gambar ke window
cvShowImage("Test2",image2);
//Tahan tampilan
cvWaitKey(0);
return 0;
}