Sign in to follow this  
Followers 0
nullschritt

Image Compare [lighting, motion detection]

16 posts in this topic

#1 ·  Posted (edited)

A few days ago I wrote a script to get the relative difference between two sets of data.

 

When this comes to images we can detect all sorts of things, more accurately.

 

Take for example you have two images with different lighting.

 

http://prodynamics.co/link.php?CMD=file&ID=compare1 (1600x976)

http://prodynamics.co/link.php?CMD=file&ID=compare2 (1600x976)

 

(These are both jpg images, their format is stored in the database)

 

You will notice that the second image is considerably brighter than the first.

Every pixel of the second image is at least one shade brighter than the second, this means that there was an absolute change of 100% to the image, HOWEVER, lets say we only want to know how much light was added to the image, that's one of the things this script can detect. The script would say the image has only changed by 12%, that's because the new data is only 12% different than the old data, even though 100% of it has changed.

 

Now in order to be efficient, the script which converts the images into pixel data are set to skip by default ever 2nd row of pixels and read every other pixel in each row. This still provides pretty accurate results for changes larger than 1px(1px changes may be missed sometimes), and could still accurately display where a change occurred or track a moving object.(with modification to use processed data in said way)

 

In the case you are comparing images which have many 1px changes, you can set the step for both y and x to 1, and the function will compare every single pixel. Be warned though, this is very slow.

 

Large images can use a higher step, but using too high of a step may exclude certain changes from being observed.

 

That being said, if you want to compare large images quickly, without leaving out too much data, there is an alternative, you can size the image down to 1/4th 1/6th or 1/8th it's size and compare it. Scaling down two images keeps the relative data in them the same places, so the comparison will return almost identical results (off by maybe 2% max)Note: In most cases scaling will result in more accurate results than stepping.

 

The below example compares the above two images, and output the data to the console.

;~ #include <_PixelGetColor.au3>
#include <GDIPlus.au3>
#include <inet.au3>
#include <array.au3>
$hDll = DllOpen("gdi32.dll")
_GDIPlus_Startup()

Global $image1, $image2

$f1 = binary(_INetGetSource("http://prodynamics.co/link.php?CMD=file&ID=compare1")) ;image 1
$f2 = binary(_INetGetSource("http://prodynamics.co/link.php?CMD=file&ID=compare2")) ;image 2 brighter

;here we use the default step options
$t1 = TimerInit()
$image1 = _Capturepixels($f1) ;get image 1 pixel
ConsoleWrite(TimerDiff($t1)/1000 &' Default Step'&@CRLF)
$t1 = TimerInit()
$image2 = _CapturePixels($f2) ;get image 2 pixels
ConsoleWrite(TimerDiff($t1)/1000& ' Default Step'&@CRLF)
$timer = TimerInit()
$compare = _datacompare($image1[0], $image2[0]);compare them
ConsoleWrite($compare[0]&'% Different(Localized) '&$compare[1]&'% Different(Global)'&@CRLF&'Took '&(TimerDiff($timer)/1000)&' seconds. Default Step'&@CRLF)

;here we double them, notice the preformance increase
$t1 = TimerInit()
$image1 = _Capturepixels($f1, 4, 8) ;get image 1 pixels
ConsoleWrite(TimerDiff($t1)/1000 &' Double Step'&@CRLF)
$t1 = TimerInit()
$image2 = _CapturePixels($f2,4 , 8) ;get image 2 pixels
ConsoleWrite(TimerDiff($t1)/1000& ' Double Step'&@CRLF)
$timer = TimerInit()
$compare = _datacompare($image1[0], $image2[0])
ConsoleWrite($compare[0]&'% Different(Localized) '&$compare[1]&'% Different(Global)'&@CRLF&'Took '&(TimerDiff($timer)/1000)&' seconds. Default Step'&@CRLF)
sleep(5000)


;~ $t1 = TimerInit()
;~ $diffarray = _mapchange($image1[0], $image2[0], $image1[1], $image1[2]) ;compare two images for difference
;~ ConsoleWrite(TimerDiff($t1)/1000& ' _mapchange'&@CRLF)
;~ $t1 = TimerInit()
;~ $image = _toimage($diffarray) ;here we turn the array of colors back into an image
;~ ConsoleWrite(TimerDiff($t1)/1000& ' _toimage'&@CRLF)
;~ _GDIPlus_ImageSaveToFile($image, @scriptdir&'\test.jpg') ;write it to a file
;~ shellexecute(@scriptdir&'\test.jpg')


#cs
Function _datacompare($data1, $data2, [$declimal])
    -$data1: A string of data, any length.
    -$data2: A string of data, must be the same length as $data1
    -$decimal: 1=Binary 9=Base-10, 15=Base-16, 31=Base-32

    Note: If you just want to compare two sets of binary data
    you probably want to use base-16. Unless you are sure your
    binary is in 1's and 0's.

    Returns: An array containing two floats. The first
    value is the localized change, and the second is the global change
#ce
func _datacompare($data1, $data2, $decimal=15)
    Local $difference
$data1 = StringSplit($data1, "")
$data2 = StringSplit($data2, "")
$difference = 0
$found = 0
for $i=1 to $data1[0]
if $data1[$i] <> $data2[$i] Then
    $temp = Abs(_tonum($data1[$i]) - _tonum($data2[$i]))
    $difference += $temp
    $found +=1
EndIf
Next
dim $ret[2]
$ret[0] = ((($difference/$found))/$decimal)*100
$ret[1] = ((($difference/$data1[0]))/$decimal)*100
Return $ret
EndFunc

#cs
Function: _mapchange($base, $new, $x, $y, [$decimal])
    $base: Base data to compare from
    $new: Data to compare
    $x: Width of output data (should be returned by capturepixels)
    $y: Height of outout data (should be returned by capturepixels)
    $decimal: Decimal system, you shouldn't change this

    Note: Use _toimage on data returned by this function to visually see
    a image of the change. (The lighter the color the more change the occured)

    Returns an 2D array of data. Each value of the array represents
    one pixel of the image. Each value is a percent between 0-100
    representing the change that occured in that pixel
#ce
func _mapchange($base, $new, $y, $x, $decimal = 10)
    Local $difference, $xx = 0, $yy = 0
    dim $result[1][$x+1]
    $t1 = TimerInit()
$data1 = _StringequalSplit($base, 8)
$data2 = _StringequalSplit($new, 8)
$difference = 0
for $i=1 to UBound($data1)-1
    if $xx > $x Then
        $xx=0
        $yy+=1
        ConsoleWrite($yy&'/'&$y&' ('&($yy/$y)*100&') '&@CRLF)
        redim $result[$yy+1][$x+1]
    EndIf
    if $data1[$i] <> $data2[$i] Then
    $values1 = StringSplit($data1[$i], "")
    $values2 = stringSplit($data2[$i], "")
    $diff = ""
    for $ix=1 to $values1[0]
    $diff += round((Abs(_tonum($values1[$ix]) - _tonum($values2[$ix]))/$decimal)*100)
    Next
    $diff = Round($diff/$values1[0])
    $result[$yy][$xx] = $diff
    Else
    $result[$yy][$xx] = 0
    EndIf
    $xx += 1
Next
return $result
EndFunc


#cs
Function _tonum($info)
    -$info: A single digit or carachter.

    Returns: A 0-based value.
#ce
func _tonum($info)
if $info+0 > 0 Then Return $info
$info = StringLower($info)
$return = asc($info)-87
switch $return
    Case -39
        Return 0
    Case Else
        Return $return
EndSwitch
EndFunc

#cs
Function _CapturePixels($data, [[$stepy], $stepx])
    -$data: Binary Data
    -$stepy: How often to skip a row of pixelxs. 1 = Never
    -$stepx: How often to skip a single pixel. 1 = Nevere
    Note: Use higher steps for larger images and lower steps
    for smaller images.
#ce
Func _CapturePixels($data, $stepy = 2, $stepx = 2)
    $ret = ""
    $HBITMAP2 = _GDIPlus_BitmapCreateFromMemory($data)
    $y=_GDIPlus_ImageGetWidth($HBITMAP2)
    $x=_GDIPlus_ImageGetHeight($HBITMAP2)

    For $iY = 0 To $x step $stepy
        For $iX = 0 To $y step $stepx
            $rety = StringRight(hex(_GDIPlus_BitmapGetPixel($hBitmap2, $ix, $iy)),8) ;get current pixel color
            $ret &= $rety
;~          ConsoleWrite($iy&'/'&$x&' '&$rety&@CRLF)
            Next
    Next


       ;For $x = 0 To _GDIPlus_ImageGetWidth($HBITMAP2)
       ;  For $y = 0 To _GDIPlus_ImageGetHeight($HBITMAP2)
       ;      $ret &= _PixelGetColor_GetPixel($vDC, $x, $y, $hDll)
      ;   Next
     ;Next
    _WinAPI_DeleteObject($HBITMAP2)
    dim $retx[3]
    $retx[0] = $ret
    $retx[1] = $x/$stepx
    $retx[2] = $y/$stepy
    Return $retx
EndFunc   ;==>Capturepixels

Func _toimage($colors)
    _GDIPlus_Startup()
    Local $hBitmap = _GDIPlus_BitmapCreateFromScan0(UBound($colors, 2), UBound($colors, 1)) ;create an empty bitmap
    Local $hBmpCtxt = _GDIPlus_ImageGetGraphicsContext($hBitmap) ;get the graphics context of the bitmap
    _GDIPlus_GraphicsSetSmoothingMode($hBmpCtxt, $GDIP_SMOOTHINGMODE_HIGHQUALITY)
    _GDIPlus_GraphicsClear($hBmpCtxt, 0x00000000) ;clear bitmap with color white

    for $i=0 to UBound($colors)-1
        for $i2=0 to UBound($colors,2 )-1
;~          if $colors[$i][$i2] > 30 Then
;~          ConsoleWrite($i&","&$i2&' - '&$colors[$i][$i2]&@CRLF)
        _GDIPlus_BitmapSetPixel($hBitmap, $i2, $i, $colors[$i][$i2]&'0')
;~      ConsoleWrite($i2&','&$i&' '&$colors[$i][$i2]&@CRLF)
;~          EndIf
        Next
    Next

    return $hBitmap ;return bitmap
    ;cleanup GDI+ resources
    _GDIPlus_GraphicsDispose($hBmpCtxt)
EndFunc   ;==>Example

Func _StringEqualSplit($sString, $iNumChars)
    If (Not IsString($sString)) Or $sString = "" Then Return SetError(1, 0, 0)
    If (Not IsInt($iNumChars)) Or $iNumChars < 1 Then Return SetError(2, 0, 0)
    Return StringRegExp($sString, "(?s).{1," & $iNumChars & "}", 3)
EndFunc
Cheers,

NullSchritt

 

PS: If I find the time, I'll add a motion tracking version of the script as well. (It can detect but not track motion in it's current form)

Edited by nullschritt
1 person likes this

Share this post


Link to post
Share on other sites



Notes: for simple motions detection, it may be faster and acceptable to use high step numbers instead of shrinking the image down. (unless you're trying to catch ninjas)

Further explanation on stepping:

A stepping value of 1, 1 will means every detail of change is detected, clear down to a small bug. Increasing the scaling value will create gaps between the scanned data, splitting it into a grid. For example a stepping value of 4, 12 would scan only scan every 4th horizontal line, and every 12th pixel. Imagine a grid laid over the image, and the higher the step values get the bigger the cell sizes get. A setting of 4, 12 would probably not detect a fly buzzing about, but could detect a person or animal walking past. If you only wanted to detect an adult human you could probably even use values of up to 16, 32.

If you want stepping type speed without losing any detail, you should scale your image down.

Share this post


Link to post
Share on other sites

So cool.  Has anyone seen that program that highlights movements red?  So you can see minor variations in motion?  I want to do that and this script might help do that.  But it's all on the back burner for now.

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Updated

  • added _trackchange()
  • added _toimage()
  • tonumber() to _tonumber
  • capturepixels to _capturePixels()
  • bug in capturepixels fixed.
You can now track motion using the arrays returned by _trackchange(). use _trackchange() on image 1 and 2 and then on 2 and 3. Then overlay the second array on the first, only replacing the values if they are above 20%. This will result in an array containing the path taken by any moving objects. _toimage can visually display the path on an image, among other uses.

 

See first post for updated code.

Note: 20% is a general threshold for ambient lighting changes, you should adjust this value for your personal needs.

Edited by nullschritt

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Find Attached a mapped images displaying the lighting changes between the two pictures in the example.

This was produced with a step setting of 1,1, using _trackchange() and _toimage()
post-70883-0-77762600-1392321576_thumb.j
(click to enlarge)

This was produced with the default step setting(2, 2)[notice some detail loss]

post-70883-0-48494800-1392325179_thumb.j

(click to enlarge).

And Here's the same result using a step setting of 4, 4 (notice how the structure of the data is still nicely preserved, but detail is lost.)

post-70883-0-11534600-1392325299_thumb.j

(max size)

The darker blues represent areas of less change, and lighter blues represent areas of more change

Note: The above three images show how stepping works like a make-shift scaling system, but as you can see, fine detail is lost.

And because why not.

Here's a 8,8 step

post-70883-0-77387600-1392325527_thumb.j

and here's a 16,16 step

post-70883-0-15310300-1392325558_thumb.j

Edited by nullschritt

Share this post


Link to post
Share on other sites

So cool.  Has anyone seen that program that highlights movements red?  So you can see minor variations in motion?  I want to do that and this script might help do that.  But it's all on the back burner for now.

 

You mean this ?...

http://bits.blogs.nytimes.com/2013/02/27/scientists-uncover-invisible-motion-in-video/?_php=true&_type=blogs&_r=0

Matlab source is available somewhere in one of the links on the page.

Share this post


Link to post
Share on other sites

You mean this ?...

http://bits.blogs.nytimes.com/2013/02/27/scientists-uncover-invisible-motion-in-video/?_php=true&_type=blogs&_r=0

Matlab source is available somewhere in one of the links on the page.

 

That's amazing! My functions above could preform this same functionality(with the_trackchange() function)! Cool. (Though autoit is not fast enough to process the video in real time)

Share this post


Link to post
Share on other sites

You mean this ?...

http://bits.blogs.nytimes.com/2013/02/27/scientists-uncover-invisible-motion-in-video/?_php=true&_type=blogs&_r=0

Matlab source is available somewhere in one of the links on the page.

Yes that thank you.

But matlab though.  I dunno, honestly, autoit has made me kinda lazy about other languages.

Share this post


Link to post
Share on other sites

That's amazing! My functions above could preform this same functionality(with the_trackchange() function)! Cool. (Though autoit is not fast enough to process the video in real time)

Yeah I know right!  I think it might be a little more complex than I suspect.  Wouldn't I need to be able to find lines in an image?

For instance, I want to record my car engine running.  Then run a script which would highlight movements.  So if I aim it at the belts, I'm thinking that it will need to be able to identify outlines.  Dunno yet, just a seed of an idea so far.  ...

OK, thinking on it, I don't think so, any change is colored red for a short time.  I'm thinking it will keep track of which regions changed to red the most to identify possible trouble spots.

Share this post


Link to post
Share on other sites

Update:

  • Updated the _datacompare() function to be more accurate.

 

Also here:s an example of using _trackchange with an object.

n29wvW7.png

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

Yeah I know right!  I think it might be a little more complex than I suspect.  Wouldn't I need to be able to find lines in an image?

 

For instance, I want to record my car engine running.  Then run a script which would highlight movements.  So if I aim it at the belts, I'm thinking that it will need to be able to identify outlines.  Dunno yet, just a seed of an idea so far.  ...

 

OK, thinking on it, I don't think so, any change is colored red for a short time.  I'm thinking it will keep track of which regions changed to red the most to identify possible trouble spots.

No you don't need to identify the outlines of anything. When motion occurs it slightly changes the observed color in that area. All you have to do is amplify the change.

 

For example if you ran a video of a belt turning through _mapchanges() each array would have a belt shaped set of (low)percentage changes. To amplify the change you only need to then amplify the color which shade changed. Though I cant pretend to be an expert, I think it would be easiest to identify change by boosting the color in that area by the percentage that is already changed times ten. for example if the color changed by 5% we would further increase the shade by 50% to make the motion easily apparent to the naked eye.

Edited by nullschritt

Share this post


Link to post
Share on other sites

#12 ·  Posted (edited)

UPDATE

  • _Datacompare() now returns an array with two values, the first value is localized change, which only accounts for pixels that have actually changed, and measures how much they have changed. Global calculates in all pixels in the photo, even ones that haven't changed. As such, to put them simply. Global calculates the difference that occurred overall in the whole photo, localized calculated how much has changed in the areas that have changed.
Note: These two values are relevant to detecting the difference between ambient light shifts, and on screen motion. (though a simple script that monitors the local changes should be enough for simple motion detection, anything above 25% local change should indicate motion rather than lighting change).

 

If you have any recommendations or suggestions, please throw them my way.

Edit: Tonight/Tomorrow I will be modifying the local analysis algorithm, in order to exclude most lighting updates. This way local results will only return moving objects or VERY bright lights. Global percentage will include all data, including local data. This does not affect motion tracking in any way. Motion tracking returns the raw percentage of change for each pixel, it is up to you to decide how to process that data/determine lighting/motion.

Edited by nullschritt
1 person likes this

Share this post


Link to post
Share on other sites

Yeah I know right!  I think it might be a little more complex than I suspect.  Wouldn't I need to be able to find lines in an image?

For instance, I want to record my car engine running.  Then run a script which would highlight movements.  So if I aim it at the belts, I'm thinking that it will need to be able to identify outlines.  Dunno yet, just a seed of an idea so far.  ...

OK, thinking on it, I don't think so, any change is colored red for a short time.  I'm thinking it will keep track of which regions changed to red the most to identify possible trouble spots.

You might be thinking of opencv library.


AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Share this post


Link to post
Share on other sites

Sorry I abandoned this project, I might take it up at some point.

Just thought I would leave an update saying that this code can be used to detect objects cloaked with the new light bending cloaking technologies we are seeing.

(as the object/person being cloaked will cause motion to occur, even if its invisible to the naked eye) [which I think is a fairly interesting use of the software]

If I do pick this back up, it'll be to add support for processing videos instead of just pictures/frames, and a better lighting filter(show only changes in motion)

Share this post


Link to post
Share on other sites

Hello,

I tried your example but I get the following erorr:

>"D:\rocimpma\Desktop\autoit-v3\install\SciTe\..\autoit3.exe" /ErrorStdOut "D:\rocimpma\Desktop\calculator.au3"    
0.000279591963674815 Default Step
0.00016856378677614 Default Step
-1.#IND% Different(Localized) -1.#IND% Different(Global)
Took 4.32294582322573e-005 seconds. Default Step
0.000165142750513155 Double Step
0.000156123654910742 Double Step
-1.#IND% Different(Localized) -1.#IND% Different(Global)
Took 3.17223362567643e-005 seconds. Default Step
>Exit code: 0    Time: 5.694

 

Can somebody help me please? I really need something like this

Share this post


Link to post
Share on other sites

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
Sign in to follow this  
Followers 0

  • Similar Content

    • czardas
      By czardas
      Haven't had much time to code recently. However the following thread inspired me.
      The debate about linear, parallel and binary search methods was rather interesting and, in an attempt to be diplomatic, I decided to combine @jchd's suggestion with @LarsJ's binary search example. I decided that the binary search algorithm required modification to make it more linear. As usual, 'if you invent something, it probably already exists and if it already exists, it exists for a reason'. My first attempt was not all that good. The code worked but was really a mess. I blame peer pressure (to post an example of a parallel search method).  I will delete that old code in due course.
      With a little memory jogging and a glance at the help file, the solution turned out to be quite easy: I just needed a better understanding of Euler. Further modification will be needed to work with more complicated unicode strings. The output could be returned as an array or a delimitered string. I'm not so interested in those details. I'm just going to post the algorithm for now and anyone, who wants to, can modify it to suit their needs. Both arrays must contain at least 1 element.
      Local $aFoo = [0,1,2,3,4,5,6,7,9,10,11,12,13,14,15,16,19,20,23,24,26,30,35,39,40,41] Local $aBar = [0,1,5,6,7,8,9,10,11,12,13,14,17,18,19,21,24,25,26,27,34,35,38,40] ParallelExponetialSearch($aFoo, $aBar) ; Compares two lists - returning positive matches. Each input array must be unique (individually) and in alphabetical order. Func ParallelExponetialSearch($aFoo, $aBar) Local $sFind, _ $iMin_F = -1, $iMax_F = UBound($aFoo) -1, $Lo_F = $iMin_F, $Hi_F, _ $iMin_B = -1, $iMax_B = UBound($aBar) -1, $Lo_B = $iMin_B, $Hi_B While $iMin_F < $iMax_F And $iMin_B < $iMax_B ; Toggle Arrays - Which array has most untested elements? This is the one we want to search next, ; so we can bypass more comparisons because (in theory) mismatches have a greater chance of being skipped. If $iMax_F - $iMin_F >= $iMax_B - $iMin_B Then ; $aFoo has more (or an equal number of) untested elements $Hi_F = $iMax_F $iMin_B += 1 $sFind = $aBar[$iMin_B] While $Lo_F < $Hi_F ; search $aFoo For $i = 0 To Floor(Log($Hi_F - $Lo_F) / Log(2)) $Lo_F = $iMin_F + 2^$i If $aFoo[$Lo_F] = $sFind Then $iMin_F = $Lo_F ; each match should be added to the output [perhaps an array] ConsoleWrite($sFind & " found at $aFoo[" & $Lo_F & "] = $aBar[" & $iMin_B & "]" & @LF) ExitLoop 2 ElseIf $aFoo[$Lo_F] > $sFind Then $Hi_F = $Lo_F -1 $iMin_F += Floor(2^($i -1)) $Lo_F = $iMin_F ContinueLoop 2 EndIf Next $iMin_F = $Lo_F ; minimum increment is one WEnd Else ; $aBar has more untested elements $Hi_B = $iMax_B $iMin_F += 1 $sFind = $aFoo[$iMin_F] While $Lo_B < $Hi_B ; search $aBar For $i = 0 To Floor(Log($Hi_B - $Lo_B) / Log(2)) $Lo_B = $iMin_B + 2^$i If $aBar[$Lo_B] = $sFind Then $iMin_B = $Lo_B ; each match should be added to the output [perhaps an array] ConsoleWrite($sFind & " found at $aFoo[" & $iMin_F & "] = $aBar[" & $Lo_B & "]" & @LF) ExitLoop 2 ElseIf $aBar[$Lo_B] > $sFind Then $Hi_B = $Lo_B -1 $iMin_B += Floor(2^($i -1)) $Lo_B = $iMin_B ContinueLoop 2 EndIf Next $iMin_B = $Lo_B ; minimum increment is one WEnd EndIf WEnd EndFunc ;==> ParallelExponetialSearch I hope this will be useful to someone. I believe it deserved a thread of its own!
    • ur
      By ur
      We can get a list of file using the below code.
      Local $aFileList = _FileListToArray(@DesktopDir, "*") Is there any option to use the above one recursively to get sub folders and their contents also.??
      And also, is there any way to serialize the above array locally to some file and load it later when we want in another program on another machine so that we can compare its contents with a folder in different machine, which is not network connected also.?
    • ur
      By ur
      Generally we will use tools like Winmerge or Beyond Compare for this purpose.
      Are there any UDF or libraries available in AutoIT to compare any two files or folder contents.
    • FMS
      By FMS
      Hello,

      I'm having trouble whit a scipt what I'm building where this is a snippit from, and hope somebody can help me whit.
      The problem lies in when i push the "add" button i want to check if the "user" already exists.
      But the search code i build founds 2 hits when i know there is only 1 hit.
      does somebody knows what I'm doing wrong?
      thanks in advance.

      Ps. if somebody knows " if i found the right user how can i rewrite the password for him/her? " an answer to that will be most appriciated
      #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <AutoItConstants.au3> #include <Array.au3> #include <FileConstants.au3> #include <MsgBoxConstants.au3> #include <WinAPIFiles.au3> #include <File.au3> #Include <Timers.au3> #include <Crypt.au3> #include <GuiEdit.au3> $Form1 = GUICreate("Pie", 170, 235, 190, 200) local $usernames[0] local $passwords[0] global $selectuser = GUICtrlCreateCombo("", 21, 95, 130, 20) $addusername = GUICtrlCreateButton("Add", 21, 170, 130, 30) $usernamefield = GUICtrlCreateInput("", 21, 120, 130, 20) $passwordfield = GUICtrlCreateInput("", 21, 145, 130, 20, 0x0020) func encrypt() Local $hFileOpen = FileOpen("data.srmt", $FO_APPEND) if guictrlread($usernamefield) <> "" then ;~ local $encryptedusername = string(guictrlread($usernamefield)) ;~ local $encryptedpassword = string(guictrlread($passwordfield)) local $encryptedusername = string(_Crypt_EncryptData(guictrlread($usernamefield), "P14h735536jk3fvvbg", $CALG_AES_128)) local $encryptedpassword = string(_Crypt_EncryptData(guictrlread($passwordfield ), "P14h735536jk3fvvbg", $CALG_AES_128)) Local $iCheck_hit = False ConsoleWrite (@CRLF & "##############################################"& @CRLF) if ubound($usernames)> 0 then for $i = 0 to ubound($usernames)-1 If guictrlread($usernamefield) = $usernames[$i] Then $iCheck_hit = True ConsoleWrite ( "Found! "& @CRLF & $usernames[$i] & " = " & guictrlread($usernamefield) & @CRLF & "i = " & $i & @CRLF & @CRLF) ;~ Else ;~ ConsoleWrite ( "No! "& @CRLF & $usernames[$i] & " = " & guictrlread($usernamefield) & @CRLF & "i = " & $i & @CRLF & @CRLF) EndIf next EndIf ConsoleWrite ( "##############################################"& @CRLF) If $iCheck_hit = False Then FileWrite($hFileOpen, $encryptedusername & @CRLF) FileWrite($hFileOpen, $encryptedpassword & @CRLF) EndIf EndIf FileClose($hFileOpen) EndFunc func decrypt() Local $hFileOpen = FileOpen("data.srmt", $FO_READ) ;~ consolewrite(_FileCountLines("data.srmt") & " lines in the file" & @CRLF) for $i = 1 to _FileCountLines("data.srmt")/2 local $encryptedusername = FileReadLine($hFileOpen) local $encryptedpassword = FileReadLine($hFileOpen) ;~ consolewrite($encryptedusername & @CRLF) ;~ consolewrite($encryptedpassword & @CRLF) ;~ _ArrayAdd($usernames, FileReadLine($hFileOpen)) ;~ _ArrayAdd($passwords, FileReadLine($hFileOpen)) _ArrayAdd($usernames, binarytostring(_Crypt_DecryptData(binary($encryptedusername), "P14h735536jk3fvvbg", $CALG_AES_128))) _ArrayAdd($passwords, binarytostring(_Crypt_DecryptData(binary($encryptedpassword), "P14h735536jk3fvvbg", $CALG_AES_128))) Next FileClose($hFileOpen) ;~ consolewrite(ubound($usernames) & " entries in array") ;~ _arraydisplay($usernames) if ubound($userNames)> 0 then for $i = 0 to ubound($usernames)-1 GUICtrlSetData($selectuser, $usernames[$i]) next EndIf endfunc func updatecomboandinfo() if not GUICtrlRead($usernamefield) = "" Then _ArrayAdd($usernames, GUICtrlRead($usernamefield)) _ArrayAdd($passwords, GUICtrlRead($passwordfield)) GUICtrlSetData($selectuser, $usernames[UBound($usernames)-1]) EndIf EndFunc decrypt() GUISetState(@SW_SHOW) While True $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $addusername updatecomboandinfo() encrypt() GUICtrlSetData($usernamefield, "") GUICtrlSetData($passwordfield, "") Case $selectuser if ubound($usernames)> 0 then for $i = 0 to ubound($usernames)-1 ;~ msg( "error",$array_decrypted_usernames[$i]) If $usernames[$i] = GUICtrlRead($selectuser) Then GUICtrlSetData($usernamefield, $usernames[$i]) GUICtrlSetData($passwordfield, $passwords[$i]) consolewrite("YES " & $i & " = " & $usernames[$i] & " | ctr = " & GUICtrlRead($selectuser) & @CRLF) Else ;~ msg( "error",$array_decrypted_usernames[$i]) consolewrite("NO " & $i & " = " & $usernames[$i] & " | ctr = " & GUICtrlRead($selectuser) & @CRLF) EndIf next EndIf EndSwitch WEnd  
    • cherrylatte
      By cherrylatte
      hi 
      I'm trying to make a script that runs different functions depending on the local time of the computer
      I tried to do
      if _NowCalcDate < 2016/04/12 Then
       functionA()
      Else
       functionB()
      Endif
       
      and that doesn't seem to work.
      I am assuming that value returned from _NowCalcDate doesn't match with the date type I wrote
       
      What should I do? I'd appreciate for any help that's given.