This repository was archived by the owner on Apr 14, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathimageprocessor.cpp
More file actions
49 lines (46 loc) · 1.41 KB
/
imageprocessor.cpp
File metadata and controls
49 lines (46 loc) · 1.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include "imageprocessor.h"
#include <opencv2/core/core.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include<vector>
using namespace cv;
using namespace std;
Bgr2Rgb::Bgr2Rgb()
{}
void Bgr2Rgb::process(cv::Mat &image)
{
cvtColor(image,image,CV_BGR2RGB);
}
MouthClassifierProcessor::MouthClassifierProcessor(CascadeClassifier &face, CascadeClassifier &mouth)
{
this->mouthClassifier = &mouth;
this->faceClassifier =&face;
}
void MouthClassifierProcessor::process(cv::Mat &image)
{
Mat grayScaled;
vector<Rect> faces;
vector<Rect> mouths;
double reduceFactor = 3;
resize(image,grayScaled,Size(),1/reduceFactor,1/reduceFactor);
cvtColor(grayScaled,grayScaled,COLOR_BGR2GRAY);
faceClassifier->detectMultiScale(grayScaled,faces);
for(vector<Rect>::iterator it1=faces.begin();it1!=faces.end();it1++){
it1->y += it1->height/2;
it1->height /= 2;
cv::Mat halfFaceRoi = grayScaled(*it1);
mouthClassifier->detectMultiScale(halfFaceRoi,mouths);
Rect rect;
rect.y = 0;
for(vector<Rect>::iterator it2=mouths.begin();it2!=mouths.end();it2++){
if(it2->y>rect.y)
rect = *it2;
}
rect.x += it1->x;
rect.y += it1->y;
rect.x *= reduceFactor;
rect.y *= reduceFactor;
rect.width *= reduceFactor;
rect.height *= reduceFactor;
rectangle(image,rect,Scalar(255,0,0));
}
}