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

37
LINES

< > BotCompany Repo | #305 // Find border thickness bug test 2

Lua code

1  
w, h = 100, 100
2  
img = {getInt = function (x,y)
3  
  return x > 2 and x < 98 and y > 2 and y < 98 and -1 or
4  
0
5  
end}
6  
7  
ofs = 0
8  
9  
while ofs <= w/2 and ofs <= h/2 do
10  
  colors = {}
11  
  
12  
  for y=ofs, h-ofs-1 do
13  
    colors[img.getInt(ofs, y)] = 1
14  
    colors[img.getInt(w-ofs-1, y)] = 1
15  
  end
16  
  
17  
  for x=ofs, w-ofs-1 do
18  
    colors[img.getInt(x, ofs)] = 1
19  
    colors[img.getInt(x, h-ofs-1)] = 1
20  
  end
21  
  
22  
  list, n = {}, 0
23  
  for color, _ in pairs(colors) do
24  
    n=n+1
25  
    list[n] = color
26  
  end
27  
  
28  
  if #list > 1 then
29  
    return ofs == 0 and "no border found" or "border thickness: "..ofs
30  
  elseif lastcolor == nil then
31  
    lastcolor = list[1]
32  
  elseif lastcolor ~= list[1] then
33  
    return ofs == 0 and "no border found" or "border thickness: "..ofs
34  
  end
35  
  
36  
  ofs = ofs+1
37  
end

Author comment

Bug description: Click "test run". Sometimes it returns "ndrder..." instead of "border...".

Began life as a copy of #304

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

Image recognition results

Recognizer Recognition Result Visualize Recalc
#308 795 [visualize]

Snippet ID: #305
Snippet name: Find border thickness bug test 2
Eternal ID of this version: #305/1
Text MD5: 56da9d081305b1b79c90916b9b39f4c6
Author: stefan
Category: image recognition
Type: Lua code
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2015-01-04 19:50:33
Source code size: 795 bytes / 37 lines
Pitched / IR pitched: No / Yes
Views / Downloads: 720 / 199
Referenced in: [show references]