if not term.isColor() then
  print("Advanced computer required")
  error()
end

local function showError(message)
  term.setBackgroundColor(colors.black)
  term.setTextColor(colors.red)
  term.write(message)
  term.setBackgroundColor(colors.black)
  term.setTextColor(colors.white)
  print()
end

local function showErrorAndExit(message)
  showError(message)
  error()
end

local camera
local sides = peripheral.getNames()
for key,side in pairs(sides) do
  if peripheral.getType(side) == "warpdriveCamera" then
    print("Camera found on " .. side)
    camera = peripheral.wrap(side)
  end
end
if camera == nil or camera.isInterfaced() == nil then
  showErrorAndExit("No camera detected")
end

local argv = { ... }
if #argv ~= 0 then
  showErrorAndExit("Usage: recognition")
end

local delay = 0
local count
repeat
  count = camera.getResultsCount()
  os.sleep(0.1)
  delay = delay + 1
until (count ~= nil and count ~= -1) or delay > 10

if count ~= nil and count > 0 then
  for i=0, count-1 do
    local success, type, name, x, y, z, vx, vy, vz = camera.getResult(i)
    x = math.floor(x * 10) / 10
    y = math.floor(y * 10) / 10
    z = math.floor(z * 10) / 10
    if success then
      print(type .. " " .. name .. " @ (" .. x .. " " .. y .. " " .. z .. ")")
    else
      showError("Error " .. type)
    end
  end
else
  print("Nothing was found =(")
end
