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

65
LINES

< > BotCompany Repo | #428 // LXTerminal Contents Finder (include)

Lua code

get("#388") -- rect functions
get("#348") -- rgb functions
get("#356") -- num2hex

function findContents()
  hashes = otherresults["#442"] or error("Need result of #442, please recalc")
  
  j, icons = nil, {}
  while true do
    i, j, r, hash = string.find(hashes, "(%d+, %d+, %d+, %d+) %-> ([a-f0-9]+)", j)
    if i == nil then break end
    
    icons[hash] = r
  end
  
  r = icons["00645074"] or icons["0061777a"]
  if r == nil then return "LXTerminal icon not found" end
  
  -- look for a mostly black line below the icon
  r = stringtorect(r)
  x, y = r.x, r.y
  contents_y1 = nil
  while y < img.height and contents_y1 == nil do
    w = 50
    b = 0
    for xx = x, x+w-1 do
      b = b+bright(rgb(img.getInt(xx, y)))
    end
    b = b/w
    --print("Brightness at", y, ":", b)
    if b < 0.01 then
      contents_y1 = y
    end
    y = y+1
  end
  
  if contents_y1 == nil then return "Terminal contents not found" end
  
  -- find left side of contents
  
  contents_x1 = x
  while contents_x1 > 0 and img.getInt(contents_x1-1, contents_y1) == 0 do
    contents_x1 = contents_x1-1
  end
  
  -- find width of contents
  while x < img.width and img.getInt(x, contents_y1) == 0 do
    x = x+1
  end
  
  contents_x2 = x-1
  
  -- find bottom of contents
  y = contents_y1+1
  
  while y < img.height and
    (img.getInt(contents_x1, y) ~= 0xa4a4a4 or
     img.getInt(contents_x1+1, y) ~= 0xa4a4a4) do
    --print("y", y, num2hex(img.getInt(contents_x1, y)), num2hex(img.getInt(contents_x1+1, y)))
    y = y+1
  end
  
  contents_y2 = y
  contents_y1 = contents_y1+1
end

Author comment

Began life as a copy of #424

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: #428
Snippet name: LXTerminal Contents Finder (include)
Eternal ID of this version: #428/1
Text MD5: 4ea8daaf613bf90210cb565921e7759b
Author: stefan
Category: image recognition
Type: Lua code
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2015-02-09 20:38:15
Source code size: 1644 bytes / 65 lines
Pitched / IR pitched: No / Yes
Views / Downloads: 1002 / 256
Referenced in: #412 - LXTerminal Cursor Finder
#424 - LXTerminal Contents Finder
#425 - LXTerminal Contents Segmenter
#426 - LXTerminal Contents Recognizer
#427 - LXTerminal character reference maker
#429 - LXTerminal character reference maker 2
#432 - LXTerminal Contents Recognizer 2
#434 - LXTerminal Cursor Finder 2
#437 - LXTerminal Contents Recognizer 2 (cursor line only)
#438 - LXTerminal Contents Recognizer 2 (repeatable)
#439 - LXTerminal Contents Recognizer 2 (cursor line only, repeatable)
#440 - LXTerminal Cursor Finder 2 (repeatable)
#1025977 - bootstrap.min.css v3.3.0
#3000189 - Answer for stefanreich(>> t bla)
#3000202 - Answer for stefanreich (>> T conversion bot)
#3000238 - Answer for stefanreich (>> t power bot)
#3000382 - Answer for ferdie (>> t = 1, f = 0)
#3000383 - Answer for funkoverflow (>> t=1, f=0 okay)