1 | function col2hex(num) |
2 | local hexstr = '0123456789abcdef' |
3 | local s = '' |
4 | for i=1, 6 do |
5 | local mod = math.fmod(num, 16) |
6 | s = string.sub(hexstr, mod+1, mod+1) .. s |
7 | num = math.floor(num / 16) |
8 | end |
9 | return s |
10 | end |
11 | |
12 | function colortostring(c) |
13 | if c == 0xFFFFFF then return "white" end |
14 | return col2hex(c) |
15 | end |
16 | |
17 | w, h = 100, 100 |
18 | img = {getInt = function (x,y) |
19 | return x > 2 and x < 98 and y > 2 and y < 98 and -1 or |
20 | 0 |
21 | end} |
22 | |
23 | ofs = 0 |
24 | |
25 | while ofs <= w/2 and ofs <= h/2 do |
26 | colors = {} |
27 | |
28 | for y=ofs, h-ofs-1 do |
29 | colors[img.getInt(ofs, y)] = 1 |
30 | colors[img.getInt(w-ofs-1, y)] = 1 |
31 | end |
32 | |
33 | for x=ofs, w-ofs-1 do |
34 | colors[img.getInt(x, ofs)] = 1 |
35 | colors[img.getInt(x, h-ofs-1)] = 1 |
36 | end |
37 | |
38 | list, n = {}, 0 |
39 | for color, _ in pairs(colors) do |
40 | n=n+1 |
41 | list[n] = color |
42 | end |
43 | |
44 | if #list > 1 then |
45 | return ofs == 0 and "no border found" or "border thickness: "..ofs |
46 | elseif lastcolor == nil then |
47 | lastcolor = list[1] |
48 | elseif lastcolor ~= list[1] then |
49 | return ofs == 0 and "no border found" or "border thickness: "..ofs |
50 | end |
51 | |
52 | ofs = ofs+1 |
53 | end |
54 | |
55 | --return "unicolor "..colortostring(lastcolor) |
56 | return "unicolor "..lastcolor |
Began life as a copy of #302
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
ID | Author/Program | Comment | Date | |
---|---|---|---|---|
344 | #1000604 (pitcher) | 2015-08-18 00:07:22 | ||
343 | #1000610 | Edit suggestion: !636 !629 main { static Object androidContext; static String programID; public static void main(String[] args) throws Exception { function col2hex(num) local hexstr = '0123456789abcdef' local s = '' for i=1, 6 do local mod = math.fmod(num, 16) s = string.sub(hexstr, mod+1, mod+1) .. s num = math.floor(num / 16) end return s end function colortostring(c) if c == 0xFFFFFF then return "white" end return col2hex(c) end w, h = 100, 100 img = {getInt = function (x,y) return x > 2 and x < 98 and y > 2 and y < 98 and -1 or 0 end} ofs = 0 while ofs <= w/2 and ofs <= h/2 do colors = {} for y=ofs, h-ofs-1 do colors[img.getInt(ofs, y)] = 1 colors[img.getInt(w-ofs-1, y)] = 1 end for x=ofs, w-ofs-1 do colors[img.getInt(x, ofs)] = 1 colors[img.getInt(x, h-ofs-1)] = 1 end list, n = {}, 0 for color, _ in pairs(colors) do n=n+1 list[n] = color end if #list > 1 then return ofs == 0 and "no border found" or "border thickness: "..ofs elseif lastcolor == nil then lastcolor = list[1] elseif lastcolor ~= list[1] then return ofs == 0 and "no border found" or "border thickness: "..ofs end ofs = ofs+1 end --return "unicolor "..colortostring(lastcolor) return "unicolor "..lastcolor }} | 2015-08-18 03:11:31 | delete |
Recognizer | Recognition Result | Visualize | Recalc |
---|---|---|---|
#308 | 1211 | [visualize] |
Snippet ID: | #304 |
Snippet name: | Find border thickness bug test |
Eternal ID of this version: | #304/1 |
Text MD5: | 10bc997feb46fdee8e32ccb43c84f74f |
Author: | stefan |
Category: | image recognition |
Type: | Lua code |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2014-12-25 20:39:07 |
Source code size: | 1211 bytes / 56 lines |
Pitched / IR pitched: | No / Yes |
Views / Downloads: | 1280 / 304 |
Referenced in: | [show references] |