wangrong
2025-03-19 291afb9c81aae1d15d9e3edcea618d0a2e1fc5a6
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
 
#include <opencv2/imgproc.hpp>
#include "vp_expr_osd_node.h"
#include "../../utils/vp_utils.h"
 
 
namespace vp_nodes {
    
    vp_expr_osd_node::vp_expr_osd_node(std::string node_name, std::string font):vp_node(node_name) {
        assert(font != "");
        ft2 = cv::freetype::createFreeType2();
        ft2->loadFontData(font, 0);    
        this->initialized();  
    }
    
    vp_expr_osd_node::~vp_expr_osd_node() {
        deinitialized();
    }
 
    std::shared_ptr<vp_objects::vp_meta> vp_expr_osd_node::handle_frame_meta(std::shared_ptr<vp_objects::vp_frame_meta> meta) {
        // operations on osd_frame
        if (meta->osd_frame.empty()) {
            meta->osd_frame = meta->frame.clone();
        }
        auto& canvas = meta->osd_frame;
 
        for (auto& i: meta->text_targets) {
            cv::Point rook_points[4];
            for (int m = 0; m < i->region_vertexes.size(); m++) {
                rook_points[m] =
                    cv::Point(i->region_vertexes[m].first, i->region_vertexes[m].second);
            }
 
            const cv::Point *ppt[1] = {rook_points};
            int npt[] = {4};
 
            if (i->flags.find("yes") != std::string::npos) {
                cv::polylines(canvas, ppt, npt, 1, 1, CV_RGB(0, 255, 0), 2, cv::LINE_AA, 0);   // green
                ft2->putText(canvas, "√", rook_points[1], 30, CV_RGB(0, 255, 0), cv::FILLED, cv::LINE_AA, true);
            }
            else if (i->flags.find("no") != std::string::npos) {
                auto right_value = vp_utils::string_split(i->flags, '_')[1];
                cv::polylines(canvas, ppt, npt, 1, 1, CV_RGB(255, 0, 0), 2, cv::LINE_AA, 0);   // red
                ft2->putText(canvas, "×(" + right_value + ")", rook_points[1], 30, CV_RGB(255, 0, 0), cv::FILLED, cv::LINE_AA, true);
            }
            else if (i->flags == "invalid") {
                cv::polylines(canvas, ppt, npt, 1, 1, CV_RGB(255, 165, 0), 2, cv::LINE_AA, 0); // orange
                ft2->putText(canvas, "invalid", rook_points[1], 30, CV_RGB(255, 165, 0), cv::FILLED, cv::LINE_AA, true);
            }
            else {
                // to-do
            }
        }
        return meta;
    }
}