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

35
LINES

< > BotCompany Repo | #343 // RecogUtil

Lua code

1  
function getLeftmostPoint(y)
2  
  local x1 = 0
3  
  while x1 < img.width and img.getInt(x1, y) >= 0xF00000 do
4  
    x1 = x1+1
5  
  end
6  
  return x1
7  
end
8  
9  
function getRightmostPoint(y)
10  
  local x2 = img.width
11  
  while x2 > 0 and img.getInt(x2-1, y) >= 0xF00000 do
12  
    x2 = x2-1
13  
  end
14  
  return x2
15  
end
16  
17  
function getWidth(y)
18  
  local x2 = getRightmostPoint(y)
19  
  local x1 = getLeftmostPoint(y)
20  
  return math.max(0, x2-x1)
21  
end
22  
23  
function getAverageWidth(y1, y2)
24  
  local sum = 0
25  
  for y = y1, y2-1 do
26  
    sum = sum+getWidth(y)
27  
  end
28  
  return sum/(y2-y1)
29  
end
30  
31  
function upperWidthToLowerWidth()
32  
  local upper = getAverageWidth(0, math.floor(img.height/3))
33  
  local lower = getAverageWidth(math.floor(img.height*2/3), img.height)
34  
  return upper/lower
35  
end

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: #343
Snippet name: RecogUtil
Eternal ID of this version: #343/1
Text MD5: ae07172ab7235e0f4b52cdf4d1ef496a
Author: stefan
Category: image recognition
Type: Lua code
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2015-01-26 01:45:37
Source code size: 760 bytes / 35 lines
Pitched / IR pitched: No / Yes
Views / Downloads: 555 / 138
Referenced in: [show references]