;start dll opencv
h1 := DllCall("LoadLibrary", "Str", "opencv_core2413.dll", "Ptr")
h2 := DllCall("LoadLibrary", "Str", "opencv_highgui2413.dll", "Ptr")
h3 := DllCall("LoadLibrary", "Str", "opencv_imgproc2413.dll", "Ptr")
file1 := "1.jpg"
file2 := "2.jpg"
window := "gui"
;// load IPL type image both images must have same number of bits and color channels!
pimg := DllCall("opencv_highgui2413.dll\cvLoadImage", "AStr", file1, "int", CV_LOAD_IMAGE_COLOR := 1, "Cdecl Int")
ptemp := DllCall("opencv_highgui2413.dll\cvLoadImage", "AStr", file2, "int", CV_LOAD_IMAGE_COLOR := 1, "Cdecl Int")
;// Create some windows to show the input
;// and output images in.
;//
DllCall("opencv_highgui2413.dll\cvNamedWindow", "AStr", window, "int", CV_WINDOW_AUTOSIZE := 0x00000001, "Cdecl Int")
;// show our input image
;//
DllCall("opencv_highgui2413.dll\cvShowImage", "AStr", window, "ptr", pimg, "Cdecl")
;// Determine images height and width to create results matrix
WidthHeight := DllCall("opencv_core2413.dll\cvGetSize", "ptr", pimg, "Cdecl int64")
width := 0xFFFFFFFF & WidthHeight
height := WidthHeight >> 32
WidthHeight := DllCall("opencv_core2413.dll\cvGetSize", "ptr", ptemp, "Cdecl int64")
width2 := 0xFFFFFFFF & WidthHeight
height2 := WidthHeight >> 32
rw := width - width2 + 1
rh := height - height2 + 1
;// Create Opencv matrix object 32 bit floating
presult := DllCall("opencv_core2413.dll\cvCreateMat", "int", rh, "int", rw, "int", CV_32FC1 := 5, "Cdecl ptr")
;// Template matching
DllCall("opencv_imgproc2413.dll\cvMatchTemplate", "ptr", pimg, "ptr", ptemp, "ptr", presult, "int", CV_TM_CCOEFF_NORMED := 5, "Cdecl")
DllCall("opencv_core2413.dll\cvNormalize", "ptr", presult, "ptr", presult, "Double", 0, "Double", CV_C := 1, "int", CV_MINMAX := 32, "ptr", 0, "Cdecl")
DllCall("opencv_imgproc2413.dll\cvThreshold", "ptr", presult, "ptr", presult, "Double", thresh := 0.9, "Double", maxval := 1, "int", CV_THRESH_BINARY := 0, "Cdecl double")
;//locate matches
;
;// Create minmax variables to pass to opencv
VarSetCapacity(pmaxloc, 8, 0)
VarSetCapacity(pminloc, 8, 0)
VarSetCapacity(pmaxval, 8, 0)
VarSetCapacity(pminval, 8, 0)
;// create mask to find multiple matches
pmask := DllCall("opencv_core2413.dll\cvCreateImage", "int", rw, "int", rh, "int", IPL_DEPTH_8U := 8, "int", channels := 1, "Cdecl ptr")
DllCall("opencv_core2413.dll\cvSet", "ptr", pmask, "double", 1, "double", 1, "double", 1, "double", 1, "ptr", 0, "Cdecl")
;// Find location of maximum
DllCall("opencv_core2413.dll\cvMinMaxLoc", "ptr", presult, "ptr", &pminval, "ptr", &pmaxval, "ptr", &pminloc, "ptr", &pmaxloc, "ptr", pmask, "Cdecl")
loop
{
;// Mask it to find others if exists and draw red rectangle on input image
DllCall("opencv_core2413.dll\cvRectangle", "ptr", pmask, "int", NumGet(pmaxloc, 0, "int")-5, "int", NumGet(pmaxloc, 4, "int")-5, "int", NumGet(pmaxloc, 0, "int")+ width2, "int", NumGet(pmaxloc, 4, "int")+height2, "double", 0, "double", 0, "double", 0, "double", 0, "int", -1, "int", 8, "int", 0, "Cdecl")
DllCall("opencv_core2413.dll\cvRectangle", "ptr", pimg, "int", NumGet(pmaxloc, 0, "int")-5, "int", NumGet(pmaxloc, 4, "int")-5, "int", NumGet(pmaxloc, 0, "int")+ width2+10, "int", NumGet(pmaxloc, 4, "int")+height2+10, "double", 0, "double", 0, "double", 255, "double", 0, "int", 2, "int", 8, "int", 0, "Cdecl")
;// Update input image
DllCall("opencv_highgui2413.dll\cvShowImage", "AStr", window, "ptr", pimg, "Cdecl")
;// Find location of maximum
DllCall("opencv_core2413.dll\cvMinMaxLoc", "ptr", presult, "ptr", &pminval, "ptr", &pmaxval, "ptr", &pminloc, "ptr", &pmaxloc, "ptr", pmask, "Cdecl")
if (NumGet(pmaxval, 0, "double") < 0.99)
break
sleep 1000
}
msgbox done
DllCall("opencv_core2413.dll\cvReleaseImage", "ptr*", pmask, "Cdecl")
DllCall("opencv_core2413.dll\cvReleaseMat", "ptr*", presult, "Cdecl")
DllCall("opencv_core2413.dll\cvReleaseImage", "ptr*", ptemp, "Cdecl")
DllCall("opencv_core2413.dll\cvReleaseImage", "ptr*", pimg, "Cdecl")
DllCall("opencv_highgui2413.dll\cvDestroyAllWindows", "Cdecl")