Ritt Posted December 12, 2013 Share Posted December 12, 2013 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. expandcollapse popupHotkeyset("{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 Link to comment Share on other sites More sharing options...
Solution Jfish Posted December 12, 2013 Solution Share Posted December 12, 2013 You should use loops for $startPosition = -3 to 3 step 1 ; this will go -3,-2,-1,0,1,2,3 Then you could have another loop going through all the rows. for $rows=3 to -3 step -1; this will go 3,2,1,0,-1,-2,-3 Build your own poker game with AutoIt: pokerlogic.au3 | Learn To Program Using FREE Tools with AutoIt Link to comment Share on other sites More sharing options...
Ritt Posted December 12, 2013 Author Share Posted December 12, 2013 (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 December 12, 2013 by Ritt Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now