Jump to content

help or advice to improve pixel(s) detection


spike_s2
 Share

Recommended Posts

I've managed to write the code below. Detection is partially working tho it is far from satisfactory.

In resume, screen is divided in a couple of area and each area is searched for a number of pixels.

The pixel closer to the geometrical mean (?) is chosen to aquire the target. So far, the size of the areas is customizable and also the number of pixels required to aquire a target.

Func Scan()

___$shadevariation = GUICtrlRead($input_sv)

___$step = GUICtrlRead($input_step)

______for $i=0 to $nbAreas-1

_________scanArea($i)

______Next

EndFunc

Func scanArea($areaNb)

___$found=0

___$gMeanX=1

___$gMeanY=1

___Dim $ppos

___Dim $storePos[$nbPixels][2]

___Dim $targetCoord

___for $i=0 to $nbMonster-1

______for $c=0 to $nbPixels-1

_________$ppos=getPosition($areaNb, $i, $c)

_________If $errorstatus == 0 Then

__________________$found=$found+1

__________________$gMeanX=$gMeanX*$ppos[0]/100

__________________$gMeanY=$gMeanY*$ppos[1]/100

__________________$storePos[$c][0]=$ppos[0]

__________________$storePos[$c][1]=$ppos[1]

_________EndIf

______Next

___if $found >= $plimit Then

______$gMeanX=Int($gMeanX^(1/$found)*100)

______$gMeanY=Int($gMeanY^(1/$found)*100)

______$targetCoord=getTargetCoord($storePos,$gMeanX,$gMeanY,$found)

______aquireTarget($targetCoord[0],$targetCoord[1])

___EndIf

___$found=0

___$gMeanX=0

___$gMeanY=0

___Next

EndFunc

Func getPosition($areaNb, $monsterNb, $pixelNb)

___Dim $ppos

___$ppos=PixelSearch($areas[$areaNb][0][0],$areas[$areaNb][1][1],$areas[$areaNb][1][0],$areas[$areaNb][0][1],Dec($monsterPixelData[$monsterNb][$pixelNb]),$shadevariation,$step)

___If Not @error Then

______$errorstatus=0

___else

______$errorstatus=1

___endif

___return $ppos

EndFunc

Func getTargetCoord($coordPixels,$gMeanX,$gMeanY,$nbPix)

___$sX=0

___$sY=0

___Dim $coord[2]

___$coord[0]=$coordPixels[0][0]

___$coord[1]=$coordPixels[0][1]

___for $i=0 to $nbPix-1

______If (ABS($coordPixels[$i][0] - $gMeanX)) < (ABS($coord[0] - $gmeanX)) Then $coord[0]=$coordPixels[$i][0]

______If (ABS($coordPixels[$i][1] - $gMeanY)) < (ABS($coord[1] - $gmeanY)) Then $coord[1]=$coordPixels[$i][1]

___Next

___return $coord

EndFunc

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...