Advertisement
Guest User

Untitled

a guest
Apr 18th, 2015
190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.12 KB | None | 0 0
  1. #include "face_detection.h"
  2.  
  3. using namespace cv;
  4.  
  5. // Function detectAndDisplay
  6. void detectAndDisplay(const std::string& file_name, cv::CascadeClassifier& face_cascade, cv::CascadeClassifier& mouth_cascade)
  7. {
  8. Mat frame = imread(file_name);
  9. std::vector<Rect> faces;
  10. Mat frame_gray;
  11. Mat crop;
  12. Mat res;
  13. Mat gray;
  14.  
  15. cvtColor(frame, frame_gray, COLOR_BGR2GRAY);
  16. equalizeHist(frame_gray, frame_gray);
  17.  
  18. // Detect faces
  19. face_cascade.detectMultiScale(frame_gray, faces, 1.1, 3, 0 | CASCADE_SCALE_IMAGE, Size(30, 30));
  20.  
  21. for(unsigned int i=0;i<faces.size();i++)
  22. {
  23. rectangle(frame,faces[i],Scalar(255,0,0),1,8,0);
  24. Mat face = frame(faces[i]);
  25. cvtColor(face,face,CV_BGR2GRAY);
  26. std::vector <Rect> mouthi;
  27. mouth_cascade.detectMultiScale(face, mouthi);
  28. for(unsigned int k=0;k<mouthi.size();k++)
  29. {
  30. Point pt1(mouthi[k].x+faces[i].x , mouthi[k].y+faces[i].y);
  31. Point pt2(pt1.x+mouthi[k].width, pt1.y+mouthi[k].height);
  32. rectangle(frame, pt1,pt2,Scalar(0,255,0),1,8,0);
  33. }
  34.  
  35. }
  36.  
  37. imshow("Frame", frame);
  38. waitKey(33);
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement