Ok, I don't know why, but I can't find a solution for my problem. Can someone help me here? Maybe it's so simple, but I don't get it.
I'm making a Videotracking with the JMyron example "Myron_CameraAsMouse" and I like it, but what I want to change, is that circle don't stay on same Position, when the movement is over. It should move to the point 0,0. But that is not my real problem.
My Problem is that this shouldend happen immediatelly. I tried to make something like a countdown for this thing. It means, when the movement stop, it should start a countdown for e.g. 3 seconds and than the circle should move to the point 0,0. All I made doesn't works. So I only post the JMyron Version with the 0,0 movement.
import JMyron.*;
JMyron m;//a camera object
//variables to maintain the floating green circle
float objx = 160;
float objy = 120;
float objdestx = 160;
float objdesty = 120;
void setup() {
size(320, 240);
m = new JMyron();//make a new instance of the object
m.start(width, height);//start a capture at 320x240
m.trackColor(255, 255, 255, 256*3-100);//track white
m.update();
m.adaptivity(10);
m.adapt();// immediately take a snapshot of the background for differencing
println("Myron " + m.version());
rectMode(CENTER);
noStroke();
}
void draw() {
m.update();//update the camera view
drawCamera();
int[][] centers = m.globCenters();//get the center points
//draw all the dots while calculating the average.
float avX=0;
float avY=0;
for (int i=0;i<centers.length;i++) {
fill(80);
rect(centers[i][0], centers[i][1], 5, 5);
avX += centers[i][0];
avY += centers[i][1];
}
if (centers.length-1>0) {
avX/=centers.length-1;
avY/=centers.length-1;
}
////////////THIS IS WHAT I ADD!!!!!!
if (centers.length == 0) {
objdestx = 0;
objdesty = 0;
}
//draw the average of all the points in red.
fill(255, 0, 0);
rect(avX, avY, 5, 5);
//update the location of the thing on the screen.
if (!(avX==0&&avY==0)&¢ers.length>0) {
objdestx = avX;
objdesty = avY;
}
objx += (objdestx-objx)/10.0f;
objy += (objdesty-objy)/10.0f;
fill(30, 100, 0);
ellipseMode(CENTER);
ellipse(objx, objy, 30, 30);
}
void drawCamera() {
int[] img = m.differenceImage(); //get the normal image of the camera
loadPixels();
for (int i=0;i<width*height;i++) { //loop through all the pixels
pixels[i] = img[i]; //draw each pixel to the screen
}
updatePixels();
}
void mousePressed() {
m.settings();//click the window to get the settings
I was trying to make a tracking with a IR cam, but the problem is that processing doesn't recognize my cam.
I'm working with a Asus Eee PC 1000H and I've tested this little script with three cam's. First with the internal cam from my Netbook. Secondly with a Logitech C310 and at last with the IDS uEye UI-1555LE-C-GL. Which is my IR cam.
My result was that the first and second cam works, but the third not. I have all the drivers and progs installed that I could find for this cam, but it only works with the own programs. Of course I've Quick Time Player and VDig installed.
I try this script also in to different processing Versions. First the 1.5.1 and secondly the 2.0b7. In the first Version nothing works and in the second only the first and the second cam.
This is the script that I found here in the processing Website, which I've used for trying:
import processing.video.*;
Capture cam;
void setup() {
size(640, 480);
String[] cameras = Capture.list();
if (cameras.length == 0) {
println("There are no cameras available for capture.");
exit();
} else {
println("Available cameras:");
for (int i = 0; i < cameras.length; i++) {
println(cameras[i]);
}
// The camera can be initialized directly using an
// element from the array returned by list():
cam = new Capture(this, cameras[0]);
cam.start();
}
}
void draw() {
if (cam.available() == true) {
cam.read();
}
image(cam, 0, 0);
// The following does the same, and is faster when just drawing the image
// without any additional resizing, transformations, or tint.
//set(0, 0, cam);
}
I don't know if this example doesn't work with IR cams.
I was also trying to solve it with the other processing Video examples and also with OpenCV, but it doesn't works at all. Only with this example.
Maybe you have an idea for my solution. Thanks for your time.
I'm new here and I make this this little Script for the university:
int anzahl = 50;
Innen q;
Kreis[] k;
Kreis[] k2;
Kreis[] k3;
void setup() {
frameRate(20);
size(1000, 500);
q = new Innen();
k = new Kreis[anzahl];
k2 = new Kreis[anzahl];
k3 = new Kreis[anzahl];
for (int i=0;i<anzahl;i++) {
k[i] = new Kreis();
k2[i] = new Kreis();
k3[i] = new Kreis();
}
}
void draw() {
background(0);
q.display();
if ((mouseX>q.rx)&&(mouseX<q.rx+q.rb)) {
if ((mouseY>q.ry)&&(mouseY<q.ry+q.rh)) {
for (int i=0;i<anzahl;i++) {
k[i].verfolgen(0.01, 7);
k2[i].verfolgen(0.005, 57);
k3[i].verfolgen(0.00125, 157);
}
}
else {
for (int i=0;i<anzahl;i++) {
k[i].display();
k2[i].display();
k3[i].display();
}
}
}
else {
for (int i=0;i<anzahl;i++) {
k[i].display();
k2[i].display();
k3[i].display();
}
}
}
class Innen {
int rx = (width/4);
int ry = (height/4);
int rb = (width/2);
int rh = (height/2);
void display() {
rect(rx, ry, rb, rh);
}
}
class Kreis {
float ex = random(q.rx, q.rx+q.rb);
float ey = random(q.ry, q.ry+q.rh);
int d = 20; //Durchmesser
float a = 25; //Abstand
//Maus-Verfolgung
void verfolgen(float easing, int z) {
noCursor();
float targetX = mouseX;
float targetY = mouseY;
if (dist(ex, ey, mouseX, mouseY)>45) {
ex += (targetX - ex) * easing;
ey += (targetY - ey) * easing;
}
else {
ex -= (targetX - ex) * easing * z;
ey -= (targetY - ey) * easing * z;
}
smooth();
stroke(255);
noFill();
ellipse(ex, ey, d, d);
stroke(100, 200, 200);
ellipse(mouseX, mouseY, d, d);
}
void display() {
noCursor();
smooth();
stroke(255);
noFill();
ellipse(ex, ey, d, d);
stroke(100, 200, 200);
ellipse(mouseX, mouseY, d, d);
float ex = random(q.rx, q.rx+q.rb);
float ey = random(q.ry, q.ry+q.rh);
}
}
I'm more or less fine with this code, but what I also want to do, is that the circles k move, if the mouse circle is outside from the rectangle, from their last position to another random position..
I was trying this thing with the random position with another Script and I really found a kind of solution, but only for ONE circle and not for more..
This is wath I try:
Kreis[] k;
int anzahl = 2;
void setup() {
size(1000, 500);
k = new Kreis[anzahl];
for (int i=0; i<anzahl; i++) {
k[i] = new Kreis();
}
}
void draw() {
background(0);
for (int i=0; i<anzahl; i++) {
k[i].display();
k[i].bewegen();
}
}
class Kreis {
float x;
float y;
float angle = 0.0; // Direction of motion
float speed = 1.5; // Speed of motion
int d = 10;
Kreis() {
x = 100; // X-coordinate
y = 50; // Y-coordinate
stroke(255);
//random(121);
}
void bewegen() {
angle += random(-0.2, 0.2);
translate(x, y);
rotate(angle);
if ((x>0) && (x<width-d)) {
if ((y>0) && (x<height-d)) {
pushMatrix();
x += cos(angle);// * speed; // Update x-coordinate
y += sin(angle);// * speed; // Update y-coordinate
popMatrix();
}
else {
angle = PI;
speed = 2.0;
}
}
else {
angle = PI;
speed = 2.0;
}
}
void display() {
ellipse(0, -10, d, d);
}
}
know.. if you put the variable "anzahl = 10".. then you will get completly another thing.. and I dont know how to match this problem..
Thx a lot for reading my Quetion.. I hope someone can help me..