Esempio n. 1
0
void TrainDetector::Detect(){
  Options& opt = Options::GetInstance();

  GAB Gab;
  Gab.LoadModel(opt.model_dir);

  timeval start, end;
  float time = 0;

  string path = "1.jpg";
  Mat img = imread(path, CV_LOAD_IMAGE_GRAYSCALE);
  vector<Rect> rects;
  vector<float> scores;
  vector<int> index;
  gettimeofday(&start,NULL);
  index = Gab.DetectFace(img,rects,scores);
  gettimeofday(&end,NULL);
  float t = 1000 * (end.tv_sec-start.tv_sec)+ (end.tv_usec-start.tv_usec)/1000;
  printf("use time:%f\n",t);
  for(int i = 0;i < index.size(); i++){
    printf("%d %d %d %d %lf\n", rects[index[i]].x, rects[index[i]].y, rects[index[i]].width, rects[index[i]].height, scores[index[i]]);
   for (int i = 0; i < index.size(); i++) {
    if(scores[index[i]]>0)
      img = Gab.Draw(img, rects[index[i]]);
  }
  imwrite("2.jpg",img);
 }
}
Esempio n. 2
0
void TrainDetector::Live() {
  Options& opt = Options::GetInstance();

  VideoCapture cap(0);
  if (!cap.isOpened()) {
    printf("Can not open Camera, Please Check it!");
    return;
  }

  GAB Gab;
  Gab.LoadModel(opt.model_dir);

  while (true) {
    Mat frame;
    Mat gray;
    cap >> frame;

    cvtColor(frame, gray, CV_BGR2GRAY);
    vector<Rect> rects;
    vector<float> scores;
    vector<int> index;
    index = Gab.DetectFace(gray,rects,scores);

    for (int i = 0; i < index.size(); i++) {
      if(scores[index[i]]>100)
        frame = Gab.Draw(frame, rects[index[i]]);
    }
    cv::imshow("live", frame);
    int key = cv::waitKey(30);
    if (key == 27) {
      break;
    }
  }
}