Sign in to follow this  
Followers 0
Ritt

Starting Image recognition

3 posts in this topic

I'm trying to do some image recognition. Before I can start I need to capture the colors within a specified area, and record them within a document.   So I started small with a 7x7 box. You can see the plots below, 0,0 being where your mouse is.

 

-3,3  -2,3  -1,3  0,3  1,3  2,3  3,3

-3,2  -2,2  -1,2  0,2  1,2  2,2  3,2

-3,1  -2,1  -1,1  0,1  1,1  2,1  3,1

-3,0  -2,0  -1,0  0,0  1,0  2,0  3,0

-3,-1 -2,-1 -1,-1 0,-1 1,-1 2,-1 3,-1

-3,-2 -2,-2 -1,-2 0,-2 1,-2 2,-2 3,-2

-3,-3 -2,-3 -1,-3 0,-3 1,-3 2,-3 3,-3

Below is what I wrote, however it's extremely long and tedious. Is there a better way to do this? I feel like this is something that constitutes the use of arrays, but I'm really not sure how to use them. If anyone has any suggestions on how I can better do this in the future it would be much appreciated. I'm not well versed in programming, and not opposed to reading so any suggested reading/reference will be helpful.

Thank you.

Hotkeyset("{F7}","Capture")

While 1
   Sleep(10)
   WEnd
   
Func Capture()
   $Pos = MouseGetPos()
   
 Local $File = Fileopen("Txt.txt",1)
   If $File = -1 then
      Msgbox(0,"Error","Cant open")
      Exit
   EndIf
   
;Row 1
Filewrite($File,"Row 1" & @CRLF)
$var = PixelGetColor($Pos[0] -3, $Pos[1] +3)
Filewrite($File, Hex($var, 6) & @CRLF)
$var = PixelGetColor($Pos[0] -3, $Pos[1] +2)
Filewrite($File, Hex($var, 6) & @CRLF)
$var = PixelGetColor($Pos[0] -3, $Pos[1] +1)
Filewrite($File, Hex($var, 6) & @CRLF)
$var = PixelGetColor($Pos[0] -3, $Pos[1])
Filewrite($File, Hex($var, 6) & @CRLF)
$var = PixelGetColor($Pos[0] -3, $Pos[1] -1)
Filewrite($File, Hex($var, 6) & @CRLF)
$var = PixelGetColor($Pos[0] -3, $Pos[1] -2)
Filewrite($File, Hex($var, 6) & @CRLF)
$var = PixelGetColor($Pos[0] -3, $Pos[1] -3)
Filewrite($File, Hex($var, 6) & @CRLF)


;Row 2
Filewrite($File,"Row 2" & @CRLF)
Local $var = PixelGetColor($Pos[0] -2, $Pos[1] +3)
Filewrite($File, Hex($var, 6) & @CRLF)
Local $var = PixelGetColor($Pos[0] -2, $Pos[1] +2)
Filewrite($File, Hex($var, 6) & @CRLF)
Local $var = PixelGetColor($Pos[0] -2, $Pos[1] +1)
Filewrite($File, Hex($var, 6) & @CRLF)
Local $var = PixelGetColor($Pos[0] -2, $Pos[1])
Filewrite($File, Hex($var, 6) & @CRLF)
Local $var = PixelGetColor($Pos[0] -2, $Pos[1] -1)
Filewrite($File, Hex($var, 6) & @CRLF)
Local $var = PixelGetColor($Pos[0] -2, $Pos[1] -2)
Filewrite($File, Hex($var, 6) & @CRLF)
Local $var = PixelGetColor($Pos[0] -2, $Pos[1] -3)
Filewrite($File, Hex($var, 6) & @CRLF)
;Row 3
   Filewrite($File,"Row 3" & @CRLF)
Local $var = PixelGetColor($Pos[0] -1, $Pos[1] +3)
Filewrite($File, Hex($var, 6) & @CRLF)
Local $var = PixelGetColor($Pos[0] -1, $Pos[1] +2)
Filewrite($File, Hex($var, 6) & @CRLF)
Local $var = PixelGetColor($Pos[0] -1, $Pos[1] +1)
Filewrite($File, Hex($var, 6) & @CRLF)
Local $var = PixelGetColor($Pos[0] -1, $Pos[1])
Filewrite($File, Hex($var, 6) & @CRLF)
Local $var = PixelGetColor($Pos[0] -1, $Pos[1] -1)
Filewrite($File, Hex($var, 6) & @CRLF)
Local $var = PixelGetColor($Pos[0] -1, $Pos[1] -2)
Filewrite($File, Hex($var, 6) & @CRLF)
Local $var = PixelGetColor($Pos[0] -1, $Pos[1] -3)
;Row 4
   Filewrite($File,"Row 4" & @CRLF)
Local $var = PixelGetColor($Pos[0], $Pos[1] +3)
Filewrite($File, Hex($var, 6) & @CRLF)
Local $var = PixelGetColor($Pos[0], $Pos[1] +2)
Filewrite($File, Hex($var, 6) & @CRLF)
Local $var = PixelGetColor($Pos[0], $Pos[1] +1)
Filewrite($File, Hex($var, 6) & @CRLF)
Local $var = PixelGetColor($Pos[0], $Pos[1])
Filewrite($File, Hex($var, 6) & @CRLF)
Local $var = PixelGetColor($Pos[0], $Pos[1] -1)
Filewrite($File, Hex($var, 6) & @CRLF)
Local $var = PixelGetColor($Pos[0], $Pos[1] -2)
Filewrite($File, Hex($var, 6) & @CRLF)
Local $var = PixelGetColor($Pos[0], $Pos[1] -3)
Filewrite($File, Hex($var, 6) & @CRLF)
;Row 5
   Filewrite($File,"Row 5" & @CRLF)
Local $var = PixelGetColor($Pos[0] +3, $Pos[1] +3)
Filewrite($File, Hex($var, 6) & @CRLF)
Local $var = PixelGetColor($Pos[0] +3, $Pos[1] +2)
Filewrite($File, Hex($var, 6) & @CRLF)
Local $var = PixelGetColor($Pos[0] +3, $Pos[1] +1)
Filewrite($File, Hex($var, 6) & @CRLF)
Local $var = PixelGetColor($Pos[0] +3, $Pos[1])
Filewrite($File, Hex($var, 6) & @CRLF)
Local $var = PixelGetColor($Pos[0] +3, $Pos[1] -1)
Filewrite($File, Hex($var, 6) & @CRLF)
Local $var = PixelGetColor($Pos[0] +3, $Pos[1] -2)
Filewrite($File, Hex($var, 6) & @CRLF)
Local $var = PixelGetColor($Pos[0] +3, $Pos[1] -3)
Filewrite($File, Hex($var, 6) & @CRLF)
;Row 6
   Filewrite($File,"Row 6" & @CRLF)
Local $var = PixelGetColor($Pos[0] +2, $Pos[1] +3)
Filewrite($File, Hex($var, 6) & @CRLF)
Local $var = PixelGetColor($Pos[0] +2, $Pos[1] +2)
Filewrite($File, Hex($var, 6) & @CRLF)
Local $var = PixelGetColor($Pos[0] +2, $Pos[1] +1)
Filewrite($File, Hex($var, 6) & @CRLF)
Local $var = PixelGetColor($Pos[0] +2, $Pos[1])
Filewrite($File, Hex($var, 6) & @CRLF)
Local $var = PixelGetColor($Pos[0] +2, $Pos[1] -1)
Filewrite($File, Hex($var, 6) & @CRLF)
Local $var = PixelGetColor($Pos[0] +2, $Pos[1] -2)
Filewrite($File, Hex($var, 6) & @CRLF)
Local $var = PixelGetColor($Pos[0] +2, $Pos[1] -3)
Filewrite($File, Hex($var, 6) & @CRLF)
;Row 7
   Filewrite($File,"Row 7" & @CRLF)
Local $var = PixelGetColor($Pos[0] +1, $Pos[1] +3)
Filewrite($File, Hex($var, 6) & @CRLF)
Local $var = PixelGetColor($Pos[0] +1, $Pos[1] +2)
Filewrite($File, Hex($var, 6) & @CRLF)
Local $var = PixelGetColor($Pos[0] +1, $Pos[1] +1)
Filewrite($File, Hex($var, 6) & @CRLF)
Local $var = PixelGetColor($Pos[0] +1, $Pos[1])
Filewrite($File, Hex($var, 6) & @CRLF)
Local $var = PixelGetColor($Pos[0] +1, $Pos[1] -1)
Filewrite($File, Hex($var, 6) & @CRLF)
Local $var = PixelGetColor($Pos[0] +1, $Pos[1] -2)
Filewrite($File, Hex($var, 6) & @CRLF)
Local $var = PixelGetColor($Pos[0] +1, $Pos[1] -3)
Filewrite($File, Hex($var, 6) & @CRLF)
EndFunc

Share this post


Link to post
Share on other sites



#3 ·  Posted (edited)

Great idea, here's what I came up with.

Hotkeyset("{F7}","Capture")

While 1
   Sleep(10)
   WEnd
   
 Func Capture()
    $Row = 1
   Local $File = Fileopen("Txt.txt",1)
   If $File = -1 then
      Msgbox(0,"Error","Cant open")
      Exit
      EndIf
       $Pos = MouseGetPos()
       Filewrite($File,"Row:"& $Row & @CRLF)
  For $Y = 3 to -3 step -1
     ConsoleWrite($Y & @CRLF)
        Filewrite($File,"Row:"& $Row & @CRLF)
    For $X = -3 to 3 step 1
       ConsoleWrite($X & @CRLF)
        $var = PixelGetColor($Pos[0] + $X , $Pos[1] + $Y)
        Filewrite($File, Hex($Var, 6) & @CRLF)
     Next
        $Row = $Row+1
     Next
     EndFunc

Thank you.

Edited by Ritt

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