Jump to content

Loop fails on 9964th iteration


Go to solution Solved by Werty,

Recommended Posts

Posted

Could you post a screenshot of Tools.exe, so we can see what it looks like. (blur out any secrets).

Shouldnt be necessary with all the screengrab, files and color conversions, or checking for the whole pattern of each number, instead of just a small unique part.

But please, screenshot of tools.exe.

Some guy's script + some other guy's script = my script!

Posted

Something looks wrong in the _ScreenCapture.  You are reusing the same variable for 2 different purposes (without cleaning up the memory) :

Here :

$hBitmap = _WinAPI_AdjustBitmap($hHBitmap, $iBmpW, $iBmpH, $HALFTONE, $tAdj)

and there :

$hBitmap = _GDIPlus_BitmapCreateFromHBITMAP($hBitmap)

That must create major memory leak, IMO.

Posted (edited)
For $n = 0 To 100
    $aProcessMemoryInfo = _WinAPI_GetProcessMemoryInfo()
    ConsoleWrite( _GetNumber(@ScriptDir & "\code__51" & StringRight($n, 1) & "___.png") & @TAB & 'The peak working set: ' & $aProcessMemoryInfo[1] / 1024 / 1024 & ' MB'& @CRLF)
Next
510 The peak working set: 29.23046875 MB
511 The peak working set: 30.31640625 MB
512 The peak working set: 30.4375 MB
513 The peak working set: 30.47265625 MB
514 The peak working set: 30.484375 MB
515 The peak working set: 30.5 MB
516 The peak working set: 30.50390625 MB
517 The peak working set: 30.5078125 MB
518 The peak working set: 30.515625 MB
519 The peak working set: 30.5234375 MB
510 The peak working set: 30.5234375 MB
511 The peak working set: 30.5234375 MB
512 The peak working set: 30.53125 MB
513 The peak working set: 30.53125 MB
514 The peak working set: 30.54296875 MB
515 The peak working set: 30.54296875 MB
516 The peak working set: 30.546875 MB
517 The peak working set: 30.5546875 MB
518 The peak working set: 30.5546875 MB
519 The peak working set: 30.5546875 MB
510 The peak working set: 30.5546875 MB
511 The peak working set: 30.5546875 MB
512 The peak working set: 30.5546875 MB
513 The peak working set: 30.5546875 MB
514 The peak working set: 30.5546875 MB
515 The peak working set: 30.5546875 MB
516 The peak working set: 30.5546875 MB
517 The peak working set: 30.5546875 MB
518 The peak working set: 30.5546875 MB
519 The peak working set: 30.5546875 MB
510 The peak working set: 30.5546875 MB
511 The peak working set: 30.5546875 MB
512 The peak working set: 30.5703125 MB
513 The peak working set: 30.57421875 MB
514 The peak working set: 30.57421875 MB
515 The peak working set: 30.578125 MB
516 The peak working set: 30.578125 MB
517 The peak working set: 30.59375 MB
518 The peak working set: 30.59375 MB
519 The peak working set: 30.59375 MB
510 The peak working set: 30.59375 MB
511 The peak working set: 30.59375 MB
512 The peak working set: 30.59375 MB
513 The peak working set: 30.59375 MB
514 The peak working set: 30.59375 MB
515 The peak working set: 30.59375 MB
516 The peak working set: 30.59375 MB
517 The peak working set: 30.59375 MB
518 The peak working set: 30.59375 MB
519 The peak working set: 30.59375 MB
510 The peak working set: 30.59765625 MB
511 The peak working set: 30.59765625 MB
512 The peak working set: 30.6015625 MB
513 The peak working set: 30.6015625 MB
514 The peak working set: 30.6015625 MB
515 The peak working set: 30.6015625 MB
516 The peak working set: 30.609375 MB
517 The peak working set: 30.61328125 MB
518 The peak working set: 30.62109375 MB
519 The peak working set: 30.62109375 MB
510 The peak working set: 30.625 MB
511 The peak working set: 30.62890625 MB
512 The peak working set: 30.62890625 MB
513 The peak working set: 30.63671875 MB
514 The peak working set: 30.640625 MB
515 The peak working set: 30.640625 MB
516 The peak working set: 30.64453125 MB
517 The peak working set: 30.65234375 MB
518 The peak working set: 30.65234375 MB
519 The peak working set: 30.65234375 MB
510 The peak working set: 30.671875 MB
511 The peak working set: 30.68359375 MB
512 The peak working set: 30.6875 MB
513 The peak working set: 30.6875 MB
514 The peak working set: 30.69140625 MB
515 The peak working set: 30.6953125 MB
516 The peak working set: 30.6953125 MB
517 The peak working set: 30.6953125 MB
518 The peak working set: 30.6953125 MB
519 The peak working set: 30.6953125 MB
510 The peak working set: 30.6953125 MB
511 The peak working set: 30.6953125 MB
512 The peak working set: 30.6953125 MB
513 The peak working set: 30.6953125 MB
514 The peak working set: 30.6953125 MB
515 The peak working set: 30.6953125 MB
516 The peak working set: 30.6953125 MB
517 The peak working set: 30.6953125 MB
518 The peak working set: 30.6953125 MB
519 The peak working set: 30.6953125 MB
510 The peak working set: 30.6953125 MB
511 The peak working set: 30.6953125 MB
512 The peak working set: 30.6953125 MB
513 The peak working set: 30.6953125 MB
514 The peak working set: 30.6953125 MB
515 The peak working set: 30.6953125 MB
516 The peak working set: 30.6953125 MB
517 The peak working set: 30.6953125 MB
518 The peak working set: 30.6953125 MB
519 The peak working set: 30.6953125 MB
510 The peak working set: 30.6953125 MB

..in just 100 _GetNumber() the memory increases 2 MB.  It's got sporadic jumps in memory usage ?

Edited by argumentum
reviewed

Follow the link to my code contribution ( and other things too ).
FAQ - Please Read Before Posting.
autoit_scripter_blue_userbar.png

Posted
3 hours ago, Werty said:

Could you post a screenshot of Tools.exe, so we can see what it looks like. (blur out any secrets).

Shouldnt be necessary with all the screengrab, files and color conversions, or checking for the whole pattern of each number, instead of just a small unique part.

But please, screenshot of tools.exe.

Unfortunately not, I've already revealed too much just to get this working and the client is known to be litigious so I'd rather not risk that. However I don't think a screenshot of the application is needed to fix this issue as the issue doesn't lie elsewhere in the application - the necessary part of it is being screenshotted fine right up until the moment it's not. I've also verified the loop carries on without issue when not taking screenshots, so it seems increasingly likely the issue is GDI failing to take/save a screenshot on the 9664th iteration.

The current version is actually not doing any colour conversions or scaling so I don't actually need that custom function anymore, I've decided to replace it with the underlying _ScreenCapture UDF. It's true a memory-only solution that doesn't save every image to the filesystem would be a lot faster, but it will probably be easier to get it working this way first before refactoring to an even more memory-intensive version.

 

3 hours ago, Nine said:

Something looks wrong in the _ScreenCapture.  You are reusing the same variable for 2 different purposes (without cleaning up the memory) :

Here :

$hBitmap = _WinAPI_AdjustBitmap($hHBitmap, $iBmpW, $iBmpH, $HALFTONE, $tAdj)

and there :

$hBitmap = _GDIPlus_BitmapCreateFromHBITMAP($hBitmap)

That must create major memory leak, IMO.

Good shout, unfortunately changing the first one to $hBitmapAdj and replacing the reference on the second line still doesn't fix this, so it doesn't look like the 9664 bug is being caused by this. However I have now removed that custom function entirely so that should simplify things quite a bit.

Posted (edited)
49 minutes ago, argumentum said:
For $n = 0 To 100
    $aProcessMemoryInfo = _WinAPI_GetProcessMemoryInfo()
    ConsoleWrite( _GetNumber(@ScriptDir & "\code__51" & StringRight($n, 1) & "___.png") & @TAB & 'The peak working set: ' & $aProcessMemoryInfo[1] / 1024 / 1024 & ' MB'& @CRLF)
Next
510 The peak working set: 29.23046875 MB
511 The peak working set: 30.31640625 MB
512 The peak working set: 30.4375 MB
513 The peak working set: 30.47265625 MB
514 The peak working set: 30.484375 MB
515 The peak working set: 30.5 MB
516 The peak working set: 30.50390625 MB
517 The peak working set: 30.5078125 MB
518 The peak working set: 30.515625 MB
519 The peak working set: 30.5234375 MB
510 The peak working set: 30.5234375 MB
511 The peak working set: 30.5234375 MB
512 The peak working set: 30.53125 MB
513 The peak working set: 30.53125 MB
514 The peak working set: 30.54296875 MB
515 The peak working set: 30.54296875 MB
516 The peak working set: 30.546875 MB
517 The peak working set: 30.5546875 MB
518 The peak working set: 30.5546875 MB
519 The peak working set: 30.5546875 MB
510 The peak working set: 30.5546875 MB
511 The peak working set: 30.5546875 MB
512 The peak working set: 30.5546875 MB
513 The peak working set: 30.5546875 MB
514 The peak working set: 30.5546875 MB
515 The peak working set: 30.5546875 MB
516 The peak working set: 30.5546875 MB
517 The peak working set: 30.5546875 MB
518 The peak working set: 30.5546875 MB
519 The peak working set: 30.5546875 MB
510 The peak working set: 30.5546875 MB
511 The peak working set: 30.5546875 MB
512 The peak working set: 30.5703125 MB
513 The peak working set: 30.57421875 MB
514 The peak working set: 30.57421875 MB
515 The peak working set: 30.578125 MB
516 The peak working set: 30.578125 MB
517 The peak working set: 30.59375 MB
518 The peak working set: 30.59375 MB
519 The peak working set: 30.59375 MB
510 The peak working set: 30.59375 MB
511 The peak working set: 30.59375 MB
512 The peak working set: 30.59375 MB
513 The peak working set: 30.59375 MB
514 The peak working set: 30.59375 MB
515 The peak working set: 30.59375 MB
516 The peak working set: 30.59375 MB
517 The peak working set: 30.59375 MB
518 The peak working set: 30.59375 MB
519 The peak working set: 30.59375 MB
510 The peak working set: 30.59765625 MB
511 The peak working set: 30.59765625 MB
512 The peak working set: 30.6015625 MB
513 The peak working set: 30.6015625 MB
514 The peak working set: 30.6015625 MB
515 The peak working set: 30.6015625 MB
516 The peak working set: 30.609375 MB
517 The peak working set: 30.61328125 MB
518 The peak working set: 30.62109375 MB
519 The peak working set: 30.62109375 MB
510 The peak working set: 30.625 MB
511 The peak working set: 30.62890625 MB
512 The peak working set: 30.62890625 MB
513 The peak working set: 30.63671875 MB
514 The peak working set: 30.640625 MB
515 The peak working set: 30.640625 MB
516 The peak working set: 30.64453125 MB
517 The peak working set: 30.65234375 MB
518 The peak working set: 30.65234375 MB
519 The peak working set: 30.65234375 MB
510 The peak working set: 30.671875 MB
511 The peak working set: 30.68359375 MB
512 The peak working set: 30.6875 MB
513 The peak working set: 30.6875 MB
514 The peak working set: 30.69140625 MB
515 The peak working set: 30.6953125 MB
516 The peak working set: 30.6953125 MB
517 The peak working set: 30.6953125 MB
518 The peak working set: 30.6953125 MB
519 The peak working set: 30.6953125 MB
510 The peak working set: 30.6953125 MB
511 The peak working set: 30.6953125 MB
512 The peak working set: 30.6953125 MB
513 The peak working set: 30.6953125 MB
514 The peak working set: 30.6953125 MB
515 The peak working set: 30.6953125 MB
516 The peak working set: 30.6953125 MB
517 The peak working set: 30.6953125 MB
518 The peak working set: 30.6953125 MB
519 The peak working set: 30.6953125 MB
510 The peak working set: 30.6953125 MB
511 The peak working set: 30.6953125 MB
512 The peak working set: 30.6953125 MB
513 The peak working set: 30.6953125 MB
514 The peak working set: 30.6953125 MB
515 The peak working set: 30.6953125 MB
516 The peak working set: 30.6953125 MB
517 The peak working set: 30.6953125 MB
518 The peak working set: 30.6953125 MB
519 The peak working set: 30.6953125 MB
510 The peak working set: 30.6953125 MB

..in just 100 _GetNumber() the memory increases 2 MB.  It's got sporadic jumps in memory usage ?

 

Thanks for this, these results look stable to me but I suppose that's expected for a simple loop. I'll implement in my own loop after all the GDI disposal and see what the results look like.

Edited by Hashim
Posted (edited)
51 minutes ago, Hashim said:

unfortunately changing the first one to $hBitmapAdj and replacing the reference on the second line still doesn't fix this

You need to delete the object otherwise it is just as useless as using the same variable

ps. next time, post a runable script that we actually can run that shows the issue, otherwise it is just a guessing game

Edited by Nine
Posted
21 minutes ago, Nine said:

You need to delete the object otherwise it is just as useless as using the same variable

ps. next time, post a runable script that we actually can run that shows the issue, otherwise it is just a guessing game

Good point, I completely forgot about disposal. This may well have been the issue as I've just tested again after replacing the _GetCapture wrapper function with using _ScreenCapture directly, and have managed to successfully get past 15,000 iterations! Either way it seems the bug was somewhere in that wrapper function, which isn't surprising since ioa747 didn't write it with this level of abuse in mind, but good to know anyway for anyone that does actually need its scaling and adjustment functions.

Posted (edited)

if the "\Bitmap ID Failed\" folder is placed on a ram drive
the process will speed up significantly
 

; Version: 5.0

#include <GDIPlus.au3>
#include <Array.au3>
#include <File.au3>

;~ Local $Result = _GetNumber(@ScriptDir & "\100num\152.png")
;~ MsgBox($MB_SYSTEMMODAL, "_GetNumber", $Result)

Test()

;--------------------------------------------------------------------------------------------------------------------------------
Func _Exit()   ; Cleanup & exit
    ; Cleanup resources
    _GDIPlus_Shutdown()
    
    Exit
EndFunc
;--------------------------------------------------------------------------------------------------------------------------------
Func _GetNumber($sFileName, $hColor = 0x00FF00)   ; Main Program
    ; Initialize GDI+ to work with bitmaps
    _GDIPlus_Startup()

    ; Capture the color map for the specified area
    Local $aColorMap = CaptureAreaColorMap($sFileName)
    If @error = 1 Then
        MsgBox($MB_SYSTEMMODAL, "LineNumber:" & @ScriptLineNumber, "Path was invalid.")
        _Exit()
    EndIf

;~  _ArrayDisplay($aColorMap)

    Local $Result = FindNumberUsingColorMap($aColorMap, $hColor)
;~  MsgBox($MB_SYSTEMMODAL, "$Result", $Result)

    ; Cleanup resources
    _GDIPlus_Shutdown()

    Return $Result
EndFunc   ;==>_GetNumber
;--------------------------------------------------------------------------------------------------------------------------------
Func CaptureAreaColorMap($sFileName)   ; create color map array

    ; Capture the screen area as a bitmap
    Local $hBitmap = _GDIPlus_BitmapCreateFromFile($sFileName)
    If @error Then Return SetError(1, 0, "") ; because the user ( me ) might do the unexpected  ;)

    ; Get the width and height of the captured area
    Local $width = _GDIPlus_ImageGetWidth($hBitmap)
    Local $height = _GDIPlus_ImageGetHeight($hBitmap)
;~  ConsoleWrite("Image: $width=" & $width & ", $height=" & $height & @CRLF)

    ; Create an array to store color values
    Local $aColorMap[$width][$height]

    ; Loop through each pixel in the bitmap and retrieve its color
    For $y = 0 To $height - 1
        For $x = 0 To $width - 1
            ; Get the pixel color from the bitmap in ARGB format
            Local $argbColor = _GDIPlus_BitmapGetPixel($hBitmap, $x, $y)
            ; Convert ARGB to BGR for comparison (ignore the alpha channel)
            Local $bgrColor = BitAND($argbColor, 0x00FFFFFF)
            $aColorMap[$x][$y] = $bgrColor
        Next
    Next

    ; Cleanup resources
    _GDIPlus_BitmapDispose($hBitmap)

    Return $aColorMap
EndFunc   ;==>CaptureAreaColorMap
;--------------------------------------------------------------------------------------------------------------------------------
Func FindNumberUsingColorMap($aColorMap, $hColor = 0x00FF00)   ; find number in color map array
    Local $width = UBound($aColorMap, 1)
    Local $height = UBound($aColorMap, 2)

    Local $firstRow = -1, $lastRow = -1, $firstCol = -1, $lastCol = -1

    ; Scan for the first and last rows and columns with $hColor pixels
    For $y = 0 To $height - 1
        For $x = 0 To $width - 1
            If $aColorMap[$x][$y] = $hColor Then
                If $firstRow = -1 Then $firstRow = $y
                $lastRow = $y
                If $firstCol = -1 Or $x < $firstCol Then $firstCol = $x
                If $lastCol = -1 Or $x > $lastCol Then $lastCol = $x
            EndIf
        Next
    Next

    If $firstRow = -1 Or $lastRow = -1 Or $firstCol = -1 Or $lastCol = -1 Then
        MsgBox($MB_SYSTEMMODAL, "LineNumber:" & @ScriptLineNumber, "No color found" & @TAB & @TAB)
        _Exit()
    EndIf

    ; each number Display is a matrix of 14x20 pixels
    Local $numberWidth = 14 ; set number width per digit
    Local $numberSpace = 2  ; set Space between digits

    Local $Empty = 0, $Corection = 0

    ; Corection for boundaries if 1st digit = 1
    For $x = $firstCol To $lastCol - 1
        If $aColorMap[$x][$firstRow] = 0x000000 Then
            $Empty += 1
            If $Empty = 3 Then
                ;found 1st Space between digits
                $Corection = $firstCol - 1 - Abs($x - $numberWidth - $numberSpace)
                ExitLoop
            EndIf
        Else
            $Empty = 0
        EndIf
    Next

    If $Corection > 0 Then $firstCol = $firstCol - $Corection

    Local $numberStart = $firstCol

;~  ConsoleWrite("$Corection=" & $Corection & @CRLF)
;~  ConsoleWrite("Display_boundaries firstRow:" & $firstRow & " lastRow:" & $lastRow & " firstCol:" & $firstCol & " lastCol:" & $lastCol & @CRLF)
;~  ConsoleWrite("" & @CRLF)

    Local $aNum[11][3]

    ; Define boundaries for each number position
    For $i = 1 To 10
        $aNum[$i][0] = $numberStart
        $aNum[$i][1] = $numberStart + $numberWidth
        If $numberStart + $numberWidth + $numberSpace > $lastCol Then ExitLoop
        $numberStart += $numberWidth + $numberSpace
        $aNum[0][0] = $i + 1
    Next
;~  _ArrayDisplay($aNum)
    Local $sNumber

    ; Generate patterns for each found number
    For $i = 1 To $aNum[0][0]
        Local $sPattern = ""
        For $y = $firstRow To $lastRow
            For $x = $aNum[$i][0] To $aNum[$i][1] - 1
                If $aColorMap[$x][$y] = $hColor Then
                    $sPattern &= "1"
                Else
                    $sPattern &= "."
                EndIf
            Next
            $sPattern &= @CRLF
        Next
        $sNumber &= _GetPattern($sPattern)
    Next

    Return $sNumber
EndFunc   ;==>FindNumberUsingColorMap
;--------------------------------------------------------------------------------------------------------------------------------
Func _GetPattern($sPattern)  ; patterns for each digit
;~  ConsoleWrite("**************" & @CRLF & $sPattern & @CRLF)
    Local $aNumber[10]

    ; Define simplified patterns for each digit

    $aNumber[0] = "" ; Pattern for '0'
    $aNumber[0] &= "...11.11.11..." & @CRLF
    $aNumber[0] &= "...11.11.11..." & @CRLF
    $aNumber[0] &= ".............." & @CRLF
    $aNumber[0] &= "11..........11" & @CRLF
    $aNumber[0] &= "11..........11" & @CRLF
    $aNumber[0] &= ".............." & @CRLF
    $aNumber[0] &= "11.......11.11" & @CRLF
    $aNumber[0] &= "11.......11.11" & @CRLF
    $aNumber[0] &= ".............." & @CRLF
    $aNumber[0] &= "11....11....11" & @CRLF
    $aNumber[0] &= "11....11....11" & @CRLF
    $aNumber[0] &= ".............." & @CRLF
    $aNumber[0] &= "11.11.......11" & @CRLF
    $aNumber[0] &= "11.11.......11" & @CRLF
    $aNumber[0] &= ".............." & @CRLF
    $aNumber[0] &= "11..........11" & @CRLF
    $aNumber[0] &= "11..........11" & @CRLF
    $aNumber[0] &= ".............." & @CRLF
    $aNumber[0] &= "...11.11.11..." & @CRLF
    $aNumber[0] &= "...11.11.11..." & @CRLF


    $aNumber[1] = "" ; Pattern for '1'
    $aNumber[1] &= "......11......" & @CRLF
    $aNumber[1] &= "......11......" & @CRLF
    $aNumber[1] &= ".............." & @CRLF
    $aNumber[1] &= "...11.11......" & @CRLF
    $aNumber[1] &= "...11.11......" & @CRLF
    $aNumber[1] &= ".............." & @CRLF
    $aNumber[1] &= "......11......" & @CRLF
    $aNumber[1] &= "......11......" & @CRLF
    $aNumber[1] &= ".............." & @CRLF
    $aNumber[1] &= "......11......" & @CRLF
    $aNumber[1] &= "......11......" & @CRLF
    $aNumber[1] &= ".............." & @CRLF
    $aNumber[1] &= "......11......" & @CRLF
    $aNumber[1] &= "......11......" & @CRLF
    $aNumber[1] &= ".............." & @CRLF
    $aNumber[1] &= "......11......" & @CRLF
    $aNumber[1] &= "......11......" & @CRLF
    $aNumber[1] &= ".............." & @CRLF
    $aNumber[1] &= "...11.11.11..." & @CRLF
    $aNumber[1] &= "...11.11.11..." & @CRLF


    $aNumber[2] = "" ; Pattern for '2'
    $aNumber[2] &= "...11.11.11..." & @CRLF
    $aNumber[2] &= "...11.11.11..." & @CRLF
    $aNumber[2] &= ".............." & @CRLF
    $aNumber[2] &= "11..........11" & @CRLF
    $aNumber[2] &= "11..........11" & @CRLF
    $aNumber[2] &= ".............." & @CRLF
    $aNumber[2] &= "............11" & @CRLF
    $aNumber[2] &= "............11" & @CRLF
    $aNumber[2] &= ".............." & @CRLF
    $aNumber[2] &= "......11.11..." & @CRLF
    $aNumber[2] &= "......11.11..." & @CRLF
    $aNumber[2] &= ".............." & @CRLF
    $aNumber[2] &= "...11........." & @CRLF
    $aNumber[2] &= "...11........." & @CRLF
    $aNumber[2] &= ".............." & @CRLF
    $aNumber[2] &= "11............" & @CRLF
    $aNumber[2] &= "11............" & @CRLF
    $aNumber[2] &= ".............." & @CRLF
    $aNumber[2] &= "11.11.11.11.11" & @CRLF
    $aNumber[2] &= "11.11.11.11.11" & @CRLF


    $aNumber[3] = "" ; Pattern for '3'
    $aNumber[3] &= "...11.11.11..." & @CRLF
    $aNumber[3] &= "...11.11.11..." & @CRLF
    $aNumber[3] &= ".............." & @CRLF
    $aNumber[3] &= "11..........11" & @CRLF
    $aNumber[3] &= "11..........11" & @CRLF
    $aNumber[3] &= ".............." & @CRLF
    $aNumber[3] &= "............11" & @CRLF
    $aNumber[3] &= "............11" & @CRLF
    $aNumber[3] &= ".............." & @CRLF
    $aNumber[3] &= "......11.11..." & @CRLF
    $aNumber[3] &= "......11.11..." & @CRLF
    $aNumber[3] &= ".............." & @CRLF
    $aNumber[3] &= "............11" & @CRLF
    $aNumber[3] &= "............11" & @CRLF
    $aNumber[3] &= ".............." & @CRLF
    $aNumber[3] &= "11..........11" & @CRLF
    $aNumber[3] &= "11..........11" & @CRLF
    $aNumber[3] &= ".............." & @CRLF
    $aNumber[3] &= "...11.11.11..." & @CRLF
    $aNumber[3] &= "...11.11.11..." & @CRLF


    $aNumber[4] = "" ; Pattern for '4'
    $aNumber[4] &= ".........11..." & @CRLF
    $aNumber[4] &= ".........11..." & @CRLF
    $aNumber[4] &= ".............." & @CRLF
    $aNumber[4] &= "......11.11..." & @CRLF
    $aNumber[4] &= "......11.11..." & @CRLF
    $aNumber[4] &= ".............." & @CRLF
    $aNumber[4] &= "...11....11..." & @CRLF
    $aNumber[4] &= "...11....11..." & @CRLF
    $aNumber[4] &= ".............." & @CRLF
    $aNumber[4] &= "11.......11..." & @CRLF
    $aNumber[4] &= "11.......11..." & @CRLF
    $aNumber[4] &= ".............." & @CRLF
    $aNumber[4] &= "11.11.11.11.11" & @CRLF
    $aNumber[4] &= "11.11.11.11.11" & @CRLF
    $aNumber[4] &= ".............." & @CRLF
    $aNumber[4] &= ".........11..." & @CRLF
    $aNumber[4] &= ".........11..." & @CRLF
    $aNumber[4] &= ".............." & @CRLF
    $aNumber[4] &= ".........11..." & @CRLF
    $aNumber[4] &= ".........11..." & @CRLF


    $aNumber[5] = "" ; Pattern for '5'
    $aNumber[5] &= "11.11.11.11.11" & @CRLF
    $aNumber[5] &= "11.11.11.11.11" & @CRLF
    $aNumber[5] &= ".............." & @CRLF
    $aNumber[5] &= "11............" & @CRLF
    $aNumber[5] &= "11............" & @CRLF
    $aNumber[5] &= ".............." & @CRLF
    $aNumber[5] &= "11.11.11.11..." & @CRLF
    $aNumber[5] &= "11.11.11.11..." & @CRLF
    $aNumber[5] &= ".............." & @CRLF
    $aNumber[5] &= "............11" & @CRLF
    $aNumber[5] &= "............11" & @CRLF
    $aNumber[5] &= ".............." & @CRLF
    $aNumber[5] &= "............11" & @CRLF
    $aNumber[5] &= "............11" & @CRLF
    $aNumber[5] &= ".............." & @CRLF
    $aNumber[5] &= "11..........11" & @CRLF
    $aNumber[5] &= "11..........11" & @CRLF
    $aNumber[5] &= ".............." & @CRLF
    $aNumber[5] &= "...11.11.11..." & @CRLF
    $aNumber[5] &= "...11.11.11..." & @CRLF


    $aNumber[6] = "" ; Pattern for '6'
    $aNumber[6] &= "......11.11..." & @CRLF
    $aNumber[6] &= "......11.11..." & @CRLF
    $aNumber[6] &= ".............." & @CRLF
    $aNumber[6] &= "...11........." & @CRLF
    $aNumber[6] &= "...11........." & @CRLF
    $aNumber[6] &= ".............." & @CRLF
    $aNumber[6] &= "11............" & @CRLF
    $aNumber[6] &= "11............" & @CRLF
    $aNumber[6] &= ".............." & @CRLF
    $aNumber[6] &= "11.11.11.11..." & @CRLF
    $aNumber[6] &= "11.11.11.11..." & @CRLF
    $aNumber[6] &= ".............." & @CRLF
    $aNumber[6] &= "11..........11" & @CRLF
    $aNumber[6] &= "11..........11" & @CRLF
    $aNumber[6] &= ".............." & @CRLF
    $aNumber[6] &= "11..........11" & @CRLF
    $aNumber[6] &= "11..........11" & @CRLF
    $aNumber[6] &= ".............." & @CRLF
    $aNumber[6] &= "...11.11.11..." & @CRLF
    $aNumber[6] &= "...11.11.11..." & @CRLF

    $aNumber[7] = "" ; Pattern for '7'
    $aNumber[7] &= "11.11.11.11.11" & @CRLF
    $aNumber[7] &= "11.11.11.11.11" & @CRLF
    $aNumber[7] &= ".............." & @CRLF
    $aNumber[7] &= "............11" & @CRLF
    $aNumber[7] &= "............11" & @CRLF
    $aNumber[7] &= ".............." & @CRLF
    $aNumber[7] &= ".........11..." & @CRLF
    $aNumber[7] &= ".........11..." & @CRLF
    $aNumber[7] &= ".............." & @CRLF
    $aNumber[7] &= "......11......" & @CRLF
    $aNumber[7] &= "......11......" & @CRLF
    $aNumber[7] &= ".............." & @CRLF
    $aNumber[7] &= "...11........." & @CRLF
    $aNumber[7] &= "...11........." & @CRLF
    $aNumber[7] &= ".............." & @CRLF
    $aNumber[7] &= "...11........." & @CRLF
    $aNumber[7] &= "...11........." & @CRLF
    $aNumber[7] &= ".............." & @CRLF
    $aNumber[7] &= "...11........." & @CRLF
    $aNumber[7] &= "...11........." & @CRLF

    $aNumber[8] = "" ; Pattern for '8'
    $aNumber[8] &= "...11.11.11..." & @CRLF
    $aNumber[8] &= "...11.11.11..." & @CRLF
    $aNumber[8] &= ".............." & @CRLF
    $aNumber[8] &= "11..........11" & @CRLF
    $aNumber[8] &= "11..........11" & @CRLF
    $aNumber[8] &= ".............." & @CRLF
    $aNumber[8] &= "11..........11" & @CRLF
    $aNumber[8] &= "11..........11" & @CRLF
    $aNumber[8] &= ".............." & @CRLF
    $aNumber[8] &= "...11.11.11..." & @CRLF
    $aNumber[8] &= "...11.11.11..." & @CRLF
    $aNumber[8] &= ".............." & @CRLF
    $aNumber[8] &= "11..........11" & @CRLF
    $aNumber[8] &= "11..........11" & @CRLF
    $aNumber[8] &= ".............." & @CRLF
    $aNumber[8] &= "11..........11" & @CRLF
    $aNumber[8] &= "11..........11" & @CRLF
    $aNumber[8] &= ".............." & @CRLF
    $aNumber[8] &= "...11.11.11..." & @CRLF
    $aNumber[8] &= "...11.11.11..." & @CRLF

    $aNumber[9] = "" ; Pattern for '9'
    $aNumber[9] &= "...11.11.11..." & @CRLF
    $aNumber[9] &= "...11.11.11..." & @CRLF
    $aNumber[9] &= ".............." & @CRLF
    $aNumber[9] &= "11..........11" & @CRLF
    $aNumber[9] &= "11..........11" & @CRLF
    $aNumber[9] &= ".............." & @CRLF
    $aNumber[9] &= "11..........11" & @CRLF
    $aNumber[9] &= "11..........11" & @CRLF
    $aNumber[9] &= ".............." & @CRLF
    $aNumber[9] &= "...11.11.11.11" & @CRLF
    $aNumber[9] &= "...11.11.11.11" & @CRLF
    $aNumber[9] &= ".............." & @CRLF
    $aNumber[9] &= "............11" & @CRLF
    $aNumber[9] &= "............11" & @CRLF
    $aNumber[9] &= ".............." & @CRLF
    $aNumber[9] &= ".........11..." & @CRLF
    $aNumber[9] &= ".........11..." & @CRLF
    $aNumber[9] &= ".............." & @CRLF
    $aNumber[9] &= "...11.11......" & @CRLF
    $aNumber[9] &= "...11.11......" & @CRLF


    Switch $sPattern
        Case $aNumber[0]
            Return 0
        Case $aNumber[1]
            Return 1
        Case $aNumber[2]
            Return 2
        Case $aNumber[3]
            Return 3
        Case $aNumber[4]
            Return 4
        Case $aNumber[5]
            Return 5
        Case $aNumber[6]
            Return 6
        Case $aNumber[7]
            Return 7
        Case $aNumber[8]
            Return 8
        Case $aNumber[9]
            Return 9
        Case Else
            Return SetError(1, 0, "")
    EndSwitch
EndFunc   ;==>_GetPattern
;--------------------------------------------------------------------------------------------------------------------------------
Func Test()   ; _GetNumber for all

    Run("Tool.exe") ;
    Local $tool = WinWaitActive("Tool", "", 3)
    ControlClick($tool, "", "TTabSheet1", "primary", 1, 210, 50)
    ControlCommand($tool, "", "TFlatComboBox1", "SelectString", "Old")

    Local $db = FileOpen(@ScriptDir & "\tool-db.txt", 1)

    DirRemove("Bitmap ID Failed", 1)
    DirCreate("Bitmap ID Failed")

    ; Initialize GDI+ to work with bitmaps
    _GDIPlus_Startup()

    For $loop = 0 To 999999

        $serial = StringFormat('%06i', $loop)

        ControlSetText($tool, "", "TFlatMaskEdit3", "S.N: 9" & $serial) ; Enter serial number prefixed with the check digit
        ControlClick($tool, "", "TTabSheet1", "primary", 1, 69, 50) ; Press "Generate"

        ; Captures a region of the screen
        $sImageFile = @ScriptDir & "\Bitmap ID Failed\" & $serial & ".png"
        _ScreenCapture_Capture($sImageFile, 792, 450, 927, 480, False)

        ; Capture the color map for the specified area
        Local $aColorMap = CaptureAreaColorMap($sImageFile)
        If @error = 1 Then
            MsgBox($MB_SYSTEMMODAL, "LineNumber:" & @ScriptLineNumber, "File:" & @CRLF &  $sImageResult & @CRLF & " not found")
            _Exit()
        EndIf

        Local $output = FindNumberUsingColorMap($aColorMap)

        If (StringLen($output) = 3 And StringIsDigit($output)) Then FileDelete($sImageResult)

        FileWrite($db, $serial & "," & $output & @LF)

    Next

    FileClose($db)

    ; Cleanup resources
    _GDIPlus_Shutdown()
EndFunc   ;==>Test
;--------------------------------------------------------------------------------------------------------------------------------

 

I modified the script so that it calls _GDIPlus_Startup() once at the beginning,
and _GDIPlus_Shutdown() once at the end
instead of calling her for every number
I replaced the _ScreenCapture  function (although I believe I fixed it after  @Nine 's comments),
with _ScreenCapture_Capture  (since you didn't need the extras staff of _ScreenCapture)

I did a test with
Test("M:\TEMP\100num") 
where M: is my ram disk, and  100num is a folder with 17 .png files

Func Test($sFolderPath, $hColor = 0x00FF00)   ; _GetNumber for all the *.png files in $sFolderPath directory

    ; List all the *.png files in $sFolderPath directory
    Local $aFileList = _FileListToArray($sFolderPath, "*.png", $FLTA_FILES)
    If @error = 1 Then
        MsgBox($MB_SYSTEMMODAL, "LineNumber:" & @ScriptLineNumber, "Path was invalid.")
        Exit
    EndIf
    If @error = 4 Then
        MsgBox($MB_SYSTEMMODAL, "LineNumber:" & @ScriptLineNumber, "No file(s) were found.")
        Exit
    EndIf

    _ArrayColInsert($aFileList, 1) ; add 1 column to hold the numbers

    ; Initialize GDI+ to work with bitmaps
    _GDIPlus_Startup()

    Local $cnt = 0
    Local $CleanTime = 0

    For $j = 1 To 1000
        For $i = 1 To $aFileList[0][0]
            $cnt += 1
            ConsoleWrite("$cnt: " & $cnt & @CRLF)

            ; Capture the color map for the specified area
            Local $aColorMap = CaptureAreaColorMap($sFolderPath & "\" & $aFileList[$i][0])
            If @error = 1 Then
                MsgBox($MB_SYSTEMMODAL, "LineNumber:" & @ScriptLineNumber, "Path was invalid.")
                Exit
            EndIf

            $aFileList[$i][1] = FindNumberUsingColorMap($aColorMap, $hColor)

            ; Rename a file using FileMove and overwrite the new file if it exists.
;~          FileMove($sFolderPath & "\" & $aFileList[$i][0], $sFolderPath & "\" & $aFileList[$i][1] & ".png", $FC_OVERWRITE)

;~          $aProcessMemoryInfo = _WinAPI_GetProcessMemoryInfo()
;~          ConsoleWrite('The peak working set: ' & $aProcessMemoryInfo[1] / 1024 / 1014 & ' MB' & @CRLF)

        Next
    Next

    _ArrayDisplay($aFileList, "$aFileList")

    ; Cleanup resources
    _GDIPlus_Shutdown()
EndFunc   ;==>Test

 

Edited by ioa747

I know that I know nothing

Posted
4 hours ago, ioa747 said:
 $aNumber[0] = "" ; Pattern for '0'
    $aNumber[0] &= "...11.11.11..." & @CRLF
    $aNumber[0] &= "...11.11.11..." & @CRLF
    $aNumber[0] &= ".............." & @CRLF
    $aNumber[0] &= "11..........11" & @CRLF
    $aNumber[0] &= "11..........11" & @CRLF
    $aNumber[0] &= ".............." & @CRLF
    $aNumber[0] &= "11.......11.11" & @CRLF
    $aNumber[0] &= "11.......11.11" & @CRLF
    $aNumber[0] &= ".............." & @CRLF
    $aNumber[0] &= "11....11....11" & @CRLF
    $aNumber[0] &= "11....11....11" & @CRLF
    $aNumber[0] &= ".............." & @CRLF
    $aNumber[0] &= "11.11.......11" & @CRLF
    $aNumber[0] &= "11.11.......11" & @CRLF
    $aNumber[0] &= ".............." & @CRLF
    $aNumber[0] &= "11..........11" & @CRLF
    $aNumber[0] &= "11..........11" & @CRLF
    $aNumber[0] &= ".............." & @CRLF
    $aNumber[0] &= "...11.11.11..." & @CRLF
    $aNumber[0] &= "...11.11.11..." & @CRLF

You dont need to check the whole pattern, the first column in each digit is unique...

 

Image49.png

Some guy's script + some other guy's script = my script!

Posted
37 minutes ago, argumentum said:

as the number one could be just empty.

Doesnt matter, it'll work fine as the numbers are always 3 digits with a leading zero when the number is less than 100, like "......043......", as per his other thread where he posts examples of numbers.

Some guy's script + some other guy's script = my script!

Posted

True, but you must be careful about the order you are looking for a match (ex : don't look for 4 before 6, don't look for 3 before 8 ) because you may end up for false positive.

Posted (edited)

@Werty  just for information

the first column actually are 2 columns (2 pixels)

I did a test on a sample of 1700 images (1700 * 3 = 5100 numbers)

with 1 columns processed in: 103.986 seconds
with 2 columns processed in: 104.018 seconds
with 14 columns processed in: 105.922 seconds

in the 17 numbers I have, they didn't make any mistakes

 

Edited by ioa747
add with 1 columns

I know that I know nothing

Posted (edited)

@Nine

How so, they are unique so how can they give a false positive? You check both the lit and unlit pixels.

We could store them in one byte each, they are 7 pixels tall (yes, i know they are actually taller but we only use those we need), and 7 bits fits a byte they would become (reading from top to bottom in little-endian)...

0 = 62
1 = 0
2 = 35
3 = 34
4 = 12
5 = 114
6 = 30
7 = 64
8 = 54
9 = 48

Edited by Werty

Some guy's script + some other guy's script = my script!

Posted
1 minute ago, ioa747 said:

the first column actually are 2 columns

Yes, but you are supposed to skip those second ones, and only read the needed ones, i'll see if I can mock up an example later using pixelgetcolor, dinner time now. 😛

Some guy's script + some other guy's script = my script!

Posted
1 hour ago, Werty said:

Doesnt matter, it'll work fine as the numbers are always 3 digits with a leading zero when...

Don't know about that. The OP shares bits and pieces. The extra millisecond saved is not that important. Producing an unequivocal output is**.
We should see if the OP fixed the high loop count crush. That merits attention. 

** Not saying that your trend of thought is wrong  

Follow the link to my code contribution ( and other things too ).
FAQ - Please Read Before Posting.
autoit_scripter_blue_userbar.png

Posted (edited)

Here it is the edition with a single column patern
 

; https://www.autoitscript.com/forum/topic/211521-ocr-from-a-small-area/?do=findComment&comment=1538057
; Version: 5.0.2

#include <GDIPlus.au3>
#include <Array.au3>
#include <File.au3>
#include <WinAPIProc.au3>

;~ Local $Result = _GetNumber(@ScriptDir & "\100num\040.png")
;~ MsgBox($MB_SYSTEMMODAL, "_GetNumber", $Result)

Test("M:\TEMP\100num")

;--------------------------------------------------------------------------------------------------------------------------------
Func _GetNumber($sFileName, $hColor = 0x00FF00)   ; Main Program
    ; Initialize GDI+ to work with bitmaps
    _GDIPlus_Startup()

    ; Capture the color map for the specified area
    Local $aColorMap = CaptureAreaColorMap($sFileName)
    If @error = 1 Then
        MsgBox($MB_SYSTEMMODAL, "LineNumber:" & @ScriptLineNumber, "Path was invalid.")
        Exit
    EndIf

;~  _ArrayDisplay($aColorMap)

    Local $Result = FindNumberUsingColorMap($aColorMap, $hColor)
;~  MsgBox($MB_SYSTEMMODAL, "$Result", $Result)

    ; Cleanup resources
    _GDIPlus_Shutdown()

    Return $Result
EndFunc   ;==>_GetNumber
;--------------------------------------------------------------------------------------------------------------------------------
Func CaptureAreaColorMap($sFileName)   ; create color map array
    ; Initialize GDI+ to work with bitmaps
    ;_GDIPlus_Startup()

    ; Capture the screen area as a bitmap
    Local $hBitmap = _GDIPlus_BitmapCreateFromFile($sFileName)
    If @error Then Return SetError(1, 0, "") ; because the user ( me ) might do the unexpected  ;)

    ; Get the width and height of the captured area
    Local $width = _GDIPlus_ImageGetWidth($hBitmap)
    Local $height = _GDIPlus_ImageGetHeight($hBitmap)
;~  ConsoleWrite("Image: $width=" & $width & ", $height=" & $height & @CRLF)

    ; Create an array to store color values
    Local $aColorMap[$width][$height]

    ; Loop through each pixel in the bitmap and retrieve its color
    For $y = 0 To $height - 1
        For $x = 0 To $width - 1
            ; Get the pixel color from the bitmap in ARGB format
            Local $argbColor = _GDIPlus_BitmapGetPixel($hBitmap, $x, $y)
            ; Convert ARGB to BGR for comparison (ignore the alpha channel)
            Local $bgrColor = BitAND($argbColor, 0x00FFFFFF)
            $aColorMap[$x][$y] = $bgrColor
        Next
    Next

    ; Cleanup resources
    _GDIPlus_BitmapDispose($hBitmap)
    ;_GDIPlus_Shutdown()

    Return $aColorMap
EndFunc   ;==>CaptureAreaColorMap
;--------------------------------------------------------------------------------------------------------------------------------
Func FindNumberUsingColorMap($aColorMap, $hColor = 0x00FF00)   ; find number in color map array
    Local $width = UBound($aColorMap, 1)
    Local $height = UBound($aColorMap, 2)

    Local $firstRow = -1, $lastRow = -1, $firstCol = -1, $lastCol = -1

    ; Scan for the first and last rows and columns with $hColor pixels
    For $y = 0 To $height - 1
        For $x = 0 To $width - 1
            If $aColorMap[$x][$y] = $hColor Then
                If $firstRow = -1 Then $firstRow = $y
                $lastRow = $y
                If $firstCol = -1 Or $x < $firstCol Then $firstCol = $x
                If $lastCol = -1 Or $x > $lastCol Then $lastCol = $x
            EndIf
        Next
    Next

    If $firstRow = -1 Or $lastRow = -1 Or $firstCol = -1 Or $lastCol = -1 Then
        MsgBox($MB_SYSTEMMODAL, "LineNumber:" & @ScriptLineNumber, "No color found" & @TAB & @TAB)
        Exit
    EndIf

    ; each number Display is a matrix of 14x20 pixels
    Local $numberWidth = 14 ; set number width per digit
    Local $numberSpace = 2  ; set Space between digits

    Local $Empty = 0, $Corection = 0

    ; Corection for boundaries if 1st digit = 1
    For $x = $firstCol To $lastCol - 1
        If $aColorMap[$x][$firstRow] = 0x000000 Then
            $Empty += 1
            If $Empty = 3 Then
                ;found 1st Space between digits
                $Corection = $firstCol - 1 - Abs($x - $numberWidth - $numberSpace)
                ExitLoop
            EndIf
        Else
            $Empty = 0
        EndIf
    Next

    If $Corection > 0 Then $firstCol = $firstCol - $Corection

    Local $numberStart = $firstCol

;~  ConsoleWrite("$Corection=" & $Corection & @CRLF)
;~  ConsoleWrite("Display_boundaries firstRow:" & $firstRow & " lastRow:" & $lastRow & " firstCol:" & $firstCol & " lastCol:" & $lastCol & @CRLF)
;~  ConsoleWrite("" & @CRLF)

    Local $aNum[11][3]

    ; Define boundaries for each number position
    For $i = 1 To 10
        $aNum[$i][0] = $numberStart
        $aNum[$i][1] = $numberStart + $numberWidth
        If $numberStart + $numberWidth + $numberSpace > $lastCol Then ExitLoop
        $numberStart += $numberWidth + $numberSpace
        $aNum[0][0] = $i + 1
    Next
;~  _ArrayDisplay($aNum)
    Local $sNumber

    ; Generate patterns for each found number
    For $i = 1 To $aNum[0][0]
        Local $sPattern = ""
        For $y = $firstRow To $lastRow
            $x = $aNum[$i][0]
            If $aColorMap[$x][$y] = $hColor Then
                $sPattern &= "1"
            Else
                $sPattern &= "."
            EndIf
            $sPattern &= @CRLF
        Next
        $sNumber &= _GetPattern($sPattern)
    Next

    Return $sNumber
EndFunc   ;==>FindNumberUsingColorMap
;--------------------------------------------------------------------------------------------------------------------------------
Func _GetPattern($sPattern)  ; patterns for each digit
;~  ConsoleWrite("**************" & @CRLF & $sPattern & @CRLF)

    Local Static $aPNum

    ; Define simplified patterns for each digit

    If Not IsArray($aPNum) Then

        Local $aNumber[10]

        $aNumber[0] = "" ; Pattern for '0'
        $aNumber[0] &= "." & @CRLF
        $aNumber[0] &= "." & @CRLF
        $aNumber[0] &= "." & @CRLF
        $aNumber[0] &= "1" & @CRLF
        $aNumber[0] &= "1" & @CRLF
        $aNumber[0] &= "." & @CRLF
        $aNumber[0] &= "1" & @CRLF
        $aNumber[0] &= "1" & @CRLF
        $aNumber[0] &= "." & @CRLF
        $aNumber[0] &= "1" & @CRLF
        $aNumber[0] &= "1" & @CRLF
        $aNumber[0] &= "." & @CRLF
        $aNumber[0] &= "1" & @CRLF
        $aNumber[0] &= "1" & @CRLF
        $aNumber[0] &= "." & @CRLF
        $aNumber[0] &= "1" & @CRLF
        $aNumber[0] &= "1" & @CRLF
        $aNumber[0] &= "." & @CRLF
        $aNumber[0] &= "." & @CRLF
        $aNumber[0] &= "." & @CRLF

        $aNumber[1] = "" ; Pattern for '1'
        $aNumber[1] &= "." & @CRLF
        $aNumber[1] &= "." & @CRLF
        $aNumber[1] &= "." & @CRLF
        $aNumber[1] &= "." & @CRLF
        $aNumber[1] &= "." & @CRLF
        $aNumber[1] &= "." & @CRLF
        $aNumber[1] &= "." & @CRLF
        $aNumber[1] &= "." & @CRLF
        $aNumber[1] &= "." & @CRLF
        $aNumber[1] &= "." & @CRLF
        $aNumber[1] &= "." & @CRLF
        $aNumber[1] &= "." & @CRLF
        $aNumber[1] &= "." & @CRLF
        $aNumber[1] &= "." & @CRLF
        $aNumber[1] &= "." & @CRLF
        $aNumber[1] &= "." & @CRLF
        $aNumber[1] &= "." & @CRLF
        $aNumber[1] &= "." & @CRLF
        $aNumber[1] &= "." & @CRLF
        $aNumber[1] &= "." & @CRLF

        $aNumber[2] = "" ; Pattern for '2'
        $aNumber[2] &= "." & @CRLF
        $aNumber[2] &= "." & @CRLF
        $aNumber[2] &= "." & @CRLF
        $aNumber[2] &= "1" & @CRLF
        $aNumber[2] &= "1" & @CRLF
        $aNumber[2] &= "." & @CRLF
        $aNumber[2] &= "." & @CRLF
        $aNumber[2] &= "." & @CRLF
        $aNumber[2] &= "." & @CRLF
        $aNumber[2] &= "." & @CRLF
        $aNumber[2] &= "." & @CRLF
        $aNumber[2] &= "." & @CRLF
        $aNumber[2] &= "." & @CRLF
        $aNumber[2] &= "." & @CRLF
        $aNumber[2] &= "." & @CRLF
        $aNumber[2] &= "1" & @CRLF
        $aNumber[2] &= "1" & @CRLF
        $aNumber[2] &= "." & @CRLF
        $aNumber[2] &= "1" & @CRLF
        $aNumber[2] &= "1" & @CRLF

        $aNumber[3] = "" ; Pattern for '3'
        $aNumber[3] &= "." & @CRLF
        $aNumber[3] &= "." & @CRLF
        $aNumber[3] &= "." & @CRLF
        $aNumber[3] &= "1" & @CRLF
        $aNumber[3] &= "1" & @CRLF
        $aNumber[3] &= "." & @CRLF
        $aNumber[3] &= "." & @CRLF
        $aNumber[3] &= "." & @CRLF
        $aNumber[3] &= "." & @CRLF
        $aNumber[3] &= "." & @CRLF
        $aNumber[3] &= "." & @CRLF
        $aNumber[3] &= "." & @CRLF
        $aNumber[3] &= "." & @CRLF
        $aNumber[3] &= "." & @CRLF
        $aNumber[3] &= "." & @CRLF
        $aNumber[3] &= "1" & @CRLF
        $aNumber[3] &= "1" & @CRLF
        $aNumber[3] &= "." & @CRLF
        $aNumber[3] &= "." & @CRLF
        $aNumber[3] &= "." & @CRLF

        $aNumber[4] = "" ; Pattern for '4'
        $aNumber[4] &= "." & @CRLF
        $aNumber[4] &= "." & @CRLF
        $aNumber[4] &= "." & @CRLF
        $aNumber[4] &= "." & @CRLF
        $aNumber[4] &= "." & @CRLF
        $aNumber[4] &= "." & @CRLF
        $aNumber[4] &= "." & @CRLF
        $aNumber[4] &= "." & @CRLF
        $aNumber[4] &= "." & @CRLF
        $aNumber[4] &= "1" & @CRLF
        $aNumber[4] &= "1" & @CRLF
        $aNumber[4] &= "." & @CRLF
        $aNumber[4] &= "1" & @CRLF
        $aNumber[4] &= "1" & @CRLF
        $aNumber[4] &= "." & @CRLF
        $aNumber[4] &= "." & @CRLF
        $aNumber[4] &= "." & @CRLF
        $aNumber[4] &= "." & @CRLF
        $aNumber[4] &= "." & @CRLF
        $aNumber[4] &= "." & @CRLF

        $aNumber[5] = "" ; Pattern for '5'
        $aNumber[5] &= "1" & @CRLF
        $aNumber[5] &= "1" & @CRLF
        $aNumber[5] &= "." & @CRLF
        $aNumber[5] &= "1" & @CRLF
        $aNumber[5] &= "1" & @CRLF
        $aNumber[5] &= "." & @CRLF
        $aNumber[5] &= "1" & @CRLF
        $aNumber[5] &= "1" & @CRLF
        $aNumber[5] &= "." & @CRLF
        $aNumber[5] &= "." & @CRLF
        $aNumber[5] &= "." & @CRLF
        $aNumber[5] &= "." & @CRLF
        $aNumber[5] &= "." & @CRLF
        $aNumber[5] &= "." & @CRLF
        $aNumber[5] &= "." & @CRLF
        $aNumber[5] &= "1" & @CRLF
        $aNumber[5] &= "1" & @CRLF
        $aNumber[5] &= "." & @CRLF
        $aNumber[5] &= "." & @CRLF
        $aNumber[5] &= "." & @CRLF

        $aNumber[6] = "" ; Pattern for '6'
        $aNumber[6] &= "." & @CRLF
        $aNumber[6] &= "." & @CRLF
        $aNumber[6] &= "." & @CRLF
        $aNumber[6] &= "." & @CRLF
        $aNumber[6] &= "." & @CRLF
        $aNumber[6] &= "." & @CRLF
        $aNumber[6] &= "1" & @CRLF
        $aNumber[6] &= "1" & @CRLF
        $aNumber[6] &= "." & @CRLF
        $aNumber[6] &= "1" & @CRLF
        $aNumber[6] &= "1" & @CRLF
        $aNumber[6] &= "." & @CRLF
        $aNumber[6] &= "1" & @CRLF
        $aNumber[6] &= "1" & @CRLF
        $aNumber[6] &= "." & @CRLF
        $aNumber[6] &= "1" & @CRLF
        $aNumber[6] &= "1" & @CRLF
        $aNumber[6] &= "." & @CRLF
        $aNumber[6] &= "." & @CRLF
        $aNumber[6] &= "." & @CRLF

        $aNumber[7] = "" ; Pattern for '7'
        $aNumber[7] &= "1" & @CRLF
        $aNumber[7] &= "1" & @CRLF
        $aNumber[7] &= "." & @CRLF
        $aNumber[7] &= "." & @CRLF
        $aNumber[7] &= "." & @CRLF
        $aNumber[7] &= "." & @CRLF
        $aNumber[7] &= "." & @CRLF
        $aNumber[7] &= "." & @CRLF
        $aNumber[7] &= "." & @CRLF
        $aNumber[7] &= "." & @CRLF
        $aNumber[7] &= "." & @CRLF
        $aNumber[7] &= "." & @CRLF
        $aNumber[7] &= "." & @CRLF
        $aNumber[7] &= "." & @CRLF
        $aNumber[7] &= "." & @CRLF
        $aNumber[7] &= "." & @CRLF
        $aNumber[7] &= "." & @CRLF
        $aNumber[7] &= "." & @CRLF
        $aNumber[7] &= "." & @CRLF
        $aNumber[7] &= "." & @CRLF

        $aNumber[8] = "" ; Pattern for '8'
        $aNumber[8] &= "." & @CRLF
        $aNumber[8] &= "." & @CRLF
        $aNumber[8] &= "." & @CRLF
        $aNumber[8] &= "1" & @CRLF
        $aNumber[8] &= "1" & @CRLF
        $aNumber[8] &= "." & @CRLF
        $aNumber[8] &= "1" & @CRLF
        $aNumber[8] &= "1" & @CRLF
        $aNumber[8] &= "." & @CRLF
        $aNumber[8] &= "." & @CRLF
        $aNumber[8] &= "." & @CRLF
        $aNumber[8] &= "." & @CRLF
        $aNumber[8] &= "1" & @CRLF
        $aNumber[8] &= "1" & @CRLF
        $aNumber[8] &= "." & @CRLF
        $aNumber[8] &= "1" & @CRLF
        $aNumber[8] &= "1" & @CRLF
        $aNumber[8] &= "." & @CRLF
        $aNumber[8] &= "." & @CRLF
        $aNumber[8] &= "." & @CRLF

        $aNumber[9] = "" ; Pattern for '9'
        $aNumber[9] &= "." & @CRLF
        $aNumber[9] &= "." & @CRLF
        $aNumber[9] &= "." & @CRLF
        $aNumber[9] &= "1" & @CRLF
        $aNumber[9] &= "1" & @CRLF
        $aNumber[9] &= "." & @CRLF
        $aNumber[9] &= "1" & @CRLF
        $aNumber[9] &= "1" & @CRLF
        $aNumber[9] &= "." & @CRLF
        $aNumber[9] &= "." & @CRLF
        $aNumber[9] &= "." & @CRLF
        $aNumber[9] &= "." & @CRLF
        $aNumber[9] &= "." & @CRLF
        $aNumber[9] &= "." & @CRLF
        $aNumber[9] &= "." & @CRLF
        $aNumber[9] &= "." & @CRLF
        $aNumber[9] &= "." & @CRLF
        $aNumber[9] &= "." & @CRLF
        $aNumber[9] &= "." & @CRLF
        $aNumber[9] &= "." & @CRLF

        $aPNum = $aNumber
    EndIf

    Switch $sPattern
        Case $aPNum[0]
            Return 0
        Case $aPNum[1]
            Return 1
        Case $aPNum[2]
            Return 2
        Case $aPNum[3]
            Return 3
        Case $aPNum[4]
            Return 4
        Case $aPNum[5]
            Return 5
        Case $aPNum[6]
            Return 6
        Case $aPNum[7]
            Return 7
        Case $aPNum[8]
            Return 8
        Case $aPNum[9]
            Return 9
        Case Else
            Return SetError(1, 0, "")
    EndSwitch
EndFunc   ;==>_GetPattern
;--------------------------------------------------------------------------------------------------------------------------------
Func Test($sFolderPath, $hColor = 0x00FF00)   ; _GetNumber for all the *.png files in $sFolderPath directory

    ; List all the *.png files in $sFolderPath directory
    Local $aFileList = _FileListToArray($sFolderPath, "*.png", $FLTA_FILES)
    If @error = 1 Then
        MsgBox($MB_SYSTEMMODAL, "LineNumber:" & @ScriptLineNumber, "Path was invalid.")
        Exit
    EndIf
    If @error = 4 Then
        MsgBox($MB_SYSTEMMODAL, "LineNumber:" & @ScriptLineNumber, "No file(s) were found.")
        Exit
    EndIf

    _ArrayColInsert($aFileList, 1) ; add 1 column to hold the numbers

    ; Initialize GDI+ to work with bitmaps
    _GDIPlus_Startup()

    Local $cnt = 0
    Local $CleanTime = 0
    Local $hTimer = TimerInit()

    For $j = 1 To 100
    For $i = 1 To $aFileList[0][0]
        $cnt += 1
        ConsoleWrite("$cnt: " & $cnt & @CRLF)

        ; Capture the color map for the specified area
        Local $aColorMap = CaptureAreaColorMap($sFolderPath & "\" & $aFileList[$i][0])
        If @error = 1 Then
            MsgBox($MB_SYSTEMMODAL, "LineNumber:" & @ScriptLineNumber, "Path was invalid.")
            Exit
        EndIf

        $aFileList[$i][1] = FindNumberUsingColorMap($aColorMap, $hColor)

        ; Rename a file using FileMove and overwrite the new file if it exists.
;~          FileMove($sFolderPath & "\" & $aFileList[$i][0], $sFolderPath & "\" & $aFileList[$i][1] & ".png", $FC_OVERWRITE)

;~          $aProcessMemoryInfo = _WinAPI_GetProcessMemoryInfo()
;~          ConsoleWrite('The peak working set: ' & $aProcessMemoryInfo[1] / 1024 / 1014 & ' MB' & @CRLF)

    Next
    Next

    ConsoleWrite("processed in: " & Round(TimerDiff($hTimer) / 1000, 3) & " seconds " & @LF)

    _ArrayDisplay($aFileList, "$aFileList")

    ; Cleanup resources
    _GDIPlus_Shutdown()
EndFunc   ;==>Test
;--------------------------------------------------------------------------------------------------------------------------------

 

Edited by ioa747
Update to Version: 5.0.2

I know that I know nothing

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...