Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

38
LINES

< > BotCompany Repo | #452 // Java grid locator (include)

Lua code

1  
get("#451") -- getIcons (grid size=3)
2  
get("#388") -- rect functions
3  
4  
fw, fh = 7, 15 -- font size
5  
6  
function findLeftBorder()
7  
  for x = 0, w-1 do
8  
    local nwhite = 0
9  
    for y = 0, fh*2-1 do
10  
      if img.getInt(x, y) == 0xFFFFFF then
11  
        nwhite = nwhite+1
12  
      end
13  
    end
14  
    if nwhite >= fh-1 then -- one row might not be white
15  
      leftBorder = x
16  
      return
17  
    end
18  
    print("x", x, "nwhite", nwhite)
19  
  end
20  
  error("left border not found")
21  
end
22  
23  
w, h = img.width, img.height
24  
25  
function findGrid()
26  
  findLeftBorder()
27  
  getIcons()
28  
  
29  
  r = icons["00f8a328"] or icons["00919df2"] or icons["002afe9a"] -- the latter is in black
30  
  if r == nil then error "package statement not found" end
31  
  
32  
  r = stringtorect(r)
33  
  
34  
  --return r.x..", "..r.y
35  
  
36  
  sx, sy = r.x, r.y-2
37  
  sx, sy = (sx-leftBorder) % fw + leftBorder, sy%fh
38  
end

Author comment

Began life as a copy of #447

test run  test run with input  download  show line numbers   

Travelled to 12 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #452
Snippet name: Java grid locator (include)
Eternal ID of this version: #452/1
Text MD5: f7b9ded8aba83cbb0fef3c38daf2507d
Author: stefan
Category: image recognition
Type: Lua code
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2015-02-13 00:50:55
Source code size: 863 bytes / 38 lines
Pitched / IR pitched: No / Yes
Views / Downloads: 1034 / 211
Referenced in: [show references]