#Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_Compile_Both=y #AutoIt3Wrapper_UseX64=y #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** #include #include #include #include ;start dll opencv _GDIPlus_Startup() _OpenCV_Startup() ;// load IPL type image both images must have same number of bits and color channels! $pimg = _cvLoadImage("whereWally3.jpg") $ptemp = _cvLoadImage("wally3.jpg") ;image to look for ;// Create some windows to show the input ;// and output images in. ;// _cvNamedWindow( "Where's Wally" ) ;// show our input image ;// _cvShowImage( "Where's Wally", $pimg) Sleep(1000) ;// Determine images height and width to create results matrix Local $width = DllStructGetData(_cvGetSize( $pimg ),"width") Local $height = DllStructGetData(_cvGetSize( $pimg ),"height") Local $width2 = DllStructGetData(_cvGetSize( $ptemp ),"width") Local $height2 = DllStructGetData(_cvGetSize( $ptemp ),"height") Local $rw = $width - $width2 + 1 Local $rh = $height - $height2 + 1 ;// Create Opencv matrix object 32 bit floating Local $presult=_cvCreateMat($rh,$rw,$CV_32FC1) ;// Template matching _cvMatchTemplate( $pimg , $ptemp , $presult , 5 ) _cvNormalize($presult,$presult,0,1,$CV_MINMAX,Null) _cvThreshold($presult,$presult,0.90,1,$CV_THRESH_BINARY) ;//locate matches ; ;// Create minmax variables to pass to opencv Local $tmaxloc = DllStructCreate($tagCvPoint) Local $tminloc = DllStructCreate($tagCvPoint) Local $tmaxval = DllStructCreate("double max;") Local $tminval = DllStructCreate("double min;") Local $pmaxloc = DllStructGetPtr($tmaxloc) Local $pminloc = DllStructGetPtr($tminloc) Local $pmaxval = DllStructGetPtr($tmaxval) Local $pminval = DllStructGetPtr($tminval) ;// create mask to find multiple matches Local $pmask = _cvCreateImage(_cvSize($rw, $rh), 8, 1) _cvSet($pmask,_cvScalar(1)) ;// Find location of maximum _cvMinMaxLoc( $presult, $pminval, $pmaxval, $pminloc, $pmaxloc, $pmask ) Do ;// Mask it to find others if exists and draw red rectangle on input image _cvRectangle($pmask,_cvPoint(DllStructGetData($tmaxloc, "x")- 5,DllStructGetData($tmaxloc, "y")-5),_cvPoint(DllStructGetData($tmaxloc, "x")+$width2,DllStructGetData($tmaxloc, "y")+$height2),_cvScalar(0),-1,8,0) _cvRectangle($pimg,_cvPoint(DllStructGetData($tmaxloc, "x")- 5,DllStructGetData($tmaxloc, "y")-5),_cvPoint(DllStructGetData($tmaxloc, "x")+$width2+10,DllStructGetData($tmaxloc, "y")+$height2+10),_CV_RGB(255, 0, 0),2,8,0) ;// Update input image _cvShowImage( "Where's Wally", $pimg) ;// Used to show that only one match is located each time sleep(3000) ;// Find location of maximum _cvMinMaxLoc( $presult, $pminval, $pmaxval, $pminloc, $pmaxloc, $pmask ) Until (DllStructGetData($tmaxval, "max")<.99) ;// Wait for the user to hit a key, then clean up the windows ;// _cvWaitKey( 0 ) ;// Be tidy ;// _cvReleaseImage( $pmask ) _cvReleaseMat( $presult ) _cvReleaseImage( $ptemp ) _cvReleaseImage( $pimg ) _cvDestroyAllWindows() _Opencv_CloseDLL() _GDIPlus_Shutdown() Exit