-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheeks.cpp
More file actions
81 lines (64 loc) · 2.53 KB
/
Copy pathcheeks.cpp
File metadata and controls
81 lines (64 loc) · 2.53 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#include <iostream>
#include <opencv2/opencv.hpp>
#include "cheeks.hpp"
using namespace std;
using namespace cv;
int CheeksDetection(vector<cv::Rect>& tmpRect, Mat& tmpImg) {
for (const auto& face : tmpRect) {
int x_cheekA = face.x + face.width / 6;
int y_cheekA = face.y + face.height / 2;
int width_cheekA = face.width / 4;
int height_cheekA = face.height / 4;
int x_cheekB = face.x + face.width * 4 / 6;
int y_cheekB = face.y + face.height / 2;
int width_cheekB = face.width / 4;
int height_cheekB = face.height / 4;
rectangle(tmpImg, Rect(x_cheekA, y_cheekA, width_cheekA, height_cheekA), Scalar(0, 255, 0), 2);
rectangle(tmpImg, Rect(x_cheekB, y_cheekB, width_cheekB, height_cheekB), Scalar(0, 255, 0), 2);
}
return 0;
}
int CheeksDetection(vector<cv::Rect>& tmpRect, Mat& tmpImg, string& tmpmask) {
Mat overlayImage = imread(tmpmask, IMREAD_UNCHANGED);
if (overlayImage.empty()) {
std::cerr << "Error loading overlayImage." << std::endl;
return -1;
}
Mat resized_image;
for (const auto& face : tmpRect) {
int x_cheekA = face.x + face.width / 6;
int y_cheekA = face.y + face.height / 2;
int width_cheekA = face.width / 4;
int height_cheekA = face.height / 4;
int x_cheekB = face.x + face.width * 4 / 6;
int y_cheekB = face.y + face.height / 2;
int width_cheekB = face.width / 4;
int height_cheekB = face.height / 4;
rectangle(tmpImg, Rect(x_cheekA, y_cheekA, width_cheekA, height_cheekA), Scalar(0, 255, 0), 2);
rectangle(tmpImg, Rect(x_cheekB, y_cheekB, width_cheekB, height_cheekB), Scalar(0, 255, 0), 2);
cv::Rect roiRectA(x_cheekA, y_cheekA, width_cheekA, height_cheekA);
cv::Rect roiRectB(x_cheekB, y_cheekB, width_cheekB, height_cheekB);
cv::Mat roi = tmpImg(roiRectA).clone();
resize(overlayImage, resized_image, Size(width_cheekA, height_cheekA), INTER_LINEAR);
/////////////////////////
if (resized_image.channels() != roi.channels()) {
cv::cvtColor(resized_image, resized_image, cv::COLOR_RGBA2RGB);
}
if (resized_image.channels() != roi.channels() || roi.cols != resized_image.cols || resized_image.channels() != roi.channels()) {
std::cerr << "Error: Number of channels mismatch between source and destination." << std::endl;
return -1;
}
for (int i = 0; i < roi.cols; i++)
{
for (int j = 0; j < roi.rows; j++)
{
if (!(resized_image.at<Vec3b>(j, i) == Vec3b(255, 255, 255)))
{
tmpImg(roiRectA).at<Vec3b>(j, i) = Vec3b(255, 41, 251);// resized_image.at<Vec3b>(j, i);
tmpImg(roiRectB).at<Vec3b>(j, i) = Vec3b(255, 41, 251);
}
}
}
}
return 0;
}