LiveCam Contour Line Map

Travail de visualisation 3D en temps réel réalisé avec Processing et les librairies BlobDetection et PeasyCam.
Le sketch dessine les contours de Blob depuis un flux vidéo direct, la profondeur est déterminée par le niveau de gris (le plus clair au premier plan).
Real time 3D visualization work done with Processing and BlobDetection and PeasyCam libraries.
The sketch draws Blob’s contours from greyscale to depth (brightest on top) with a live cam stream.

Basé sur le code de Cedric Kiefer.
Based upon Cedric Kiefer’s Contour Line maps from heightmap code – Thanks for his great work.
https://forum.processing.org/topic/creating-contour-maps

Réalisé en collaboration avec Johann Aussage.
Made in collaboration with Johann Aussage.
http://www.9ko.fr/
http://www.pentagon.fr/

CODE:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import processing.opengl.*;
import processing.video.*;
import blobDetection.*;
import peasy.*;
 
PeasyCam cam;
Capture video;
PImage img;
boolean newFrame=false;
boolean rec=false;
 
float levels = 20; // nombre de niveaux de gris
float factor = 1; // coeff d'echelle
float elevation = 20; // elevation entre chaque level du graphique 3D
float colorStart =  0; // HSB Mode (0-360)
float colorRange =  200; // color range / peut etre negatif
 
// Array of BlobDetection Instances
BlobDetection[] theBlobDetection = new BlobDetection[int(levels)];
 
void setup() {
	size(800, 600, OPENGL);
	colorMode(HSB,360, 120, 120);
	video = new Capture(this, 40*4, 30*4, 50);
	img = new PImage(80,60); 
	cam = new PeasyCam(this, 90);
 
	//Computing Blobs with different thresholds 
	for (int i=0 ; i<levels ; i++) {
		theBlobDetection[i] = new BlobDetection(img.width, img.height);
		theBlobDetection[i].setThreshold(i/levels);
	}
}
 
public void captureEvent(Capture c) {
	c.read();
	newFrame=true;
}
 
void draw() {
	for (int i=0 ; i<levels ; i++) {
		theBlobDetection[i].computeBlobs(img.pixels);
	}
 
	background(0);
 
	if (newFrame) {
		newFrame=false;
		img.copy(video, 0, 0, video.width, video.height, 
		0, 0, img.width, img.height);
 
		// compense le centrage de la camera
		translate(-img.width*factor/2,-img.height*factor/2);
		for (int i=0 ; i<levels ; i++) {
			translate(0,0,elevation/levels);	
			drawContours(i);
		}
	}
}
 
void drawContours(int i) {
	Blob b;
	EdgeVertex eA,eB;
 
	for (int n=0 ; n<theBlobDetection[i].getBlobNb() ; n++) {
		b=theBlobDetection[i].getBlob(n);
		if (b!=null) {
			strokeWeight(.5);
			stroke((i/levels*colorRange)+colorStart,100,100);      // coloring the contours
			for (int m=0;m<b.getEdgeNb();m++) {
				eA = b.getEdgeVertexA(m);
				eB = b.getEdgeVertexB(m);
				if (eA !=null && eB !=null) {
					line(eA.x*img.width*factor, eA.y*img.height*factor,
					eB.x*img.width*factor, eB.y*img.height*factor);
				}
			}
		}
	}
}