pansen
2019-04-10 ecb47d89dcb2b1d8e4be9b6cb0a84d8b49e2e3cc
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
//
// Created by ps on 19-4-10.
//
 
#include "VptServerI.h"
#include <QtCore/QString>
#include <QtCore/QSharedMemory>
 
VptServerI::VptServerI() {}
 
VptServerI::~VptServerI() {
 
}
 
VptDetect::ObjInfos
VptServerI::VptDetect(Ice::Int width, Ice::Int height, const ::std::string &shM,
                      const ::Ice::Current &current) {
 
    VptDetect::ObjInfos objInfos;
    QSharedMemory shareMemory(QString(shM.c_str()));
    if (shareMemory.attach()) {
        int channel = 3;
        cv::Mat _mat = bufferToMat(width, height, channel, shareMemory.constData());
        auto res = std::move(m_vptDetectWrapper.process_image(_mat));
 
        for (auto &item : res) {
            ::VptDetect::VptDetectResult vptDetectResult;
 
            vptDetectResult.sdkDetectType = static_cast<Ice::Int>(item.sdkDetectType);
 
            vptDetectResult.bskRect.left = item.bskRect.left_;
            vptDetectResult.bskRect.top = item.bskRect.top_;
            vptDetectResult.bskRect.width = item.bskRect.width_;
            vptDetectResult.bskRect.height = item.bskRect.height_;
 
            switch (vptDetectResult.sdkDetectType) {
                case 0 : {
                    vptDetectResult.personDetectRes.res_objs.resize(HP_FIR_INDEX_SIZE);
                    memcpy(vptDetectResult.personDetectRes.res_objs.data(), item.vptDetectRes.personDetectRes.res_objs,
                           sizeof(classfy_boj_res) * HP_FIR_INDEX_SIZE);
                };
                    break;
                case 1:
                case 2 : {
                    vptDetectResult.perRideCarDetectRes.res_objs.resize(HCP_FIR_INDEX_SIZE);
                    memcpy(vptDetectResult.perRideCarDetectRes.res_objs.data(),
                           item.vptDetectRes.perRideCarDetectRes.res_objs,
                           sizeof(classfy_boj_res) * HCP_FIR_INDEX_SIZE);
                };
                    break;
                case 4 :
                case 5 :
                case 6 :
                case 8 : {
                    //#todo
                    vptDetectResult.carDetectRes;
                };
                    break;
            }
            objInfos.push_back(vptDetectResult);
        }
 
    }
    return objInfos;
}
 
VptDetect::stringDatas VptServerI::getStr(Ice::Int type_, const ::Ice::Current &current) {
    VptDetect::stringDatas res;
    //#todo extern to func
    switch (type_) {
        case 0 : {
            for (auto &items : HpResStr) {
                ::VptDetect::stringData stringData;
                for (auto &item : items) {
                    stringData.push_back(item);
                }
                res.push_back(std::move(stringData));
            }
        };
            break;
        case 1 : {
            for (auto &items : HcpResStr) {
                ::VptDetect::stringData stringData;
                for (auto &item : items) {
                    stringData.push_back(item);
                }
                res.push_back(std::move(stringData));
            }
        };
            break;
        case 2 : {
            ::VptDetect::stringData stringData;
            for (auto &item : type) {
                stringData.push_back(item);
            }
            res.push_back(std::move(stringData));
        };
            break;
        case 3 : {
            ::VptDetect::stringData stringData;
            for (auto &item : colorLabelStr) {
                stringData.push_back(item);
            }
            res.push_back(std::move(stringData));
        };
            break;
    }
    return res;
}
 
VptDetect::stringData VptServerI::getTypeStr(const ::Ice::Current &current) {
    //#todo
    return VptDetect::stringData();
}
 
VptDetect::stringData VptServerI::getColorLabel(const ::Ice::Current &current) {
    //#todo
    return VptDetect::stringData();
}
 
VptDetect::stringDatas VptServerI::getHpResStr(const ::Ice::Current &current) {
    //#todo
    return VptDetect::stringDatas();
}
 
VptDetect::stringDatas VptServerI::getHcpResStr(const ::Ice::Current &current) {
    //#todo
    return VptDetect::stringDatas();
}
 
cv::Mat VptServerI::bufferToMat(const int w, const int h, const int channels, const void *buffer) {
    int nType = -1;
    switch (channels) {
        case 1: {
            nType = CV_8UC1;
            break;
        }
        case 2: {
            nType = CV_8UC2;
            break;
        }
        case 3: {
            nType = CV_8UC3;
            break;
        }
        default: {
            nType = CV_8UC3;
            break;
        }
    }
    cv::Mat mat(h, w, nType, (void *) buffer);
    return mat;
}