
-----------------------------------
zylum
Sat Jan 15, 2005 7:46 pm

video recognition
-----------------------------------
tonys post in the airhockey topic has inspired me to create a video recognition program which will recognize where an airpuck is located on the table

setscreen ("offscreenonly, graphics:500;300")

var cx : flexible array 1 .. 1 of int
var cy : flexible array 1 .. 1 of int

proc fillArray (tx, ty : int)
    drawdot (tx, ty, 0)
    if whatdotcolor (tx + 1, ty) = 7 then
        new cx, upper (cx) + 1
        new cy, upper (cy) + 1
        cx (upper (cx)) := tx + 1
        cy (upper (cy)) := ty
        fillArray (tx + 1, ty)
    end if
    if whatdotcolor (tx - 1, ty) = 7 then
        new cx, upper (cx) + 1
        new cy, upper (cy) + 1
        cx (upper (cx)) := tx - 1
        cy (upper (cy)) := ty
        fillArray (tx - 1, ty)
    end if
    if whatdotcolor (tx, ty + 1) = 7 then
        new cx, upper (cx) + 1
        new cy, upper (cy) + 1
        cx (upper (cx)) := tx
        cy (upper (cy)) := ty + 1
        fillArray (tx, ty + 1)
    end if
    if whatdotcolor (tx, ty - 1) = 7 then
        new cx, upper (cx) + 1
        new cy, upper (cy) + 1
        cx (upper (cx)) := tx
        cy (upper (cy)) := ty - 1
        fillArray (tx, ty - 1)
    end if
end fillArray

proc findCoords
    for x : 1 .. maxx by 20
        for y : 1 .. maxy by 20
            if whatdotcolor (x, y) = 7 then
                cx (1) := x
                cy (1) := y
                fillArray (x, y)
                exit
            end if
            exit when whatdotcolor (x, y) = 7
        end for
    end for
    if upper (cx) = 1 then
        return
    end if

    var tx := 0
    var ty := 0
    for i : 1 .. upper (cx)
        tx += cx (i)
        ty += cy (i)
    end for
    tx := tx div upper (cx)
    ty := ty div upper (cy)

    locate (1, 1)
    put "Puck Coordinates: ", tx, " ", ty
    new cx, 1
    new cy, 1
end findCoords

var mx, my, md : int

loop
    mousewhere (mx, my, md)
    drawfilloval (mx, my, 15, 15, 7)
    findCoords
    put "Mouse Coordinates: ", mx, " ", my
    drawfilloval (mx, my, 15, 15, 7)
    View.Update
    cls
end loop

-----------------------------------
sport
Sat Jan 15, 2005 11:11 pm


-----------------------------------
Pretty usefull Nice Job :clap:

-----------------------------------
Tony
Sat Jan 15, 2005 11:58 pm


-----------------------------------
that's preaty cool. Even with some random noise

    for i : 1 .. 10
        Draw.Line (Rand.Int (0, maxx), Rand.Int (0, maxy), Rand.Int (0, maxx), Rand.Int (0, maxy), 7)
    end for


the results are still quite accurate :)
