派生自 development/c++

pansen
2019-01-10 59408e43480b48b6acd6e76641ff1a97811e7ab5
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 = "";
@@ -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 : 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,7 +2572,7 @@
                DBG("path=" << vec[i]);
                t_FilePath += vec[i] + ".mp4";
                sub = t - t1;
                find = sub < getVideoTime(t_FilePath);
//                find = sub < getVideoTime(t_FilePath);
                break;
            }
@@ -2551,7 +2582,7 @@
                DBG("path=" << vec[i]);
                t_FilePath += vec[i] + ".mp4";
                find = sub < getVideoTime(t_FilePath);
//                find = sub < getVideoTime(t_FilePath);
                DBG("find:" << find);
                break;
@@ -2561,18 +2592,18 @@
    }
    DBG("sub=" << sub);
    if (!find) {
        t_FilePath = "";
    }
//    if (!find) {
//        t_FilePath = "";
//    }
    return t_FilePath;
}
qint64 devHttpServer_c::getVideoTime(const std::string &videoPath) {
    std::string cmd_getVideoFileTime(
        " ffmpeg -i '" + videoPath + "' 2>&1 | grep 'Duration' | cut -d ' ' -f 4 | sed s/,//");
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/,//");
    std::string str_tmpTime = AppUtil::getCmdResult(cmd_getVideoFileTime);
//     str_tmpTime = AppUtil::getCmdResult(cmd_getVideoFileTime);
    DBG("str_tmpTime:" << str_tmpTime);//00:00:06.89
    qint64 len_ms = 0;
@@ -2801,4 +2832,4 @@
        return "";
//        return "{\"error\":\"传输错误,请检查!\"}";
    }
}
}