advance only when a new camera capture frame exists

@AxiomCrux Here’s something I threw together. The top image is a live image. Tap the screen once to capture the first image. Tap the screen again to capture the second image. The difference image shows the pixels of image 1 that don’t match image 2 by the amount of the slider diff value. The smaller the diff value, the closer the r,g,b,a values have to be between the 2 images. Slide the diff parameter and watch the differences change. Maybe you can use something from this code for what you’re trying to do.

supportedOrientations(PORTRAIT_ANY)

function setup()
    parameter.watch("1/DeltaTime//1")
    parameter.number("diff",0,1,.2)
    cameraSource(CAMERA_BACK)
    size=200
    img1=image(size,size)
    img2=image(size,size)
    getImage1=true
    getImage2=false
    print("The smaller the diff value, the more the images have to be the same.")
end

function draw()
    background(44, 44, 117, 255)     
    fill(255)
    text("Tap screen to capture image1, then again for image 2",WIDTH/2,HEIGHT-50)
    text("Current image",400,750)
    text("Image 1",400,540)
    text("Image 2",400,330)
    text("Difference (image 1)",400,120)
    collectgarbage()
    if img1~=nil then
        sprite(img1,200,540)
    end
    if showDiff then
        sprite(img2,200,330)
        m.shader=shader(DS.vs, DS.fs)
        m.shader.texture2=img2
        m.shader.dd=diff
        m:draw()
    end    
    i=image(CAMERA)
    if i~=nil then
        sprite(i:copy(WIDTH//2,HEIGHT//2,size,size),200,750)
    end
end

function getImage()
    if getImage1 then
        i=image(CAMERA)
        if i~=nil then
            img1=i:copy(WIDTH//2,HEIGHT//2,size,size)
            m=mesh()
            m:addRect(200,120,size,size)
            m.texture=img1
            getImage1=false
            getImage2=true
        end        
    elseif getImage2 then
        i=image(CAMERA)
        if i~=nil then
            img2=i:copy(WIDTH//2,HEIGHT//2,size,size)
            getImage2=false
            showDiff=true
        end        
    end    
end

function touched(t)
    if t.state==BEGAN then
        getImage()
    end
end

DS={   
    vs= [[  uniform mat4 modelViewProjection;
            attribute vec4 position;
            attribute vec2 texCoord;
            varying highp vec2 vTexCoord;
            uniform float dd;
            void main()
            {   vTexCoord = texCoord;
                gl_Position = modelViewProjection * position;
            }    
        ]],
    fs= [[  precision highp float;
            uniform lowp sampler2D texture;
            uniform lowp sampler2D texture2;
            varying highp vec2 vTexCoord;
            uniform float dd;
            void main()
            {   lowp vec4 col1 = texture2D( texture,  vTexCoord );
                lowp vec4 col2 = texture2D( texture2, vTexCoord );
                if (abs(col2.r-col1.r)<dd &&  abs(col2.g-col1.g)<dd && 
                        abs(col2.b-col1.b)<dd)
                    discard; 
                else 
                    gl_FragColor = col1;
            }
        ]]
}