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

function setPixel(x, y, pix)
  if x >= 0 and y >= 0 and x < w and y < h then
    pixels[y*w+x+1] = pix
  end
end

-- copy image

w, h = img.width, img.height
pixels = {}
for y = 0, h-1 do
  for x = 0, w-1 do
    pixels[y*w+x+1] = img.getInt(x, y)
  end
end

-- iterate over all rectangles in recognition result (with pattern matching)

j = nil
while true do
  i, j, x1, y1, x2, y2 = string.find(result, "(%d+),%s*(%d+),%s*(%d+),%s*(%d+)", j)
  if i == nil then break end
  
  -- paint rectangle
  
  x1, y1 = x1-1, y1-1 -- paint AROUND the found image
  x2, y2 = tonumber(x2), tonumber(y2)
  
  for y = y1, y2 do
    setPixel(x1, y, 0xFF0000)
    setPixel(x2, y, 0xFF0000)
  end
  
  for x = x1, x2 do
    setPixel(x, y1, 0xFF0000)
    setPixel(x, y2, 0xFF0000)
  end
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: 1112 / 181
Referenced in: [show references]