Anda di halaman 1dari 4

Interfacing Webcam dengan openCV

Oleh: mulkan.ms@gmail.com http://softcients.blogspot.com http://mulkan.web.ugm.ac.id

OpenCV dapat melakukan interfacing dengan webcam secara mudah, berikut adalah salah satu tampilan dari Window nya

/* by: mulkan.ms@gmail.com http://mulkan.web.ugm.ac.id http://softscients.blogspot.com date: 28 juli 2012 */ #define _WIN32_WINNT 0x0500 #define WIN32_LEAN_AND_MEAN #include <iostream> #include <cstdlib> #include "cv.h" #include "highgui.h" #define TITLE "openCV: mulkan.ms@gmail.com" // pesan kepada compiler untuk compile win32 // Exclude rarely-used stuff from Windows headers

int main(){ IplImage * pImag; //create font CvFont font; double hScale=1; double vScale=1; int lineWidth=1; CvCapture* capture; int noDevice=0; //default webcam or autodetect capture = cvCaptureFromCAM(noDevice);

while(true){ pImag = cvQueryFrame(capture);

cvInitFont(&font,CV_FONT_HERSHEY_SIMPLEX|CV_FONT_ITALIC, hScale,vScale,0,lineWidth); cvPutText (pImag,"mulkan.ms@gmail.com",cvPoint(50,50), &font, cvScalar(0,255,0)); cvPutText (pImag,"openCV",cvPoint(50,80), &font, cvScalar(0,255,255)); if(!pImag) break; cvShowImage(TITLE, pImag); char c = cvWaitKey(33); if(c == 27) break; }

cvNamedWindow(TITLE,1); cvDestroyWindow("image"); cvReleaseImage(&pImag); cvWaitKey(0); return -1; }