派生自 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
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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
//
// Created by pans on 5/4/18.
//
 
//
// Created by ps on 3/1/18.
//
 
 
#include <thread>
#include "opencv2/opencv.hpp"
#include "basic/util/BASE64/Base64.h"
#include <basic/util/opencv/CvUtil.h>
#include <dirent.h>
#include <THFeature_i.h>
#include <zconf.h>
#include <Ice/Ice.h>
#include <basic/util/app/AppUtil.h>
#include <FaceData.hpp>
#include <FaceSearchServer.h>
#include <CasiaFaceWrapperN.h>
#include <basic/util/app/AppPreference.hpp>
#include <basic/rpc/IceRpc.hpp>
#include <CurlDownloadImg.hpp>
#include <uuid/uuid.h>
#include <jsoncpp/json/json.h>
 
using namespace cv;
using namespace std;
 
Base64 base64;
//void* test(void* arg){
//#ifdef TestCode
//    IceRpcClient<AlarmServerInterface::AlarmCompareServerPrx> client("FaceDBCompare", "", 10028, "tcp");
//    auto server = client.getServer();
//#else
//#endif
//
//    std::map<int,std::vector<unsigned char>> db_handle;
//    {
//        LoginDB g_dbLogin;
//        g_dbLogin.ip = "192.168.1.81";
//        g_dbLogin.port = 8066;
//        g_dbLogin.dbName = "VIDEO_STRUCTURE";
//        g_dbLogin.userName = "root";
//        g_dbLogin.pwd = "root";
//        MYSQL conn;
//        mysql_init(&conn);
//        bool connectStatus = mysql_real_connect(&conn,g_dbLogin.ip.c_str(),g_dbLogin.userName.c_str()
//                ,g_dbLogin.pwd.c_str(),g_dbLogin.dbName.c_str(),g_dbLogin.port,NULL,CLIENT_FOUND_ROWS);
//        if(connectStatus)
//        {
//            //#todo modify sql
//            string sql = "select drug_id,feature FROM o_t_p_drug_feature where 1=1 and feature is not NULL limit 500";
//            {
//                ClockTimer ct2("mysql_query");
//                int ret=mysql_query(&conn,sql.data());
//                if(ret == 0){
//                    printf("OK\n");
//                }else{
//                    printf("error::%s\n",mysql_error(&conn));
//                }
//            }
//
//            //将查询到的结果集存放在临时变量中
//            MYSQL_RES *result = NULL;
//            result = mysql_store_result( &conn );
//
//            //得到查询出来所有数据的条数
//            int row_count = mysql_num_rows(result);
//            if (row_count <= 0) {
//                INFO("not found data!!!")
//                return NULL;
//            }
//            //显示表中的所有数据
//            {
//                ClockTimer ct2("mysql_fetch_row");
//                int loop = 0;
//
//                MYSQL_ROW row = NULL;
//                row = mysql_fetch_row( result );
//                while ( NULL != row )
//                {
//                    string ft = row[1];
//                    string str2;
//                    int a = ft.length();
//                    str2 = base64.Decode(ft.data(),ft.length());
//
//                    FaceFeature tmp;
//                    tmp.resize(str2.length());
//                    memset(tmp.data(), 0,str2.length());
//                    memcpy(tmp.data(),str2.data(),str2.length());
//                    int b = tmp.size();
//                    db_handle[atoi(row[0])] = tmp;
//                    tmp.clear();
//                    row = mysql_fetch_row( result );
//                }
//
//                mysql_free_result(result);
//            }
//
//        }else{
//            printf("connectStatus error\n");
//        }
//
//        {
//            ClockTimer ct3("close");
//            mysql_close(&conn);
//        }
//    }
//
//    ::AlarmServerInterface::AlarmInformation t_alarmData;
//
//    t_alarmData.carmera_id = "1";
//    t_alarmData.create_time = "2018-03-25 18:07:53";
//    t_alarmData.alarm_url = "vvvvvadsfasd";
//    t_alarmData.resoure_id = "vvvvvadsfasd";
//    t_alarmData.flag_eq_pf = "aaa";
//    int loop = 0;
//    while(true){
//        for(auto item : db_handle){
//            if(loop++ > 20 ){
//                break;
//            }
//            t_alarmData.faceFeature = item.second;
//            int c = t_alarmData.faceFeature.size();
//            INFO("sumbitData"<<item.first);
//            server->sumbitData(t_alarmData);
//            sleep(1);
//        }
////        while(loop <= 20)
////        {
////            ::AlarmServerInterface::AlarmRule iceP_alarmRule;
////            ::AlarmServerInterface::PersonAlarmRule m;
////            iceP_alarmRule.fllow_id = to_string(loop++);
////            iceP_alarmRule.tableName = "o_t_p_fllow22";
////            iceP_alarmRule.rule_Type = "0";
////            server->addRules(iceP_alarmRule);
////        }
//        loop=0;
//    }
//}
//
 
CvUtil cvutil;
 
int main(int argc, char *argv[]) {
    SAVE_APP_ARGS
 
    ENABLEGLOG("./log/");
    Ice::CommunicatorHolder ich(argc, argv);
 
//    Ice::ObjectPrx base = ich->stringToProxy("FaceSearchServer");
    IceRpcClient<FaceSearch::FaceFeatureSearchServerPrx> client("faceCmServer", "", 10004, "tcp");
    auto server = client.getServer();
//    auto server = FaceSearch::FaceFeatureSearchServerPrx::checkedCast(base);
 
 
    string str_uuid;
    uuid_t t_uuid;
    char str[36];
    uuid_generate(t_uuid);
    uuid_unparse(t_uuid, str);
    str_uuid = str;
 
    Json::Value t_json;
    t_json["Id"] = str_uuid; //主键
//#todo
    t_json["FaceFeature"] = "base64";//确认对不对 人脸特征转成字符串!!!//格式转化
 
    t_json["picName"] = "wait todo";
 
    t_json["personId"] = "wait todo";//关联底库人员id,人脸id
    t_json["BaseName"] = "wait todo";//关联底库表名
 
    t_json["personPicUrl"] = "wait todo";//人员图片 store
    t_json["likePer"] = "";//人员相似度 Score
    t_json["likeDate"] = "2018-01-01 01:01:01";//比较时间
    t_json["picAddress"] = "wait todo";//抓拍地址
    t_json["picMaxUrl"] = "wait todo";//大图路径
    t_json["picLocalUrl"] = "wait todo";//本地路径
    t_json["picSmUrl"] = "wait todo";//人员抓小图
    t_json["picDate"] = "2018-01-01 01:01:01";
    t_json["content"] = "wait todo";
    t_json["viType"] = "1";//只有4种类型 1:personface 2:personbody 3:car 4:bicycle 5:none 未知类型
    t_json["personIsHub"] = "1";//1: 报警  2: 可疑  3: 安全  4: 未知
 
 
    //faceExtractElement.setProperty("dev_id", str_device_id);
    //faceExtractElement.setProperty("cg_id", str_ch_id);
    t_json["videoNum"] = "";//Vide编号 外键
    t_json["videoReqNum"] = "123456";//Video设备编号
    t_json["ChannlId"] = "33";//通道id
    t_json["isDelete"] = "1";//默认1 ,0无效 1有效
 
    //人脸属性
    t_json["Age"] = "18";//检测的年龄  应该为空 无检测结果
    t_json["Gender"] = "1";//检测的性别 为空 无检测结果
    t_json["BeautyLevel"] = "5";//检测的美化水平 为空 无检测结果
    t_json["SimleLevel"] = "25";//检测的微笑水平 为空 无检测结果
    t_json["Race"] = "1";//检测的种族  应该为空 无检测结果
 
 
    DBG(t_json.toStyledString());
 
 
//    return 0;
    appPref.setLongData("thread.max", 1);
    CasiaFaceWrapperN t_CasiaFaceWapper;
//    string test1 = "http://192.168.1.65:8888/group1/M00/04/52/wKgBQVr5J-WAJ4lQAAAObkm3j38169.jpg";
//    string test2 = "http://192.168.1.65:8888/group1/M00/04/52/wKgBQVr5JGOAXmx9AAAK0Xp3QhA271.jpg";
//    CurlDownloadImg curlDownloadImg;
    {
//        auto curlImg = curlDownloadImg.download_jpeg(const_cast<char *>(test2.c_str()));
//        cout << " image is " << test1 << endl;
        long t_id = 0;
//        if (curlImg.all > 0) {
        if (true) {
            Mat image = imread("/home/bsk/work/development/c++/Qt-test/testFastDfs/build/fastdfs/18.jpg");
//            cvutil.buffer2CvMat(curlImg.buffer, image);
 
            FaceImageN faceImage2{image.cols, image.rows, image.step, image.data};
//            auto res = t_CasiaFaceWapper.extractFace(faceImage2);
            auto faceResults = t_CasiaFaceWapper.extractFace(faceImage2);
 
            DBG("faceResults" << faceResults.size());
            for (auto item : faceResults) {
                ::FaceSearch::Data t_fea;
                t_fea.resize(item.feature.size());
                memcpy(t_fea.data(), item.feature.data(), item.feature.size());
                try {
                    std::vector<::std::string> tables{"aaa1", "TestFace2", "TestFace3", "TestFace4"};
                    auto re = server->faceSearchTopN(t_fea, t_json.toStyledString(), 1, 0.8);
                    INFO("faceSearchMax  " << re.size());
                    for (auto item : re) {
                        INFO("faceSearchMax id " << (item.uuid));
                        INFO("faceSearchMax confidence " << (item.confidence));
                        INFO("faceSearchMax tableName " << (item.tableName));
                    }
                    //                                sleep(3);
//                    ::std::vector<::std::string> tables2{"aaa1", "TestFace2", "TestFace3", "TestFace4"};
//                    auto re2 = server->faceSearchTopN(t_fea, 5, tables2);
//                    INFO("faceSearchTopN  " << re2.size());
//                    for (auto item : re2) {
//                        INFO("faceSearchTopN id " << (item.uuid));
//                        INFO("faceSearchTopN confidence " << (item.confidence));
//                        INFO("faceSearchTopN tableName " << (item.tableName));
//                    }
                } catch (std::exception ex) {
                    ERR(ex.what());
                }
                t_fea.clear();
            }
        }
    }
    return 0;
}
 
//void test22333() {
//
//    int loop = 0;
////#todo
//    while (1) {
//        string t_path = "./img/";
//        DIR *dp = opendir(t_path.c_str());
//        if (dp != NULL) {
//            struct dirent *ep;
//            int loop = 0;
//            while (
//                ep = readdir(dp)
//                ) {
//                string path(ep->d_name);
//                if (path.find(".jpg") == std::string::npos) {
//                    ERR("Couldn't find jpg.");
//                    continue;
//                } else {
//                    printf("jpg url: %s\n", path.
//
//                        c_str()
//
//                    );
//                }
//
//                string tName(t_path);
//                tName.
//                    append(path);
//                Mat img1 = imread(tName);           // ST_PIX_FMT_BGR888
//                if (!img1.data) {
//                    printf("read first image file failed. url: %s\n", tName.
//
//                        c_str()
//
//                    );
//                    continue;
//                } else {
//                    INFO("read img ok!");
//                }
//                FaceImageN faceImage{img1.cols, img1.rows, img1.step, img1.data};
////    m_casiaFaceWrapper.extractFace(faceImage);
//                auto faceResults = t_CasiaFaceWapper.extractFace(faceImage);
//
//                DBG("faceResults" << faceResults.size());
//                for (
//                    auto item
//                    : faceResults) {
//                    ::FaceSearch::Data t_fea;
//                    t_fea.
//                        resize(item
//                                   .feature.
//
//                        size()
//
//                    );
//                    memcpy(t_fea
//                               .
//
//                                   data(), item
//
//                               .feature.
//
//                        data(), item
//
//                               .feature.
//
//                        size()
//
//                    );
//                    try {
//                        ::std::vector<::std::string> tables{"o_t_p_escape", "TestFace2", "TestFace3", "TestFace4"};
//                        auto re = server->faceSearchMax(t_fea, tables);
//                        INFO("faceSearchMax  " << re.size());
//                        for (
//                            auto &item
//                            : re) {
//                            INFO("faceSearchMax id " << (item.id));
//                            INFO("faceSearchMax confidence " << (item.confidence));
//                            INFO("faceSearchMax tableName " << (item.tableName));
//                        }
////                                sleep(3);
//                        ::std::vector<::std::string> tables2{"o_t_p_escape", "TestFace2", "TestFace3", "TestFace4"};
//                        auto re2 = server->faceSearchTopN(t_fea, 5, tables2);
//                        INFO("faceSearchTopN  " << re2.size());
//                        for (
//                            auto &item
//                            : re2) {
//                            INFO("faceSearchTopN id " << (item.id));
//                            INFO("faceSearchTopN confidence " << (item.confidence));
//                            INFO("faceSearchTopN tableName " << (item.tableName));
//                        }
//                    } catch (
//                        std::exception ex
//                    ) {
//                        ERR(ex.what());
//                    }
//                    t_fea.
//
//                        clear();
////#todo if sc add message
////else nothing
//                }
////        extractFace(FaceImage image, vector<unsigned char>& feature, int& faceNum);
////                        vector<unsigned char> feature;
////                        vector<unsigned char> feature2;
////                        cvutil.cvMat2Buffer(img1,feature);
////                        auto test = feature.size();
//////                        DBG(test)
////                        ::FaceSearch::Data t_fea;
////                        t_fea.resize(feature.size());
////                        memcpy(t_fea.data(),feature.data(),feature.size());
////                        try {
//////                server->addFace(t_fea,"aaa");addFaceWithId
//////                            server->addFaceWithId(t_fea,(++loop),"aaa");
//////                            sleep(1);
//////                            server->addFaceWithId(t_fea,(loop),"bbb");
////                            ::std::vector< ::std::string> tables{"aaa","bbb"};
////                            auto re = server->faceSearchMax(t_fea,tables);
////
////                            INFO("faceSearchMax  " << re.size() );
////                            for (auto& item : re) {
////                                INFO("faceSearchMax id " << ( item.id));
////                                INFO("faceSearchMax confidence " << ( item.confidence));
////                                INFO("faceSearchMax tableName " << ( item.tableName));
////                            }
////                            sleep(3);
////                        }catch (std::exception ex){
////                            ERR(ex.what());
////                        }
////                        feature.clear();
////            break;
////            int faceNum;
////            FaceImageN faceImage {img1.cols, img1.rows, img1.step, img1.data};
////            //#todo pthread
////            auto res = t_CasiaFaceWapper.extractFace(faceImage);
////            for (auto item : res) {
//////                item.feature
//////addFace(const ::FaceSearch::Data& iceP_jpgData, const ::std::string& iceP_tableName, const ::Ice::Context& context = ::Ice::noExplicitContext)
////                ::FaceSearch::Data t_fea;
////                t_fea.resize(item.feature.size());
////                memcpy(t_fea.data(),item.feature.data(),item.feature.size());
////
////                try {
////                    server->addFace(t_fea,"aaa");
////                    INFO("add");
////                }catch (std::exception ex){
////                    ERR(ex.what());
////                }
////            }
//
//                printf("\n");
//                printf("\n");
//                printf("\n");
//                printf("\n");
//            }
//            closedir(dp);
//        } else {
//            ERR("Couldn't open the directory.");
//        }
////                break;
//        sleep(10);
//    }
//
//
//
//
////    try {
////        long out;
////        auto temp = server2->getDbActions(000,out);
////        cout << temp.size() << endl;
////        cout << out << endl;
////        INFO("getDbActions");
////    }catch (std::exception ex){
////        ERR(ex.what());
////    }
////getchar();
//    return 0;
//
//}