Sign in to follow this  
Followers 0
DigitalLocksmith

pixel search writing coordinates to a 2 dimensional array help needed.

17 posts in this topic

Ok, I can get the coordinates to write to the same column, but for some reason I'm having trouble getting x in column0 and y in column1 and so on like this...

[col0],[col1]

149, 248

164, 326

112, 543

This is where I started but it's returning a blank array.

CODE
#include<Array.au3>

Dim $avArray[10][2]

While 1

$coord = PixelSearch(0, 0, 320, 240, 0xFFFF00, 10)

If @error Then

Sleep(1000)

Else

MsgBox(0, "X and Y are:", $coord[0] & "," & $coord[1], 3)

_ArrayAdd($avArray[0][0], $coord[0])

_ArrayAdd($avArray[0][1], $coord[1])

_ArrayDisplay( $avArray, "Whole array" )

EndIf

WEnd

Share this post


Link to post
Share on other sites



why not just do

$avArray[0][0] = $coord[0]

$avArray[0][1] = $coord[1]

not sure, but your #include<Array.au3> doesn't have a space between include and <


My site for HTML Help :)[quote name='Valik' date='Oct 15 2004, 12:29 PM']Maybe nobody is an "elite uber-coder" like me because thinking is a capital offense in today's online-world?[right][snapback]36427[/snapback][/right][/quote]

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

If you add this in your loop, it will add an x and y element each time:

$avArray[$count][0] = $coord[0]
$avArray[$count][1] = $coord[1]
$count += 1

You have to initialize $count as 0 outside your loop.

However, I don't see how this script will work. Are you aware that PixelSearch only returns the first found pixel, so you'll be finding the same coordinates repeatedly?

Edited by mikehunt114

IE Dev ToolbarMSDN: InternetExplorer ObjectMSDN: HTML/DHTML Reference Guide[quote]It is surprising what a man can do when he has to, and how little most men will do when they don't have to. - Walter Linn[/quote]--------------------[font="Franklin Gothic Medium"]Post a reproducer with less than 100 lines of code.[/font]

Share this post


Link to post
Share on other sites

Oh, wow...So you're saying that there is no way to return all pixels found of a given color? I hope not. This was going to be sweet. I'm working on a motion sensor script for webcams that can identify a specific signature. It's almost a crude facial recognition breakthrough. This is why I want to plot and compare the #FFFF00 yellow array coordinates signatures.

Posted Image

Now I'm sure you understand why. Is there any way to make this happen with autoit?

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

PixelSearch() looks for the 1st occurence of a given color. If you already know the color, loop though with PixelGetColor() and check each pixel agianst whatever color your looking for, if it matches add it to your array.

Edited by evilertoaster

Share this post


Link to post
Share on other sites

Good idea...I'm going to check that out while I think...

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

Awesome, SmOke_N....Got it working...Can these arrays be compared, though...Let me get deeper into what I'm trying to do. If you look at the picture of the hand on my last post, you'll notice the yellow outline. What I hope to accomplish is to recognize the hand even if you move the hand farther from the camera, causing it to be smaller in the captured image. Technically, even though the hand is smaller, it retains the same relative shape. I'd like to figure out a way to use a ratio, -/+ a certain % threshold by comparing (array values * ratio) to determine that it is still a hand even though the size has changed. This has to be possible. Any suggestions?

Edited by DigitalLocksmith

Share this post


Link to post
Share on other sites

Awesome, SmOke_N....Got it working...Can these arrays be compared, though...

Sure they can. You just need to figure out what to compare it to :whistle:

IE Dev ToolbarMSDN: InternetExplorer ObjectMSDN: HTML/DHTML Reference Guide[quote]It is surprising what a man can do when he has to, and how little most men will do when they don't have to. - Walter Linn[/quote]--------------------[font="Franklin Gothic Medium"]Post a reproducer with less than 100 lines of code.[/font]

Share this post


Link to post
Share on other sites

Awesome, SmOke_N....Got it working...Can these arrays be compared, though...

:whistle: Compared to what? :lmao:

[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

Let me get deeper into what I'm trying to do. If you look at the picture of the hand on my last post, you'll notice the yellow outline. What I hope to accomplish is to recognize the hand even if you move the hand farther from the camera, causing it to be smaller in the captured image. Technically, even though the hand is smaller, it retains the same relative shape. I'd like to figure out a way to use a ratio, -/+ a certain % threshold by comparing (array values * ratio) to determine that it is still a hand even though the size has changed. This has to be mathematically possible. Any suggestions?

Edited by DigitalLocksmith

Share this post


Link to post
Share on other sites

Would PixelCheckSum be appropriate?


IE Dev ToolbarMSDN: InternetExplorer ObjectMSDN: HTML/DHTML Reference Guide[quote]It is surprising what a man can do when he has to, and how little most men will do when they don't have to. - Walter Linn[/quote]--------------------[font="Franklin Gothic Medium"]Post a reproducer with less than 100 lines of code.[/font]

Share this post


Link to post
Share on other sites

Pixel checksum isn't going to work well enough for this because it always changes. I have the exact color dialed in, I just need to figure out a way to compare the arrays on different scales if that makes any sense. I can already get it to recognize movement and take what ever action, but I want to take it further by having the ability to make a decision based on the shape, or what it sees. Not just that it sees movement. This is going to be amazing if I can ever get it to work. I have a few other things in mind already like a completely automated paintball turret. When you walk by, you get unloaded on!

Share this post


Link to post
Share on other sites

Pixel checksum isn't going to work well enough for this because it always changes. I have the exact color dialed in, I just need to figure out a way to compare the arrays on different scales if that makes any sense. I can already get it to recognize movement and take what ever action, but I want to take it further by having the ability to make a decision based on the shape, or what it sees. Not just that it sees movement. This is going to be amazing if I can ever get it to work. I have a few other things in mind already like a completely automated paintball turret. When you walk by, you get unloaded on!

Why not just make an array of every size possible, then make that an array a string, then compare the arrays to the array received that way?

Or as mike suggested, do a pixelchecksum of every possible size, and compare that way... The issue I can definately see you running into is speed doing it the way I think you are suggesting.


[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

Ok, I think I understand where you're going with that. I guess I could start with the array signature for the largest "hand" and subtract 1 from every value per array...? Then see if it falls into a relative size of one of those arrays? This is going to be complicated and speed will be an issue. I guess it doesn't have to be real time as long as it works. You could still use captured video, I guess. Maybe a combo pixelgetcolor and pixelchecksum will work. This may be too much for it to handle.

Share this post


Link to post
Share on other sites

#16 ·  Posted (edited)

Smoke, how can I add all of the values of the 2 columns seperately and divide (average) by the number of elements in each column? Also, Filewrite from array isn't working...I'm researching, I'm just turning up nothing.

Like:

add all column0 = Whatever/number of elements

add all column1 = Whatever/number of elements

With this code:

CODE
#include<Array.au3>

#include <File.au3>

Sleep(3000)

$poop = 0

While $poop <10

$array = _PixelSearchEx(0, 0, 320, 240, 0xFFFF00)

If @error Then

Exit

EndIf

$poop = $poop + 1

WEnd

_FileWriteFromArray("fan club.txt", $array, 1)

_ArrayDisplay($array)

Func _PixelSearchEx($xTop, $yTop, $xBottom, $yBottom, $nColor, $iShade = 0, $iStep = 1)

Local $aPix, $aCoords, $nYAdd, $iAdd

For $xCC = $xTop To $xBottom

$nYAdd = 0

While $nYAdd <= $yBottom

$aPix = PixelSearch($xCC, $yTop + $nYAdd, $xCC, $yBottom, $nColor, $iShade, $iStep)

If Not IsArray($aPix) Then ExitLoop

If Not IsArray($aCoords) Then Local $aCoords[1][2]

$nYAdd += ($aPix[1] - $yTop) + 1

$iAdd += 1

ReDim $aCoords[$iAdd + 1][2]

$aCoords[$iAdd][0] = $aPix[0]

$aCoords[$iAdd][1] = $aPix[1]

WEnd

Next

If IsArray($aCoords) Then Return $aCoords

Return SetError(1, 0, 0)

EndFunc

Func _ArrayDisplay2D($aArray, $sTitle = 'Array Display 2Dim', $iBase = 1, $sToConsole = 0)

If Not IsArray($aArray) Then Return SetError(1, 0, 0)

Local $sHold = 'Dimension 1 Has: ' & UBound($aArray, 1) -1 & ' Element(s)' & @LF & _

'Dimension 2 Has: ' & UBound($aArray, 2) - 1 & ' Element(s)' & @LF & @LF

For $iCC = $iBase To UBound($aArray, 1) - 1

For $xCC = 0 To UBound($aArray, 2) - 1

$sHold &= '[' & $iCC & '][' & $xCC & '] = ' & $aArray[$iCC][$xCC] & @LF

Next

Next

If $sToConsole Then Return ConsoleWrite(@LF & $sHold)

Return MsgBox(262144, $sTitle, StringTrimRight($sHold, 1))

EndFunc

Edited by DigitalLocksmith

Share this post


Link to post
Share on other sites

1. I believe _FileWriteFromArray() only works on 1 dimensional arrays.

2. I have no idea what you are really asking... and would hate to waste the brain power to just figure out I was going down the wrong path.


[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

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