malcev wrote: ↑03 Jan 2022, 02:27For me imwrite works:How to use matchTemplate nadure already showed in this topic.Code: Select all
cv.imwrite("filename.jpg", img)
Post Your code.
This is my test code.
Thanks.
Code: Select all
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn ; Enable warnings to assist with detecting common errors.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
#include gdip_all.ahk
#include Gdip_ImageSearch.ahk
;openCV test
F3::
{
; register com
hOpencv := DllCall("LoadLibrary", "str", "c:\work\opencv454\build\x64\vc14\bin\opencv_world454.dll", "ptr")
hOpencvCom := DllCall("LoadLibrary", "str", "C:\WORK\AHKs\autoit_opencv_com454.dll", "ptr")
DllCall("autoit_opencv_com454.dll\DllInstall", "int", 1, "wstr", "", "cdecl")
;cmd runas admin
; regsvr32 /n /i autoit_opencv_com454.dll
cv := ComObjCreate("OpenCV.cv")
mat := ComObjCreate("OpenCV.cv.Mat")
; gdi
pToken := Gdip_StartUp()
hwndAHKs:=WinExist("AHKs")
WinGetPos ,,,wid, hei
pBits:=0x00000000
chdc := CreateCompatibleDC(GetDC(hwndAHKs))
hbm := CreateDIBSection(wid, hei,chdc,32,pBits)
obm := SelectObject(chdc, hbm)
hhdc := GetDC(hwndAHKs)
;NOTSRCCOPY
;BitBlt(chdc, 0, 0, wid, hei, hhdc, 0, 0, 0x330008)
;SRCCOPY
BitBlt(chdc, 0, 0, wid, hei, hhdc, 0, 0, 0xCC0020)
;hbm HBITMAP for BitBlt result check
;pBitmap := Gdip_CreateBitmapFromHBITMAP(hbm)
;Gdip_SaveBitmapToFile(pBitmap,"test2.png")
val:= (wid * 4 + 3) & -4
resultMat := mat.create( hei, wid, 24, pBits, val )
resultMat := cv.flip(resultMat, 0)
; it works (haystack)
cv.imshow("img", resultMat)
; it works (imwrite test)
cv.imwrite("filename.jpg", resultMat)
; it works (needle)
img_tmpl := cv.imread(".\s.png")
; it works (for MatchTemplate test)
;resultMat2 := cv.imread(".\filename.jpg")
;cv.TM_SQDIFF_NORMED
method:=3
;An error occured 0xE06D7363 , normal "imread"ed image works, but ".create"ed memDC image doesn't . I dunno why..
;res := cv.matchTemplate(resultMat2,img_tmpl,method)
res := cv.matchTemplate(resultMat,img_tmpl,method)
cv.minMaxLoc(res)
exts:=cv.extended
x:=exts[3][0]
y:=exts[3][1]
msgbox, match %x% %y%
SelectObject(chdc, obm)
ReleaseDC(hhdc)
DeleteObject(hbm)
DeleteDC(hhdc)
DeleteDC(chdc)
Gdip_Shutdown(pToken)
cv.destroyAllWindows()
DllCall("autoit_opencv_com454.dll\DllInstall", "int", 0, "wstr", "", "cdecl")
DllCall("FreeLibrary", "ptr", hOpencv)
DllCall("FreeLibrary", "ptr", hOpencvCom)
return
}
;openCV test