PageRenderTime 83ms CodeModel.GetById 25ms RepoModel.GetById 1ms app.codeStats 0ms

/face-src/Face/Face.cpp

https://gitlab.com/shinvdu/rcs-db
C++ | 69 lines | 46 code | 17 blank | 6 comment | 6 complexity | 5fb58c726126b28fa85a55d59d4af0d7 MD5 | raw file
  1. // Face.cpp : Defines the exported functions for the DLL application.
  2. //
  3. #include "stdafx.h"
  4. #include "Face.h"
  5. #include <iostream>
  6. #include <stdio.h>
  7. #include <opencv2/opencv.hpp>
  8. using namespace std;
  9. using namespace cv;
  10. int detect_and_draw_faces( IplImage* image, CvHaarClassifierCascade* cascade)
  11. {
  12. CvMemStorage* storage = cvCreateMemStorage(0);
  13. CvSeq* faces;
  14. /* use the fastest variant */
  15. //faces = cvHaarDetectObjects( image, cascade, storage, 1.2, 2, CV_HAAR_DO_CANNY_PRUNING );
  16. faces = cvHaarDetectObjects( image, cascade, storage, 1.1, 3, CV_HAAR_DO_CANNY_PRUNING );
  17. /* draw all the rectangles */
  18. for(int i = 0; i < faces->total; i++ ) {
  19. /* extract the rectangles only */
  20. CvRect face_rect = *(CvRect*)cvGetSeqElem( faces, i);
  21. cvRectangle( image, cvPoint(face_rect.x, face_rect.y),
  22. cvPoint((face_rect.x + face_rect.width), (face_rect.y + face_rect.height)),
  23. CV_RGB(255,0,0), 3 );
  24. }
  25. cvReleaseMemStorage( &storage );
  26. return faces->total;
  27. }
  28. FACE_API int detect_faces(char* input_file, char *xml, int display)
  29. {
  30. CvHaarClassifierCascade *classifier = NULL;
  31. IplImage* image = NULL;
  32. int faces;
  33. classifier = (CvHaarClassifierCascade*)cvLoad(xml, 0, 0, 0);
  34. if (!CV_IS_HAAR_CLASSIFIER(classifier)) {
  35. printf("Cannot load haar classifier file: %s\n", xml);
  36. return -1;
  37. }
  38. image = cvLoadImage( input_file );
  39. if (image == NULL) {
  40. printf("Cannot load image: %s\n", input_file);
  41. return -2;
  42. }
  43. faces = detect_and_draw_faces( image, classifier);
  44. if (display == 1) {
  45. cvNamedWindow( "test", 0 );
  46. cvShowImage( "test", image );
  47. cvWaitKey(0);
  48. }
  49. cvReleaseHaarClassifierCascade( &classifier );
  50. cvReleaseImage( &image );
  51. return faces;
  52. }