派生自 Algorithm/baseDetector

sunty
2022-03-21 d0a24896f95b4e060011852f80048ebfb0bf5f55
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
//
// Created by Scheaven on 2020/4/23.
//
 
#include "draw_util.h"
#include <sys/types.h>
#include <sys/stat.h>
#include <stdlib.h>
#include <iostream>
#include <unistd.h>
#include <stdio.h>
#include <dirent.h>
#include <string.h>
#include "log_util.h"
#include <opencv2/opencv.hpp>                   // C++
 
using namespace cv;
using namespace std;
 
 
void create_foldert(const char *path)
{
    // if(access(path, 0) == -1)
    // {
    //     int flag = mkdir(path,0777);
    //     if(flag==0)
    //     {
    //         DEBUG( ":::::::::create folder!::::::");
    //     }else
    //     {
    //         DEBUG( ":::::::::create folder! error!::::::");
    //     }
    // }
    DEBUG("=2==create_path:");
    char DirName[256];
    strcpy(DirName,path);
    int i,len = strlen(DirName);
    if(DirName[len-1]!='/')
        strcat(DirName,"/");
    len = strlen(DirName);
    for(i=1;i<len;i++)
    {
        if(DirName[i]=='/')
        {
            // DirName[i] = 0;
            // if(access(DirName,NULL) != 0)
            // {
            //    if(mkdir(DirName,0777) == -1)
            //    {
            //        perror("mkdir error");
            //    }
            // }
            DEBUG("=1==create_path:");
            int a = access(DirName, F_OK);
            if(a ==-1)
            {
                mkdir(DirName,0755);
            }
            DirName[i] = '/';
         }
     }
}
 
void save_human_img(cv::Mat aaaa, string path, int type, string name)
{
    // aaaa.convertTo(aaaa, CV_8UC3, 255.0f);
    // cv::cvtColor(aaaa, aaaa, cv::COLOR_RGB2BGR); // 颜色空间需要确认一下Z
    string file_path ="./02_humanID/"+ path +"/";
    create_foldert(file_path.c_str());
    cv::imwrite(file_path + name + "_" + to_string(type) + ".jpg", aaaa);
}
 
void draw_SDK_result(cv::Mat mat_img, Target* target)
{
    cv::Rect tmp_rect = cv::Rect(target->rect.left,target->rect.top,target->rect.right-target->rect.left,target->rect.bottom-target->rect.top);
    cv::rectangle(mat_img, tmp_rect , cv::Scalar(50, 200, 50), 2);
    // cv::resize(mat_img, mat_img, frameSize);
    // cv::imwrite("1111.jpg", mat_img);
    cv::imshow(to_string(1), mat_img);
    cv::waitKey(1);
}
 
cv::VideoWriter writer("./01_baseDetector.avi", cv::VideoWriter::fourcc('M','J','P','G'),24, cv::Size(800,500), true);
// cv::VideoWriter writer("/opt/vasystem/valog/01_Scheanve/01_baseDetector.avi", cv::VideoWriter::fourcc('M','J','P','G'),24, cv::Size(800,500), true);
 
void draw_SDK_result(const int cam_id, cv::Mat mat_img, TResult* t_result)
{
    cv::Rect tmp_rect;
 
    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.right)/2,result.rect.top+150), 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::imwrite("1111.jpg", mat_img);
    // cv::imshow("RESULT", mat_img);
    writer<< mat_img;
    // cv::waitKey(0);
}