SlideShare uma empresa Scribd logo
1 de 32
Getting Started with OpenCV Vadim Pisarevsky (vadim.pisarevsky@intel.com)
Agenda ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
What is OpenCV? ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Can you use OpenCV? ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],In brief: Sure!
Now the question is: Should you use it?
OpenCV structure CXCORE basic structures and algoritms, XML support, drawing functions CV Image processing and vision algorithms HighGUI GUI, Image and Video I/O We will mostly focus on these two in this presentation
First OpenCV Program 1. #include <cxcore.h> 2. #include <highgui.h> 3. #include <math.h> 4. int main( int argc, char** argv ) { 5.  CvPoint center; 6.  double scale=-3; 7.  IplImage* image = argc==2 ? cvLoadImage(argv[1]) : 0; 8.  if(!image) return -1; 9.  center = cvPoint(image->width/2,image->height/2); 10.  for(int i=0;i<image->height;i++) 11.  for(int j=0;j<image->width;j++) { 12.  double dx=(double)(j-center.x)/center.x; 13.  double dy=(double)(i-center.y)/center.y; 14.  double weight=exp((dx*dx+dy*dy)*scale); 15.  uchar* ptr = &CV_IMAGE_ELEM(image,uchar,i,j*3); 16.  ptr[0] = cvRound(ptr[0]*weight); 17.  ptr[1] = cvRound(ptr[1]*weight); 18.  ptr[2] = cvRound(ptr[2]*weight);  } 19.  cvSaveImage( “copy.png”, image ); 20.  cvNamedWindow( &quot;test&quot;, 1 ); 21.  cvShowImage( &quot;test&quot;, image ); 22.  cvWaitKey(); 23.  return 0; } Radial gradient
How to build and run the program? ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
The Program Quick Review ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],1. #include <cxcore.h> 2. #include <highgui.h> 3. #include <math.h> 4. int main( int argc, char** argv ) { 5.  CvPoint center; 6.  double scale=-3; 7.  IplImage* image = argc==2 ?  cvLoadImage (argv[1]) : 0; 8.  if(!image) return -1; 9.  center =  cvPoint (image->width/2,image->height/2); 10.  for(int i=0;i<image->height;i++) 11.  for(int j=0;j<image->width;j++) { 12.  double dx=(double)(j-center.x)/center.x; 13.  double dy=(double)(i-center.y)/center.y; 14.  double weight=exp((dx*dx+dy*dy)*scale); 15.  uchar* ptr = & CV_IMAGE_ELEM (image,uchar,i,j*3); 16.  ptr[0] =  cvRound (ptr[0]*weight); 17.  ptr[1] =  cvRound (ptr[1]*weight); 18.  ptr[2] =  cvRound (ptr[2]*weight);  } 19.  cvSaveImage ( “copy.png”, image ); 20.  cvNamedWindow ( &quot;test&quot;, 1 ); 21.  cvShowImage ( &quot;test&quot;, image ); 22.  cvWaitKey (); 23.  return 0; }
What else HighGUI can do? ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Windows ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Image I/O ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],IplImage* img = cvLoadImage(“picture.jpeg”,-1); if( img ) cvSaveImage( “picture.png”, img );
Waiting for keys… ,[object Object],[object Object],[object Object],[object Object],[object Object],// opencv/samples/c/delaunay.c … for(…) { … int c = cvWaitKey(100); if( c >= 0 ) // key_pressed break; } delaunay.c, 240 lines
Trackbars ,[object Object],[object Object],[object Object],[object Object],// opencv/samples/c/morphology.c int dilate_pos=0; // initial position value void Dilate(int pos) { …  cvShowImage( “E&D”, erode_result ); } int main(…){ … cvCreateTrackbar(“Dilate”,”E&D”, &dilate_pos,10,Dilate); … cvWaitKey(0); // check for events & process them ...} morphology.c, 126 lines
Mouse Events ,[object Object],[object Object],// opencv/samples/c/lkdemo.c void on_mouse(int event,int x,int y,int flags, void* param) { … } int main(…){ … cvSetMouseCallback(“LkDemo”,on_mouse,0); … cvWaitKey(0); // check for events & process them … } Scroll forward for example  
Video I/O API ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Video I/O Example // opencv/samples/c/lkdemo.c int main(…){ … CvCapture* capture = <…> ? cvCaptureFromCAM(camera_id) : cvCaptureFromFile(path); if( !capture ) return -1; for(;;) { IplImage* frame=cvQueryFrame(capture); if(!frame) break; // … copy and process image cvShowImage( “LkDemo”, result ); c=cvWaitKey(30); // run at ~20-30fps speed if(c >= 0) { // process key }} cvReleaseCapture(&capture);}  lkdemo.c, 190 lines (needs camera to run)
Using OpenCV in User Apps ,[object Object],// was (A – NxN matrix, b – Nx1 right-side vector, x – solution): some_old_least_sq_func_32f( /*  float*  */ A, /*  int  */ N, /*  int  */ N, /*  float*  */ b, /*  float*  */ x); // has been converted to: { CvMat _A=cvMat(N,N,CV_32F,A), _b=cvMat(N,1,CV_32F,b), _x=cvMat(N,1,CV_32F,x); cvSolve( &_A, &_b, &_x, CV_SVD ); } ,[object Object],[object Object],[object Object],[object Object]
Using OpenCV in User Apps (II) Case 2. Film Grain DirectShow filter prototype. // inside DirectShow filter Transform method …  pMediaSample->GetPointer(&pData); AM_MEDIA_TYPE* pType = &m_pInput->CurrentMediaType(); BITMAPINFOHEADER *bh = &((VIDEOINFOHEADER *)pType->pbFormat)->bmiHeader; IplImage* img = cvCreateImageHeader(cvSize(bh.biWidth,bh.biHeight), 8, 3); cvSetData( img, pData, (bh.biWdith*3 + 3) & -4 ); cvCvtColor( img, img, CV_BGR2YCrCb ); IplImage* Y=cvCreateImage(cvGetSize(img),8,1); cvSplit(img,Y,0,0,0); IplImage* Yf=cvCreateImage(cvGetSize(img),32,1); CvRNG rng=cvRNG(<seed>); cvRandArr(&rng,Yf,cvScalarAll(0),cvScalarAll(GRAIN_MAG),CV_RAND_NORMAL); cvSmooth(Yf,Yf,CV_GAUSSIAN,GRAIN_SIZE,0,GRAIN_SIZE*0.5); cvAcc(Y, Yf); cvConvert(Yf,Y); cvMerge(Y,0,0,0,img); cvCvtColor( img, img, CV_YCrCb2BGR ); cvReleaseImage(&Yf); cvReleaseImage(&Y); cvReleaseImageHeader(&img);…
Using OpenCV in User Apps (III) Case 3. Visualization inside some test program (hypothetical example,yet quite real too). //  was …  /* some image processing code containing bug */ … //  has been converted to  … …  /* at this point we have the results */ #if VISUALIZE #include <highgui.h> #pragma comment(“lib”,”cxcore.lib”) #pragma comment(“lib”,”highgui.lib”) CvMat hdr; cvInitMatHeader (&hdr,200/*height*/,320/*width*/,CV_8UC3, data_ptr); CvMat* vis_copy=cvCloneMat(&hdr); cvNamedWindow(“test”,1); cvCircle (vis_copy, cvCenter(bug_x,bug_y), 30, CV_RGB(255,0,0), 3, CV_AA ); // mark the suspicious area cvShowImage(“test”,vis_copy); cvWaitKey (0 /* or use some delay, e.g. 1000 */); // cvSaveImage( “buggy.png”, vis_copy ); // if need, save for post-mortem analysis //  cvDestroyWindow (“test”); // if need #endif
What can be drawn in image (besides circles)? ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Using OpenCV with IPP #include <cv.h> #include <highgui.h> #include <ipp.h> #include <stdio.h> int main(int,char**){ const int M=3; IppiSize msz={M,M}; IppiPoint ma={M/2,M/2}; IplImage* img=cvLoadImage(“lena.jpg”,1); IplImage* med1= cvCreateImage (cvGetSize(img),8,3); IplImage* med2= cvCloneImage (med1); int64 t0 =  cvGetTickCount() ,t1,t2; IppiSize sz = {img->width-M+1,img->height-M+1}; double isz=1./(img->width*img->height); cvSmooth (img,med1,CV_MEDIAN,M); // use IPP via OpenCV t0= cvGetTickCount ()-t0; cvUseOptimized (0); // unload IPP t1 =  cvGetTickCount (); cvSmooth (img,med1,CV_MEDIAN,M); // use C code t1= cvGetTickCount ()-t1; t2= cvGetTickCount (); ippiMedianFilter_8u_C3R ( // use IPP directly & CV_IMAGE_ELEM (img,uchar,M/2,M/2*3), img->widthStep, & CV_IMAGE_ELEM (med1,uchar,M/2,M/2*3), med1->widthStep, sz, msz, ma ); t2= cvGetTickCount ()-t2; printf(“t0=%.2f, t1=%.2f, t2=%.2f”, (double)t0*isz,(double)t1*isz,(double)t2*isz); return 0; } Triple 3x3 median filter
How does it works? ,[object Object],// cv/src/_cvipp.h … IPCVAPI_EX(CvStatus, icvFilterMedian_8u_C3R, “ippiFilterMedian_8u_C3R”, CV_PLUGINS1(CV_PLUGIN_IPPI), (const void* src, int srcstep, void* dst, int dststep, CvSize roi, CvSize ksize, CvPoint anchor )) … // cv/src/cvswitcher.cpp … #undef IPCVAPI_EX #define IPCVAPI_EX() … static CvPluginFuncInfo cv_ipp_tab[] = { #undef _CV_IPP_H_ /* with redefined IPCVAPI_EX every function declaration turns to the table entry */ #include &quot;_cvipp.h“ #undef _CV_IPP_H_ {0, 0, 0, 0, 0} }; static CvModuleInfo cv_module = { 0, &quot;cv&quot;, &quot;beta 5 (0.9.7)&quot;, cv_ipp_tab }; static int loaded_functions = cvRegisterModule( &cv_module ); … // cv/src/cvsmooth.cpp icvFilterMedian_8u_C3R_t icvFilterMedian_8u_C3R_p = 0; void cvSmooth() { if( icvFilterMedian_8u_C3R_p ) { /* use IPP */ } else { /* use C code */… }
Dynamic Structures (when 2d array is not enough) ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],// construct sequence of non-zero pixel locations CvSeq*  get_non_zeros( const IplImage* img,  CvMemStorage*  storage ) { CvSeq * seq =  cvCreateSeq ( CV_32SC2, sizeof(CvSeq), sizeof(CvPoint), storage ); for( int i = 0; i < img->height; i++ ) for( int j = 0; j < img->width; j++ ) if( CV_IMAGE_ELEM(img,uchar,i,j) ) { CvPoint pt={j,i};  cvSeqPush ( seq, &pt ); } return seq; }
Memory Storages … ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Sequences ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Sets and Sparse Matrices ,[object Object],[object Object],// Collecting the image colors CvSparseMat*  get_color_map( const IplImage* img ) { int dims[] = { 256, 256, 256 }; CvSparseMat * cmap =  cvCreateSparseMat (3, dims, CV_32SC1); for( int i = 0; i < img->height; i++ ) for( int j = 0; j < img->width; j++ ) {  uchar* ptr=&CV_IMAGE_ELEM(img,uchar,i,j*3); int idx[] = {ptr[0],ptr[1],ptr[2]}; ((int*) cvPtrND (cmap,idx))[0]++; } // print the map CvSparseMatIterator  it; for( CvSparseNode  *node =  cvInitSparseMatIterator ( mat, &iterator ); node != 0; node =  cvGetNextSparseNode ( &iterator )) { int* idx =  CV_NODE_IDX (cmap,node); int count=*(int*) CV_NODE_VAL (cmap,idx); printf( “(b=%d,g=%d,r=%d): %d”, idx[0], idx[1], idx[2], count ); } return cmap; }
Save your data (to load it then) ,[object Object],[object Object],[object Object],[object Object],// somewhere deep in your code… you get 5x5 // matrix that you’d want to save { CvMat A = cvMat( 5, 5, CV_32F, the_matrix_data ); cvSave ( “my_matrix.xml”, &A ); } // to load it then in some other program use … CvMat* A1 = (CvMat*) cvLoad ( “my_matrix.xml” ); <?xml version=&quot;1.0&quot;?> <opencv_storage> <my_matrix type_id=&quot;opencv-matrix&quot;> <rows>5</rows> <cols>5</cols> <dt>f</dt> <data> 1. 0. 0. 0. 0. 0. 1. 0. 0. 0. 0. 0. 1. 0. 0. 0. 0. 0. 1. 0. 0. 0. 0. 0. 1.</data></my_matrix> </opencv_storage> my_matrix.xml
So what about config file? CvFileStorage * fs =  cvOpenFileStorage (“cfg.xml”, 0,  CV_STORAGE_WRITE ); cvWriteInt ( fs, “frame_count”, 10 ); cvWriteStartWriteStruct ( fs, “frame_size”, CV_NODE_SEQ); cvWriteInt( fs, 0, 320 ); cvWriteint( fs, 0, 200 ); cvEndWriteStruct (fs); cvWrite ( fs, “color_cvt_matrix”, cmatrix ); cvReleaseFileStorage ( &fs ); Writing config file CvFileStorage* fs = cvOpenFileStorage(“cfg.xml”, 0, CV_STORAGE_READ); int frame_count =  cvReadIntByName ( fs, 0, “frame_count”, 10 /* default value */ ); CvSeq* s =  cvGetFileNodeByName (fs,0,”frame_size”)->data.seq; int frame_width =  cvReadInt ( (CvFileNode*)cvGetSeqElem(s,0) ); int frame_height = cvReadInt( (CvFileNode*)cvGetSeqElem(s,1) ); CvMat* color_cvt_matrix = (CvMat*)cvRead(fs,0,”color_cvt_matrix”); cvReleaseFileStorage( &fs ); Reading config file <?xml version=&quot;1.0&quot;?> <opencv_storage> <frame_count>10</frame_count> <frame_size>320 200</frame_size> <color_cvt_matrix type_id=&quot;opencv-matrix&quot;> <rows>3</rows> <cols>3</cols> <dt>f</dt> <data>…</data></color_cvt_matrix> </opencv_storage> cfg.xml
Some OpenCV Tips and Tricks ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Where to get more information? ,[object Object],[object Object],[object Object]
Thank you! Questions?

Mais conteúdo relacionado

Mais procurados

Touchless technology Seminar Presentation
Touchless technology Seminar PresentationTouchless technology Seminar Presentation
Touchless technology Seminar Presentation
Aparna Nk
 
Human Area Network
Human Area NetworkHuman Area Network
Human Area Network
Sheel Shah
 
Wireless mesh network (2)
Wireless mesh network (2)Wireless mesh network (2)
Wireless mesh network (2)
Jyoti Yadav
 
Human Area Networking Technology
Human Area Networking TechnologyHuman Area Networking Technology
Human Area Networking Technology
Vinayak Hegde
 

Mais procurados (20)

Vision based system for monitoring the loss of attention in automotive driver
Vision based system for monitoring the loss of attention in automotive driverVision based system for monitoring the loss of attention in automotive driver
Vision based system for monitoring the loss of attention in automotive driver
 
Smart Camera as Embedded System
Smart Camera as Embedded SystemSmart Camera as Embedded System
Smart Camera as Embedded System
 
IP Security
IP SecurityIP Security
IP Security
 
Place reminder
Place reminderPlace reminder
Place reminder
 
Mobile ip presentation
Mobile ip presentationMobile ip presentation
Mobile ip presentation
 
Ubiquitous computing
Ubiquitous computingUbiquitous computing
Ubiquitous computing
 
Ppt presentation
Ppt presentationPpt presentation
Ppt presentation
 
Seminar report on blue eyes
Seminar report on blue eyesSeminar report on blue eyes
Seminar report on blue eyes
 
Smart note maker
Smart note makerSmart note maker
Smart note maker
 
Wireless Vision
Wireless VisionWireless Vision
Wireless Vision
 
Li Fi technology abstract document
Li Fi technology abstract documentLi Fi technology abstract document
Li Fi technology abstract document
 
Fog Screen technology
Fog Screen technologyFog Screen technology
Fog Screen technology
 
Touchless technology Seminar Presentation
Touchless technology Seminar PresentationTouchless technology Seminar Presentation
Touchless technology Seminar Presentation
 
Computer Vision
Computer VisionComputer Vision
Computer Vision
 
Night vision-tech-sanketh
Night vision-tech-sankethNight vision-tech-sanketh
Night vision-tech-sanketh
 
Hand Gesture Recognition
Hand Gesture RecognitionHand Gesture Recognition
Hand Gesture Recognition
 
Human Area Network
Human Area NetworkHuman Area Network
Human Area Network
 
8K Extremely High Resolution Camera System
8K Extremely High Resolution Camera System8K Extremely High Resolution Camera System
8K Extremely High Resolution Camera System
 
Wireless mesh network (2)
Wireless mesh network (2)Wireless mesh network (2)
Wireless mesh network (2)
 
Human Area Networking Technology
Human Area Networking TechnologyHuman Area Networking Technology
Human Area Networking Technology
 

Destaque (7)

A basic introduction to open cv for image processing
A basic introduction to open cv for image processingA basic introduction to open cv for image processing
A basic introduction to open cv for image processing
 
Who is ursula ellis
Who is ursula ellisWho is ursula ellis
Who is ursula ellis
 
Guide: How to Build OpenCV 3.0.0
Guide: How to Build OpenCV 3.0.0Guide: How to Build OpenCV 3.0.0
Guide: How to Build OpenCV 3.0.0
 
PyCon 2012: Militarizing Your Backyard: Computer Vision and the Squirrel Hordes
PyCon 2012: Militarizing Your Backyard: Computer Vision and the Squirrel HordesPyCon 2012: Militarizing Your Backyard: Computer Vision and the Squirrel Hordes
PyCon 2012: Militarizing Your Backyard: Computer Vision and the Squirrel Hordes
 
Write good papers
Write good papersWrite good papers
Write good papers
 
Introduction to OpenCV (with Java)
Introduction to OpenCV (with Java)Introduction to OpenCV (with Java)
Introduction to OpenCV (with Java)
 
I Rock Therefore I Am. 20 Legendary Quotes from Prince
I Rock Therefore I Am. 20 Legendary Quotes from PrinceI Rock Therefore I Am. 20 Legendary Quotes from Prince
I Rock Therefore I Am. 20 Legendary Quotes from Prince
 

Semelhante a Open Cv 2005 Q4 Tutorial

Gdc09 Minigames
Gdc09 MinigamesGdc09 Minigames
Gdc09 Minigames
Susan Gold
 
Threaded Programming
Threaded ProgrammingThreaded Programming
Threaded Programming
Sri Prasanna
 

Semelhante a Open Cv 2005 Q4 Tutorial (20)

PVS-Studio and Continuous Integration: TeamCity. Analysis of the Open RollerC...
PVS-Studio and Continuous Integration: TeamCity. Analysis of the Open RollerC...PVS-Studio and Continuous Integration: TeamCity. Analysis of the Open RollerC...
PVS-Studio and Continuous Integration: TeamCity. Analysis of the Open RollerC...
 
Objective-C Runtime overview
Objective-C Runtime overviewObjective-C Runtime overview
Objective-C Runtime overview
 
Gdc09 Minigames
Gdc09 MinigamesGdc09 Minigames
Gdc09 Minigames
 
Getting started with open cv in raspberry pi
Getting started with open cv in raspberry piGetting started with open cv in raspberry pi
Getting started with open cv in raspberry pi
 
OpenCVの基礎
OpenCVの基礎OpenCVの基礎
OpenCVの基礎
 
Html5
Html5Html5
Html5
 
JVM Mechanics: When Does the JVM JIT & Deoptimize?
JVM Mechanics: When Does the JVM JIT & Deoptimize?JVM Mechanics: When Does the JVM JIT & Deoptimize?
JVM Mechanics: When Does the JVM JIT & Deoptimize?
 
Rcp by example
Rcp by exampleRcp by example
Rcp by example
 
How to instantiate any view controller for free
How to instantiate any view controller for freeHow to instantiate any view controller for free
How to instantiate any view controller for free
 
Google's HTML5 Work: what's next?
Google's HTML5 Work: what's next?Google's HTML5 Work: what's next?
Google's HTML5 Work: what's next?
 
Power ai image-pipeline
Power ai image-pipelinePower ai image-pipeline
Power ai image-pipeline
 
Threaded Programming
Threaded ProgrammingThreaded Programming
Threaded Programming
 
SPU gameplay
SPU gameplaySPU gameplay
SPU gameplay
 
Intro to HTML5
Intro to HTML5Intro to HTML5
Intro to HTML5
 
Moving from Jenkins 1 to 2 declarative pipeline adventures
Moving from Jenkins 1 to 2 declarative pipeline adventuresMoving from Jenkins 1 to 2 declarative pipeline adventures
Moving from Jenkins 1 to 2 declarative pipeline adventures
 
Qt Programming on TI Processors
Qt Programming on TI ProcessorsQt Programming on TI Processors
Qt Programming on TI Processors
 
Forge - DevCon 2016: Visual Reporting with Connected Design Data
Forge - DevCon 2016: Visual Reporting with Connected Design DataForge - DevCon 2016: Visual Reporting with Connected Design Data
Forge - DevCon 2016: Visual Reporting with Connected Design Data
 
Tricks to Making a Realtime SurfaceView Actually Perform in Realtime - Maarte...
Tricks to Making a Realtime SurfaceView Actually Perform in Realtime - Maarte...Tricks to Making a Realtime SurfaceView Actually Perform in Realtime - Maarte...
Tricks to Making a Realtime SurfaceView Actually Perform in Realtime - Maarte...
 
Basic of Applet
Basic of AppletBasic of Applet
Basic of Applet
 
426 lecture 4: AR Developer Tools
426 lecture 4: AR Developer Tools426 lecture 4: AR Developer Tools
426 lecture 4: AR Developer Tools
 

Mais de antiw

Cvpr2010 open source vision software, intro and training part viii point clou...
Cvpr2010 open source vision software, intro and training part viii point clou...Cvpr2010 open source vision software, intro and training part viii point clou...
Cvpr2010 open source vision software, intro and training part viii point clou...
antiw
 
Cvpr2010 open source vision software, intro and training part vii point cloud...
Cvpr2010 open source vision software, intro and training part vii point cloud...Cvpr2010 open source vision software, intro and training part vii point cloud...
Cvpr2010 open source vision software, intro and training part vii point cloud...
antiw
 
graphical models for the Internet
graphical models for the Internetgraphical models for the Internet
graphical models for the Internet
antiw
 
Recent Advances in Computer Vision
Recent Advances in Computer VisionRecent Advances in Computer Vision
Recent Advances in Computer Vision
antiw
 
15 pieces of advice i wish my ph d advisor had given me
15 pieces of advice i wish my ph d advisor had given me15 pieces of advice i wish my ph d advisor had given me
15 pieces of advice i wish my ph d advisor had given me
antiw
 
Randy pauschtimemanagement2007
Randy pauschtimemanagement2007Randy pauschtimemanagement2007
Randy pauschtimemanagement2007
antiw
 
Write a research paper howto - good presentation
Write a research paper   howto - good presentationWrite a research paper   howto - good presentation
Write a research paper howto - good presentation
antiw
 
15 pieces of advice i wish my ph d advisor had given me
15 pieces of advice i wish my ph d advisor had given me15 pieces of advice i wish my ph d advisor had given me
15 pieces of advice i wish my ph d advisor had given me
antiw
 
Note beamer
Note beamerNote beamer
Note beamer
antiw
 

Mais de antiw (9)

Cvpr2010 open source vision software, intro and training part viii point clou...
Cvpr2010 open source vision software, intro and training part viii point clou...Cvpr2010 open source vision software, intro and training part viii point clou...
Cvpr2010 open source vision software, intro and training part viii point clou...
 
Cvpr2010 open source vision software, intro and training part vii point cloud...
Cvpr2010 open source vision software, intro and training part vii point cloud...Cvpr2010 open source vision software, intro and training part vii point cloud...
Cvpr2010 open source vision software, intro and training part vii point cloud...
 
graphical models for the Internet
graphical models for the Internetgraphical models for the Internet
graphical models for the Internet
 
Recent Advances in Computer Vision
Recent Advances in Computer VisionRecent Advances in Computer Vision
Recent Advances in Computer Vision
 
15 pieces of advice i wish my ph d advisor had given me
15 pieces of advice i wish my ph d advisor had given me15 pieces of advice i wish my ph d advisor had given me
15 pieces of advice i wish my ph d advisor had given me
 
Randy pauschtimemanagement2007
Randy pauschtimemanagement2007Randy pauschtimemanagement2007
Randy pauschtimemanagement2007
 
Write a research paper howto - good presentation
Write a research paper   howto - good presentationWrite a research paper   howto - good presentation
Write a research paper howto - good presentation
 
15 pieces of advice i wish my ph d advisor had given me
15 pieces of advice i wish my ph d advisor had given me15 pieces of advice i wish my ph d advisor had given me
15 pieces of advice i wish my ph d advisor had given me
 
Note beamer
Note beamerNote beamer
Note beamer
 

Último

Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 

Último (20)

ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 

Open Cv 2005 Q4 Tutorial

  • 1. Getting Started with OpenCV Vadim Pisarevsky (vadim.pisarevsky@intel.com)
  • 2.
  • 3.
  • 4.
  • 5. Now the question is: Should you use it?
  • 6. OpenCV structure CXCORE basic structures and algoritms, XML support, drawing functions CV Image processing and vision algorithms HighGUI GUI, Image and Video I/O We will mostly focus on these two in this presentation
  • 7. First OpenCV Program 1. #include <cxcore.h> 2. #include <highgui.h> 3. #include <math.h> 4. int main( int argc, char** argv ) { 5. CvPoint center; 6. double scale=-3; 7. IplImage* image = argc==2 ? cvLoadImage(argv[1]) : 0; 8. if(!image) return -1; 9. center = cvPoint(image->width/2,image->height/2); 10. for(int i=0;i<image->height;i++) 11. for(int j=0;j<image->width;j++) { 12. double dx=(double)(j-center.x)/center.x; 13. double dy=(double)(i-center.y)/center.y; 14. double weight=exp((dx*dx+dy*dy)*scale); 15. uchar* ptr = &CV_IMAGE_ELEM(image,uchar,i,j*3); 16. ptr[0] = cvRound(ptr[0]*weight); 17. ptr[1] = cvRound(ptr[1]*weight); 18. ptr[2] = cvRound(ptr[2]*weight); } 19. cvSaveImage( “copy.png”, image ); 20. cvNamedWindow( &quot;test&quot;, 1 ); 21. cvShowImage( &quot;test&quot;, image ); 22. cvWaitKey(); 23. return 0; } Radial gradient
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17. Video I/O Example // opencv/samples/c/lkdemo.c int main(…){ … CvCapture* capture = <…> ? cvCaptureFromCAM(camera_id) : cvCaptureFromFile(path); if( !capture ) return -1; for(;;) { IplImage* frame=cvQueryFrame(capture); if(!frame) break; // … copy and process image cvShowImage( “LkDemo”, result ); c=cvWaitKey(30); // run at ~20-30fps speed if(c >= 0) { // process key }} cvReleaseCapture(&capture);} lkdemo.c, 190 lines (needs camera to run)
  • 18.
  • 19. Using OpenCV in User Apps (II) Case 2. Film Grain DirectShow filter prototype. // inside DirectShow filter Transform method … pMediaSample->GetPointer(&pData); AM_MEDIA_TYPE* pType = &m_pInput->CurrentMediaType(); BITMAPINFOHEADER *bh = &((VIDEOINFOHEADER *)pType->pbFormat)->bmiHeader; IplImage* img = cvCreateImageHeader(cvSize(bh.biWidth,bh.biHeight), 8, 3); cvSetData( img, pData, (bh.biWdith*3 + 3) & -4 ); cvCvtColor( img, img, CV_BGR2YCrCb ); IplImage* Y=cvCreateImage(cvGetSize(img),8,1); cvSplit(img,Y,0,0,0); IplImage* Yf=cvCreateImage(cvGetSize(img),32,1); CvRNG rng=cvRNG(<seed>); cvRandArr(&rng,Yf,cvScalarAll(0),cvScalarAll(GRAIN_MAG),CV_RAND_NORMAL); cvSmooth(Yf,Yf,CV_GAUSSIAN,GRAIN_SIZE,0,GRAIN_SIZE*0.5); cvAcc(Y, Yf); cvConvert(Yf,Y); cvMerge(Y,0,0,0,img); cvCvtColor( img, img, CV_YCrCb2BGR ); cvReleaseImage(&Yf); cvReleaseImage(&Y); cvReleaseImageHeader(&img);…
  • 20. Using OpenCV in User Apps (III) Case 3. Visualization inside some test program (hypothetical example,yet quite real too). // was … /* some image processing code containing bug */ … // has been converted to … … /* at this point we have the results */ #if VISUALIZE #include <highgui.h> #pragma comment(“lib”,”cxcore.lib”) #pragma comment(“lib”,”highgui.lib”) CvMat hdr; cvInitMatHeader (&hdr,200/*height*/,320/*width*/,CV_8UC3, data_ptr); CvMat* vis_copy=cvCloneMat(&hdr); cvNamedWindow(“test”,1); cvCircle (vis_copy, cvCenter(bug_x,bug_y), 30, CV_RGB(255,0,0), 3, CV_AA ); // mark the suspicious area cvShowImage(“test”,vis_copy); cvWaitKey (0 /* or use some delay, e.g. 1000 */); // cvSaveImage( “buggy.png”, vis_copy ); // if need, save for post-mortem analysis // cvDestroyWindow (“test”); // if need #endif
  • 21.
  • 22. Using OpenCV with IPP #include <cv.h> #include <highgui.h> #include <ipp.h> #include <stdio.h> int main(int,char**){ const int M=3; IppiSize msz={M,M}; IppiPoint ma={M/2,M/2}; IplImage* img=cvLoadImage(“lena.jpg”,1); IplImage* med1= cvCreateImage (cvGetSize(img),8,3); IplImage* med2= cvCloneImage (med1); int64 t0 = cvGetTickCount() ,t1,t2; IppiSize sz = {img->width-M+1,img->height-M+1}; double isz=1./(img->width*img->height); cvSmooth (img,med1,CV_MEDIAN,M); // use IPP via OpenCV t0= cvGetTickCount ()-t0; cvUseOptimized (0); // unload IPP t1 = cvGetTickCount (); cvSmooth (img,med1,CV_MEDIAN,M); // use C code t1= cvGetTickCount ()-t1; t2= cvGetTickCount (); ippiMedianFilter_8u_C3R ( // use IPP directly & CV_IMAGE_ELEM (img,uchar,M/2,M/2*3), img->widthStep, & CV_IMAGE_ELEM (med1,uchar,M/2,M/2*3), med1->widthStep, sz, msz, ma ); t2= cvGetTickCount ()-t2; printf(“t0=%.2f, t1=%.2f, t2=%.2f”, (double)t0*isz,(double)t1*isz,(double)t2*isz); return 0; } Triple 3x3 median filter
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29. So what about config file? CvFileStorage * fs = cvOpenFileStorage (“cfg.xml”, 0, CV_STORAGE_WRITE ); cvWriteInt ( fs, “frame_count”, 10 ); cvWriteStartWriteStruct ( fs, “frame_size”, CV_NODE_SEQ); cvWriteInt( fs, 0, 320 ); cvWriteint( fs, 0, 200 ); cvEndWriteStruct (fs); cvWrite ( fs, “color_cvt_matrix”, cmatrix ); cvReleaseFileStorage ( &fs ); Writing config file CvFileStorage* fs = cvOpenFileStorage(“cfg.xml”, 0, CV_STORAGE_READ); int frame_count = cvReadIntByName ( fs, 0, “frame_count”, 10 /* default value */ ); CvSeq* s = cvGetFileNodeByName (fs,0,”frame_size”)->data.seq; int frame_width = cvReadInt ( (CvFileNode*)cvGetSeqElem(s,0) ); int frame_height = cvReadInt( (CvFileNode*)cvGetSeqElem(s,1) ); CvMat* color_cvt_matrix = (CvMat*)cvRead(fs,0,”color_cvt_matrix”); cvReleaseFileStorage( &fs ); Reading config file <?xml version=&quot;1.0&quot;?> <opencv_storage> <frame_count>10</frame_count> <frame_size>320 200</frame_size> <color_cvt_matrix type_id=&quot;opencv-matrix&quot;> <rows>3</rows> <cols>3</cols> <dt>f</dt> <data>…</data></color_cvt_matrix> </opencv_storage> cfg.xml
  • 30.
  • 31.