check if Rects intersect [closed]
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);
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.
// 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));
continued below
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));