Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

I have addedd template<typename T> void graphArray into my code below , where double data[15784];

is saving double values , 15784 is the number of frames in the video file . The code compiles witout error , when

I run , it shows the plot window but it is empty and became unresponsive after a while .

 #include <dlib/opencv.h>
 #include <opencv2/highgui/highgui.hpp>
 #include <dlib/image_processing/frontal_face_detector.h>
 #include <dlib/image_processing/render_face_detections.h>
 #include <dlib/image_processing.h>
 #include <dlib/gui_widgets.h>

using namespace dlib;
using namespace std;
using namespace cv;


template<typename T> void graphArray(const char *title,T* data, int n, int height,bool cont)
 {
    Mat img(height+1,n,CV_8UC3);
    img.setTo(Scalar(255,255,255));
    T max=0;
     for(int x=0;x<n;x++)
          if(data[x]>max)max=data[x];
           if(!cont){
            for(int x=0;x<n;x++)
            img.at<Vec3b>((int)(height-data[x]*height/max),x)=Vec3b(255,0,0);
      } else 
        {
     int si,si1,inc;
      for(int x=0;x<n-1;x++){
     si=data[x]*height/max;si1=data[x+1]*height/max;
     if(si1>si)inc=1;else inc=-1;
     for(int v=si;v!=si1+inc;v+=inc)
         img.at<Vec3b>(height-v,x)=Vec3b(255,0,0);
    }
 }
     namedWindow(title,WINDOW_FREERATIO);
     imshow(title,img);
    }



 int main()
     {
      try
     { 
    cv::VideoCapture cap("1.avi");
    if (!cap.isOpened())
    {
        cerr << "Unable to connect to camera" << endl;
        return 1;
    }

    image_window win;

    frontal_face_detector detector = get_frontal_face_detector();
    shape_predictor pose_model;
    deserialize("shape_predictor_68_face_landmarks.dat") >> pose_model;

   double data[15784];
    while(!win.is_closed())
    {
        // Grab a frame
        cv::Mat temp;
        cap >> temp;
    if ( temp.empty())
 {
    // reach to the end of the video file
    break;
}

        cv_image<bgr_pixel> cimg(temp);

        std::vector<rectangle> faces = detector(cimg);
        std::vector<full_object_detection> shapes;

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


       full_object_detection shape = pose_model(cimg, faces[i]);


        double P37_41_x = shape.part(37).x() - shape.part(41).x();
        double P37_41_y=  shape.part(37).y() -shape.part(41).y() ;

        double output=sqrt((P37_41_x * P37_41_x) + (P37_41_y * P37_41_y));


       data[i]=output;

      graphArray<double>("Plot",data,10,255,true);

   shapes.push_back(pose_model(cimg, faces[i]));
   const full_object_detection& d = shapes[0];

              }

        win.clear_overlay();
        win.set_image(cimg);
        win.add_overlay(render_face_detections(shapes));

      }
 }
       catch(serialization_error& e)
      {
          cout << "You need dlib's default face landmarking model file to run this example." << endl;
          cout << "You can get it from the following URL: " << endl;
          cout << "   http://dlib.net/files/shape_predictor_68_face_landmarks.dat.bz2" << endl;
          cout << endl << e.what() << endl;
         }
          catch(exception& e)
        {
            cout << e.what() << endl;
           }
       }