From 641eab08f214327f107ee6e96f9209f24baedabb Mon Sep 17 00:00:00 2001
From: zhangjixing <775834166@qq.com>
Date: 星期六, 05 一月 2019 19:23:20 +0800
Subject: [PATCH] 编码使用redis,多路存在问题,先传一版
---
QiaoJiaSystem/DataManagerServer/http_configserver.cpp | 116 +++++++++++++++++++++++++++++++++++++++++++--------------
1 files changed, 87 insertions(+), 29 deletions(-)
diff --git a/QiaoJiaSystem/DataManagerServer/http_configserver.cpp b/QiaoJiaSystem/DataManagerServer/http_configserver.cpp
index eee56d7..6e5fc48 100644
--- a/QiaoJiaSystem/DataManagerServer/http_configserver.cpp
+++ b/QiaoJiaSystem/DataManagerServer/http_configserver.cpp
@@ -2001,27 +2001,11 @@
auto t_results = m_curlDownloadImg.download_jpeg(const_cast<char *>(img_url.c_str()));
cvutil.buffer2CvMat(t_results.buffer, image);
} else if (img_base64.size() > 0) {
- img_url = "http://";
auto str_img = base64.Decode(img_base64.c_str(), img_base64.size());
std::vector<unsigned char> buffer(str_img.size());
memcpy(buffer.data(), str_img.data(), str_img.size());
cvutil.buffer2CvMat(buffer, image);
-
- fdfsClient.rwLock.rdlock();
- if (fdfsClient.fastFds != nullptr) {
- img_url.append(fdfsClient.fastFds->getIp() + "/");
- std::string t_strImg = "";
- if (!fdfsClient.fastFds->uploadFile(buffer, t_strImg, "jpg")) {
- img_url = "upload image fail";
- } else {
- img_url.append(t_strImg);
- img_url.clear();
- img_url = t_strImg;
-// img_url.append("/").append(t_strImg);
- }
- }
- fdfsClient.rwLock.unlock();
} else {
response->write(SimpleWeb::StatusCode::server_error_not_implemented, "{\"error\":\"not found img\"}");
return "";
@@ -2046,10 +2030,39 @@
// cv::imwrite(str_path, image);
return "";
// return "{\"error\":\"not found face\"}";
+ } else if (faceResults.size() > 1) {
+ response->write(SimpleWeb::StatusCode::server_error_not_implemented, "{\"error\":\" 浠呮敮鎸佸崟浜鸿劯鍥剧墖 \"}");
+ return "";
}
for (auto &item : faceResults) {
feature_base64 = base64.Encode(item.feature.data(), item.feature.size());
+
+
+ int x = item.left;
+ int y = item.top;
+ int w = item.width;
+ int h = item.height;
+ cv::Rect t_rect = {x, y, w, h};
+ auto t_image = image(CvUtil::zoomRect(t_rect, 1.5, 1.5) & cv::Rect(0, 0, image.cols, image.rows)).clone();
+ std::vector<uchar> buffer;
+ cvutil.cvMat2Buffer(t_image, buffer);
+ img_url = "http://";
+ fdfsClient.rwLock.rdlock();
+ if (fdfsClient.fastFds != nullptr) {
+ img_url.append(fdfsClient.fastFds->getIp() + "/");
+ std::string t_strImg = "";
+ if (!fdfsClient.fastFds->uploadFile(buffer, t_strImg, "jpg")) {
+ img_url = "upload image fail";
+ } else {
+ img_url.append(t_strImg);
+ img_url.clear();
+ img_url = t_strImg;
+// img_url.append("/").append(t_strImg);
+ }
+ }
+ fdfsClient.rwLock.unlock();
+
}
auto size = feature_base64.size();
// std::string uuid = "";
@@ -2336,7 +2349,7 @@
// sub = sub > 3000 ? sub - 3000 : 0000;
//shijian yuejie buchang
// sub = sub < 0 ? 0000 : sub;
- int haomiao = sub % 1000;
+ int haomiao = (sub % 1000) > 50 ? ((sub % 1000) - 50) : 0;
sub /= 1000;
int m = sub;
int shi, fen, miao;
@@ -2345,10 +2358,10 @@
shi = m / 3600;
fen = m / 60 % 60;
miao = m % 60;
- sprintf(ch_time, "%02d:%02d:%02d.%03d", shi, fen, miao, haomiao);
- cout << ch_time << endl;
- } else printf("杈撳叆鏁板�煎お澶�");
+ sprintf(ch_time, "%02d:%02d:%02d.%02d", shi, fen, miao, haomiao / 10);
+ } else printf("杈撳叆鏁板�煎お澶�");
+ DBG("ch_time" << ch_time);
std::string str_time(ch_time);
//#todo 鎸夌収鏃堕棿鍛藉悕
std::string str_imgName(AppUtil::getTimeString() + ".jpg");// = "test.jpg";
@@ -2358,9 +2371,27 @@
std::string str_tmpTime = AppUtil::getCmdResult(cmd_getVideoFileTime);
+
+
if (str_time > str_tmpTime) {
- ERR("{\"error\":\"Time error\"}" << str_time << " str_tmpTime " << str_tmpTime);
- str_time = str_tmpTime.size() > 0 ? str_tmpTime.substr(0, str_tmpTime.rfind(".")) : str_time;
+
+ //str_time = str_tmpTime.size() > 0 ? str_tmpTime : str_time;
+ qint64 v_time=getVideoTime(str_tmpTime)-1000;
+ int haomiao = (v_time % 1000) > 50 ? ((v_time % 1000) - 50) : 0;
+ v_time /= 1000;
+ int m = v_time;
+ int shi, fen, miao;
+ char ch_time[128];
+ if (m / 3600 < 24) {
+ shi = m / 3600;
+ fen = m / 60 % 60;
+ miao = m % 60;
+ sprintf(ch_time, "%02d:%02d:%02d.%02d", shi, fen, miao, haomiao / 10);
+
+ } else printf("杈撳叆鏁板�煎お澶�");
+
+ str_time=ch_time;
+ ERR("{\"error\":\"Time error\"}" << str_time << " str_tmpTime " << str_tmpTime<<" ch_time="<<ch_time);
// return "{\"error\":\"Time error\"}";
}
@@ -2541,16 +2572,19 @@
DBG("path=" << vec[i]);
t_FilePath += vec[i] + ".mp4";
sub = t - t1;
- find = true;
+// find = sub < getVideoTime(t_FilePath);
break;
}
} else {
sub = t - t1;
- if (t >= t1 && sub <= 3000) {
+ if (t >= t1) {
DBG("path=" << vec[i]);
t_FilePath += vec[i] + ".mp4";
- find = true;
+
+// find = sub < getVideoTime(t_FilePath);
+
+ DBG("find:" << find);
break;
}
}
@@ -2558,11 +2592,35 @@
}
DBG("sub=" << sub);
- if (!find) {
- t_FilePath = "";
- }
+// if (!find) {
+// t_FilePath = "";
+// }
return t_FilePath;
+}
+
+qint64 devHttpServer_c::getVideoTime(/*const std::string &videoPath,*/std::string& str_tmpTime) {
+// std::string cmd_getVideoFileTime(
+// " ffmpeg -i '" + videoPath + "' 2>&1 | grep 'Duration' | cut -d ' ' -f 4 | sed s/,//");
+
+// str_tmpTime = AppUtil::getCmdResult(cmd_getVideoFileTime);
+ DBG("str_tmpTime:" << str_tmpTime);//00:00:06.89
+ qint64 len_ms = 0;
+
+ QStringList list = QString::fromStdString(str_tmpTime).split(":");
+ if (list.size() == 3) {
+ len_ms = list[0].toInt() * 60 * 60 * 1000;
+ len_ms += list[1].toInt() * 60 * 1000;
+
+ QStringList s = list[2].split(".");
+ if (s.size() == 2) {
+ len_ms += s[0].toInt() * 1000;
+ len_ms += s[1].toInt() * 10;
+ }
+
+ }
+ DBG("len_ms:" << len_ms);
+ return len_ms;
}
std::vector<std::string> devHttpServer_c::forEachFile(const std::string &dir_name) {
@@ -2774,4 +2832,4 @@
return "";
// return "{\"error\":\"浼犺緭閿欒锛岃妫�鏌ワ紒\"}";
}
-}
\ No newline at end of file
+}
--
Gitblit v1.8.0