Jump to content
Sign in to follow this  
trlopes

ImgLoc Developer Manual - Mod/Devs Only - 2016.11.01 update

Recommended Posts

01/11/2016 - update: changed some bad code examples that could genrate GDI leaks; added info regarding cocDiamonds and last SC Update.

 

15/10/2016 - Still works the same. CocDiamond coordinates changes due to latest CoC Update.

Also, when testing new images you mus call cleanCache() method , otherwhise the image gets loaded to pre-cache!

 

 

Hello Community.

As several modders/devs are using imgloc features. I feel that at this time there is a need for some documentation about it.

I hope the next lines will help all of you in your efforts to make this bot even grater!

 

Special PreNote: presented code examples are just that, examples, do not complain if you perform a copy+paste and it does not work!

 

Our (mine and Yours) time is limited so I urge our community not to spam this thread with questions that can be answered by reading CAREFULLY what I describe below!

 

Spoiler

MyBotRunImgLoc Developer Manual

 
 

Description:

MyBotRunImgloc is an Image Processing DLL developed for MyBot.run to provide image search functions.

MyBotRunImgloc was developed by the AMAZING, EXTRAORDINARY, UNBELIAVABLE, FANTASTIC trlopes, A.K.A. the SupaDupaNoobMaster (  hummmm …. ME :D )

 

Please read carefully as some concepts need to be well understood in order for correct usage of imgloc.

 
 
 

CocDiamond:

CocDiamonds are (closed) Polygons where you want to search your tiles. You can specify one default or your own defined CocDiamond. There must be at least 3 points in format X,Y|X1,Y1|X2,Y2 to define a CocDiamond.

 

Default values for CocDiamond (you can use the strings that ImgLoc will translate to the corresponding values)

String  = CocDiamondPoints

ECD = "430,25|840,335|430,645|15,335";// Extended CocDiamond - External Grass Area Included

DCD = "430,70|785,335|430,605|70,335";  // Default CocDiamond -Only Village Area

TL = "20,330|430,25|430,330";  // Top Left Triangle

TR = "430,25|840,335|430,330"; //Top Right Triangle

BL = "20,330|430,650|430,330";  // Bottom Left Triangle

BR = "840,335|430,650|430,330"; //Bottom Right Triangle

TRPBAR = "0,629|860,629|860,725|0,725" //bottom troop bar on Attack window

FV = "0,0|860,0|860,780|0,780";  // Full Screen  ** DEFAULT IF EMPTY STRING IS PASSED IN SEARCH FUNCTIONS:

 

Important Note: For reduced captures (image captured is not the size of fullscreen) YOU MUST USE “FV” for CocDiamond and Redline Argument in MultiSearch and SingleSearch (only cocdiamond in single).

Important Note 2: After 2016 October Update, the predefined CocDiamonds are dinamic, this means that on every village search it is calculated the offset and zoom and the Diamond Points are ajusted dynamically.

 
 

Example Usages:

$SinglecocDiamond= “ECD”

$SinglecocDiamond= “20,330|430,25|430,330|”

VERY IMPORTANT RULE: tile images filename MUST be named with tolerance in format “tilename_level_[Fill]_tolerance” where tolerance is a 2 digit number. Ex: My-NameTile_7_92.bpm will return a 92 (0.92) value for tolerance and 7 for level,  [fill] is not mandatory. DO NOT USE THE “_” ANYWHERE ELSE IN FILENAME (YOU HAVE BEEN WARNED!

 
 
 
 
 

Available Functions exposed by the DLL:

SearchTile :  Performs single image matching in the specified CocDiamond

FindTile :  Performs single  image matching in the specified CocDiamond

Diference is that FindTile will read tolerance from filename always

AutoIt Calling Convention Example:

 

Needed Variables and Calling example:

_CaptureRegion2()   =>pointer/handle to bitmap ou source image

$tilename="X:\PATH\FileName.png(bmp)" =>filename of the template image to match

$SingleCocDiamond = "DCD"  =>CocDiamond (see definition above)

$MaxReturnPoints=0  =>Returns all found points ; N Returns N points

$ToleranceImgLoc = 0.92

 

$res = DllCall($pImgLib, "str", "SearchTile", "handle", $hHBitmap2, "str", $tilename, "float", $ToleranceImgLoc, "str", $SingleCocDiamond, "int", $MaxReturnPoints)

 

or

$res = DllCall($hImgLib, "str", "FindTile", "handle", $hHBitmap, "str", $findImage,  "str", $sArea, "Int", $MaxReturnPoints)

 

Return Values: string with found point in format TOTALFOUNDPOINTS|X,Y|X1,Y1|... (Separated by # if

If Error is returned then return values is “-1:ErrorMessage”

 
 

Example return values:

Single Diamond Defined:     4|279,467|363,530|357,526|267,458

4 Points returned

4 X,Y coordinates separated by |

 
 
 

Checking the return values:

 

If IsArray($res) Then  ;despite being a string, AutoIt receives a array[0]

If $res[0] = "0" or $res[0] = "" Then

SetLog("Template Image Not Found!")

ElseIf StringLeft($res[0],2) = "-1" Then  ;error

SetLog("DLL Error: " + $res[0], $COLOR_RED)

Else

If $DebugSetlog Then SetLog("Template Image Found!")

$expRet = StringSplit($res[0], "|")

;$expret contains 2 positions; 0 is the total objects; 1 is the point in X,Y format

$posPoint = StringSplit($expRet[1],",")

$ImageX = Int($posPoint[0])

$ImageY = Int($posPoint[1])

 

Note: Example is for 1 return point, if more points are returned $expRet will have more positions.

 
 

SearchRedLines:  Gets Redline in the specified Cocdiamond

AutoIt Calling Convention Example:

 

Needed Variables and Calling example:

_CaptureRegion2()   =>pointer/handle to bitmap ou source image

$SingleCocDiamond = "DCD"  => CocDiamond (see definition above)

 

$res = DllCall($pImgLib, "str", "SearchRedLines", "handle", $hHBitmap2, "str", $SingleCocDiamond)

 
 

Return Values: string with found point in format TOTALFOUNDPOINTS|X,Y|X1,Y1|

If Error is returned then return values is “-1:ErrorMessage”

 
 

Example return values: 4|279,467|363,530|357,526|267,458

 

GetOffSetRedLine**:  Gets Deployable Spots near to redline at the specified distance in the specified Cocdiamond

Needed Variables and Calling example:

 

$SideDiamond = "TL"  or “TR” or “BL” or “BR”

$distance = 10

$res = DllCall($pImgLib, "str", "GetOffSetRedLine", "str", $SideDiamond, “int” , $distance)

 

Return Values: string with found points in format TOTALFOUNDPOINTS|X,Y|X1,Y1|

If Error is returned then return values is “-1:ErrorMessage”

 

Example return values: 4|279,467|363,530|357,526|267,458

 

Important Info: Can only be used right after SearchRedLines or a MultiSearch that provides redline data.

 

GetDeployableNextTo**:  Gets Deployable Spots near to redline at the specified distance in the specified Cocdiamond

Needed Variables and Calling example:

 

$pointlist = "x1,y1|x2,y2|xn,yn”

$distance = 10

$res = DllCall($pImgLib, "str", "GetDeployableNextTo", "str", $pointlist, “int” , $distance)

 

Return Values: for each point in pointlistreturns 5 deployable point with $distance from redline )  X1a,Y1a|X1b,Y1b|X1c,Y1c|X1d,Y1d|X1e,Y1e#X2a,Y2a|X2b,Y2b|X2c,Y2c|X2d,Y2d|X2e,Y2e

Remember that # will separate each deployable point group from the target point

 
 

Important Info: Can only be used right after SearchRedLines or a MultiSearch that provides redline data.

 

--------------------------------------- MULTISEARCH -----------------------------------

SearchMultipleTilesBetweenLevels :  Performs image matching in the specified CocDiamond for all the files (xml/bpm/png) in the specified path and sub paths. will only gather files where Level is between min and max specified level (inclusive)

 

AutoIt Calling Convention Example:

 

Needed Variables and Calling example:

_CaptureRegion2()   =>pointer/handle to bitmap ou source image

$tilename="X:\PATH" =>path where the template images to match are placed

$SingleCocDiamond = "DCD"  =>one or more CocDiamond (see defenition ahead)

$MaxReturnPoints=0  =>Returns all found points ; N Returns N points

$redlineData=””  => Redline data obtained from previous call.

$minlevel = 1 => minimum object level

$maxLevel = 10 => maximum object level (specify 0 for MaxLevel, it will default to 100 inside imgLoc)

 

VERY IMPORTANT RULE: tile images filename MUST be named with tolerance in format “tilename_level_[Fill]_tolerance” where tolerance is a 2 digit number. Ex: My-NameTile_7_92.bpm will return a 92 (0.92) value for tolerance and 7 for level,  [fill] is not mandatory. DO NOT USE THE “_” ANYWHERE ELSE IN FILENAME (YOU HAVE BEEN WARNED!!!)

 

$res = DllCall($pImgLib, "str", "SearchMultipleTilesBetweenLevels", "handle", $hHBitmap2, "str", $tilename, "str", $SingleCocDiamond, "int", $MaxReturnPoints, “str”, $redlineData, “int”, $minLevel , “int”, $maxLevel)

 
 

Return Values: string with group of found Tile Images Names in format

Filename|Filename2|FileName3…..

If Error is returned then return values is “-1:ErrorMessage”.

 
 
 

Example return values:

Wall_9A_91.bmp|Wall_10A_94.png|Wall_10_93.png|Wall_9B_90.bmp

 
 
 
 
 

GetProperty:  Returns property data from a previous MultiSearch.

 

AutoIt Calling Convention Example:

 

Needed Variables and Calling example:

MultiSearch Example:

$pImgLib = @ScriptDir & "\lib\MyBotRunImgloc.dll"

$ImagesToUse = @ScriptDir & "\images\SOMEPATH"

SETLOG(" MultiTileSearch TEST..................STARTED")

_CaptureRegion2()

;Full Search in ALL Image (FV for cocDiamond) and return All match (maxObjects=0)

Local $hTimer = TimerInit()

; call normally SearchMultiple

$res = DllCall($pImgLib, "str", "SearchMultipleTilesBetweenLevels", "handle", $hHBitmap2, "str", $ImagesToUse, "str", "DCD",  "int", 0, "str", "", “int”, $minLevel , “int”, $maxLevel)

;Returns filenames separated by "|"

 

;get allfilenames from searchmultiple

$res = DllCall($pImgLib, "str", "GetProperty", "str", "", "str", "")     ;returns all found filenames (without paths)

 

;get single property for a filename

$KeyValue = (filename returned in SearchMultipleTiles)

$PropertyName="objectpoints"

$res = DllCall($pImgLib, "str", "GetProperty", "str", $KeyValue, "str", $PropertyName)     ;returns all found filenames (without paths)

 

;get redlines from searchmultiple

$KeyValue = "redline"

$PropertyName=""

$res = DllCall($pImgLib, "str", "GetProperty", "str", $KeyValue, "str", $PropertyName)  

 

 

 

Possible  Values for $PropertyName & Return Values

 

"objectname"  ->  “TownHall_11_93.bmp”

"objectlevel"  -> 9

"totalobjects" -> 2

"fillLevel"   -> 50

"objectpoints"  ->  X1,Y1|X2,Y2

 

"nearpoints"    ->  (for each point in ObjectPoints returns 5 NearPoints distance 2px from redline)  X1a,Y1a|X1b,Y1b|X1c,Y1c|X1d,Y1d|X1e,Y1e#X2a,Y2a|X2b,Y2b|X2c,Y2c|X2d,Y2d|X2e,Y2e

Remember that # will separate each nearpoint group from the target point

 

"farpoints" ->  (for each point in ObjectPoints returns 5 FarPoints distance 15px from redline )  X1a,Y1a|X1b,Y1b|X1c,Y1c|X1d,Y1d|X1e,Y1e#X2a,Y2a|X2b,Y2b|X2c,Y2c|X2d,Y2d|X2e,Y2e

Remember that # will separate each farpoint group from the target point

 

"redlinedistance"  -> (shortest redline point distance to each object point in px. NOTE: the distance is measured against the found point that is the center of the specified tileimage, it might not be the center of the object)  Ex: 82|154

 

"filepath"       -> Full file path of image - x:\images\Drilll_9A_50_91.bmp

"filename"      -> Filename of image   - Drilll_9A_50_91.bmp

"deploy:DFR"      -> DFR (distance from redline) - numeric value in pixels. Will get 5 nearest valid deploy points for each objectpoint nearest to the redline with the DFR distance to the object from redline.

 
 
 
 

Correct (recommended) Usage for MultiSearch:

When doing a multisearch, you must consider several available options and scenarios.

Searching on OPPONENT village.

 

On the very first search you perform on the OPPONENT village, beside the return for the object you are looking for, you will also get Redline Information. You SHOULD reuse that information on subsequent multisearches for a quicker response.

Very Important NOTE: Be aware that on every call to multisearch (or singlesearch), previous data is cleaned, so if you are going to look different objects, you must retrieve the needed properties BEFORE initializing a new search.

Also: if you are performing multiple searches, do not forget to override redlinedata from the first time you called multisearch.

 
 
 
 

For instance:

  1. You perform a TH search (set min and maxlevels to 0 to find ALL possible TH levels)

$ImagesToUse = “TH”

$res = DllCall($pImgLib, "str", "SearchMultipleTilesBetweenLevels", "handle", $hHBitmap2, "str", $ImagesToUse, "str", "DCD",  "int", 0, "str", "", “int”, 0 , “int”, 0)

;Returns filenames separated by "|"

;for example, the above search would return $res[0]=“TownHall_10_92.bmp”

; you can get the TH location by getting property “objectPoints”

 
 

$KeyValue=”TownHall_10_92.bmp” ; the return from search TH

$PropertyName="objectpoints" ; the location of TH

$REDLINEDATA = DllCall($pImgLib, "str", "GetProperty", "str", $KeyValue, "str", $PropertyName)    

;$REDLINEDATA[0]  will have the X,Y coordinates of the TH. Beware that there can be multiple found points for the object ( x,y|x1,y1 ) sometime the tile is multimatched on a very near location)

 

;the, you can obtain redline data for the next multisearch call  where you will look for other objects (mortar, wizard tower, etc…)

$KeyValue=”redline”

$PropertyName=""

$res = DllCall($pImgLib, "str", "GetProperty", "str", $KeyValue, "str", $PropertyName)    

;$res[0] will have redline data

 

2. No you want to find something else on the OPPONENT village, but has you already have redlinedata from previous search, you can pass it to imgloc

$ImagesToUse = “MORTARS”

; as you also know the TH level for the OPPONENT Village, you can use the function getTHDefenseMax by @lunaEclipse to find the max level for the object you are looking for and restrict the images imgloc will search (this improves search time a lot)

(check weakbase.au3 for example). If your target TH is a th 7 it does not make sense looking for mortars level 8 or 9. etc...

 
 

$res = DllCall($pImgLib, "str", "SearchMultipleTilesBetweenLevels", "handle", $hHBitmap2, "str", $ImagesToUse, "str", "DCD",  "int", 0, "str", $REDLINEDATA[0], “int”, $minLevel , “int”, $maxLevel)

 
 
 

Searching on YOUR OWN village.

If you want to search your OWN village, the redline information will not be retrieved (as there is none on your village). This brings a problem on ImgLoc Multisearch.

Searches are way faster because of redline information. Imgloc uses redline to compute the minimum search area for each target village, and this is what makes the difference on search times.

The lack of redline data on your OWN village, makes imgloc to fail searches. So, in order to get some result for a multisearch on your OWN village, you must “force” redline data into multisearch.

 

This can be achieved by passing the SAME values of COCDiamond into Redline argument.

So, if you specify “DCD” for CocDiamod, redline will also be DCD

 

$res = DllCall($pImgLib, "str", "SearchMultipleTilesBetweenLevels", "handle", $hHBitmap2, "str", $ImagesToUse, "str", "DCD",  "int", 0, "str", "DCD", “int”, 0 , “int”, 0)

 
 

Searching on REDUCED CAPTURES.

Reduced capture is when  you call CaptureRegion with arguments to get only a portion of the screen.

If you perform a reduced capture, you MUST specify “FV” for CocDiamond AND RedlineData, otherwise you will not get any results back.

 

---------------------------------------------

Other Very Important Info:

Imgloc supports the following image formats:

 

bpm - 24bpp

png - 24bpp

xml - (MyBot.Run proprietary format)

 

Some of the above features will only be made available after 6.3 release targeted to be released sooner than later or later than sooner, where many major features have already been ported to new imgloc.

 

 

Hope you enjoyed the reading!

 

 

 

 

Edited by trlopes
October update
  • Like 1
  • Upvote 21

Share this post


Link to post
Share on other sites

@trlopes hi, coc plain did changed or SC developed new image defender system so that about COCdiamond ?

i tested old DB images, but couldnt used it. Maybe new screencapture plain images help to found DB correctly ?(note: topic very hard show me sorry i am not a programmer) İ can only collect all lvl elexir images.

Share this post


Link to post
Share on other sites

I'm trying to fix XP Goblin mod

 

 

but I can not find the MAP GOBLIN

(the arena &  GoblinPicnic)

can help for this code

 

result = multiMatchesPixelOnly($directory, 0, "FV", "FV", "", 0, 1000, $x1, 0, $x2, $g_iGAME_HEIGHT)

==========================================================

 

Func IsGoblinMapSXFound()
    If $g_bDebugSX Then SetDebugLog("SX|Begin IsGoblinMapSXFound", $COLOR_DEBUG)
    Local $directory = $g_sImgFindSX
    Local $result = ""
    Local $x1 = 0, $x2 = 0

    Click(840, 230 + $g_iMidOffsetY)
    If _Sleep(50) Then Return False
    If $g_iGoblinMapOptSX = 1 Then
        $x1 = 565
        $x2 = 615
        $result = multiMatchesPixelOnly($directory, 0, "FV", "FV", "", 0, 1000, $x1, 0, $x2, $g_iGAME_HEIGHT)
    ElseIf $g_iGoblinMapOptSX = 2 Then
        $x1 = 680
        $x2 = 730
        $result = multiMatchesPixelOnly($directory, 0, "FV", "FV", "", 0, 1000, $x1, 0, $x2, $g_iGAME_HEIGHT)
    EndIf

    If $g_bDebugSX Then SetDebugLog("SX|IGMSX|$result = " & $result)
    If StringLen($result) < 3 And StringInStr($result, "|") = 0 Then
        If $g_bDebugSX Then SetDebugLog("SX|IGMSX|Return False", $COLOR_ERROR)
        Return False
    EndIf

    Local $ToReturn = ""
    If StringInStr($result, "|") > 0 Then
        $ToReturn = StringSplit(StringSplit($result, "|", 2)[0], ",", 2)
    Else
        $ToReturn = StringSplit($result, ",", 2)
    EndIf
    $ToReturn[0] += $x1
    $ToReturn[1] += 5
    If $g_bDebugSX Then SetDebugLog("SX|IGMSX|Found Before Return $ToReturn[2]: [0]=" & $ToReturn[0] & ", [1]=" & $ToReturn[1])

    If ($ToReturn[1] > 560) Then
        If $g_bDebugSX Then SetDebugLog("SX|IGMSX|" & $g_sGoblinMapOptSX & " Is At Bottom Non Clickable Place Drag above")
        ClickDrag(Random(510, 515, 1), Random(515, 520, 1), Random(510, 515, 1), Random(385, 390, 1), 100)
        If _Sleep(100) Then Return False
        Return IsGoblinMapSXFound()
    ElseIf ($ToReturn[1] < 110) Then
        If $g_bDebugSX Then SetDebugLog("SX|IGMSX|" & $g_sGoblinMapOptSX & " Is At Top Non Clickable Place Drag below")
        ClickDrag(Random(510, 515, 1), Random(385, 390, 1), Random(510, 515, 1), Random(515, 520, 1), 100)
        If _Sleep(100) Then Return False
        Return IsGoblinMapSXFound()
    EndIf

    If $g_bDebugSX Then SetDebugLog("SX|IGMSX|Return $ToReturn[2]: [0]=" & $ToReturn[0] & ", [1]=" & $ToReturn[1])
    Return $ToReturn
EndFunc   ;==>IsGoblinMapSXFound

 

 

SuperXP.rar SuperXP1.rar

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

×
×
  • Create New...