Commit 4ecd2107 authored by 郝文豪's avatar 郝文豪

1.新增一次上传3张图片接口。2.新增上传视频流物品进入3张图片和物品离开3张图片。

parent 7dff47ea
No preview for this file type
......@@ -138,7 +138,7 @@ int CommonTools::upload_file(const char* url, const char* fileName, string& resp
//return 0;
}
int CommonTools::upload_file1(const char* url, const char* fileName1, const char* fileName2, const char* fileName3, string& response) {
int CommonTools::upload_file1(const char* url, const char* fileName1, const char* fileName2, const char* fileName3,vector<string>&res, string& response) {
CURL* curl;
CURLcode ret;
curl = curl_easy_init();
......@@ -148,9 +148,10 @@ int CommonTools::upload_file1(const char* url, const char* fileName1, const char
{
curl_easy_setopt(curl, CURLOPT_URL, url); //指定url
curl_formadd(&post, &last, CURLFORM_PTRNAME, "path", CURLFORM_PTRCONTENTS, "device_cover", CURLFORM_END);//form-data key(path) 和 value(device_cover)
curl_formadd(&post, &last, CURLFORM_PTRNAME, "file", CURLFORM_FILE, fileName1, CURLFORM_FILENAME, "hello.jpg", CURLFORM_END);// form-data key(file) "./test.jpg"为文件路径 "hello.jpg" 为文件上传时文件名
curl_formadd(&post, &last, CURLFORM_PTRNAME, "file2", CURLFORM_FILE, fileName2, CURLFORM_FILENAME, "hello.jpg", CURLFORM_END);
curl_formadd(&post, &last, CURLFORM_PTRNAME, "file3", CURLFORM_FILE, fileName3, CURLFORM_FILENAME, "hello.jpg", CURLFORM_END);
curl_formadd(&post, &last, CURLFORM_PTRNAME, "file", CURLFORM_FILE, fileName1, CURLFORM_FILENAME,res[0].c_str(), CURLFORM_END);// form-data key(file) "./test.jpg"为文件路径 "hello.jpg" 为文件上传时文件名
curl_formadd(&post, &last, CURLFORM_PTRNAME, "file2", CURLFORM_FILE, fileName2, CURLFORM_FILENAME, res[1].c_str(), CURLFORM_END);
curl_formadd(&post, &last, CURLFORM_PTRNAME, "file3", CURLFORM_FILE, fileName3, CURLFORM_FILENAME, res[2].c_str(), CURLFORM_END);
curl_formadd(&post, &last, CURLFORM_PTRNAME,"type", CURLFORM_PTRCONTENTS, res[3].c_str(), CURLFORM_END);
curl_easy_setopt(curl, CURLOPT_HTTPPOST, post); //构造post参数
curl_easy_setopt(curl, CURLOPT_TIMEOUT, 3);
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_data); //绑定相应
......
......@@ -32,5 +32,5 @@ public:
// htpp put 请求
static CURLcode HttpPut(const std::string& strUrl, std::string szJson, std::string& strResponse, int nTimeout);
static CURLcode HttpDelete(const std::string& strUrl, std::string& strResponse, int nTimeout);
static int upload_file1(const char* url, const char* fileName1, const char* fileName2, const char* fileName3, string& response);
static int upload_file1(const char* url, const char* fileName1, const char* fileName2, const char* fileName3,vector<string>& res, string& response);
};
\ No newline at end of file
No preview for this file type
No preview for this file type
This diff is collapsed.
......@@ -71,7 +71,8 @@
//纠错存 code和id
unordered_map<string, int>reassion;
string realProductCodes[10];
int rest = 0;
int rest_in = 0;
int rest_out = 0;
using namespace std;
using namespace cv;
using namespace rapidjson;
......@@ -3292,23 +3293,40 @@ void save_in_image()
char name2[128] = {};
char name3[128] = {};
char name4[128] = {};
vector<string>res;
string pre1;
string pre2;
string pre3;
sprintf(name2, path, dir.c_str(), time.c_str(), time.c_str(), i++);
pre1 = pre1 + time.c_str() + "-" + "1" + ".jpg";
res.push_back(pre1);
cv::imwrite(name2, param_in.back);
sprintf(name3, path, dir.c_str(), time.c_str(), time.c_str(), i++);
pre2 = pre2 + time.c_str() + "-" + "2" + ".jpg";
res.push_back(pre2);
cv::imwrite(name3, param_in.frame_out[3].img);
sprintf(name4, path, dir.c_str(), time.c_str(), time.c_str(), i++);
pre3 = pre3 + time.c_str() + "-" + "3" + ".jpg";
res.push_back(pre3);
cv::imwrite(name4, param_in.frame_out[4].img);
if (rest < 10)
char in[10] = "IN";
res.push_back(in);
for (int i = 0; i < res.size(); i++)
{
logger->info("res:{}", res[i].c_str());
}
if (rest_in < 10)
{
rest++;
rest_in++;
Document d;
string response;
char uploadUrl[200];
string tenantStrs = "0";
sprintf(uploadUrl, upload_file1_url, dev.c_str(), tenantStrs.c_str());
logger->info("upload url is {}, imagePath is {}", uploadUrl, name2);
logger->info("upload url is {}, imagePath is {}", uploadUrl, name4);
int curlCode = CommonTools::upload_file1(uploadUrl,name2,name3,name4, response);
int curlCode = CommonTools::upload_file1(uploadUrl,name2,name3,name4,res,response);
//logger->info("response is {},curl code is {}", response.c_str(), curlCode);
string rrr= UTF_82ASCII(response);
logger->info("rrr is {}",rrr);
......@@ -3331,14 +3349,46 @@ void save_out_image()
int i = 1;
const char* path = "%s/%s/%s-%d.jpg";
char name[128] = {};
sprintf(name, path, dir.c_str(), time.c_str(), time.c_str(), i++);
cv::imwrite(name, param_in.back);
sprintf(name, path, dir.c_str(), time.c_str(), time.c_str(), i++);
cv::imwrite(name, param_in.frame_out[3].img);
sprintf(name, path, dir.c_str(), time.c_str(), time.c_str(), i++);
cv::imwrite(name, param_in.frame_out[4].img);
char name5[128] = {};
char name6[128] = {};
char name7[128] = {};
vector<string>res1;
string buf1, buf2, buf3;
sprintf(name5, path, dir.c_str(), time.c_str(), time.c_str(), i++);
buf1 = buf1 + time.c_str() + "-" + "1" + ".jpg";
res1.push_back(buf1);
cv::imwrite(name5, param_in.back);
sprintf(name6, path, dir.c_str(), time.c_str(), time.c_str(), i++);
buf2 = buf2 + time.c_str() + "-" + "2"+".jpg";
res1.push_back(buf2);
cv::imwrite(name6, param_in.frame_out[3].img);
sprintf(name7, path, dir.c_str(), time.c_str(), time.c_str(), i++);
buf3 = buf3 + time.c_str() + "-" + "3" + ".jpg";
res1.push_back(buf3);
cv::imwrite(name7, param_in.frame_out[4].img);
string out = "OUT";
res1.push_back(out);
if (rest_out < 10)
{
rest_out++;
Document d;
string response;
char uploadUrl[200];
string tenantStrs = "0";
sprintf(uploadUrl, upload_file1_url, dev.c_str(), tenantStrs.c_str());
logger->info("upload url is {}, imagePath is {}", uploadUrl, name5);
int curlCode = CommonTools::upload_file1(uploadUrl, name5, name6, name7,res1, response);
//logger->info("response is {},curl code is {}", response.c_str(), curlCode);
string rrr = UTF_82ASCII(response);
logger->info("rrr is {}", rrr);
logger->info("response is {}", response.c_str());
if (curlCode != 0) {
logger->info("上传图片失败,退出");
return;
}
}
}
void video_trace_result_callback(const char* data, int len, void* user)
......@@ -3374,8 +3424,8 @@ void video_trace_result_callback(const char* data, int len, void* user)
if (output->status == libvideopipe::MOTION_STATUS_TYPES::MOTION_OUT)
{
logger->info("检测到物品离开"); logger->info("{}", __LINE__);
//thread t_(save_out_image);
//t_.detach();
thread t_(save_out_image);
t_.detach();
if (param_in.result_queue.size() < param_in.queue_max)
{
DETECT_RESULT tem = result;
......
No preview for this file type
No preview for this file type
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment