派生自 development/c++

pansen
2019-03-07 d3b7bbe7102cd089680a828f5d8f6402c8cf6342
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
#include "ImageDrawElement.h"
#include <basic/util/opencv/CvUtil.h>
 
ImageDrawElement::ImageDrawElement() {
 
}
 
void ImageDrawElement::darwProperty(cv::Mat &image, string key, string value, int x, int y) {
    cv::putText(image, key + ": " + value, cv::Point(x, y), cv::HersheyFonts::FONT_HERSHEY_PLAIN, 1.5,
                cv::Scalar(255, 255, 0), 2);
}
 
void ImageDrawElement::processImage(cv::Mat &image) {
    auto faceData = faces.getData();
    auto yoloObjectsData = yoloObjects.getData();
 
    for (auto face: faceData) {
        auto rect = CvUtil::zoomRect(face.rect, 1.2, 1.2);
        cv::rectangle(image, rect, face.id >= 0 ? cv::Scalar(0, 255, 0) : cv::Scalar(0, 255, 255), 2);
        int i = 0;
        for (auto &property:face.properties) {
            darwProperty(image, property.first, property.second, rect.x + rect.width, rect.y + 40 * i++);
        }
    }
 
    for (auto yoloObj: yoloObjectsData) {
        auto rect = CvUtil::zoomRect(yoloObj.rect, 1, 1);
        //[{"x":1.5999756,"y":82.533325},{"x":1.5999756,"y":180.53333},{"x":61.599976,"y":175.53333},{"x":63.599976,"y":66.533325}]
        //cv::rectangle(image, cv::Rect(4,328,252,480 ), cv::Scalar(0, 0, 255), 2);
        cv::rectangle(image, rect, yoloObj.id >= 0 ? cv::Scalar(255, 0, 0) : cv::Scalar(0, 255, 255), 2);
        int i = 0;
        for (auto &property:yoloObj.properties) {
            darwProperty(image, property.first, property.second, rect.x + rect.width, rect.y + 40 * i++);
        }
    }
}
 
void ImageDrawElement::setFaces(std::vector<ScoredRect> value) {
    faces = value;
}
 
void ImageDrawElement::setYoloObjects(std::vector<ScoredRect> value) {
    yoloObjects = value;
}