thqby / opencv_ahk

12 stars 2 forks source link

How to convert screenshots to CV:: mat #2

Closed sbago closed 4 months ago

sbago commented 4 months ago

Forgive me for being a beginner. I want to convert the screenshot GDI BitMap to CV:: mat.

Screenshoot() { hModle := DllCall('LoadLibrary', 'str', 'AutoHotkey64.dll', 'ptr') adr := DllCall('GetProcAddress', 'ptr', hModle, 'astr', 'ahkGetApi', 'ptr') api := DllCall(adr, 'cdecl ptr') ptr := DllCall('opencv490_ahk2.0.dll\opencv_init', 'ptr', api, 'cdecl ptr') cv := ObjFromPtr(ptr) mat := cv.mat() wid := A_ScreenWidth hei := A_ScreenHeight pBits:=0x00000000 pToken := Gdip_StartUp() hhdc := GetDC(0) chdc := CreateCompatibleDC(hhdc) hbm := CreateDIBSection(wid, hei, chdc, 24, &pBits) obm := SelectObject(chdc, hbm) BitBlt(chdc, 0, 0, wid, hei, hhdc, 0, 0, 0xCC0020) val:= (wid * 3 + 3) & -4 ;copy from ... or gpt

;but here res is null
img_Screenshoot := mat.__New(hei, wid, 16, pBits,val) 

cvcons := cv.constants
img_Screenshoot := cv.cvtColor(img_Screenshoot, img_grey := cv.mat(), cvcons.COLOR_BGR2GRAY)
Gdip_Shutdown(pToken)
return img_Screenshoot

} How should I modify it?

thqby commented 4 months ago

cv.mat(hei, wid, cvcons.CV_U8C3, pBits,val)

sbago commented 4 months ago

cv.mat(hei, wid, cvcons.CV_U8C3, pBits,val)

thanks。lol