Ask Your Question

Revision history [back]

Unable to track faces. How to update trackers ???

I am doing a multiple faces detection & tracking. But the trackers are not updating properly.

The code runs without errors when compiling. During runtime I get the below message (not error tho)

''Trackers are initialized correctly.

unable to track"

Here is the code:

// Detect faces std::vector<rect> faces; Rect2d face_rect2d; face_cascade.detectMultiScale( image, faces, 1.2, 2, 0|CV_HAAR_SCALE_IMAGE, Size(min_face_size, min_face_size),Size(max_face_size, max_face_size) );

  for(unsigned int i = 0; i < faces.size(); ++i)
  {        


    face_rect2d = faces[i];

    rectangle(image,face_rect2d, Scalar( 255, 255, 0 ), 1, 4 ); // Draw the detections


    Ptr<Tracker> tracker = Tracker::create( "MEDIANFLOW" ); // Create tracker

    if (tracker.empty())
{
    std::cerr << "***Error in the instantiation of the tracker...***\n";
    return -1;
    }



      // Check if they are initialized
     if (!tracker->init(image, face_rect2d))
     {
    std::cerr << "***Could not initialize tracker...***\n";
    return -1;
 }
 else
 {

        std::cout << "Trackers are initialized correctly." << std::endl;
     }



     // Check if they are updated

     if (!(tracker->update(image, face_rect2d))) {
                printf("unable to track\n"); 
              }



     cv::rectangle(image,face_rect2d, cv::Scalar(255, 0, 255), 2, 1);

  }

Unable to track faces. How to update trackers ???

I am doing a multiple faces detection & tracking. But the trackers are not updating properly.

The code runs without errors when compiling. During runtime I get the below message (not error tho)

''Trackers are initialized correctly.

unable to track"

Here is the code:

 // Detect faces
 std::vector<rect> std::vector<Rect> faces;
  Rect2d face_rect2d;
  face_cascade.detectMultiScale( image, faces, 1.2, 2, 0|CV_HAAR_SCALE_IMAGE, Size(min_face_size, min_face_size),Size(max_face_size, max_face_size) );

);
 for(unsigned int i = 0; i < faces.size(); ++i)
{
face_rect2d = faces[i];
rectangle(image,face_rect2d, Scalar( 255, 255, 0 ), 1, 4 ); // Draw the detections
Ptr<Tracker> tracker = Tracker::create( "MEDIANFLOW" ); // Create tracker
if (tracker.empty())
{
std::cerr << "***Error in the instantiation of the tracker...***\n";
return -1;
}
// Check if they are initialized
if (!tracker->init(image, face_rect2d))
{
std::cerr << "***Could not initialize tracker...***\n";
return -1;
}
else
{
std::cout << "Trackers are initialized correctly." << std::endl;
}
// Check if they are updated
if (!(tracker->update(image, face_rect2d))) {
printf("unable to track\n");
}
cv::rectangle(image,face_rect2d, cv::Scalar(255, 0, 255), 2, 1);
}