How to track an image moving?

edited September 24 in Kinect

Hello i'm new to processing and i'm working on a little game. But i got a problem:

I don't know how to tell the position (x,y) of my image "train" (in draw section) in order to make my background ("fond" ) move .

Thanks in advance.

import processing.sound.*;
import gab.opencv.*;
import processing.video.*;
import java.awt.*;

Capture video;
OpenCV opencv;
int score = 5;
int temps;//la valeur du chronomètre

boolean depart;//commencer le compte à rebours (au clic)

float cx, cy;
boolean alive = true;
float trainX;
float trainY;


Rectangle[] faces;
Capture cam;

float x;
float y;
float easing = 1;


PImage fond;
PImage train;
PImage smiley;

void setup() {
  size(1000, 1000);

 video = new Capture(this, 640, 480);
  opencv = new OpenCV(this, 640, 480);

  opencv.loadCascade(OpenCV.CASCADE_FRONTALFACE);  
  video.start();
  faces = opencv.detect();

  fond = loadImage("Map.bmp");
  train = loadImage("train.gif");  
  smiley = loadImage("train.gif");

}

void draw() {
  scale (0.5);
  image(fond, x, y);
  scale(0.5);
  opencv.loadImage(video);
    imageMode(CENTER);

  // afficher l'image de la webcam 

  Rectangle[] faces = opencv.detect();
  for (int i = 0; i < faces.length; i++) {
   float x = faces[i].x + faces[i].width / 2;
    float y = faces[i].y + faces[i].height / 2;
    image(smiley, x, y, 300, 300);

}

float targetX = xtrain;
  float dx = targetX - x;
  x += dx * easing;

  float targetY = ytrain;
  float dy = targetY - y;
  y += dy * easing;


  //texte compte à rebours

  fill(#585858);
  text("TEMPS RESTANT :", 1170, 30);
  fill(#FF0000);
  text(temps, 1310, 30);
}



void captureEvent(Capture c) {
  c.read();
}

//fonction compte à rebours  
void compte_rebours() {
  if (depart ==true) {
    if (temps == 0 ) {
      temps = 0;
    }
    else {
      temps = 60 - millis()/1000; //compte à rebours à partir de 60
    }
  }
}  

Answers

  • I can't run your code because I don't have your images, but I'm guessing you mean the image draw at line 60, the smiley?

    When you draw an image you have to peovide an x and an y. In your code you define these coordinates right before you draw the image. If you add a line: println(x+","+y); you will be able to see the what the coordinates are.

Sign In or Register to comment.