here is my code for mouth detection.
include "stdio.h"
include <iostream>
include <opencv2 highgui="" highgui.hpp="">
include <opencv2 objdetect="" objdetect.hpp="">
include <opencv2 imgproc="" imgproc.hpp="">
int main(int argc, const char** argv) { VideoCapture cap(0); CascadeClassifier face, mouth;
face.load("/home/adarsh/opencv/opencv-4.9/data/haarcascades/haarcascade_frontalface_default.xml");
mouth.load("/home/adarsh/opencv/opencv-2.4.9/data/haarcascades/haarcascade_mcs_mouth.xml");
Mat frame, grayframe, testframe;
while (1) { cap.read(frame); if (!cap.read(frame)) { printf("an error while taking the frame from cap"); } vector<rect> faces; cvtColor(frame, grayframe, CV_BGR2GRAY); equalizeHist(grayframe, testframe); face.detectMultiScale(testframe, faces, 1.1, 3, CV_HAAR_SCALE_IMAGE, Size(30, 30)); for (int i = 0; i < faces.size(); i++) { rectangle(frame, faces[i], Scalar(255, 0, 0), 1, 8, 0); Mat face = frame(faces[i]); cvtColor(face, face, CV_BGR2GRAY); vector<rect> mouthi; mouth.detectMultiScale(face, mouthi); for (int k = 0; k < mouthi.size(); k++) { Point pt1(mouthi[0].x + faces[i].x, mouthi[0].y + faces[i].y); Point pt2(pt1.x + mouthi[0].width, pt1.y + mouthi[0].height); rectangle(frame, pt1, pt2, Scalar(255, 0, 0), 1, 8, 0); }
}
imshow("output", frame);
int c = waitKey(10);
if ((char) c == 27) {
break;
}
}
return 0;
}