ExodduS Posted July 18, 2005 Share Posted July 18, 2005 i have a screen like the attach i need to count the number of white squares in the big black square(for a game) is that possibel? can any1 help me with the function? i was thinking something like that: 1) verify a pixel 2) if it's not black is the start of a square 3) verify next pixel if its black i got 1 square 4) if not, it's still the square 5) go to 1) until the area has been search and i got the number of white squares ok, thank you very much! Link to comment Share on other sites More sharing options...
seandisanti Posted July 18, 2005 Share Posted July 18, 2005 i have a screen like the attachi need to count the number of white squares in the big black square(for a game)is that possibel?can any1 help me with the function?i was thinking something like that:1) verify a pixel2) if it's not black is the start of a square3) verify next pixel if its black i got 1 square4) if not, it's still the square5) go to 1)until the area has been search and i got the number of white squaresok, thank you very much!<{POST_SNAPBACK}>just have a couple of for loops. check each pixel in the image. if the pixel above the one being examined is black, and the one to the left of it is, then it's the top left corner of the square, otherwise move on to next pixel. if you have 5 squares, you're gonna have 5 top left corners.... Link to comment Share on other sites More sharing options...
ExodduS Posted July 18, 2005 Author Share Posted July 18, 2005 i got the idea, the only problem is this, how to make it? for example, i use the PixelSearch for the first pixel or just make a loop and use PixelGetColor for every pixel of the image? what is less time consuming, what is better ty Link to comment Share on other sites More sharing options...
seandisanti Posted July 18, 2005 Share Posted July 18, 2005 i got the idea, the only problem is this, how to make it?for example, i use the PixelSearch for the first pixel or just make a loop and use PixelGetColor for every pixel of the image?what is less time consuming, what is betterty<{POST_SNAPBACK}> here's a little quick code... operating on a few assumptions though, 1) top left pixel of pic is 0,0 bottom right is 99,99. 2) PixelGetColor() for a black pixel will return 0 and i think that's that...$squarecounter = 0 $left = 0 $up = 0 for $x = 0 to 99 for $y = 0 to 99 if $x > 0 then $left = 1 EndIf if $y > 0 then $up = 1 EndIf if $up and $left Then if PixelGetColor($x,$y -1) = 0 and PixelGetColor($x -1,$y) = 0 then $squarecounter = $squarecounter + 1 EndIf elseif $up Then if PixelGetColor($x,$y-1) = 0 then $squarecounter = $squarecounter + 1 EndIf elseif $left Then if PixelGetColor($x-1,$y)= 0 then $squarecounter = $squarecounter +1 EndIf EndIf Next Next msgbox(0,"Squares","There are " & $squarecounter & " squares") Link to comment Share on other sites More sharing options...
ExodduS Posted July 18, 2005 Author Share Posted July 18, 2005 where there's a if $x > 0 is a pixelgetcolor right? and shouldnt be a else for making $up and $left = 0? ty Link to comment Share on other sites More sharing options...
seandisanti Posted July 18, 2005 Share Posted July 18, 2005 where there's a if $x > 0 is a pixelgetcolor right?and shouldnt be a else for making $up and $left = 0?ty<{POST_SNAPBACK}> $up and $left are to determine if there is a square above and to the left... because it's possible that a pixel with an x or y coord of 0 will be a white square, or the corner square we're looking for... so if $up and $left are both 1's, then that means there are squares above and to the left, so both have to be checked, otherwise, only squares that exist are checked... make sense? Link to comment Share on other sites More sharing options...
ExodduS Posted July 18, 2005 Author Share Posted July 18, 2005 yeah sure but then u could make for $x = 1 and also there's no further checking to see if PixelGetColor($x,$y -1) = 0 and PixelGetColor($x -1,$y) = 0 AND PixelGetColor($x, $y) = WHITE then anyway, i got the idea ty Link to comment Share on other sites More sharing options...
seandisanti Posted July 18, 2005 Share Posted July 18, 2005 yeah surebut then u could makefor $x = 1 and also there's no further checking to seeif PixelGetColor($x,$y -1) = 0 and PixelGetColor($x -1,$y) = 0 AND PixelGetColor($x, $y) = WHITE then anyway, i got the idea ty<{POST_SNAPBACK}>np, glad i could help Link to comment Share on other sites More sharing options...
ExodduS Posted July 19, 2005 Author Share Posted July 19, 2005 (edited) $squarecounter = 0 $left = 0 $up = 0 for $x = 21 to 985 for $y = 432 to 715 if $x > 21 then $left = 1 EndIf if $y > 432 then $up = 1 EndIf if $up and $left Then if PixelGetColor($x,$y -1) = Dec(0x282828) and PixelGetColor($x -1,$y) = Dec(0x282828) and PixelGetColor($x,$y) = Dec(0xFFFFFF) then $squarecounter = $squarecounter + 1 EndIf elseif $up Then if PixelGetColor($x,$y -1) = Dec(0x282828) and PixelGetColor($x,$y) = Dec(0xFFFFFF) then $squarecounter = $squarecounter + 1 EndIf elseif $left Then if PixelGetColor($x -1,$y) = Dec(0x282828) and PixelGetColor($x,$y) = Dec(0xFFFFFF) then $squarecounter = $squarecounter +1 EndIf EndIf Next Next $stop1 = TimerDiff($start1) MsgBox(0,"Time",$stop1) MsgBox(0,"Squares","There are " & $squarecounter & " squares") got like 90000 mill to run it, and it's too much time is there anyway to make the check almost instant? i dont know, maybe other solution Edited July 19, 2005 by ExodduS Link to comment Share on other sites More sharing options...
seandisanti Posted July 19, 2005 Share Posted July 19, 2005 $squarecounter = 0 $left = 0 $up = 0 for $x = 21 to 985 for $y = 432 to 715 if $x > 21 then $left = 1 EndIf if $y > 432 then $up = 1 EndIf if $up and $left Then if PixelGetColor($x,$y -1) = Dec(0x282828) and PixelGetColor($x -1,$y) = Dec(0x282828) and PixelGetColor($x,$y) = Dec(0xFFFFFF) then $squarecounter = $squarecounter + 1 EndIf elseif $up Then if PixelGetColor($x,$y -1) = Dec(0x282828) and PixelGetColor($x,$y) = Dec(0xFFFFFF) then $squarecounter = $squarecounter + 1 EndIf elseif $left Then if PixelGetColor($x -1,$y) = Dec(0x282828) and PixelGetColor($x,$y) = Dec(0xFFFFFF) then $squarecounter = $squarecounter +1 EndIf EndIf Next Next $stop1 = TimerDiff($start1) MsgBox(0,"Time",$stop1) MsgBox(0,"Squares","There are " & $squarecounter & " squares")got like 90000 mill to run it, and it's too much timeis there anyway to make the check almost instant? i dont know, maybe other solution<{POST_SNAPBACK}>could you attach the pic you're using to test? i want to see if i can't speed it up, but want to use the same size, etc... Link to comment Share on other sites More sharing options...
seandisanti Posted July 19, 2005 Share Posted July 19, 2005 i have a couple of ideas to cut down on the number of comparisons, i will test them and post code and results...Here's what i got.... don't think INSTANT is really possible, but can really cut the time by reducing the number of comparisons. instead of checking each pixel, i ran with the the pixelchecksum to check 4 pixels at a time, and evaluate if white pixels were found. using the same image image that was taking 8000+ each time now i'm averaging about 2600.... if you wanted to go through and figure the possible checksums for 3x3 blocks instead of 2x2 blocks, i'm sure you could shave some more time off. here's the code: <you're going to have to change the ranges on the For loops, and filenames etc...>expandcollapse popupwinactivate("C:\Documents and Settings\lv_sdesanti\Desktop\pixel.jpg - Microsoft Internet Explorer") $squarecounter = 0 $left = 0 $up = 0 $START = TimerInit() for $x = 12 to 147 STEP 2 for $y = 114 to 311 STEP 2 select case PixelChecksum($x,$y,$x+1,$y+1)=1304300533 ;ALL 4 ARE WHITE if $x = 12 and $y = 114 Then $squarecounter = $squarecounter + 1 Else IF $Y = 114 AND PixelGetColor($X-1,$Y)=0 Then $squarecounter = $squarecounter + 1 MouseMove($X,$Y,0) MSGBOX(0,"HERE","HERE") EndIf IF PixelChecksum($X-1,$Y-1,$X,$Y) = 101057278 Then $squarecounter = $squarecounter + 1 EndIf EndIf case PixelChecksum($x,$y,$x+1,$y+1)=351733243;VERTICAL WHITE PAIR if $x = 12 Then $squarecounter = $squarecounter + 1 Else IF PixelGetColor($X+1,$Y -1) = 0 Then $squarecounter = $squarecounter + 1 EndIf EndIf CASE PixelChecksum($x,$y,$x+1,$y+1)=101057278;HORIZONTAL WHITE PAIR $squarecounter = $squarecounter + 1 EndSelect Next Next $STOP = TimerDiff($START) MSGBOX(0,"TIME",$STOP) msgbox(0,"squarecounter",$squarecounter) 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