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

61
LINES

< > BotCompany Repo | #346 // Embeddable border finder (getcrop)

Lua code

1  
function tablelength(T)
2  
  local count = 0
3  
  for _ in pairs(T) do count = count + 1 end
4  
  return count
5  
end
6  
7  
function getcrop(img)
8  
  local w, h, g = img.width, img.height, img.getInt
9  
  
10  
  local x1, y1, x2, y2 = 0, 0, w, h
11  
  
12  
  -- left side
13  
  
14  
  local colors = {}
15  
  while x1 < x2 do
16  
    for y=y1, y2-1 do
17  
      colors[g(x1, y)] = 1
18  
    end
19  
    if tablelength(colors) > 1 then break end
20  
    x1=x1+1
21  
  end
22  
    
23  
  -- top side
24  
  
25  
  colors = {}
26  
  while y1 < y2 do
27  
    for x=x1, x2-1 do
28  
      colors[g(x, y1)] = 1
29  
    end
30  
    if tablelength(colors) > 1 then break end
31  
    y1=y1+1
32  
  end
33  
    
34  
  -- right side
35  
  
36  
  colors = {}
37  
  while x2 > x1 do
38  
    for y=y1, y2-1 do
39  
      colors[g(x2-1, y)] = 1
40  
    end
41  
    if tablelength(colors) > 1 then break end
42  
    x2=x2-1
43  
  end
44  
    
45  
  -- bottom side
46  
  
47  
  colors = {}
48  
  while y2 > y1 do
49  
    for x=x1, x2-1 do
50  
      colors[g(x, y2-1)] = 1
51  
    end
52  
    if tablelength(colors) > 1 then break end
53  
    y2=y2-1
54  
  end
55  
  
56  
  if x2 <= x1 or y2 <= y1 then -- weird result? return full image
57  
    x1, y1, x2, y2 = 0, 0, w, h
58  
  end
59  
  
60  
  return x1, y1, x2, y2
61  
end

Author comment

Began life as a copy of #324

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

Comments [hide]

ID Author/Program Comment Date
208 #1000604 (pitcher) 2015-08-18 00:51:07
190 #1000610 (pitcher) Edit suggestion:
!636
!629

main {
static Object androidContext;
static String programID;

public static void main(String[] args) throws Exception {
function tablelength(T)
local count = 0
for _ in pairs(T) do count = count + 1 end
return count
end

function getcrop(img)
local w, h, g = img.width, img.height, img.getInt

local x1, y1, x2, y2 = 0, 0, w, h

-- left side

local colors = {}
while x1 < x2 do
for y=y1, y2-1 do
colors[g(x1, y)] = 1
end
if tablelength(colors) > 1 then break end
x1=x1+1
end

-- top side

colors = {}
while y1 < y2 do
for x=x1, x2-1 do
colors[g(x, y1)] = 1
end
if tablelength(colors) > 1 then break end
y1=y1+1
end

-- right side

colors = {}
while x2 > x1 do
for y=y1, y2-1 do
colors[g(x2-1, y)] = 1
end
if tablelength(colors) > 1 then break end
x2=x2-1
end

-- bottom side

colors = {}
while y2 > y1 do
for x=x1, x2-1 do
colors[g(x, y2-1)] = 1
end
if tablelength(colors) > 1 then break end
y2=y2-1
end

if x2 <= x1 or y2 <= y1 then -- weird result? return full image
x1, y1, x2, y2 = 0, 0, w, h
end

return x1, y1, x2, y2
end
}}
2015-08-18 00:50:25

add comment

Image recognition results

show nils
Image Result Result calculated
#1000003 java.io.IOException: com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: No operat... 2016-07-31 19:44:18

[raw result]
[visualize]
#201 java.io.IOException: com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: No operat... 2016-07-31 19:44:18

[raw result]
[visualize]
#183 java.io.IOException: com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: No operat... 2016-07-31 19:44:18

[raw result]
[visualize]
#182 java.io.IOException: com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: No operat... 2016-07-31 19:44:18

[raw result]
[visualize]
#178 java.io.IOException: com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: No operat... 2016-07-31 19:44:18

[raw result]
[visualize]
#145 java.io.IOException: com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: No operat... 2016-07-31 19:44:18

[raw result]
[visualize]
#141 java.io.IOException: com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: No operat... 2016-07-31 19:44:18

[raw result]
[visualize]
#115 java.io.IOException: com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: No operat... 2016-07-31 19:44:18

[raw result]
[visualize]
#113 java.io.IOException: com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: No operat... 2016-07-31 19:44:18

[raw result]
[visualize]
#112 java.io.IOException: com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: No operat... 2016-07-31 19:44:18

[raw result]
[visualize]
#100 java.io.IOException: com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: No operat... 2016-07-31 19:44:18

[raw result]
[visualize]
#98 java.io.IOException: com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: No operat... 2016-07-31 19:44:18

[raw result]
[visualize]
#93 java.io.IOException: com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: No operat... 2016-07-31 19:44:18

[raw result]
[visualize]
#92 java.io.IOException: com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: No operat... 2016-07-31 19:44:18

[raw result]
[visualize]
#91 java.io.IOException: com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: No operat... 2016-07-31 19:44:18

[raw result]
[visualize]
#90 java.io.IOException: com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: No operat... 2016-07-31 19:44:18

[raw result]
[visualize]
#87 java.io.IOException: com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: No operat... 2016-07-31 19:44:18

[raw result]
[visualize]
#85 java.io.IOException: com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: No operat... 2016-07-31 19:44:18

[raw result]
[visualize]
#84 java.io.IOException: com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: No operat... 2016-07-31 19:44:18

[raw result]
[visualize]
#49 java.io.IOException: com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: No operat... 2016-07-31 19:44:18

[raw result]
[visualize]
#48 java.io.IOException: com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: No operat... 2016-07-31 19:44:18

[raw result]
[visualize]
#1000053 java.io.IOException: com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: No operat... 2016-07-31 19:44:13

[raw result]
[visualize]
#309 java.io.IOException: com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: No operat... 2016-07-31 19:44:13

[raw result]
[visualize]

Snippet ID: #346
Snippet name: Embeddable border finder (getcrop)
Eternal ID of this version: #346/1
Text MD5: be12f03a9dba5ea4b45c2fe06a806153
Author: stefan
Category: image recognition
Type: Lua code
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2015-01-26 00:23:52
Source code size: 1135 bytes / 61 lines
Pitched / IR pitched: No / Yes
Views / Downloads: 1233 / 253
Referenced in: [show references]