//
|
// 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;
|
//
|
//}
|