check if Rects intersect [closed]

asked 2016-11-05 14:13:08 -0600

atv gravatar image

hi all, I wanted to implement a simple check to see if the face in the new frame is the same as in the previous frame. I cobbled up something like below:

But i don't think its working. Is it because when i make a copy of the faces vector, it is not a deep copy?

   haar_cascade.detectMultiScale(gray, faces,1.2,4,0|CASCADE_SCALE_IMAGE, Size(min_face_size,min_face_size),Size(max_face_size,max_face_size));
    // At this point you have the position of the faces in
    // faces. Now we'll get the faces, make a prediction and
    // annotate it in the video. Cool or what?

    vector< Rect_<int> > track=faces; // Keep the old faces in a separate vector

    Mat face_resized;

    for(int i = 0; i < faces.size(); i++) {
    Rect a=track[i];
    Rect b=faces[i];
    bool intersects=((a&b).area()>0);
    if(intersects) cout << "same window" << endl;
    else cout << "different window" << endl;
        // Process face by face:
        Rect face_i = faces[i];
        // Crop the face from the image. So simple with OpenCV C++:

        Mat face = gray(face_i);
edit retag flag offensive reopen merge delete

Closed for the following reason question is not relevant or outdated by sturkmen
close date 2020-12-05 16:03:10.521693

Comments

I came up with something like this, to make a clone() and run detectMultiscale on it again. But it still isn't working as it should. I'm doing a detectmultiscale before and after, so i get a copy of the Rect vector. But it never seems to say that j < facesold.size(), and hence never goes into the j loop. When i add another face to the picture it does work, it seems there is some sort of fencepost error there.

atv gravatar imageatv ( 2016-11-06 05:39:02 -0600 )edit

// Find the faces in the frame: vector< Rect_<int> > faces; vector< Rect_<int> > facesold; Mat tracking=gray.clone(); haar_cascade.detectMultiScale(gray, faces,1.2,4,0|CASCADE_SCALE_IMAGE, Size(min_face_size,min_face_size),Size(max_face_size,max_face_size));

    Mat face_resized;
     for(int i = 0; i < faces.size(); i++) {
    cout << "Going into i loop" << endl;
    for(int j=0;j<facesold.size();j++) {
    cout << "Going into j loop" << endl;
    Rect a=faces[j];
    Rect b=facesold[j];
    //cout << "track face:" << i << a << b << endl;
    bool intersects=((a&b).area()>0);
    if(intersects) cout << "Tracking " << j <<  endl;
    else cout << "Lost tracking for" << j << endl;
    }

continued below

atv gravatar imageatv ( 2016-11-06 05:39:08 -0600 )edit

haar_cascade.detectMultiScale(tracking, facesold,1.2,4,0|CASCADE_SCALE_IMAGE, Size(min_face_size,min_face_size),Size(max_face_size,max_face_size));

atv gravatar imageatv ( 2016-11-06 05:42:41 -0600 )edit
1
  1. Please, don't post updates on the comments section. If you have new code or progress, update your original question and add it there.
  2. Provide a minimal complete sample. Right now, your lines make no sense as there aren't within any frame-loop. Who knows what you're really doing...
LorenaGdL gravatar imageLorenaGdL ( 2016-11-06 11:03:20 -0600 )edit