We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpVideo Capture,  Movie Playback,  Vision Libraries › sure that is something simple but :: Opencv
Page Index Toggle Pages: 1
sure that is something simple but :: Opencv (Read 1854 times)
sure that is something simple but :: Opencv
Apr 16th, 2009, 3:39pm
 
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();
}
Re: sure that is something simple but :: Opencv
Reply #1 - Apr 16th, 2009, 8:11pm
 
This can help a little, I do not believe that it is the solution, but is something that is required.


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

void captureEvent(Capture myCapture2) {
 myCapture2.read();
}
Re: sure that is something simple but :: Opencv
Reply #2 - Apr 17th, 2009, 10:14am
 
I made a step forward but now I'm facing other problems
1) everytime (even with the old code) the logitech webcam starts I get this messege :

7:59:56.752 java[1479:1a023] *** _NSAutoreleaseNoPool(): Object 0x23e2cbe0 of class NSThread autoreleased with no pool in place - just leaking

2)if I try to display a opencv image instead of a rectangle the program shut down with this messege:

penCV ERROR: Unknown error code -25 ()
     in function cvSetImageROI, ../../../cxcore/src/cxarray.cpp(3469)
Terminating the application...
     called from cvUnregisterType, ../../../cxcore/src/cxpersistence.cpp(4933)
Terminating the application...
     called from cvUnregisterType, ../../../cxcore/src/cxpersistence.cpp(4933)
etc etc


this is the code now. thanks a lot.

Code:
import processing.video.*;  
import hypermedia.video.*;

OpenCV ocv1;
OpenCV ocv2;
OpenCV ocv3;
OpenCV ocv4;
Capture myCapture;  
Capture myCapture2;
Capture myCapture3;
String[] captureDevices;  
OpenCV viso1;
OpenCV viso2;
int midX;



void setup()  
{  
size(640, 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]);  //Logitech
myCapture2 = new Capture(this, 320, height, devices[3]); //ISight

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() && myCapture2.available()) {  
  myCapture.read();  
  myCapture2.read();
  ocv1.copy(myCapture);  // copy to OpenCV buffer
  image(ocv1.image(),0,0); //display Logitech to screen
  Rectangle[] faces1 = ocv1.detect();
 
  for( int i=0; i<faces1.length; i++ ) {
    ocv2.copy(myCapture2);  // copy to OpenCV buffer
    image(ocv2.image(),320,0); // display Isight to screen
    Rectangle[] faces2 = ocv2.detect();
        for( int u=0; u<faces2.length; u++ ) {
         
  // in this Iteration I have access to both "i" and "u" variables wich I need to take the origin xy and move it to the destination
         
            rect(faces2[u].x +320, faces2[u].y, faces2[u].width, faces2[u].height); // TEST with a rectangle and it works
           
  ///            This is my code to display a face instead of a blank rectangle
  ///    ocv3.copy(myCapture ,faces2[u].x +320, faces2[u].y, faces2[u].width, faces2[u].height, faces1[i].x, faces1[i].y, faces1[i].width, faces1[i].height);
  ///    image( ocv3.image(), 0, 0 );
  ///
            rect(faces1[i].x, faces1[i].y, faces1[i].width, faces1[i].height); // The other rect
             
     
         }
        }
     }
}


public void stop() {
  ocv1.stop();
  ocv2.stop();
  ocv3.stop();
  ocv4.stop();
 
  super.stop();
}
Re: sure that is something simple but :: Opencv
Reply #3 - Apr 18th, 2009, 7:01pm
 
I found this in the reference of the OpenCV

cascade()
While you may use your own cascade description files, this library links as well to a standard family of detection cascades (CASCADE_FRONTALFACE_DEFAULT, CASCADE_FULLBODY, …). These are installed automatically in the Windows installer and most Linux packages. For those using Macs, we have included these files in our opencv-framework-*.*.dmg installer. If you use a different Mac installer, you will have to import these files on your own.


As I saw that you use MAC by the type of error .cpp and iSight, can help a little, also is necessary to review if it is using the BUFFER or the SOURCE.

Page Index Toggle Pages: 1