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

22
LINES

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

Lua code

get("#348") -- rgb functions 

-- returns value between 0 and 1
-- img must be cropped already
function triangleness(img)
  local w, h = img.width, img.height
  local stepx = w < 40 and 1 or 4
  local stepy = h < 40 and 1 or 4
  
  local total = 0
  for y = 0, h-1, stepy do
    local sum = 0
    for x = 0, w-1, stepx do
      sum = sum+bright(rgb(img.getInt(x, y)))
    end
    sum = sum/math.floor(w/stepx)
    local expected = 1-(y+1)/h
    total = total+math.abs(sum-expected)
  end
  
  return 1-total/math.floor(h/stepy)
end

Author comment

Began life as a copy of #496

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: #501
Snippet name: Triangle detector (standing on bottom, include, optimized)
Eternal ID of this version: #501/1
Text MD5: 344a4d1877285082721b9e30c900480a
Author: stefan
Category: image recognition
Type: Lua code
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2015-03-09 00:12:51
Source code size: 552 bytes / 22 lines
Pitched / IR pitched: No / Yes
Views / Downloads: 596 / 151
Referenced in: [show references]