Position Tracking Of a Location Relative to Motion

In my program I create ellipse that is on top of an image taken from the camera. This ellipse starts at the middle of the screen immediately when the program starts. I am trying to change the ellipse’s position as the device moves to match the spot on the image where it originally was. For eg. if the ellipse started on a TV that was in your image from the camera then the ellipse will move up if the image of the TV moves up. That way, no matter what camera angle is present, the ellipse will be on the TV or wherever the ellipse started. However, I cannot get the tracking right. Any ideas? Here is my code:

-- Position tracking

-- Use this function to perform your initial setup
function setup()
    print("Hello World!")

-- This function gets called once every frame
function draw()
    -- This sets a dark background color 
    background(40, 40, 50)

    -- This sets the line thickness
    capturedImage = image(CAMERA)
    -- Get the size of the current camera texture
    local camWidth, camHeight = spriteSize( CAMERA )

    -- Draw the special CAMERA sprite
    sprite( CAMERA, WIDTH/2, HEIGHT/2, math.min( camWidth, WIDTH ) )

    -- Do your drawing here
    posx = posx + RotationRate.y*28
    posy = posy  -RotationRate.x*43



I actually posted something similar to what you want here: http://codea.io/talk/discussion/5697/camera-sniper#Item_15

The accelerometer is not precise enough to be able to do something like this, sadly. You can handle rotations with ease, though.

This isn’t exactly what I am trying to do. Let me try to better explain. I want to look at something and make a dot. Then I want to look away and look back and have that dot still there. Basically it should look as if that dot was actually sitting wherever my camera was pointed. Similar to if your scope shot and made a hole in the image displayed and if the hole stayed on that exact location so if you made a hole on a couch and move your camera right the hole would still be on the couch.

If you are talking about putting a dot over a specific object in a live scene (ie the camera picture is contunally changing as you move the iPad), that is difficult.

If you are talking about putting a dot on a still picture, and the still picture moves around, then it is pretty easy to keep the dot in the same relative place, just follow the movements of the picture.

Im talking about the first one. I can get it quite close but it slowly drifts from the origin over time. Is the gyroscope not accurate enough to make this work?

@austinmccoy I already answered that question, and the code I linked to seems to be exactly what you want…