Tag Archives: capture

saving hi-res, transparent png files from Processing – with a key press

self portraitAn effective method to save a frame with a different size than the size of the 3D sketch you’re drawing, is to use a PGraphics to make an enlarged copy of the scene; this image (click on it) has been created from the webcam feed wich is normally set to 320×240 pixels; when you create a PGraphics (Processing’s main graphics and rendering context) you must specify the width and height of the object itself; try to multiply the sketch’s original size by 10. You get images of 3200×2400 pixels or more. See hi-res anemone and hi-res webcam feed, they’re both transparent png files saved with this technique from two of my sketches.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
void keyPressed()
{
    switch(key) {
    case 's':
    noLoop();
    drawbg = false; // this is a boolean wich you can use to remove the background from the main draw() method; eg: if(drawbg) background(255)
    recorder = createGraphics(width*10, height*10, P3D); //  original app size is multiplied by 10
    recorder.beginDraw();
    cam.getState().apply(recorder); // useful for 3D scenes, sync the perspective - you need the peasyCam library, applies the latest CameraState
    draw();
    recorder.endDraw();
    recorder.save("test.png"); // save to disk (skecth folder)
    recorder = null;
    println("screenshot saved");
    loop();
    break;
    }
}

Computer Vision

cvision
Self-Portrait, March 2010. Fun with Processing and OpenCV.

Finalmente sono riuscito a far funzionare OpenCV (Processing implementation) sul mio PC. Questa immagine è il risultato della elaborazione con Processing e OpenCV del video feed proveniente dalla mia webcam: analizzando la luminosità brightness() dei singoli pixel di ogni frame, e sapendo che il risultato è per forza compreso nel range 0-255, è possibile usare tale valore per spostare sull’asse Z dei vertici che una volta uniti, formeranno delle linee. Maggior brighness maggior Z cioè più vicino.