hello, this is the code (made almost with other code found on the forum) i want to have a face of someone in someone else body and viceversa. I'm able to get the face from the first cam but not from the second one, using face detection in opencv. Hope you can help me, thanks a lot.
Code:import processing.video.*;
import hypermedia.video.*;
OpenCV ocv1;
OpenCV ocv2;
OpenCV ocv3;
OpenCV ocv4;
OpenCV ocv5;
Capture myCapture;
Capture myCapture2;
OpenCV myCapture3;
String[] captureDevices;
int threshold = 80;
int midX;
void setup()
{
size(800, 240);
midX = width/2; // place to start drawing image from second cam
String[] devices = Capture.list();
println(devices);
myCapture = new Capture(this, 320, height, devices[2]);
myCapture2 = new Capture(this, 320, height, devices[3]);
ocv1 = new OpenCV(this);
ocv1.allocate(320,height);
ocv2 = new OpenCV(this);
ocv2.allocate(320,height);
ocv1.cascade( OpenCV.CASCADE_FRONTALFACE_ALT );
ocv2.cascade( OpenCV.CASCADE_FRONTALFACE_ALT );
//creo lo spazio in memoria per i riqadri viso
ocv3 = new OpenCV(this);
ocv3.allocate(320,height);
ocv4 = new OpenCV(this);
ocv4.allocate(320,height);
}
void draw() {
if (myCapture.available()) {
myCapture.read();
ocv1.copy(myCapture); // copy to OpenCV buffer
image(ocv1.image(),0,0); // display to screen
Rectangle[] faces1 = ocv1.detect();// detect anything ressembling a FRONTALFACE
for( int i=0; i<faces1.length; i++ ) { // draw rect around detected face area(s)
ocv3.copy(myCapture ,faces1[i].x, faces1[i].y, faces1[i].width, faces1[i].height,faces1[i].x +100, faces1[i].y, faces1[i].width, faces1[i].height);
image( ocv3.image(), 0, 0 );
}
}
if (myCapture2.available()) {
myCapture2.read();
ocv2.copy(myCapture2);
image(ocv2.image(),320,0); // draw second image on the right half of the window
Rectangle[] faces2 = ocv2.detect();// detect anything ressembling a FRONTALFACE
for( int i=0; i<faces2.length; i++ ) {
// image(ocv3.image(), faces2[i].x + midX, faces2[i].y, faces2[i].width, faces2[i].height );
ocv4.copy( myCapture ,faces2[i].x , faces2[i].y, faces2[i].width, faces2[i].height,faces2[i].x, faces2[i].y, faces2[i].width, faces2[i].height);
image( ocv4.image(), 320, 0 );
}
}
}
public void stop() {
ocv1.stop();
ocv2.stop();
ocv3.stop();
ocv4.stop();
super.stop();
}