メニュー 閉じる

103. ProcessingでNyARToolkitを使ってなんちゃってAR04

2種類のマーカーを識別してみる。

http://www.velvet-number.com/p5_test/test071/20190208_mov.mov

import processing.video.*;
import jp.nyatla.nyar4psg.*;

Capture cam;

MultiMarker mm01;
MultiMarker mm02;

ArrayList<Particles> particles = new ArrayList<Particles> ();

void setup () {

	size (480, 270, P3D);
	colorMode (HSB, 100);

	String[] cameras = Capture.list ();

	printArray (cameras);

	cam = new Capture (this, cameras[21]);
	cam.start ();

	mm01 = new MultiMarker (this, width, height, "camera_para.dat", NyAR4PsgConfig.CONFIG_PSG);
	mm02 = new MultiMarker (this, width, height, "camera_para.dat", NyAR4PsgConfig.CONFIG_PSG);
	mm01.addNyIdMarker (1, 80);
	mm02.addNyIdMarker (2, 80);

}

void draw () {

	if (cam.available () != true) {
		return;
	}

	cam.read ();

	mm01.detect (cam);
	mm01.drawBackground (cam);

	mm02.detect (cam);
	mm02.drawBackground (cam);

	if (!mm01.isExist (0)) {
		return;
	}

	if (!mm02.isExist (0)) {
		return;
	}

	particles.add (new Particles ());

	for (int i = 0; i < particles.size (); i++) {
		mm01.beginTransform (0);
		particles.get (i).update ();
		particles.get (i).render (0);
		mm01.endTransform ();
	}

	for (int i = 0; i < particles.size (); i++) {
		mm02.beginTransform (0);
		particles.get (i).update ();
		particles.get (i).render (1);
		mm02.endTransform ();
	}

	if (particles.size () > 100) {
		particles.remove (0);
	}

	//saveFrame ();

}

class Particles {

	float posx;
	float posy;
	float posz;
	float vz;
	float bs;

	float h_value;

	Particles () {

		posx = random (-40.0, 40.0);
		posy = random (-40.0, 40.0);
		posz = 0.0;

		vz = random (0.1, 10.0);

		bs = random (1.0, 20.0);

		h_value = random (100.0);

	}

	void update () {

		posz += vz;

	}

	void render (int id) {
	
		noStroke ();
		fill (h_value, 100, 100, 50);
		translate (posx, posy, posz);
		if (id == 0) {
			box (bs);
		} else {
			sphere (bs);
		}
		

	}

}

Posted in processing