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

20
LINES

< > BotCompany Repo | #496 // Triangle detector (standing on bottom, include)

Lua code

1  
get("#348") -- rgb functions 
2  
3  
-- returns value between 0 and 1
4  
-- img must be cropped already
5  
function triangleness(img)
6  
  local w, h = img.width, img.height
7  
  
8  
  local total = 0
9  
  for y = 0, h-1 do
10  
    local sum = 0
11  
    for x = 0, w-1 do
12  
      sum = sum+bright(rgb(img.getInt(x, y)))
13  
    end
14  
    sum = sum/w
15  
    local expected = 1-(y+1)/h
16  
    total = total+math.abs(sum-expected)
17  
  end
18  
  
19  
  return 1-total/h
20  
end

Author comment

Began life as a copy of #493

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

Snippet ID: #496
Snippet name: Triangle detector (standing on bottom, include)
Eternal ID of this version: #496/1
Text MD5: 188b3a62d1052099df733f96eacc1cde
Author: stefan
Category: image recognition
Type: Lua code
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2015-03-08 20:40:37
Source code size: 432 bytes / 20 lines
Pitched / IR pitched: No / Yes
Views / Downloads: 724 / 175
Referenced in: [show references]