Leaderboard
Popular Content
Showing content with the highest reputation on 07/12/2021 in all areas
-
[HELP] Read ini-file to Array
Trong reacted to argumentum for a topic
#include <Debug.au3> readthisini() Func readthisini() Local $iCols = 0, $ini = @ScriptDir & "\zWebServer.ini" Local $aIniSectionNames = IniReadSectionNames($ini) ;~ _DebugArrayDisplay($aIniSectionNames, "$aIniSectionNames") Local $aTemp, $aArray[$aIniSectionNames[0] + 1][2] For $n = 1 To $aIniSectionNames[0] $aArray[$n][0] = $aIniSectionNames[$n] $aArray[$n][1] = IniReadSection($ini, $aIniSectionNames[$n]) If $iCols < UBound($aArray[$n][1]) Then $iCols = UBound($aArray[$n][1]) Next Local $aReturn3D[$aIniSectionNames[0] + 1][$iCols][2] For $n1 = 1 To $aIniSectionNames[0] $aTemp = $aArray[$n1][1] If Not IsArray($aTemp) Then ContinueLoop $aReturn3D[$n1][0][0] = $aIniSectionNames[$n1] ; this holds the section name For $n2 = 1 To UBound($aTemp) - 1 For $n3 = 0 To UBound($aTemp, 2) - 1 $aReturn3D[$n1][$n2][$n3] = $aTemp[$n2][$n3] Next Next Next ; show what's in the array For $n1 = 1 To UBound($aReturn3D, 1) - 1 ConsoleWrite('+ >[' & $aReturn3D[$n1][0][0] & ']' & @CRLF) For $n2 = 1 To UBound($aReturn3D, 2) - 1 If $aReturn3D[$n1][$n2][0] & $aReturn3D[$n1][$n2][1] = "" Then ContinueLoop ConsoleWrite('- >' & $aReturn3D[$n1][$n2][0] & ' = ') ConsoleWrite($aReturn3D[$n1][$n2][1] & @CRLF) ;~ For $n3 = 0 To UBound($aReturn3D, 3) - 1 ;~ ConsoleWrite($n1 & @TAB & $n2 & @TAB & $n3 & @TAB & $aReturn3D[$n1][$n2][$n3] & @CRLF) ;~ Next Next Next Return $aReturn3D EndFunc ;==>readthisini ...and the 3D version. But if today is one of those days for you, ..take a walk and code tomorrow1 point -
The mask is not mandantory. It is purely a translation of the c++ code example on opencv website. Look at the MatchTemplate_Demo.au3 Here is an example based on your Where is wally example, which was an inspiration for this work. Keep in mind that cv::matchTemplate is reliable only if you know that the template is present in the bigger image. If not, it has to be combined with something that tells you how good the match is, for example cv::compareHist Look at _cveFindTemplate in cve_extra.au3 for a "work in progress" way to reliably find a template in a bigger image. #Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_UseX64=y #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** #include <Math.au3> #include <MsgBoxConstants.au3> #include <emgucv-autoit-bindings\cve_extra.au3> ;~ Sources: ;~ https://docs.opencv.org/4.5.1/df/dfb/group__imgproc__object.html#ga586ebfb0a7fb604b35a23d85391329be ;~ https://docs.opencv.org/4.5.1/d8/ded/samples_2cpp_2tutorial_code_2Histograms_Matching_2MatchTemplate_Demo_8cpp-example.html#a16 ;~ https://www.autoitscript.com/forum/topic/160732-opencv-udf/?do=findComment&comment=1280955 ;~ https://github.com/emgucv/emgucv/tree/4.5.1/Emgu.CV.Extern ;~ https://stackoverflow.com/a/28647930 ;~ https://samwize.com/2013/06/09/using-opencv-to-match-template-multiple-times/ ;~ https://docs.opencv.org/master/d4/dc6/tutorial_py_template_matching.html ;~ https://docs.opencv.org/4.5.1/d8/dc8/tutorial_histogram_comparison.html ;~ https://learncodebygaming.com/blog/real-time-object-detection ;~ https://docs.microsoft.com/en-us/windows/uwp/audio-video-camera/process-software-bitmaps-with-opencv ;~ https://vovkos.github.io/doxyrest-showcase/opencv/sphinx_rtd_theme/page_tutorial_histogram_calculation.html $_cve_debug = 0 _OpenCV_DLLOpen("libemgucv-windesktop-4.5.1.4349\libs\x64\cvextern.dll") ;~ _cveNamedWindow("Where's Wally") Local $matImg = _cveImread("whereWally3.jpg") ; Local $matImg = _cveImread("lena_tmpl.jpg", $CV_IMREAD_COLOR) ;~ _cveImshowMat("Where's Wally", $matImg) ;~ _cveWaitKey(0) Local $matTmp = _cveImread("wally3.jpg") ; Local $matTmp = _cveImread("tmpl.png", $CV_IMREAD_COLOR) ;~ _cveImshowMat("Where's Wally", $matTmp) ;~ _cveWaitKey(0) Local $width = _cveMatGetWidth($matImg) Local $height = _cveMatGetHeight($matImg) ConsoleWrite("image width " & $width & @CRLF) ConsoleWrite("image height " & $height & @CRLF) Local $w = _cveMatGetWidth($matTmp) Local $h = _cveMatGetHeight($matTmp) ConsoleWrite("temlpate width " & $w & @CRLF) ConsoleWrite("temlpate height " & $h & @CRLF) Local $rw = $width - $w + 1 Local $rh = $height - $h + 1 ConsoleWrite("result width " & $rw & @CRLF) ConsoleWrite("result height " & $rh & @CRLF) Local $matEmpty = _cveMatCreate() Local $matResult = _cveMatCreate() _cveMatCreateData($matResult, $rw, $rh, $CV_32FC1) ; In the way it is used by this code, ; $CV_TM_SQDIFF_NORMED is only valid for the first match Local $matchMethod = $CV_TM_CCOEFF_NORMED ; $CV_TM_SQDIFF_NORMED ; $CV_TM_CCOEFF_NORMED Local $methodAcceptsMask = $matchMethod == $CV_TM_SQDIFF Or $matchMethod == $CV_TM_CCORR_NORMED If $methodAcceptsMask Then Local $matTmpMask = _cveImread("mask.png", $CV_IMREAD_GRAYSCALE) _cveMatchTemplateMat($matImg, $matTmp, $matResult, $matchMethod, $matTmpMask) _cveMatRelease($matTmpMask) Else _cveMatchTemplateMat($matImg, $matTmp, $matResult, $matchMethod, $matEmpty) EndIf _cveNormalizeMat($matResult, $matResult, 0, 1, $CV_NORM_MINMAX, -1, $matEmpty) Local $tRedColor = _cvRGB(255, 0, 0) Local $tGreenColor = _cvRGB(0, 255, 0) Local $tBlackColor = _cvScalar(0) Local $threshold = 0.95 Local $score = 0 Local $tMinVal = DllStructCreate("double min;") Local $tMaxVal = DllStructCreate("double max;") Local $tMinLoc = DllStructCreate($tagCvPoint) Local $tMaxLoc = DllStructCreate($tagCvPoint) Local $tMatchLoc Local $tMatchRect = _cvRect(0, 0, $w, $h) Local $matMask = _cveMatCreate() Local $limit = 5 While 1 ;use infinite loop since ExitLoop will get called If $limit == 0 Then MsgBox($MB_SYSTEMMODAL, "", "There are too much matches") ExitLoop EndIf $limit = $limit - 1 _cveMinMaxLocMat($matResult, $tMinVal, $tMaxVal, $tMinLoc, $tMaxLoc, $matEmpty) ; Local $tPoint = DllStructCreate($tagCvPoint) ; $rw = _cveMatGetWidth($matResult) ; $rh = _cveMatGetHeight($matResult) ; ; Extremely slow, unreliable and causes crash. ; ; May be there is an OutOfBound error ; For $i = 1 To $rw Step 1 ; $tPoint.y = $i - 1 ; For $j = 1 To $rh Step 1 ; $tPoint.x = $j - 1 ; Local $_score = _cveMatGetAt("float", $matResult, $tPoint) ; If ($matchMethod == $CV_TM_SQDIFF Or $matchMethod == $CV_TM_SQDIFF_NORMED) Then ; $_score = 1 - $_score ; EndIf ; If $_score >= $threshold Then ; ConsoleWrite("find match at (" & $j - 1 & ", " & $i - 1 & ")" & @CRLF) ; EndIf ; Next ; Next ; $tPoint = 0 ; For SQDIFF and SQDIFF_NORMED, the best matches are lower values. For all the other methods, the higher the better If ($matchMethod == $CV_TM_SQDIFF Or $matchMethod == $CV_TM_SQDIFF_NORMED) Then $tMatchLoc = $tMinLoc $score = 1 - DllStructGetData($tMinVal, 1) _cveMatSetAt("float", $matResult, $tMinLoc, 1.0) _cveMatSetAt("float", $matResult, $tMaxLoc, 1.0) Else $tMatchLoc = $tMaxLoc $score = DllStructGetData($tMaxVal, 1) _cveMatSetAt("float", $matResult, $tMinLoc, 0.0) _cveMatSetAt("float", $matResult, $tMaxLoc, 0.0) EndIf ConsoleWrite("score " & $score & @CRLF) If $score < $threshold Then MsgBox($MB_SYSTEMMODAL, "", "There are no more suitable matches") ExitLoop EndIf $tMatchRect.x = $tMatchLoc.x $tMatchRect.y = $tMatchLoc.y ConsoleWrite("found a match at (" & $tMatchLoc.x & ", " & $tMatchLoc.y & ")" & @CRLF) ; Draw a red rectangle around the matched position _cveRectangleMat($matImg, $tMatchRect, $tRedColor, 2, $CV_LINE_8, 0) _cveImshowMat("Where's Wally", $matImg) _cveWaitKey(0) ; Make the current match location to be ignored by the next processing _cveRectangleMat($matResult, $tMatchRect, $tBlackColor, 2, $CV_LINE_8, 0) WEnd ;~ There is no garbage collector, ;~ therefore resources must be released manually ;~ to avoid memory leaks on a long running process $tMinVal = 0 $tMaxVal = 0 $tMinLoc = 0 $tMaxLoc = 0 $tMatchRect = 0 $tMatchLoc = 0 $tBlackColor = 0 $tGreenColor = 0 $tRedColor = 0 _cveMatRelease($matMask) _cveMatRelease($matResult) _cveMatRelease($matEmpty) _cveMatRelease($matTmp) _cveMatRelease($matImg) _cveDestroyWindow("Where's Wally") _Opencv_DLLClose()1 point
-
i fix it in other way, the problem was on connection/putfile flags here's how i fix it #include <FTPEx.au3> $server = 'xxxx' $username = 'xxx' $pass = 'xxx' $Open = _FTP_Open('MyFTP Control') $Conn = _FTPConnect($Open, $server, $username, $pass,0,1,0x08000000) $Ftpp = _FtpPutFile($Conn,"C:\xxx.jpg", '/xxx.jpg' , 0x08000000) Func _FTPConnect($l_InternetSession, $s_ServerName, $s_Username, $s_Password, $i_ServerPort = 0, $l_Service = 1, $l_Flags = 0, $l_Context = 0) Local $ai_InternetConnect = DllCall('wininet.dll', 'long', 'InternetConnect', 'long', $l_InternetSession, 'str', $s_ServerName, 'int', $i_ServerPort, 'str', $s_Username, 'str', $s_Password, 'long', $l_Service, 'long', $l_Flags, 'long', $l_Context) If @error OR $ai_InternetConnect[0] = 0 Then SetError(-1) Return 0 EndIf Return $ai_InternetConnect[0] EndFunc Func _FtpPutFile($l_FTPSession, $s_LocalFile, $s_RemoteFile, $l_Flags = 0, $l_Context = 0) Local $ai_FTPPutFile = DllCall('wininet.dll', 'int', 'FtpPutFile', 'long', $l_FTPSession, 'str', $s_LocalFile, 'str', $s_RemoteFile, 'long', $l_Flags, 'long', $l_Context) If @error OR $ai_FTPPutFile[0] = 0 Then SetError(-1) Return 0 EndIf Return $ai_FTPPutFile[0] EndFunc at me firewall was 100% not problem, because i try it firewall off and same result, i add those flags and it's worked i found this in forum, thanks to the forums members i fixed this Regards1 point