basic版本的yolo,在yolov3版本上增加人体跟踪
xuepengqiang
2020-05-26 5966f2b095841627d62daac0159e81f83544b85c
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
//
// Created by Scheaven on 2020/4/23.
//
 
#include "draw_util.h"
 
#ifdef OPENCV
#include <opencv2/opencv.hpp>            // C++
#pragma comment(lib, "opencv_core249.lib")
#pragma comment(lib, "opencv_imgproc249.lib")
#pragma comment(lib, "opencv_highgui249.lib")
#endif    // OPENCV
using namespace cv;
 
void draw_boxes(cv::Mat& mat_img, std::vector<bbox_t> result_vec)
{
    for (auto &i : result_vec) {
        if(i.obj_id == 0)
            cv::rectangle(mat_img, cv::Rect(i.x, i.y, i.w, i.h), cv::Scalar(50, 200, 50), 1);
    }
    cv::imshow("window name", mat_img);
    cv::waitKey(0);
}
 
void draw_result(cv::Mat mat_img, FRAME_RESULT& result_vec)
{
    for (auto &result : result_vec) {
        cv::rectangle(mat_img, result.rect , cv::Scalar(50, 200, 50), 1);
        cv::putText(mat_img, std::to_string(result.human_id), Point(result.rect.x,result.rect.y), CV_FONT_HERSHEY_SIMPLEX, 0.8, Scalar(255,255,0), 2);
    }
//    delete tmp_rect;
    cv::resize(mat_img,mat_img,cv::Size(800,500));
    cv::imshow("RESULT", mat_img);
    cv::waitKey(1);
}
 
void draw_SDK_result(cv::Mat mat_img, TResult *t_result)
{
    cv::Rect tmp_rect;
//    std::cout<<t_result->targets[0].id<<"count" <<t_result->count << std::endl;
 
    for (int i = 0; i < t_result->count; ++i) {
        auto &result = t_result->targets[i];
        tmp_rect = cv::Rect(result.rect.left,result.rect.top,result.rect.right-result.rect.left,result.rect.bottom-result.rect.top);
        cv::rectangle(mat_img, tmp_rect , cv::Scalar(50, 200, 50), 2);
        cv::putText(mat_img, std::to_string(result.id), Point(result.rect.left,result.rect.top), CV_FONT_HERSHEY_SIMPLEX, 0.8, Scalar(255,255,0), 2);
        cv::putText(mat_img, std::to_string(result.confidence), Point(result.rect.left+100,result.rect.top), CV_FONT_HERSHEY_SIMPLEX, 0.8, Scalar(255,255,0), 2);
    }
    cv::resize(mat_img,mat_img,cv::Size(800,500));
    cv::imshow("RESULT", mat_img);
    cv::waitKey(1);
}
 
void show_result(std::vector<bbox_t> result_vec)
{
    std::cout<< result_vec.size() << std::endl;
    for (auto &i : result_vec) {
        if(i.obj_id == 0) {
            std::cout << "obj_id = " << i.obj_id << " - x = " << i.x << ", y = " << i.y
                      << ", w = " << i.w << ", h = " << i.h
                      << ", prob = " << i.prob << std::endl;
        }
    }
}