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

38
LINES

< > BotCompany Repo | #367 // Multi Rectangle Visualizer

Lua code - Visualizer

1  
function setPixel(x, y, pix)
2  
  if x >= 0 and y >= 0 and x < w and y < h then
3  
    pixels[y*w+x+1] = pix
4  
  end
5  
end
6  
7  
-- copy image
8  
9  
w, h = img.width, img.height
10  
pixels = {}
11  
for y = 0, h-1 do
12  
  for x = 0, w-1 do
13  
    pixels[y*w+x+1] = img.getInt(x, y)
14  
  end
15  
end
16  
17  
-- iterate over all rectangles in recognition result (with pattern matching)
18  
19  
j = nil
20  
while true do
21  
  i, j, x1, y1, x2, y2 = string.find(result, "(%d+),%s*(%d+),%s*(%d+),%s*(%d+)", j)
22  
  if i == nil then break end
23  
  
24  
  -- paint rectangle
25  
  
26  
  x1, y1 = x1-1, y1-1 -- paint AROUND the found image
27  
  x2, y2 = tonumber(x2), tonumber(y2)
28  
  
29  
  for y = y1, y2 do
30  
    setPixel(x1, y, 0xFF0000)
31  
    setPixel(x2, y, 0xFF0000)
32  
  end
33  
  
34  
  for x = x1, x2 do
35  
    setPixel(x, y1, 0xFF0000)
36  
    setPixel(x, y2, 0xFF0000)
37  
  end
38  
end

Author comment

Improved over #365 (which paints only one rectangle ^^)

test run  test run with input  download  show line numbers   

Relations

Travelled to 12 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #367
Snippet name: Multi Rectangle Visualizer
Eternal ID of this version: #367/1
Text MD5: 0f7b1e6ca4b7f7b6a55eee037bf20172
Author: stefan
Category: ir result visualizers
Type: Lua code - Visualizer
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2015-02-03 21:23:08
Source code size: 808 bytes / 38 lines
Pitched / IR pitched: No / Yes
Views / Downloads: 1059 / 162
Referenced in: [show references]