TSz19 Posted October 29, 2020 Share Posted October 29, 2020 Help : I want to find the image in the blackguard. Don't know how to write Global $Test =WinGetHandle("Program Manager") $Match1 = _MatchPicture($Test,@ScriptDir&"\Match\4.png", 0.70,False,10,500);Try to find the match picture on the screen. Number of tries: 10, Sleep between each try: 500ms. If Not @error Then _MarkMatch($Match1) ;Debugging: Draws a rect on the screen/coordinates of the match to show the user where the match was found Sleep(100) MouseMove($Match1[0],$Match1[1]) EndIf expandcollapse popupFunc _MatchPicture($Handle,$Match_Pic, $Threshold = 2, $CustomCords = False, $LoopCount = 2, $LoopWait = 2000) Local $GDC = _WinAPI_GetWindowDC($Handle) _WinAPI_ReleaseDC(0,$GDC) If Not FileExists($Match_Pic) Then _Internal_ErrorLogger("Match Image not found: " & $Match_Pic) Return SetError(1) EndIf If $LoopCount <= 0 Then ConsoleWrite("Error: $LoopCount Variable set to 0. At least 1 is required.") Return SetError(1) EndIf Local $hBitmap ;Performance Counters Local $Perf = TimerInit() ;Load Match Image Local $hMatch_Pic = _cvLoadImage($Match_Pic) Local $hMatch_Size = _cvGetSize($hMatch_Pic) Local $width2 = DllStructGetData($hMatch_Size, "width") Local $height2 = DllStructGetData($hMatch_Size, "height") Local $ScreenSize = _ScreenSize() For $iTries = 1 To $LoopCount Step +1 ;Capature Screen / Load as Main image If Not IsArray($CustomCords) Then $hBitmap = _ScreenCapture_Capture("", 0, 0, $ScreenSize[0], $ScreenSize[1], False) Else $hBitmap = _ScreenCapture_Capture("", $CustomCords[0], $CustomCords[1], $CustomCords[2], $CustomCords[3], False) EndIf Local $Bitmap = _GDIPlus_BitmapCreateFromHBITMAP($hBitmap) Local $hMain_Pic = _Opencv_BMP2IPL($Bitmap) Local $hMain_Size = _cvGetSize($hMain_Pic) Local $width = DllStructGetData($hMain_Size, "width") Local $height = DllStructGetData($hMain_Size, "height") Local $rw = $width - $width2 + 1 Local $rh = $height - $height2 + 1 Local $tmaxloc = DllStructCreate( "int x;" & "int y;") Local $tminloc = DllStructCreate( "int x;" & "int y;") 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) ;Search for Match Local $presult = _cvCreateMat($rh, $rw, 5) _cvMatchTemplate($hMain_Pic, $hMatch_Pic, $presult, 5) _cvThreshold($presult, $presult, $Threshold, 1, 0) _cvMinMaxLoc($presult, $pminval, $pmaxval, $pminloc, $pmaxloc, Null) ;Set coordinates Local $Coordinates[4] If IsArray($CustomCords) Then $Coordinates[0] = DllStructGetData($tmaxloc, "x") +2+ $CustomCords[0] ; x $Coordinates[1] = DllStructGetData($tmaxloc, "y") +2+ $CustomCords[1] ; y $Coordinates[2] = DllStructGetData($tmaxloc, "x") +2+ $width2 + $CustomCords[0] ;x2 $Coordinates[3] = DllStructGetData($tmaxloc, "y") +2+ $height2 + $CustomCords[1] ;y2 Else $Coordinates[0] = DllStructGetData($tmaxloc, "x") ; x $Coordinates[1] = DllStructGetData($tmaxloc, "y") ; y $Coordinates[2] = DllStructGetData($tmaxloc, "x") + $width2 ;x2 $Coordinates[3] = DllStructGetData($tmaxloc, "y") + $height2 ;y2 EndIf ;Release Resources _cvReleaseMat($presult) _cvReleaseImage($hMain_Pic) _GDIPlus_BitmapDispose($Bitmap) _WinAPI_DeleteObject($hBitmap) ;Check if found If Not (DllStructGetData($tmaxloc, "x") = 0 And DllStructGetData($tmaxloc, "y") = 0 And $width2 = DllStructGetData($tmaxloc, "x") + $width2 And $height2 = DllStructGetData($tmaxloc, "y") + $height2) Then _cvReleaseImage($hMatch_Pic) _Internal_MatchLogger("Match found at: " & $Coordinates[0] & "|" & $Coordinates[1] & "|" & $Coordinates[2] & "|" & $Coordinates[3] & " // Loop counter: " & $iTries & " // Threshold: " & $Threshold & " // Total check time: " & Round(TimerDiff($Perf), 0) & " ms") Return $Coordinates EndIf Sleep($LoopWait) Next _cvReleaseImage($hMatch_Pic) _Internal_ErrorLogger("No match found. Loop counter: " & $LoopCount & ". // Total check time: " & Round(TimerDiff($Perf), 0) & " ms // Wait-Time per loop: " & $LoopWait & " ms. // Threshold: " & $Threshold & " // Match Image: " & $Match_Pic) Return SetError(2) EndFunc ;==>_MatchPicture Link to comment Share on other sites More sharing options...
TSz19 Posted October 30, 2020 Author Share Posted October 30, 2020 What can I do? Let it find pictures in WinGetHandle Please write for me I will be very grateful 😭 Global $Test = WinGetHandle("Program Manager") $Match1 = _MatchPicture(,@ScriptDir&"\Match\4.png", 0.70,False,10,500);Try to find the match picture on the screen. Number of tries: 10, Sleep between each try: 500ms. If Not @error Then _MarkMatch($Match1) ;Debugging: Draws a rect on the screen/coordinates of the match to show the user where the match was found Sleep(100) MouseMove($Match1[0],$Match1[1]) EndIf expandcollapse popupFunc _MatchPicture($Match_Pic, $Threshold = 0.9, $CustomCords = False, $LoopCount = 1, $LoopWait = 2000) If Not FileExists($Match_Pic) Then _Internal_ErrorLogger("Match Image not found: " & $Match_Pic) Return SetError(1) EndIf If $LoopCount <= 0 Then ConsoleWrite("Error: $LoopCount Variable set to 0. At least 1 is required.") Return SetError(1) EndIf Local $hBitmap ;Performance Counters Local $Perf = TimerInit() ;Load Match Image Local $hMatch_Pic = _cvLoadImage($Match_Pic) Local $hMatch_Size = _cvGetSize($hMatch_Pic) Local $width2 = DllStructGetData($hMatch_Size, "width") Local $height2 = DllStructGetData($hMatch_Size, "height") Local $ScreenSize = _ScreenSize() For $iTries = 1 To $LoopCount Step +1 ;Capature Screen / Load as Main image If Not IsArray($CustomCords) Then $hBitmap = _ScreenCapture_Capture("", 0, 0, $ScreenSize[0], $ScreenSize[1], False) Else $hBitmap = _ScreenCapture_Capture("", $CustomCords[0], $CustomCords[1], $CustomCords[2], $CustomCords[3], False) EndIf Local $Bitmap = _GDIPlus_BitmapCreateFromHBITMAP($hBitmap) Local $hMain_Pic = _Opencv_BMP2IPL($Bitmap) Local $hMain_Size = _cvGetSize($hMain_Pic) Local $width = DllStructGetData($hMain_Size, "width") Local $height = DllStructGetData($hMain_Size, "height") Local $rw = $width - $width2 + 1 Local $rh = $height - $height2 + 1 Local $tmaxloc = DllStructCreate( "int x;" & "int y;") Local $tminloc = DllStructCreate( "int x;" & "int y;") 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) ;Search for Match Local $presult = _cvCreateMat($rh, $rw, 5) _cvMatchTemplate($hMain_Pic, $hMatch_Pic, $presult, 5) _cvThreshold($presult, $presult, $Threshold, 1, 0) _cvMinMaxLoc($presult, $pminval, $pmaxval, $pminloc, $pmaxloc, Null) ;Set coordinates Local $Coordinates[4] If IsArray($CustomCords) Then $Coordinates[0] = DllStructGetData($tmaxloc, "x") + $CustomCords[0] ; x $Coordinates[1] = DllStructGetData($tmaxloc, "y") + $CustomCords[1] ; y $Coordinates[2] = DllStructGetData($tmaxloc, "x") + $width2 + $CustomCords[0] ;x2 $Coordinates[3] = DllStructGetData($tmaxloc, "y") + $height2 + $CustomCords[1] ;y2 Else $Coordinates[0] = DllStructGetData($tmaxloc, "x") ; x $Coordinates[1] = DllStructGetData($tmaxloc, "y") ; y $Coordinates[2] = DllStructGetData($tmaxloc, "x") + $width2 ;x2 $Coordinates[3] = DllStructGetData($tmaxloc, "y") + $height2 ;y2 EndIf ;Release Resources _cvReleaseMat($presult) _cvReleaseImage($hMain_Pic) _GDIPlus_BitmapDispose($Bitmap) _WinAPI_DeleteObject($hBitmap) ;Check if found If Not (DllStructGetData($tmaxloc, "x") = 0 And DllStructGetData($tmaxloc, "y") = 0 And $width2 = DllStructGetData($tmaxloc, "x") + $width2 And $height2 = DllStructGetData($tmaxloc, "y") + $height2) Then _cvReleaseImage($hMatch_Pic) _Internal_MatchLogger("Match found at: " & $Coordinates[0] & "|" & $Coordinates[1] & "|" & $Coordinates[2] & "|" & $Coordinates[3] & " // Loop counter: " & $iTries & " // Threshold: " & $Threshold & " // Total check time: " & Round(TimerDiff($Perf), 0) & " ms") Return $Coordinates EndIf Sleep($LoopWait) Next _cvReleaseImage($hMatch_Pic) _Internal_ErrorLogger("No match found. Loop counter: " & $LoopCount & ". // Total check time: " & Round(TimerDiff($Perf), 0) & " ms // Wait-Time per loop: " & $LoopWait & " ms. // Threshold: " & $Threshold & " // Match Image: " & $Match_Pic) Return SetError(2) EndFunc ;==>_MatchPicture Link to comment Share on other sites More sharing options...
Nine Posted October 30, 2020 Share Posted October 30, 2020 And how is this different from your last thread. “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
TSz19 Posted October 30, 2020 Author Share Posted October 30, 2020 @Nine Yes , That one I tried to fix. But failed😅 Link to comment Share on other sites More sharing options...
Developers Jos Posted October 30, 2020 Developers Share Posted October 30, 2020 24 minutes ago, Venter said: @Nine Yes , That one I tried to fix. But failed😅 FIne as long as you keep failing in this thread and don't open another one to fail there! SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
TSz19 Posted October 30, 2020 Author Share Posted October 30, 2020 @Jos code can find a picture for me But when something hides the picture, I can't find it. Link to comment Share on other sites More sharing options...
Developers Jos Posted October 30, 2020 Developers Share Posted October 30, 2020 (edited) What's up with the shouting at me? I didn't ask what your issue is but rather told you not to open a new thread with the same question.... please. Edited October 30, 2020 by Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
TSz19 Posted October 30, 2020 Author Share Posted October 30, 2020 @Jos Ho!! Sorry i must apologize to you I rookie Sorry Link to comment Share on other sites More sharing options...
Nine Posted October 30, 2020 Share Posted October 30, 2020 To get the best chance of getting help in this forum, I would suggest a few things : 1- Make your code runable. The code you provided is obviously unrunable for any of us. 2- Make your code as small as possible. The code you provided is way too long and contains many steps that are useless to us and to your issue. 3- Provide files example if needed. 4- Show exactly what is the problem (by using comments inside the code for example) and make it easily replicable for us Good luck. “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
TSz19 Posted October 30, 2020 Author Share Posted October 30, 2020 @Nine Thank Nine Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now