We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hello :-) I am not good at English, so please understand for poor explanation about my question.
Could you help me to figure it out?
PImage img;
import gab.opencv.*;
import processing.video.*;
import java.awt.*;
int incMov=0; // i is the increment of the array
Capture video;
OpenCV opencv;
Movie[] myMovies = new Movie[3];
void setup() {
size(640, 480);
video = new Capture(this, 640/2, 480/2);
opencv = new OpenCV(this, 640/2, 480/2);
opencv.loadCascade(OpenCV.CASCADE_EYE);
video.start();
//movie
//for (int i=0; i<myMovies.length; i++) {
myMovies[0] = new Movie(this, "eye2_A.mov" );
myMovies[0].loop();
myMovies[1] = new Movie(this, "eye1_A.mov");
myMovies[1].loop();
myMovies[2] = new Movie(this, "eye1_RGB.mov");
myMovies[2].loop();
//myMovies[0] = new Movie(this, );
//myMovies[0] = new Movie(this, );
}
void mousePressed(){
video.stop();
}
void movieEvent(Movie m){
m.read();
}
void draw() {
scale(2);
opencv.loadImage(video);
image(video, 0, 0 );
//opencv.loadImage(movie);
//rect
noFill();
stroke(0, 255, 0);
strokeWeight(3);
//detect:
Rectangle[] faces = opencv.detect();
println("lenght" + faces.length);
if (faces.length > 0){
incMov = incMov + 1;
}
// use an if to loop back
for (int i = 0; i < faces.length; i++) {
image(myMovies[incMov], faces[i].x, faces[i].y, faces[i].width, faces[i].height);
println("number of movie:" + incMov);
}
}
void captureEvent(Capture c) {
c.read();
}
Answers
Format your code. Edit your post, select your code and press ctrl+o. Please make sure there is an empty line above and below your code. More info at:
https://forum.processing.org/two/discussion/15473/readme-how-to-format-code-and-text#latest
Kf
I have some comments.
I suggest changing the name of video to videoCam or just cam, short for camera. Your code will be more clear, specially because you are using movies (aka. recorded video).
noFill(); stroke(0, 255, 0); strokeWeight(3); should be called in setup() unless you are modifying them continuously in real time. Then you can also call them continuosly in draw().
You need to revise the following code:
The previous code is run in draw() so I can see your incMov would be larger than 3. Then myMovies[incMov] will through a null point exception. My suggested correction:
Last but not least, I am not sure what your code does unless you provide the movies.
Kf