Merge branch 'yw.1.2.fixbug' of http://192.168.1.226:10010/r/development/c++ into yw.1.2.fixbug
| | |
| | | #add_subdirectory(VideoToImage) |
| | | add_subdirectory(UnitTest) |
| | | add_subdirectory(VideoToImageMulth) |
| | | add_subdirectory(GB28181DecoderModel) |
| | | #add_subdirectory(GB28181DecoderModel) |
| | | #add_subdirectory(FaceSearchDbWithImg) |
| | | |
| | |
| | | fdfsClient.rwLock.unlock(); |
| | | } |
| | | |
| | | //# http client 127.0.0.1:9999/resetFdfs |
| | | std::string http_cmd = "http://127.0.0.1:9999/resetFdfs"; |
| | | HttpRequestWithCrul httpRequestWithCrul; |
| | | std::string response_bak = ""; |
| | | std::string postParams_bak = ""; |
| | | httpRequestWithCrul.curl_post_req("http://127.0.0.1:9999/resetFdfs", postParams_bak, response_bak); |
| | | // //# http client 127.0.0.1:9999/resetFdfs |
| | | // std::string http_cmd = "http://127.0.0.1:9999/resetFdfs"; |
| | | // HttpRequestWithCrul httpRequestWithCrul; |
| | | // std::string response_bak = ""; |
| | | // std::string postParams_bak = ""; |
| | | // httpRequestWithCrul.curl_post_req("http://127.0.0.1:9999/resetFdfs", postParams_bak, response_bak); |
| | | } |
| | | } else { |
| | | return "{\"ret_status\": \"传输错误,请检查!\"}"; |
| | |
| | | // appConfig.getIntProperty("db_port") |
| | | // )) { |
| | | if (conn->connect( |
| | | "basic_business_table", |
| | | "EGEyesForVSS", |
| | | "127.0.0.1", |
| | | "root", |
| | | "root", |
| | | "123456", |
| | | 3306 |
| | | )) { |
| | | cout << "connect success" << endl; |
| | |
| | | ../../../BasicPlatForm/basic/pipe/ |
| | | |
| | | |
| | | |
| | | ../../../BasicPlatForm/libs/opencv/include |
| | | |
| | | ../../../BasicPlatForm/libs/ffmpeg/include |
| | | ../../../BasicPlatForm/libs/jsoncpp/include |
| | | |
| | | |
| | | |
| | | /usr/include/x86_64-linux-gnu/qt5 |
| | |
| | | ../../../BasicPlatForm/libs/ffmpeg/lib |
| | | ../../../BasicPlatForm/libs/jsoncpp/lib |
| | | |
| | | # ../../../BasicPlatForm/libs/libuuid/lib |
| | | # ../../../BasicPlatForm/libs/libuuid/lib |
| | | |
| | | |
| | | ../../../BasicPlatForm/libs/hiredis-master/lib |
| | | ) |
| | | |
| | | add_executable(${PROJECT_NAME} |
| | | ../../../BasicPlatForm/basic/pipe_element/ffmpeg/VideoChangeScore.cpp |
| | | ../../../BasicPlatForm/basic/pipe_element/ffmpeg/FfmpegElement.cpp |
| | | ../StructureApp/NewRecordVideoElement.cpp |
| | | ../../../BasicPlatForm/basic/timer_counter/TimerRecorder.cpp |
| | | ../../../BasicPlatForm/basic/pipe_element/ffmpeg/VideoChangeScore.cpp |
| | | ../../../BasicPlatForm/basic/pipe_element/ffmpeg/FfmpegElement.cpp |
| | | ../StructureApp/NewRecordVideoElement.cpp |
| | | ../../../BasicPlatForm/basic/timer_counter/TimerRecorder.cpp |
| | | ../../../BasicPlatForm/basic/util/BASE64/Base64.cpp |
| | | |
| | | EncodeVideoManager.cpp |
| | | EncodeVideo.cpp |
| | | ../StructureApp/HiredisTool.cpp |
| | | main.cpp |
| | | EncodeVideoManager.cpp |
| | | EncodeVideo.cpp |
| | | ../StructureApp/HiredisTool.cpp |
| | | main.cpp |
| | | ) |
| | | target_link_libraries(${PROJECT_NAME} |
| | | ${LIBS} |
| | |
| | | ENABLEGLOG(GET_STR_CONFIG("logPath").c_str()); |
| | | auto ich = Ice::initialize(argc, argv); |
| | | |
| | | appPref.setLongData("gpu.index", 1); |
| | | appPref.setLongData("gpu.index", 0); |
| | | appPref.setLongData("thread.max", 32); |
| | | |
| | | IceRpcServer<FaceDetectServerI> server("faceServer", 10002, "tcp"); |
| | |
| | | ../../../BasicPlatForm/libs/Ice-3.7.0/lib64 |
| | | ../../../BasicPlatForm/libs/opencv/lib |
| | | ../../../BasicPlatForm/libs/ffmpeg/lib |
| | | ../../../BasicPlatForm/libs/Casia_Face/FaceSdk/lib/cpu |
| | | ../../../BasicPlatForm/libs/Casia_Face/FaceSdk/lib/gpu |
| | | ../../../BasicPlatForm/libs/crul/lib |
| | | ../../../BasicPlatForm/libs/jsoncpp/lib |
| | | ../../../BasicPlatForm/libs/libuuid/lib |
| | |
| | | ../../../../BasicPlatForm/libs/jsoncpp/lib |
| | | ) |
| | | |
| | | |
| | | add_executable(syncDBClient |
| | | main.cpp |
| | | |
| | |
| | | |
| | | DBG("\n\n\nstart\n\n"); |
| | | |
| | | appPref.setLongData("thread.max", 32); |
| | | appPref.setLongData("thread.max", 16); |
| | | //#todo |
| | | |
| | | // appPref.setStringData("ipAdd", "192.168.1.185"); |
| | |
| | | return bufsize; |
| | | } |
| | | |
| | | /*** |
| | | * 解码线程 |
| | | * @param p_this |
| | | */ |
| | | void BASICGB28181::FFmpegDecoderJPG::BareFlowDecoderThd(FFmpegDecoderJPG *p_this) { |
| | | DBG(p_this->m_camIdx << " BareFlowDecoderThd ok ... gpuIdx is " << p_this->m_gpuIdx); |
| | | p_this->m_running = true; |
| | |
| | | //# todo save package |
| | | p_this->frame_number++; |
| | | |
| | | //DBG("GotPicture "<<m_camId<<":"<<frame_number); |
| | | //放在此处是因为之前放在前面,收到的帧不完成 |
| | | p_this->SaveToPacketVector(pkt); |
| | | p_this->CheckSave(); |
| | | |
| | | int err6 = avcodec_send_packet(ctx, &pkt); |
| | | av_packet_unref(&pkt); |
| | | int err7 = avcodec_receive_frame(ctx, frame); |
| | |
| | | usleep(40000); |
| | | continue; |
| | | } |
| | | //DBG("GotPicture "<<m_camId<<":"<<frame_number); |
| | | //放在此处是因为之前放在前面,收到的帧不完成 |
| | | p_this->SaveToPacketVector(pkt); |
| | | p_this->CheckSave(); |
| | | |
| | | // BASICGB28181::avframe_to_cvmat(frame).copyTo(p_this->m_image); |
| | | p_this->m_image = std::move(BASICGB28181::avframe_to_cvmat(frame)); |
| | | |
| | | #ifdef TestCode |
| | | { |
| | | // TestCode |
| | | // TestCode 测试代码保存图片到本地 |
| | | ClockTimer cl("TestCode"); |
| | | std::string strNewTime2 = AppUtil::getTimeUSecString(); |
| | | cv::putText(p_this->m_image, strNewTime2, cv::Point(408, 540), cv::HersheyFonts::FONT_HERSHEY_PLAIN, |
| | |
| | | #ifdef TestCode |
| | | DBG("emitSigal(\"DecoderImageOK\") begin"); |
| | | #endif |
| | | |
| | | //触发信号 |
| | | gSignalLock.emitSigal(p_this->m_camIdx + "DecoderImageOK"); |
| | | //#ifdef TestCode |
| | | // DBG("emitSigal(\"DecoderImageOK\") after"); |
| | |
| | | |
| | | bool BASICGB28181::FFmpegDecoderJPG::stopThd() { |
| | | TryCath( |
| | | DBG(m_camIdx << " FFmpegDecoderJPG stopThd ... "); |
| | | DBG(m_camIdx << " FFmpegDecoderJPG stopThd ... " << m_camIdx); |
| | | m_running = false; |
| | | ); |
| | | return true; |
| | |
| | | int64_t firstKeyFrameDts = m_packetsVec[0].m_packet.dts; |
| | | for (const auto &item:m_packetsVec) { |
| | | if (item.m_frameId < lastFrameId) { |
| | | DBG("item.m_frameId < lastFrameId " << item.m_frameId << " " << lastFrameId); |
| | | conversion(const_cast<AVPacket *> (&item.m_packet), firstKeyFramePts, firstKeyFrameDts, video_st); |
| | | av_write_frame(m_pOutFmtCtx, &item.m_packet); |
| | | } else { |
| | | DBG("item.m_frameId > lastFrameId " << item.m_frameId << " " << lastFrameId); |
| | | break; |
| | | } |
| | | } |
| | |
| | | #include <iostream> |
| | | #include <unistd.h> |
| | | #include <MyQueue.h> |
| | | #include <Debug.h> |
| | | #include <atomic> |
| | | #include "GlobalSignalWaitLock.hpp" |
| | | |
| | | #include "opencv2/core.hpp" |
| | | #include "opencv2/highgui.hpp" |
| | | #include <list> |
| | | #include "GlobalSignalWaitLock.hpp" |
| | | #include "basic_struct_for_video_image.h" |
| | | |
| | | extern "C" |
| | |
| | | // Created by ps on 19-3-1. |
| | | // |
| | | |
| | | #include <basic/debug/Debug.h> |
| | | #include "GB28181Server.h" |
| | | |
| | | bool bGetLoaclRes = {false}; |
| | |
| | | bool GB28181Server::initServer() { |
| | | |
| | | bool iRet = C_InitSDK(&GBServerParam, &MysqlConnParam, NULL, enventcallback); |
| | | DBG("iRet is " << iRet); |
| | | sleep(90); |
| | | |
| | | return iRet; |
| | |
| | | #define GB28181SDK_GLOBALSIGNALWAITLOCK_H |
| | | |
| | | #include <iostream> |
| | | #include <Debug.h> |
| | | #include <basic/util/thread/RWLock.hpp> |
| | | |
| | | //#define TryCath(CODE) try { \ |
| | |
| | | #include <qt5/QtCore/QDateTime> |
| | | #include <basic/util/app/AppPreference.hpp> |
| | | #include "VideoCaptureElementWithRtp.h" |
| | | #include <VideoToImageMulth/RtspAnalysManager.h> |
| | | |
| | | //std::string BASICGB28181::VideoCaptureElementWithRtp::m_chanPubID; |
| | | //BASICGB28181::FFmpegDecoderJPG BASICGB28181::VideoCaptureElementWithRtp::m_fFmpegDecoderJPG; |
| | | |
| | | BASICGB28181::VideoCaptureElementWithRtp::VideoCaptureElementWithRtp(std::string &chanPubID, int fps, |
| | | int streamTransType, |
| | | int gpuIdx) : m_chanPubID(chanPubID), m_fps(fps), |
| | | m_running(false), |
| | | m_waitSignal(false), |
| | | m_streamTransType(streamTransType), |
| | | m_gpuIdx(gpuIdx), |
| | | m_userdata((long) this) { |
| | | int gpuIdx, RtspAnalysManager *manager) |
| | | : m_chanPubID(chanPubID), m_fps(fps), m_running(false), |
| | | m_waitSignal(false), m_streamTransType(streamTransType), |
| | | m_gpuIdx(gpuIdx), m_userdata((long) this), m_pManager(manager) { |
| | | // m_chanPubID = chanPubID; |
| | | |
| | | m_cutPath = appPref.getStringData("user.loop.absolute.path"); |
| | |
| | | cv::Mat copyMat; |
| | | std::string imageName = p_this->m_fFmpegDecoderJPG.GetImageName(); |
| | | p_this->m_image.copyTo(copyMat); |
| | | // m_pManager->SaveImageToRedis(m_camId, imageName, copyMat); |
| | | m_pManager->SaveImageToRedis(p_this->m_chanPubID, imageName, copyMat); |
| | | } |
| | | p_this->submit(); |
| | | } |
| | |
| | | #include "FFmpegDecoderJPG.h" |
| | | #include "28181SDK.h" |
| | | #include <basic/pipe/PipeElement.h> |
| | | #include "GlobalSignalWaitLock.hpp" |
| | | //#include <RtspAnalysManager.h> |
| | | //#include <VideoToImageMulth/RtspAnalysManager.h> |
| | | |
| | | class RtspAnalysManager; |
| | | |
| | | namespace BASICGB28181 { |
| | | |
| | | class VideoCaptureElementWithRtp : public basic::PipeElement { |
| | | public: |
| | | explicit VideoCaptureElementWithRtp(std::string &chanPubID, int fps, int streamTransType, int gpuIdx = -1); |
| | | explicit VideoCaptureElementWithRtp(std::string &chanPubID, int fps, int streamTransType, int gpuIdx = -1, |
| | | RtspAnalysManager *manager = nullptr); |
| | | |
| | | virtual ~VideoCaptureElementWithRtp(); |
| | | |
| | | |
| | | /*** |
| | | * 获取当前实时流接收数据线程运行状态 |
| | |
| | | FFmpegDecoderJPG m_fFmpegDecoderJPG; |
| | | cv::Mat m_image; |
| | | long m_userdata; |
| | | RtspAnalysManager *m_pManager; |
| | | |
| | | std::atomic<bool> m_running; |
| | | std::atomic<bool> m_waitSignal; |
| | |
| | | int m_index; |
| | | std::string m_camId; |
| | | std::string m_folderPath; |
| | | Json::Value m_json; |
| | | Json::Value m_json_Record; |
| | | // Json::Value m_json; |
| | | // Json::Value m_json_Record; |
| | | // Json::FastWriter m_fastWriter; |
| | | |
| | | Json::FastWriter m_fastWriter; |
| | | FastFdsWithLock *fdfsClient; |
| | | |
| | | bool bRecordVideoEnable; |
| | |
| | | appPref.getIntData("faceSear.port"), "tcp"), |
| | | // faceSearchRpcClient("faceCmServer", "", 10004, "tcp") |
| | | m_sdkRule(rule), |
| | | m_rpcClient("RtspAnalysServer", "127.0.0.1",appPref.getIntData("RpcServerPort"),"tcp") |
| | | { |
| | | m_rpcClient("RtspAnalysServer", "127.0.0.1", appPref.getIntData("RpcServerPort"), "tcp") { |
| | | sharedMemory = new QSharedMemory(QString(shareMemoryName.c_str())); |
| | | if (!sharedMemory->create(4608 * 2592 * 4)) { |
| | | sharedMemory->attach(); |
| | |
| | | std::vector<FaceToExtract> faceExtractQueueTmp; |
| | | { |
| | | std::lock_guard<std::mutex> lg(imageQueueMutex); |
| | | if (faceExtractQueue.empty()) |
| | | { |
| | | if (faceExtractQueue.empty()) { |
| | | ERR("faceExtractQueue.empty "); |
| | | return; |
| | | } |
| | |
| | | // cv::imwrite(string1, image); |
| | | // } |
| | | if (feature.empty()) { |
| | | INFO("No Face Find: "<<getProperty("imgKey")); |
| | | INFO("No Face Find: " << getProperty("imgKey")); |
| | | continue; |
| | | } |
| | | features.clear(); |
| | |
| | | CvUtil::cvMat2Buffer(faceExtractQueueTmp[i].faceImages[j], buffer); |
| | | std::string strImgUrlTmp = ""; |
| | | fdfsClient->fastFds->uploadFile(buffer, strImgUrlTmp, "jpg"); |
| | | // strImgUrl.append(fdfsClient->fastFds->getIp() + "/" + strImgUrlTmp); |
| | | DBG("strImgUrlTmp="<<strImgUrlTmp); |
| | | // strImgUrl.append(fdfsClient->fastFds->getIp() + "/" + strImgUrlTmp); |
| | | DBG("strImgUrlTmp=" << strImgUrlTmp); |
| | | strImgUrl.clear(); |
| | | strImgUrl = strImgUrlTmp; |
| | | // strImgUrl.append("/").append(strImgUrlTmp); |
| | | fdfsClient->rwLock.unlock(); |
| | | } else { |
| | | strImgUrl = ""; |
| | | ERR("fdfsClient is nullptr ???"); |
| | | } |
| | | |
| | | //拼接json |
| | |
| | | |
| | | t_json["personPicUrl"] = "";//人员图片 store |
| | | t_json["picAddress"] = getProperty("str_addr");//抓拍地址 |
| | | DBG("picAddress="<< t_json["picAddress"] ); |
| | | DBG("picAddress=" << t_json["picAddress"]); |
| | | t_json["picMaxUrl"] = "";//大图路径 |
| | | t_json["picLocalUrl"] = "";//本地路径 |
| | | t_json["picSmUrl"] = strImgUrl;//人员抓小图 |
| | |
| | | |
| | | t_json["content"] = ""; |
| | | //t_json["viType"] = "2";//只有4种类型 1:personface 2:personbody 3:car 4:bicycle 5:none 未知类型 |
| | | t_json["sdkType"] = std::to_string(m_sdkRule.nSdkType);//只有4种类型 1:personface 2:personbody 3:car 4:bicycle 5:none 未知类型 |
| | | t_json["sdkType"] = std::to_string( |
| | | m_sdkRule.nSdkType);//只有4种类型 1:personface 2:personbody 3:car 4:bicycle 5:none 未知类型 |
| | | t_json["personIsHub"] = "4";//1: 报警 2: 可疑 3: 安全 4: 未知 |
| | | |
| | | |
| | |
| | | t_json["indevicename"] = appPref.getStringData("fxDevNAME"); |
| | | |
| | | std::string strImageKey = faceExtractQueueTmp[i].scoredRects[j].properties["imgKey"]; |
| | | INFO("SaveImageKey To ES: "<<strImageKey); |
| | | INFO("SaveImageKey To ES: " << strImageKey); |
| | | t_json["imgKey"] = strImageKey; |
| | | |
| | | try { |
| | | auto server = m_rpcClient.getServer(); |
| | | if (!server) |
| | | { |
| | | if (!server) { |
| | | ERR("server is null"); |
| | | //return; |
| | | } |
| | | INFO("Record Video "<<strImageKey); |
| | | INFO("Record Video " << strImageKey); |
| | | server->recordVideo(strImageKey); |
| | | } |
| | | catch (std::exception &e) |
| | | { |
| | | ERR("Record Video Err: "<<strImageKey <<" Message: "<<e.what()); |
| | | } catch (std::exception &e) { |
| | | ERR("Record Video Err: " << strImageKey << " Message: " << e.what()); |
| | | //return; |
| | | } |
| | | auto faceSearchServer = faceSearchRpcClient.getServer(); |
| | |
| | | #include <basic/util/opencv/CvUtil.h> |
| | | #include <QJsonDocument> |
| | | #include <QJsonObject> |
| | | |
| | | #define GETSCORE(IDENT) appPref.getFloatData(IDENT) == -1 ? 95 : appPref.getFloatData(IDENT); |
| | | |
| | | //************************************ |
| | |
| | | } |
| | | |
| | | //todo appPref.getStringData("face.detect.proxy") |
| | | FaceRpcElement::FaceRpcElement(string shareMemoryName,const SdkRule& rule) : |
| | | FaceRpcElement::FaceRpcElement(string shareMemoryName, const SdkRule &rule) : |
| | | //#todo |
| | | rpcClient(appPref.getStringData("faceDete.proxy"), appPref.getStringData("faceDete.ip"), |
| | | appPref.getIntData("faceDete.port"), "tcp"), |
| | |
| | | trackingTrigger(nullptr), |
| | | m_sdkRule(rule), |
| | | m_bIsMask(true), |
| | | m_bSetWH(false) |
| | | { |
| | | m_bSetWH(false) { |
| | | sharedMemory = new QSharedMemory(QString(shareMemoryName.c_str())); |
| | | if (!sharedMemory->create(4608 * 2592 * 4)) { |
| | | sharedMemory->attach(); |
| | |
| | | |
| | | // string t_camIdex = getProperty("dev_id"); |
| | | //#todo |
| | | string t_camIdex; |
| | | if (shareMemoryName.find("/")) { |
| | | string_replace(shareMemoryName, "//", "/"); |
| | | auto dev_pos = shareMemoryName.find("/cut/") + 5; |
| | | auto ch_pos = shareMemoryName.find("/", dev_pos) + 1; |
| | | auto str_device_id = shareMemoryName.substr(dev_pos, ch_pos - dev_pos - 1); |
| | | auto str_ch_id = shareMemoryName.substr(ch_pos, shareMemoryName.find("/", ch_pos) - ch_pos); |
| | | t_camIdex.append(str_device_id).append(str_ch_id); |
| | | } else { |
| | | t_camIdex = shareMemoryName.substr(0, shareMemoryName.rfind("faceRpc")); |
| | | } |
| | | // string t_camIdex; |
| | | // if (shareMemoryName.find("/")) { |
| | | // string_replace(shareMemoryName, "//", "/"); |
| | | // auto dev_pos = shareMemoryName.find("/cut/") + 5; |
| | | // auto ch_pos = shareMemoryName.find("/", dev_pos) + 1; |
| | | // auto str_device_id = shareMemoryName.substr(dev_pos, ch_pos - dev_pos - 1); |
| | | // auto str_ch_id = shareMemoryName.substr(ch_pos, shareMemoryName.find("/", ch_pos) - ch_pos); |
| | | // t_camIdex.append(str_device_id).append(str_ch_id); |
| | | // } else { |
| | | // t_camIdex = shareMemoryName.substr(0, shareMemoryName.rfind("faceRpc")); |
| | | // } |
| | | |
| | | float t_score = m_sdkRule.nQuality; |
| | | |
| | | DBG(" TESTCODE getValue" << t_camIdex << " " << t_score << " " << t_score / 100); |
| | | DBG(" TESTCODE getValue" << shareMemoryName << " " << t_score << " " << t_score / 100); |
| | | |
| | | t_score = t_score / 100; |
| | | |
| | |
| | | // string string1(AppUtil::getTimeString() + "-ff2" + getProperty("time") + ".jpg"); |
| | | // cv::imwrite(string1, image); |
| | | // } |
| | | if(!isInWeek(m_sdkRule.weekRuleVec)) |
| | | { |
| | | if (!isInWeek(m_sdkRule.weekRuleVec)) { |
| | | ERR("In Week"); |
| | | return; |
| | | } |
| | |
| | | int y = face.rcFace.top; |
| | | int w = face.rcFace.right - face.rcFace.left; |
| | | int h = face.rcFace.bottom - face.rcFace.top; |
| | | QRect re(x,y,w,h); |
| | | QRect re(x, y, w, h); |
| | | QPoint center = re.center(); |
| | | if(m_bIsMask && !mPolygon.containsPoint(center,Qt::OddEvenFill)) |
| | | { |
| | | ERR("m_bIsMask :"<<m_bIsMask) |
| | | if (m_bIsMask && !mPolygon.containsPoint(center, Qt::OddEvenFill)) { |
| | | ERR("m_bIsMask :" << m_bIsMask) |
| | | return; |
| | | } |
| | | scoredRect.rect = {x, y, w, h}; |
| | |
| | | trackingTrigger->getLastRect().properties["time"] = getProperty("time"); |
| | | trackingTrigger->getLastRect().properties["detectscore"] = scoredRect.score; |
| | | trackingTrigger->getLastRect().properties["imgKey"] = getProperty("imgKey"); |
| | | INFO("FaceRpcElement SaveToES: "<<getProperty("imgKey")); |
| | | INFO("FaceRpcElement SaveToES: " << getProperty("imgKey")); |
| | | triggerFaces.push_back(face); |
| | | triggerMats.push_back(image( |
| | | CvUtil::zoomRectEqual(scoredRect.rect, 1.5, 1.5) & cv::Rect(0, 0, image.cols, image.rows)).clone()); |
| | | triggerScoredRects.push_back(trackingTrigger->getLastRect()); |
| | | } else { |
| | | INFO("No Face Find: "<<getProperty("imgKey")); |
| | | INFO("No Face Find: " << getProperty("imgKey")); |
| | | // DBG("trackingTrigger->triggerOnce(scoredRect) is false "); |
| | | } |
| | | } |
| | | if(faces.empty()) |
| | | { |
| | | INFO("No Face Find: "<<getProperty("imgKey")); |
| | | if (faces.empty()) { |
| | | INFO("No Face Find: " << getProperty("imgKey")); |
| | | } |
| | | trackingTrigger->triggerLine(); |
| | | // DBG("faces.size " << faces.size()); |
| | |
| | | image = cv::Mat(value.rows, value.cols, CV_8UC3, sharedMemory->data()); |
| | | } |
| | | value.copyTo(image); |
| | | if(!m_bSetWH) |
| | | { |
| | | if (!m_bSetWH) { |
| | | setMask(m_sdkRule.strAreas.toStdString()); |
| | | m_bSetWH=true; |
| | | m_bSetWH = true; |
| | | } |
| | | } |
| | | |
| | | bool FaceRpcElement::getTriggerState() const { |
| | | return m_triggerElement.getTriggerState(); |
| | | } |
| | | void FaceRpcElement::setMask(std::string mask) |
| | | { |
| | | |
| | | void FaceRpcElement::setMask(std::string mask) { |
| | | QJsonArray arrayAreas = getJsonArrayFromQString(QString::fromStdString(mask)); |
| | | if(arrayAreas.isEmpty()) |
| | | { |
| | | m_bIsMask=false; |
| | | if (arrayAreas.isEmpty()) { |
| | | m_bIsMask = false; |
| | | return;//do not detect |
| | | } |
| | | float sizeW=(float)appPref.getIntData(m_sdkRule.strCamId.toStdString()+"width")/480; |
| | | float sizeH=(float)appPref.getIntData(m_sdkRule.strCamId.toStdString()+"height")/270; |
| | | for(int i = 0;i < arrayAreas.size();++i) |
| | | { |
| | | float sizeW = (float) appPref.getIntData(m_sdkRule.strCamId.toStdString() + "width") / 480; |
| | | float sizeH = (float) appPref.getIntData(m_sdkRule.strCamId.toStdString() + "height") / 270; |
| | | for (int i = 0; i < arrayAreas.size(); ++i) { |
| | | QJsonValue jsonValue = arrayAreas[i]; |
| | | QJsonObject obj = jsonValue.toObject(); |
| | | int x = obj.value("x").toDouble() *sizeW ; |
| | | int y = obj.value("y").toDouble() *sizeH; |
| | | mPolygon<<(QPoint(x,y)); |
| | | DBG("width="<<sizeW); |
| | | DBG("height="<<sizeH); |
| | | int x = obj.value("x").toDouble() * sizeW; |
| | | int y = obj.value("y").toDouble() * sizeH; |
| | | mPolygon << (QPoint(x, y)); |
| | | DBG("width=" << sizeW); |
| | | DBG("height=" << sizeH); |
| | | |
| | | } |
| | | } |
| | | QJsonArray FaceRpcElement::getJsonArrayFromQString(const QString& strJson) |
| | | { |
| | | |
| | | QJsonArray FaceRpcElement::getJsonArrayFromQString(const QString &strJson) { |
| | | QJsonDocument jsonDocument = QJsonDocument::fromJson(strJson.toLocal8Bit()); |
| | | if( jsonDocument.isNull() ){ |
| | | DBG("please check the string"<< strJson.toStdString()); |
| | | if (jsonDocument.isNull()) { |
| | | DBG("please check the string" << strJson.toStdString()); |
| | | return QJsonArray(); |
| | | } |
| | | QJsonArray jsonArray = jsonDocument.array(); |
| | | return jsonArray; |
| | | } |
| | | bool FaceRpcElement::isInWeek(const std::vector<LActRuleWeekRecord>& ruleWeek) |
| | | { |
| | | |
| | | bool FaceRpcElement::isInWeek(const std::vector<LActRuleWeekRecord> &ruleWeek) { |
| | | |
| | | int nWeek = QDate::currentDate().dayOfWeek(); |
| | | for(int i = 0;i < ruleWeek.size();++i) |
| | | { |
| | | if(ruleWeek[i].m_nType == nWeek) |
| | | { |
| | | for (int i = 0; i < ruleWeek.size(); ++i) { |
| | | if (ruleWeek[i].m_nType == nWeek) { |
| | | QString strCurrent = QDateTime::currentDateTime().toString("hh:mm"); |
| | | if(strCurrent >= ruleWeek[i].m_strBegin && strCurrent <= ruleWeek[i].m_strEnd) |
| | | { |
| | | return true; |
| | | if (strCurrent >= ruleWeek[i].m_strBegin && strCurrent <= ruleWeek[i].m_strEnd) { |
| | | return true; |
| | | } |
| | | } |
| | | } |
| | |
| | | using TASK_FUNCTION = std::function<void(std::shared_ptr<finishSdkHdlManage> &, int)>; |
| | | public: |
| | | BaiscSDKAnalysVideo(TASK_FUNCTION task_f = nullptr) : m_task_function(task_f) { |
| | | resetFdfs(); |
| | | { |
| | | std::thread httpServer([&]() { |
| | | HttpSrvRetRecieve httpSrvRetRecieve("0.0.0.0", 9090, 1); |
| | | httpSrvRetRecieve.setInfo("^/resetFdfs$", "POST", std::bind(&BaiscSDKAnalysVideo::resetFdfs, this, |
| | | std::placeholders::_1, |
| | | std::placeholders::_2, |
| | | std::placeholders::_3)); |
| | | httpSrvRetRecieve.start(); |
| | | httpSrvRetRecieve.waitForShutDown(); |
| | | }); |
| | | httpServer.detach(); |
| | | } |
| | | // resetFdfs(); |
| | | // { |
| | | // std::thread httpServer([&]() { |
| | | // HttpSrvRetRecieve httpSrvRetRecieve("0.0.0.0", 9090, 1); |
| | | // httpSrvRetRecieve.setInfo("^/resetFdfs$", "POST", std::bind(&BaiscSDKAnalysVideo::resetFdfs, this, |
| | | // std::placeholders::_1, |
| | | // std::placeholders::_2, |
| | | // std::placeholders::_3)); |
| | | // httpSrvRetRecieve.start(); |
| | | // httpSrvRetRecieve.waitForShutDown(); |
| | | // }); |
| | | // httpServer.detach(); |
| | | // } |
| | | } |
| | | |
| | | ~BaiscSDKAnalysVideo() { |
| | | } |
| | | |
| | | std::string resetFdfs(std::string ip = "", unsigned int port = 0, std::string content = "") { |
| | | |
| | | std::thread reset([&]() { |
| | | fdfsClient.rwLock.rdlock(); |
| | | if (fdfsClient.fastFds != nullptr) { |
| | | delete fdfsClient.fastFds; |
| | | } |
| | | fdfsClient.fastFds = new FastFds("fastDfsClient.conf"); |
| | | fdfsClient.rwLock.unlock(); |
| | | }); |
| | | reset.detach(); |
| | | |
| | | return ""; |
| | | } |
| | | // std::string resetFdfs(std::string ip = "", unsigned int port = 0, std::string content = "") { |
| | | // |
| | | // std::thread reset([&]() { |
| | | // fdfsClient.rwLock.rdlock(); |
| | | // if (fdfsClient.fastFds != nullptr) { |
| | | // delete fdfsClient.fastFds; |
| | | // } |
| | | // fdfsClient.fastFds = new FastFds("fastDfsClient.conf"); |
| | | // fdfsClient.rwLock.unlock(); |
| | | // }); |
| | | // reset.detach(); |
| | | // |
| | | // return ""; |
| | | // } |
| | | |
| | | private: |
| | | virtual void doFunc(std::shared_ptr<getsdkHdlManage> spPacket) { |
| | |
| | | set(CMAKE_BUILD_TYPE debug) |
| | | add_compile_options(-fPIC) |
| | | add_definitions(-DGLOG) |
| | | add_definitions(-DGB28181) |
| | | add_definitions(-DDEBUG_ERR -DDEBUG_INFO -fpermissive) |
| | | SET(SOURCES |
| | | |
| | |
| | | # cudart |
| | | # cublas |
| | | opencv_world |
| | | jsoncpp |
| | | # jsoncpp |
| | | curl |
| | | uuid |
| | | pthread |
| | |
| | | } |
| | | |
| | | void RtspAnalysElement::init() { |
| | | auto lst = m_lDBTool->searchCamDevTableAll(); |
| | | Record_Config lst_dev = m_lDBTool->searchConfigTableWithinServerInfo(); |
| | | #ifndef GB28181 |
| | | auto lst = m_lDBTool->searchCamDevTableAll(); |
| | | |
| | | appPref.setIntData("n_cut_max_duration", lst_dev.n_cut_max_duration); |
| | | appPref.setIntData("n_cut_min_duration", lst_dev.n_cut_min_duration); |
| | |
| | | int CamCount = appPref.getIntData("CamStep"); |
| | | auto itor = lst.begin(); |
| | | |
| | | if(startCamNO >= lst.size()) |
| | | { |
| | | if (startCamNO >= lst.size()) { |
| | | ERR("startCamNO > lst.size()"); |
| | | return; |
| | | } |
| | | |
| | | for(int i=0; i < startCamNO; i++){ |
| | | for (int i = 0; i < startCamNO; i++) { |
| | | itor++; |
| | | } |
| | | |
| | | for (int i = 0; i < CamCount; i++) { |
| | | if (itor == lst.end()) |
| | | { |
| | | if (itor == lst.end()) { |
| | | ERR("itor == lst.end()"); |
| | | return; |
| | | } |
| | |
| | | rule.second.strAddr = itor->str_addr; |
| | | rule.second.weekRuleVec = m_lDBTool->searchCameraWeekRuleByCamId(itor->str_cam_dev_id, rule.first); |
| | | |
| | | if(rule.second.nSdkType == PerStaticSdk) |
| | | { |
| | | float temp=1-(float)(rule.second.nThreshold)/100; |
| | | rule.second.fSensitivity=(75+25*temp)/100; |
| | | if (rule.second.nSdkType == PerStaticSdk) { |
| | | float temp = 1 - (float) (rule.second.nThreshold) / 100; |
| | | rule.second.fSensitivity = (75 + 25 * temp) / 100; |
| | | |
| | | } |
| | | else if(rule.second.nSdkType != FaceSdk) |
| | | { |
| | | float temp=1-(float)(rule.second.nThreshold)/100; |
| | | rule.second.fSensitivity=(5+90*temp)/100; |
| | | } else if (rule.second.nSdkType != FaceSdk) { |
| | | float temp = 1 - (float) (rule.second.nThreshold) / 100; |
| | | rule.second.fSensitivity = (5 + 90 * temp) / 100; |
| | | } |
| | | // if (rule.second.nThreshold < 5 ) |
| | | // { |
| | |
| | | addCamera(t_camIdex, ruleMap); |
| | | itor++; |
| | | } |
| | | |
| | | // for (auto item : lst) { |
| | | // std::string t_camIdex = item.str_cam_dev_id.toStdString(); |
| | | // std::string rtsp_url = rtspAddrBuild(item.str_ip.toStdString(), 554, item.str_username.toStdString(), |
| | |
| | | ERR("searchCamDevTableAll size is 0"); |
| | | } |
| | | |
| | | #else |
| | | auto lst = m_lDBTool->searchCamDevTableByType(1); |
| | | |
| | | appPref.setIntData("n_cut_max_duration", lst_dev.n_cut_max_duration); |
| | | appPref.setIntData("n_cut_min_duration", lst_dev.n_cut_min_duration); |
| | | if (lst.size() > 0) { |
| | | // Json::Value json; |
| | | |
| | | for (auto &item : lst) { |
| | | std::string t_camIdex = item.str_cam_dev_id.toStdString(); |
| | | std::string rtsp_url = "GB28181"; |
| | | // rtspAddrBuild(item.str_ip.toStdString(), 554, item.str_username.toStdString(), |
| | | // item.str_password.toStdString(), item.str_brand.toStdString()); |
| | | SdkRuleMap ruleMap = m_lDBTool->searchSdkRuleByCamId(item.str_cam_dev_id); |
| | | for (auto &rule:ruleMap) { |
| | | |
| | | rule.second.strAddr = item.str_addr; |
| | | rule.second.weekRuleVec = m_lDBTool->searchCameraWeekRuleByCamId(item.str_cam_dev_id, rule.first); |
| | | |
| | | if (rule.second.nSdkType == PerStaticSdk) { |
| | | float temp = 1 - (float) (rule.second.nThreshold) / 100; |
| | | rule.second.fSensitivity = (75 + 25 * temp) / 100; |
| | | |
| | | } else if (rule.second.nSdkType != FaceSdk) { |
| | | float temp = 1 - (float) (rule.second.nThreshold) / 100; |
| | | rule.second.fSensitivity = (5 + 90 * temp) / 100; |
| | | } |
| | | DBG("fSensitivity" << rule.second.fSensitivity); |
| | | } |
| | | appPref.setStringData(t_camIdex + "rtsp", rtsp_url); |
| | | // appPref.setStringData(t_camIdex+"addr", item.str_addr.toStdString()); |
| | | // json["rtsp"] = rtsp_url; |
| | | // json["addr"] = item.str_addr.toStdString(); |
| | | |
| | | INFO("cam add is " << item.str_addr.toStdString()); |
| | | |
| | | addCamera(t_camIdex, ruleMap); |
| | | } |
| | | } else { |
| | | ERR("searchCamDevTableAll size is 0"); |
| | | } |
| | | |
| | | #endif |
| | | } |
| | | |
| | | RtspAnalysElement::~RtspAnalysElement() { |
| | |
| | | |
| | | virtual ~RtspAnalysElement(); |
| | | |
| | | int addCamera(const std::string &, const std::map<int, SdkRule>& sdkRuleMap); |
| | | int addCamera(const std::string &, const std::map<int, SdkRule> &sdkRuleMap); |
| | | |
| | | int removeCamera(const std::string &); |
| | | |
| | |
| | | |
| | | static std::vector<int> chnString2Vec(std::string str_list); |
| | | |
| | | void setDataByType(Json::Value& json,const SdkRule& rule); |
| | | // void setDataByType(Json::Value& json,const SdkRule& rule); |
| | | |
| | | private: |
| | | LDBTool *m_lDBTool; |
| | |
| | | |
| | | int main(int argc, char **argv) { |
| | | SAVE_APP_ARGS |
| | | std::cout<<__DATE__<<" "<<__TIME__<<std::endl; |
| | | std::cout << __DATE__ << " " << __TIME__ << std::endl; |
| | | #ifdef GLOG |
| | | ENABLEGLOG(GET_STR_CONFIG("logPath").c_str()); |
| | | ENABLEGLOG(GET_STR_CONFIG("logPath").c_str()); |
| | | #endif |
| | | |
| | | #ifndef GB28181 |
| | | DBG("no GB28181"); |
| | | #else |
| | | DBG("hava GB28181"); |
| | | #endif |
| | | |
| | | appPref.setLongData("gpu.index", 0); |
| | |
| | | //todo |
| | | appPref.setIntData("CamStart", atoi(argv[1])); |
| | | appPref.setIntData("CamStep", atoi(argv[2])); |
| | | appPref.setIntData("RpcServerPort",atoi(argv[3])); |
| | | appPref.setIntData("RpcServerPort", atoi(argv[3])); |
| | | |
| | | //#todo get from config File |
| | | // appPref.setStringData("ipAdd", "192.168.1.185"); |
| | |
| | | |
| | | bool loopRet = true; |
| | | while (loopRet) { |
| | | switch (_dbTool.searchDevTypeFromConfigTable()) { |
| | | switch (_dbTool.searchDevTypeFromConfigTable()) { |
| | | |
| | | case 0: { |
| | | DBG("case 0"); |
| | |
| | | #include <QDateTime> |
| | | #include <QVector> |
| | | #include <map> |
| | | struct Record_Storage_Dev |
| | | { |
| | | Record_Storage_Dev() |
| | | { |
| | | |
| | | struct Record_Storage_Dev { |
| | | Record_Storage_Dev() { |
| | | n_id = 0; |
| | | str_storage_dev_id = ""; |
| | | str_dev_name = ""; |
| | |
| | | QString str_reserved;//截图地址 |
| | | }; |
| | | |
| | | struct Record_Cam_Dev |
| | | { |
| | | Record_Cam_Dev() |
| | | { |
| | | struct Record_Cam_Dev { |
| | | Record_Cam_Dev() { |
| | | n_id = 0; |
| | | str_name = ""; |
| | | str_addr = ""; |
| | |
| | | str_password = ""; |
| | | str_brand = ""; |
| | | str_reserved = ""; |
| | | n_type = -1; |
| | | } |
| | | |
| | | int n_id;//自增id |
| | |
| | | QString str_password;//摄像机密码 |
| | | QString str_brand;//摄像机品牌 |
| | | QString str_reserved;//预留 |
| | | int n_type;//预留 |
| | | }; |
| | | |
| | | struct Record_Cam_Chn |
| | | { |
| | | struct Record_Cam_Chn { |
| | | |
| | | Record_Cam_Chn() |
| | | { |
| | | Record_Cam_Chn() { |
| | | n_id = 0; |
| | | str_storage_dev_id = ""; |
| | | n_chn = 0; |
| | |
| | | QString str_reserved;//预留 |
| | | }; |
| | | |
| | | struct Record_Load_File_info |
| | | { |
| | | struct Record_Load_File_info { |
| | | |
| | | // Record_Load_File_info() |
| | | // { |
| | |
| | | QString str_reserved;//预留 |
| | | }; |
| | | |
| | | struct Record_Cut_Video_info |
| | | { |
| | | struct Record_Cut_Video_info { |
| | | |
| | | // Record_Cut_Video_info() |
| | | // { |
| | |
| | | QString str_reserved;//预留 |
| | | }; |
| | | |
| | | struct Record_Sdk_Hdl_info |
| | | { |
| | | struct Record_Sdk_Hdl_info { |
| | | |
| | | // Record_Sdk_Hdl_info() |
| | | // { |
| | |
| | | QString str_reserved;//预留 |
| | | }; |
| | | |
| | | struct Record_Chn_Sdk |
| | | { |
| | | struct Record_Chn_Sdk { |
| | | |
| | | Record_Chn_Sdk() |
| | | { |
| | | Record_Chn_Sdk() { |
| | | n_id = 0; |
| | | str_storage_dev_id = ""; |
| | | n_chn = 0; |
| | |
| | | QString str_reserved;//预留 |
| | | }; |
| | | |
| | | struct Record_Cam_Sdk |
| | | { |
| | | struct Record_Cam_Sdk { |
| | | |
| | | Record_Cam_Sdk() |
| | | { |
| | | Record_Cam_Sdk() { |
| | | n_id = 0; |
| | | str_cam_dev_id = ""; |
| | | str_sdks = ""; |
| | |
| | | QString str_reserved;//预留 |
| | | }; |
| | | |
| | | struct Record_Config |
| | | { |
| | | Record_Config() |
| | | { |
| | | struct Record_Config { |
| | | Record_Config() { |
| | | str_alarm_ip = ""; |
| | | n_alarm_port = 0; |
| | | str_web_pic_ip = ""; |
| | |
| | | n_dev_type = 0; |
| | | str_reserved = ""; |
| | | dev_id = ""; |
| | | dev_name= ""; |
| | | dev_name = ""; |
| | | } |
| | | |
| | | QString str_alarm_ip;//报警服务器ip |
| | |
| | | QString dev_name; |
| | | }; |
| | | |
| | | struct LActRuleWeekRecord |
| | | { |
| | | LActRuleWeekRecord() |
| | | { |
| | | m_strCamId=""; |
| | | m_nSdkType=0; |
| | | struct LActRuleWeekRecord { |
| | | LActRuleWeekRecord() { |
| | | m_strCamId = ""; |
| | | m_nSdkType = 0; |
| | | m_nType = 0; |
| | | m_strBegin = ""; |
| | | m_strEnd = ""; |
| | | } |
| | | |
| | | QString m_strCamId; |
| | | int m_nSdkType; |
| | | int m_nType; //周几 |
| | |
| | | }; |
| | | |
| | | |
| | | struct SdkRule |
| | | { |
| | | SdkRule() |
| | | { |
| | | nIsRun=0; |
| | | nSdkType = 0 ; |
| | | struct SdkRule { |
| | | SdkRule() { |
| | | nIsRun = 0; |
| | | nSdkType = 0; |
| | | strCamId = ""; |
| | | strAreas = ""; |
| | | strLine = ""; |
| | | strImageUrl = ""; |
| | | nTriggerTolerance = 0; |
| | | nTriggerDelay=0; |
| | | nQuality=0; |
| | | nThreshold=0; |
| | | nTriggerDelay = 0; |
| | | nQuality = 0; |
| | | nThreshold = 0; |
| | | nAlarmNumUpperLimit = 0; |
| | | nAlarmNumLowerLimit = 0; |
| | | fSensitivity=0; |
| | | strExAreas=""; |
| | | strLine=""; |
| | | strAddr=""; |
| | | fSensitivity = 0; |
| | | strExAreas = ""; |
| | | strLine = ""; |
| | | strAddr = ""; |
| | | } |
| | | |
| | | int nSdkType; |
| | | QString strCamId; |
| | | QString strAreas; //监测区域 |
| | |
| | | |
| | | std::vector<LActRuleWeekRecord> weekRuleVec; |
| | | }; |
| | | typedef std::map<int,SdkRule> SdkRuleMap; |
| | | enum SdkType |
| | | { |
| | | SdkTypeStart=0, |
| | | |
| | | typedef std::map<int, SdkRule> SdkRuleMap; |
| | | enum SdkType { |
| | | SdkTypeStart = 0, |
| | | FaceSdk, |
| | | CarSdk, |
| | | YoloSdk, //人体 |
| | |
| | | ERR("deleteLDeviceTable err ,Database Error: " \ |
| | | << pModel_cam.lastError().text().toStdString() \ |
| | | << pModel_sdk.lastError().text().toStdString() \ |
| | | << pModel_week.lastError().text().toStdString() ); |
| | | << pModel_week.lastError().text().toStdString()); |
| | | // QMessageBox::warning(NULL,QObject::tr("deleteLDeviceTable"),QObject::tr("Database Error: %1").arg(pModel.lastError().text())); |
| | | return false; |
| | | } |
| | |
| | | return false; |
| | | } |
| | | } |
| | | bool LDBTool::updateCamDevSnapshot(const QString& strIp,const QString& imgUrl) |
| | | { |
| | | |
| | | bool LDBTool::updateCamDevSnapshot(const QString &strIp, const QString &imgUrl) { |
| | | QMutexLocker mutexLocker(&m_mutexVisit);//TODO |
| | | QSqlTableModel pModel(NULL, m_db); |
| | | pModel.setTable("cam_dev"); |
| | |
| | | rec.setValue("reserved", imgUrl); |
| | | |
| | | int rowCount = pModel.rowCount(); |
| | | if (rowCount > 0) |
| | | { |
| | | if (rowCount > 0) { |
| | | pModel.setRecord(0, rec);//TODO |
| | | } |
| | | |
| | | m_db.transaction();//开始事务操作 |
| | | |
| | | if (pModel.submitAll()) |
| | | { |
| | | if (pModel.submitAll()) { |
| | | m_db.commit();//提交 |
| | | return true; |
| | | } |
| | | else |
| | | { |
| | | } else { |
| | | m_db.rollback();//回滚 |
| | | ERR("updateCamDevSnapshot err ,Database Error: " << pModel.lastError().text().toStdString()); |
| | | return false; |
| | | } |
| | | } |
| | | |
| | | int LDBTool::searchCamDevNumber(void) { |
| | | QSqlTableModel pModel(NULL, m_db); |
| | | pModel.setTable("cam_dev"); |
| | |
| | | |
| | | return lst; |
| | | } |
| | | bool LDBTool::searchCamDevByCamId(QString strCamId) |
| | | { |
| | | |
| | | bool LDBTool::searchCamDevByCamId(QString strCamId) { |
| | | QMutexLocker mutexLocker(&m_mutexVisit);//TODO |
| | | std::list<Record_Cam_Dev> lst; |
| | | QSqlTableModel pModel(NULL, m_db); |
| | |
| | | |
| | | |
| | | //config 修改裁剪视频时长 |
| | | bool LDBTool::updateConfigTableByCutDuration(int n_cut_max_duration,int n_cut_min_duration) { |
| | | bool LDBTool::updateConfigTableByCutDuration(int n_cut_max_duration, int n_cut_min_duration) { |
| | | QMutexLocker mutexLocker(&m_mutexVisit);//TODO |
| | | QSqlTableModel pModel(NULL, m_db); |
| | | pModel.setTable("config"); |
| | |
| | | lRec.dev_name = rec.value("dev_name").toString(); |
| | | } |
| | | lRec.dev_id = QString::fromStdString(appConfig.getStringProperty("DEV_ID")); |
| | | if(lRec.n_cut_max_duration == 0) |
| | | { |
| | | if (lRec.n_cut_max_duration == 0) { |
| | | lRec.n_cut_max_duration = 20; |
| | | } |
| | | if(lRec.n_cut_min_duration == 0) |
| | | { |
| | | if (lRec.n_cut_min_duration == 0) { |
| | | lRec.n_cut_min_duration = 4; |
| | | } |
| | | return lRec; |
| | | } |
| | | |
| | | |
| | | |
| | | bool LDBTool::insertRecordVedioPath(QString pathKey, QString filePath) { |
| | |
| | | } |
| | | |
| | | |
| | | bool LDBTool::updateCameraWeekRule(const LActRuleWeekRecord &weekRule) { |
| | | QMutexLocker mutexLocker(&m_mutexVisit);//TODO |
| | | QSqlTableModel pModel(NULL, m_db); |
| | | pModel.setTable("rule_week"); |
| | | pModel.setFilter(QObject::tr("camera_id = '%1' and type='%2' and sdk_type='%3'").arg(weekRule.m_strCamId).arg( |
| | | weekRule.m_nType).arg(weekRule.m_nSdkType)); |
| | | pModel.setEditStrategy(QSqlTableModel::OnManualSubmit);//OnManualSubmit OnFieldChange |
| | | pModel.select(); |
| | | QSqlRecord rec = pModel.record(0); |
| | | //rec.setGenerated("id", false); |
| | | rec.setValue("camera_id", weekRule.m_strCamId); |
| | | rec.setValue("sdk_type", weekRule.m_nSdkType); |
| | | rec.setValue("type", weekRule.m_nType); |
| | | rec.setValue("begin_time", weekRule.m_strBegin); |
| | | rec.setValue("end_time", weekRule.m_strEnd); |
| | | |
| | | int rowCount = pModel.rowCount(); |
| | | if (rowCount == 0) { |
| | | pModel.insertRecord(-1, rec); |
| | | } else if (rowCount > 0) { |
| | | pModel.setRecord(0, rec);//TODO |
| | | } |
| | | |
| | | m_db.transaction();//开始事务操作 |
| | | |
| | | if (pModel.submitAll()) { |
| | | m_db.commit();//提交 |
| | | return true; |
| | | } else { |
| | | m_db.rollback();//回滚 |
| | | ERR("updateCameraWeekRule ,pModel_load Error: " << pModel.lastError().text().toStdString()); |
| | | |
| | | return false; |
| | | } |
| | | } |
| | | |
| | | std::vector<LActRuleWeekRecord> LDBTool::searchCameraWeekRuleByCamId(const QString &camId, const int &sdkType) { |
| | | std::vector<LActRuleWeekRecord> vecWeek; |
| | | QMutexLocker mutexLocker(&m_mutexVisit);//TODO |
| | | QSqlTableModel pModel(NULL, m_db); |
| | | pModel.setTable("rule_week"); |
| | | pModel.setFilter(QObject::tr("camera_id = '%1' and sdk_type='%2'").arg(camId).arg(sdkType)); |
| | | pModel.setEditStrategy(QSqlTableModel::OnManualSubmit);//OnManualSubmit OnFieldChange |
| | | pModel.select(); |
| | | |
| | | int rowCount = pModel.rowCount(); |
| | | for (int i = 0; i < rowCount; ++i) { |
| | | LActRuleWeekRecord lActRuleWeekRec; |
| | | QSqlRecord rec = pModel.record(i); |
| | | lActRuleWeekRec.m_nSdkType = rec.value("sdk_type").toInt(); |
| | | lActRuleWeekRec.m_nType = rec.value("type").toInt(); |
| | | lActRuleWeekRec.m_strBegin = rec.value("begin_time").toString(); |
| | | lActRuleWeekRec.m_strEnd = rec.value("end_time").toString(); |
| | | lActRuleWeekRec.m_strCamId = rec.value("camera_id").toString(); |
| | | vecWeek.push_back(lActRuleWeekRec); |
| | | } |
| | | |
| | | return vecWeek; |
| | | } |
| | | |
| | | |
| | | bool LDBTool::updateCameraWeekRule(const LActRuleWeekRecord& weekRule) |
| | | { |
| | | QMutexLocker mutexLocker(&m_mutexVisit);//TODO |
| | | QSqlTableModel pModel(NULL, m_db); |
| | | pModel.setTable("rule_week"); |
| | | pModel.setFilter(QObject::tr("camera_id = '%1' and type='%2' and sdk_type='%3'").arg(weekRule.m_strCamId).arg(weekRule.m_nType).arg(weekRule.m_nSdkType)); |
| | | pModel.setEditStrategy(QSqlTableModel::OnManualSubmit);//OnManualSubmit OnFieldChange |
| | | pModel.select(); |
| | | QSqlRecord rec = pModel.record(0); |
| | | //rec.setGenerated("id", false); |
| | | rec.setValue("camera_id",weekRule.m_strCamId); |
| | | rec.setValue("sdk_type",weekRule.m_nSdkType); |
| | | rec.setValue("type", weekRule.m_nType); |
| | | rec.setValue("begin_time", weekRule.m_strBegin); |
| | | rec.setValue("end_time",weekRule.m_strEnd); |
| | | |
| | | int rowCount = pModel.rowCount(); |
| | | if (rowCount == 0) |
| | | { |
| | | pModel.insertRecord(-1, rec); |
| | | } |
| | | else if (rowCount > 0) |
| | | { |
| | | pModel.setRecord(0, rec);//TODO |
| | | } |
| | | |
| | | m_db.transaction();//开始事务操作 |
| | | |
| | | if (pModel.submitAll()) { |
| | | m_db.commit();//提交 |
| | | return true; |
| | | } else { |
| | | m_db.rollback();//回滚 |
| | | ERR("updateCameraWeekRule ,pModel_load Error: " << pModel.lastError().text().toStdString()); |
| | | |
| | | return false; |
| | | } |
| | | } |
| | | std::vector<LActRuleWeekRecord> LDBTool::searchCameraWeekRuleByCamId(const QString& camId,const int& sdkType) |
| | | { |
| | | std::vector<LActRuleWeekRecord> vecWeek; |
| | | QMutexLocker mutexLocker(&m_mutexVisit);//TODO |
| | | QSqlTableModel pModel(NULL, m_db); |
| | | pModel.setTable("rule_week"); |
| | | pModel.setFilter(QObject::tr("camera_id = '%1' and sdk_type='%2'").arg(camId).arg(sdkType)); |
| | | pModel.setEditStrategy(QSqlTableModel::OnManualSubmit);//OnManualSubmit OnFieldChange |
| | | pModel.select(); |
| | | |
| | | int rowCount = pModel.rowCount(); |
| | | for(int i = 0;i < rowCount;++i) |
| | | { |
| | | LActRuleWeekRecord lActRuleWeekRec; |
| | | QSqlRecord rec = pModel.record(i); |
| | | lActRuleWeekRec.m_nSdkType = rec.value("sdk_type").toInt(); |
| | | lActRuleWeekRec.m_nType = rec.value("type").toInt(); |
| | | lActRuleWeekRec.m_strBegin = rec.value("begin_time").toString(); |
| | | lActRuleWeekRec.m_strEnd = rec.value("end_time").toString(); |
| | | lActRuleWeekRec.m_strCamId=rec.value("camera_id").toString(); |
| | | vecWeek.push_back(lActRuleWeekRec); |
| | | } |
| | | |
| | | return vecWeek; |
| | | } |
| | | |
| | | |
| | | |
| | | bool LDBTool::updateSdkRule(const SdkRule& sdkRule) |
| | | { |
| | | bool LDBTool::updateSdkRule(const SdkRule &sdkRule) { |
| | | QMutexLocker mutexLocker(&m_mutexVisit);//TODO |
| | | QSqlTableModel pModel(NULL, m_db); |
| | | pModel.setTable("sdk_rule"); |
| | |
| | | rec.setValue("cam_id", sdkRule.strCamId); |
| | | rec.setValue("sdk_type", sdkRule.nSdkType); |
| | | rec.setValue("area", sdkRule.strAreas); |
| | | rec.setValue("ex_area",sdkRule.strExAreas); |
| | | rec.setValue("line",sdkRule.strLine); |
| | | rec.setValue("ex_line",sdkRule.strExLine); |
| | | rec.setValue("alarm_delay",sdkRule.nTriggerDelay); |
| | | rec.setValue("tolerance",sdkRule.nTriggerTolerance); |
| | | rec.setValue("alarm_num_upper",sdkRule.nAlarmNumUpperLimit); |
| | | rec.setValue("alarm_num_lower",sdkRule.nAlarmNumLowerLimit); |
| | | rec.setValue("broadcast_area",sdkRule.strBroadcast); |
| | | rec.setValue("is_run",sdkRule.nIsRun); |
| | | rec.setValue("img_threshold",sdkRule.nThreshold); |
| | | rec.setValue("img_quality",sdkRule.nQuality); |
| | | rec.setValue("ex_area", sdkRule.strExAreas); |
| | | rec.setValue("line", sdkRule.strLine); |
| | | rec.setValue("ex_line", sdkRule.strExLine); |
| | | rec.setValue("alarm_delay", sdkRule.nTriggerDelay); |
| | | rec.setValue("tolerance", sdkRule.nTriggerTolerance); |
| | | rec.setValue("alarm_num_upper", sdkRule.nAlarmNumUpperLimit); |
| | | rec.setValue("alarm_num_lower", sdkRule.nAlarmNumLowerLimit); |
| | | rec.setValue("broadcast_area", sdkRule.strBroadcast); |
| | | rec.setValue("is_run", sdkRule.nIsRun); |
| | | rec.setValue("img_threshold", sdkRule.nThreshold); |
| | | rec.setValue("img_quality", sdkRule.nQuality); |
| | | |
| | | int rowCount = pModel.rowCount(); |
| | | if (rowCount == 0) |
| | | { |
| | | if (rowCount == 0) { |
| | | pModel.insertRecord(-1, rec); |
| | | } |
| | | else if (rowCount > 0) |
| | | { |
| | | } else if (rowCount > 0) { |
| | | pModel.setRecord(0, rec);//TODO |
| | | } |
| | | |
| | | m_db.transaction();//开始事务操作 |
| | | |
| | | if (pModel.submitAll()) |
| | | { |
| | | if (pModel.submitAll()) { |
| | | m_db.commit();//提交 |
| | | return true; |
| | | } |
| | | else |
| | | { |
| | | } else { |
| | | m_db.rollback();//回滚 |
| | | ERR("updateSdkRule ,pModel_load Error: " << pModel.lastError().text().toStdString()); |
| | | return false; |
| | | } |
| | | } |
| | | SdkRuleMap LDBTool::searchSdkRuleByCamId(const QString& camId) |
| | | { |
| | | |
| | | SdkRuleMap LDBTool::searchSdkRuleByCamId(const QString &camId) { |
| | | QMutexLocker mutexLocker(&m_mutexVisit);//TODO |
| | | QSqlTableModel pModel(NULL, m_db); |
| | | pModel.setTable("sdk_rule"); |
| | | pModel.setFilter(QObject::tr("cam_id = '%1' ").arg(camId)); |
| | | pModel.setEditStrategy(QSqlTableModel::OnManualSubmit);//OnManualSubmit OnFieldChange |
| | | pModel.select(); |
| | | std::map<int,SdkRule> ruleMap; |
| | | std::map<int, SdkRule> ruleMap; |
| | | |
| | | //std::vector<SdkRule> ruleVec; |
| | | int rowCount = pModel.rowCount(); |
| | | for(int i=0;i<rowCount;++i) |
| | | { |
| | | for (int i = 0; i < rowCount; ++i) { |
| | | SdkRule rule; |
| | | QSqlRecord rec = pModel.record(i); |
| | | rule.strCamId=rec.value("cam_id").toString(); |
| | | rule.strAreas=rec.value("area").toString(); |
| | | rule.strExAreas=rec.value("ex_area").toString(); |
| | | rule.strLine=rec.value("line").toString(); |
| | | rule.strExLine=rec.value("ex_line").toString(); |
| | | rule.nTriggerDelay=rec.value("alarm_delay").toInt(); |
| | | rule.nTriggerTolerance=rec.value("tolerance").toInt(); |
| | | rule.nQuality=rec.value("img_quality").toInt(); |
| | | rule.nThreshold=rec.value("img_threshold").toInt(); |
| | | rule.nAlarmNumUpperLimit=rec.value("alarm_num_upper").toInt(); |
| | | rule.nAlarmNumLowerLimit=rec.value("alarm_num_lower").toInt(); |
| | | rule.strBroadcast=rec.value("broadcast_area").toString(); |
| | | rule.nIsRun=rec.value("is_run").toInt(); |
| | | rule.nSdkType=rec.value("sdk_type").toInt(); |
| | | ruleMap[rule.nSdkType]=rule; |
| | | rule.strCamId = rec.value("cam_id").toString(); |
| | | rule.strAreas = rec.value("area").toString(); |
| | | rule.strExAreas = rec.value("ex_area").toString(); |
| | | rule.strLine = rec.value("line").toString(); |
| | | rule.strExLine = rec.value("ex_line").toString(); |
| | | rule.nTriggerDelay = rec.value("alarm_delay").toInt(); |
| | | rule.nTriggerTolerance = rec.value("tolerance").toInt(); |
| | | rule.nQuality = rec.value("img_quality").toInt(); |
| | | rule.nThreshold = rec.value("img_threshold").toInt(); |
| | | rule.nAlarmNumUpperLimit = rec.value("alarm_num_upper").toInt(); |
| | | rule.nAlarmNumLowerLimit = rec.value("alarm_num_lower").toInt(); |
| | | rule.strBroadcast = rec.value("broadcast_area").toString(); |
| | | rule.nIsRun = rec.value("is_run").toInt(); |
| | | rule.nSdkType = rec.value("sdk_type").toInt(); |
| | | ruleMap[rule.nSdkType] = rule; |
| | | //ruleVec.push_back(rule); |
| | | } |
| | | |
| | |
| | | std::list<Record_Cam_Dev> lst; |
| | | QSqlTableModel pModel(NULL, m_db); |
| | | pModel.setTable("cam_dev"); |
| | | pModel.setFilter(QObject::tr((string("cam_dev_id != '' and cam_dev_id is not null and type='")+to_string(type)+"'").c_str())); |
| | | pModel.setFilter(QObject::tr( |
| | | (string("cam_dev_id != '' and cam_dev_id is not null and type='") + to_string(type) + "'").c_str())); |
| | | pModel.setEditStrategy(QSqlTableModel::OnManualSubmit);//OnManualSubmit OnFieldChange |
| | | pModel.select(); |
| | | |
| | |
| | | lChannelRec.str_password = rec.value("password").toString(); |
| | | lChannelRec.str_brand = rec.value("brand").toString(); |
| | | lChannelRec.str_reserved = rec.value("reserved").toString(); |
| | | lChannelRec.n_type = rec.value("type").toInt(); |
| | | lst.push_back(lChannelRec); |
| | | } |
| | | } |
| | |
| | | set(CMAKE_BUILD_TYPE debug) |
| | | add_compile_options(-fPIC) |
| | | add_definitions(-DGLOG) |
| | | add_definitions(-DGB28181) |
| | | add_definitions(-DDEBUG_ERR -DDEBUG_INFO -fpermissive) |
| | | add_definitions(-Wall -Wextra) |
| | | SET(LIBS |
| | |
| | | Ice |
| | | |
| | | crypto |
| | | |
| | | mysqlpp |
| | | |
| | | #ffmpeg |
| | | avformat |
| | |
| | | jsoncpp |
| | | pthread |
| | | hiredis |
| | | 28181sdk |
| | | mysqlclient |
| | | StreamParse |
| | | |
| | | ) |
| | | include_directories( |
| | | |
| | | #glog |
| | | ../../../BasicPlatForm/libs/glog/include |
| | | ./rpc |
| | |
| | | ../VideoServer/QiaoJia/DB |
| | | ../VideoServer/QiaoJia/dispatchTool |
| | | ../StructureApp/ |
| | | ../GB28181DecoderModel |
| | | ../VideoToImageMulth |
| | | |
| | | ../../../BasicPlatForm/basic/pipe_element/ffmpeg/ |
| | | ../../../BasicPlatForm/basic/debug/ |
| | | ../../../BasicPlatForm/ |
| | | |
| | | ../../../BasicPlatForm/basic/pipe/ |
| | | |
| | | |
| | | |
| | | ../../../BasicPlatForm/libs/opencv/include |
| | |
| | | |
| | | ../../BasicPlatForm/libs/hiredis-master/include |
| | | ../../../BasicPlatForm/basic/timer_counter/ |
| | | ../../../BasicPlatForm/libs/GB28181/include |
| | | |
| | | ../../../BasicPlatForm/libs/mysqlpp/include |
| | | ../../../BasicPlatForm/libs/mysql/include/mysql/ |
| | | ) |
| | | |
| | | link_directories( |
| | | ../../../BasicPlatForm/libs/GB28181/libs |
| | | #glog |
| | | ../../../BasicPlatForm/libs/glog/lib |
| | | ../../../BasicPlatForm/libs/openssl/lib |
| | |
| | | ../../../BasicPlatForm/libs/ffmpeg/lib |
| | | ../../../BasicPlatForm/libs/jsoncpp/lib |
| | | |
| | | # ../../../BasicPlatForm/libs/libuuid/lib |
| | | # ../../../BasicPlatForm/libs/libuuid/lib |
| | | ../../../BasicPlatForm/libs/Ice-3.7.0/lib64 |
| | | |
| | | ../../../BasicPlatForm/libs/hiredis-master/lib |
| | | ../../../BasicPlatForm/libs/mysqlpp/lib |
| | | ) |
| | | |
| | | add_executable(${PROJECT_NAME} |
| | | ../../../BasicPlatForm/basic/pipe_element/ffmpeg/VideoChangeScore.cpp |
| | | ../GB28181DecoderModel/FFmpegDecoderJPG.cpp |
| | | ../GB28181DecoderModel/GB28181Server.cpp |
| | | ../GB28181DecoderModel/VideoCaptureElementWithRtp.cpp |
| | | ../../../BasicPlatForm/basic/pipe_element/ffmpeg/VideoChangeScore.cpp |
| | | ../../../BasicPlatForm/basic/util/BASE64/Base64.cpp |
| | | # ../../../BasicPlatForm/basic/pipe_element/ffmpeg/FfmpegElement.cpp |
| | | ../VideoServer/QiaoJia/DB/LDBTool.cpp |
| | | ./rpc/RtspAnalysServer.cpp |
| | | RtspCaptureElement.cpp |
| | | RtspAnalysManager.cpp |
| | | ../StructureApp/HiredisTool.cpp |
| | | ../../../BasicPlatForm/basic/timer_counter/Clocktimer.h |
| | | ../../../BasicPlatForm/basic/timer_counter/Clocktimer.cpp |
| | | ./RtspImageRedis.h |
| | | ./RtspImageRedis.cpp |
| | | main.cpp |
| | | # ../../../BasicPlatForm/basic/pipe_element/ffmpeg/FfmpegElement.cpp |
| | | ../VideoServer/QiaoJia/DB/LDBTool.cpp |
| | | ./rpc/RtspAnalysServer.cpp |
| | | RtspCaptureElement.cpp |
| | | RtspAnalysManager.cpp |
| | | ../StructureApp/HiredisTool.cpp |
| | | ../../../BasicPlatForm/basic/timer_counter/Clocktimer.h |
| | | ../../../BasicPlatForm/basic/timer_counter/Clocktimer.cpp |
| | | ../../../BasicPlatForm/basic/util/net_config/net_config.cpp |
| | | ./RtspImageRedis.h |
| | | ./RtspImageRedis.cpp |
| | | main.cpp |
| | | ) |
| | | target_link_libraries(${PROJECT_NAME} |
| | | ${LIBS} |
| | |
| | | //初始化函数 |
| | | void RtspAnalysManager::init() { |
| | | INFO("MYH DEBUG HERE") |
| | | auto lst = m_lDBTool->searchCamDevTableAll(); |
| | | Record_Config lst_dev = m_lDBTool->searchConfigTableWithinServerInfo(); |
| | | |
| | | //设置视频的最长和最短时间间隔 |
| | | appPref.setIntData("n_cut_max_duration", lst_dev.n_cut_max_duration); |
| | | appPref.setIntData("n_cut_min_duration", lst_dev.n_cut_min_duration); |
| | | if (lst.size() > 0) { |
| | | int startCamNO = appPref.getIntData("CamStart") * appPref.getIntData("CamStep"); |
| | | int CamCount = appPref.getIntData("CamStep"); |
| | | INFO("StartCamNO: " << startCamNO << " CamStep: " << CamCount); |
| | | auto itor = lst.begin(); |
| | | m_GB28181_Enable = appPref.getIntData("GB28181_Enable"); |
| | | //#todo GB28181 |
| | | if (m_GB28181_Enable) { |
| | | auto lst = m_lDBTool->searchCamDevTableByType(1); |
| | | Record_Config lst_dev = m_lDBTool->searchConfigTableWithinServerInfo(); |
| | | |
| | | if (startCamNO >= lst.size()) { |
| | | ERR("startCamNO > lst.size()"); |
| | | return; |
| | | //设置视频的最长和最短时间间隔 |
| | | appPref.setIntData("n_cut_max_duration", lst_dev.n_cut_max_duration); |
| | | appPref.setIntData("n_cut_min_duration", lst_dev.n_cut_min_duration); |
| | | if (lst.size() > 0) { |
| | | for (auto item : lst) { |
| | | std::string t_camIdex = item.str_cam_dev_id.toStdString(); |
| | | std::string rtsp_url = "GB28181"; |
| | | // rtspAddrBuild(item.str_ip.toStdString(), 554, item.str_username.toStdString(), |
| | | // item.str_password.toStdString(), item.str_brand.toStdString()); |
| | | INFO("cam add is " << item.str_addr.toStdString()); |
| | | addCamera(t_camIdex, rtsp_url); |
| | | } |
| | | } else { |
| | | ERR("searchCamDevTableAll size is 0"); |
| | | } |
| | | |
| | | for (int i = 0; i < startCamNO; i++) { |
| | | } else { |
| | | auto lst = m_lDBTool->searchCamDevTableAll(); |
| | | Record_Config lst_dev = m_lDBTool->searchConfigTableWithinServerInfo(); |
| | | |
| | | std::string t_camIdex = itor->str_cam_dev_id.toStdString(); |
| | | std::string rtsp_url = rtspAddrBuild(itor->str_ip.toStdString(), 554, itor->str_username.toStdString(), |
| | | itor->str_password.toStdString(), itor->str_brand.toStdString()); |
| | | INFO("JumpCam: " << t_camIdex << " URL: " << rtsp_url); |
| | | itor++; |
| | | } |
| | | //设置视频的最长和最短时间间隔 |
| | | appPref.setIntData("n_cut_max_duration", lst_dev.n_cut_max_duration); |
| | | appPref.setIntData("n_cut_min_duration", lst_dev.n_cut_min_duration); |
| | | if (lst.size() > 0) { |
| | | int startCamNO = appPref.getIntData("CamStart") * appPref.getIntData("CamStep"); |
| | | int CamCount = appPref.getIntData("CamStep"); |
| | | INFO("StartCamNO: " << startCamNO << " CamStep: " << CamCount); |
| | | auto itor = lst.begin(); |
| | | |
| | | for (int i = 0; i < CamCount; i++) { |
| | | if (itor == lst.end()) { |
| | | ERR("itor == lst.end()"); |
| | | if (startCamNO >= lst.size()) { |
| | | ERR("startCamNO > lst.size()"); |
| | | return; |
| | | } |
| | | std::string t_camIdex = itor->str_cam_dev_id.toStdString(); |
| | | std::string rtsp_url = rtspAddrBuild(itor->str_ip.toStdString(), 554, itor->str_username.toStdString(), |
| | | itor->str_password.toStdString(), itor->str_brand.toStdString()); |
| | | INFO("cam add is " << itor->str_addr.toStdString()); |
| | | |
| | | addCamera(t_camIdex, rtsp_url); |
| | | itor++; |
| | | } |
| | | for (int i = 0; i < startCamNO; i++) { |
| | | |
| | | std::string t_camIdex = itor->str_cam_dev_id.toStdString(); |
| | | std::string rtsp_url = rtspAddrBuild(itor->str_ip.toStdString(), 554, itor->str_username.toStdString(), |
| | | itor->str_password.toStdString(), itor->str_brand.toStdString()); |
| | | INFO("JumpCam: " << t_camIdex << " URL: " << rtsp_url); |
| | | itor++; |
| | | } |
| | | |
| | | for (int i = 0; i < CamCount; i++) { |
| | | if (itor == lst.end()) { |
| | | ERR("itor == lst.end()"); |
| | | return; |
| | | } |
| | | std::string t_camIdex = itor->str_cam_dev_id.toStdString(); |
| | | std::string rtsp_url = rtspAddrBuild(itor->str_ip.toStdString(), 554, itor->str_username.toStdString(), |
| | | itor->str_password.toStdString(), itor->str_brand.toStdString()); |
| | | INFO("cam add is " << itor->str_addr.toStdString()); |
| | | |
| | | addCamera(t_camIdex, rtsp_url); |
| | | itor++; |
| | | } |
| | | |
| | | // for (auto item : lst) |
| | | // { |
| | |
| | | // addCamera(t_camIdex, rtsp_url); |
| | | // |
| | | // } |
| | | } else { |
| | | ERR("searchCamDevTableAll size is 0"); |
| | | } else { |
| | | ERR("searchCamDevTableAll size is 0"); |
| | | } |
| | | } |
| | | |
| | | } |
| | | |
| | | RtspAnalysManager::~RtspAnalysManager() { |
| | |
| | | delete controller.second; |
| | | } |
| | | m_controllers.clear(); |
| | | for (auto controller: m_controllers_videoCapElem) { |
| | | INFO("Delete Controller: " << controller.first); |
| | | delete controller.second; |
| | | } |
| | | m_controllers_videoCapElem.clear(); |
| | | } |
| | | |
| | | /** |
| | |
| | | * @return -1 添加失败,0 添加成功 |
| | | */ |
| | | int RtspAnalysManager::addCamera(const std::string &index, const std::string &rtsp) { |
| | | auto lst = m_lDBTool->searchCamDevTableAll(); |
| | | Record_Config lst_dev = m_lDBTool->searchConfigTableWithinServerInfo(); |
| | | |
| | | if (m_controllers.find(index) == m_controllers.end()) { |
| | | INFO("MYH DEBUG HERE"); |
| | | if (m_currentCount >= m_maxCount) { |
| | | ERR("addCamera faild, camera's num is full!") |
| | | return -1; |
| | | if (m_GB28181_Enable) { |
| | | //#todo |
| | | // why search lst ? |
| | | // auto lst = m_lDBTool->searchCamDevTableAll(); |
| | | Record_Config lst_dev = m_lDBTool->searchConfigTableWithinServerInfo(); |
| | | |
| | | //#todo end |
| | | if (m_controllers_videoCapElem.find(index) == m_controllers_videoCapElem.end()) { |
| | | INFO("MYH DEBUG HERE"); |
| | | if (m_currentCount >= m_maxCount) { |
| | | ERR("addCamera faild, camera's num is full!") |
| | | return -1; |
| | | } |
| | | INFO("RTSP: " << rtsp << " INDEX:" << index); |
| | | |
| | | m_imgRedisCRwLock.wrlock(); |
| | | m_imgRedisControllers[index] = new RtspImageRedisElement(index); |
| | | m_imgRedisControllers[index]->start(); |
| | | m_imgRedisCRwLock.unlock(); |
| | | |
| | | //VideoCaptureElementWithRtp(std::string &chanPubID, int fps, int streamTransType, int gpuIdx = -1) |
| | | m_controllers_videoCapElem[index] = new BASICGB28181::VideoCaptureElementWithRtp( |
| | | const_cast<string &>(index), |
| | | 25, 0, 0, this); |
| | | m_controllers_videoCapElem[index]->SetVideoMinMaxSeconds(lst_dev.n_cut_min_duration, |
| | | lst_dev.n_cut_max_duration); |
| | | m_controllers_videoCapElem[index]->start(); |
| | | m_currentCount++; |
| | | return 0; |
| | | |
| | | } else { |
| | | removeCamera(index); |
| | | INFO("removeCamera " << index); |
| | | //DBG("removeCamera " << index); |
| | | return addCamera(index, rtsp); |
| | | } |
| | | INFO("RTSP: " << rtsp << " INDEX:" << index); |
| | | m_imgRedisControllers[index] = new RtspImageRedisElement(index); |
| | | m_imgRedisControllers[index]->start(); |
| | | |
| | | m_controllers[index] = new RtspCaptureElement(rtsp, index, 25, 3000, 0, this); |
| | | m_controllers[index]->start(); |
| | | m_controllers[index]->SetVideoMinMaxSeconds(lst_dev.n_cut_min_duration, lst_dev.n_cut_max_duration); |
| | | m_currentCount++; |
| | | return 0; |
| | | |
| | | } else { |
| | | removeCamera(index); |
| | | INFO("removeCamera " << index); |
| | | //DBG("removeCamera " << index); |
| | | return addCamera(index, rtsp); |
| | | // why search lst ? |
| | | // auto lst = m_lDBTool->searchCamDevTableAll(); |
| | | Record_Config lst_dev = m_lDBTool->searchConfigTableWithinServerInfo(); |
| | | if (m_controllers.find(index) == m_controllers.end()) { |
| | | INFO("MYH DEBUG HERE"); |
| | | if (m_currentCount >= m_maxCount) { |
| | | ERR("addCamera faild, camera's num is full!") |
| | | return -1; |
| | | } |
| | | INFO("RTSP: " << rtsp << " INDEX:" << index); |
| | | m_imgRedisControllers[index] = new RtspImageRedisElement(index); |
| | | m_imgRedisControllers[index]->start(); |
| | | |
| | | m_controllers[index] = new RtspCaptureElement(rtsp, index, 25, 3000, 0, this); |
| | | m_controllers[index]->SetVideoMinMaxSeconds(lst_dev.n_cut_min_duration, lst_dev.n_cut_max_duration); |
| | | m_controllers[index]->start(); |
| | | m_currentCount++; |
| | | return 0; |
| | | |
| | | } else { |
| | | removeCamera(index); |
| | | INFO("removeCamera " << index); |
| | | //DBG("removeCamera " << index); |
| | | return addCamera(index, rtsp); |
| | | } |
| | | } |
| | | |
| | | #ifndef GB28181 |
| | | |
| | | #else |
| | | |
| | | #endif |
| | | } |
| | | |
| | | /** |
| | |
| | | */ |
| | | int RtspAnalysManager::removeCamera(const std::string &index) { |
| | | INFO("MYH DEBUG HERE"); |
| | | #ifndef GB28181 |
| | | if (m_controllers.find(index) == m_controllers.end())return -1; |
| | | auto controller = m_controllers[index]; |
| | | controller->stop(); |
| | |
| | | m_controllers.erase(index); |
| | | m_currentCount--; |
| | | |
| | | #else |
| | | if (m_controllers_videoCapElem.find(index) == m_controllers_videoCapElem.end())return -1; |
| | | auto controller = m_controllers_videoCapElem[index]; |
| | | controller->stop(); |
| | | controller->wait(); |
| | | delete controller; |
| | | m_controllers_videoCapElem.erase(index); |
| | | m_currentCount--; |
| | | #endif |
| | | |
| | | m_imgRedisCRwLock.wrlock(); |
| | | auto imgRedis = m_imgRedisControllers[index]; |
| | | imgRedis->stop(); |
| | | imgRedis->wait(); |
| | | delete imgRedis; |
| | | m_imgRedisControllers.erase(index); |
| | | m_imgRedisCRwLock.unlock(); |
| | | INFO("MYH DEBUG HERE"); |
| | | return 0; |
| | | } |
| | |
| | | */ |
| | | int RtspAnalysManager::removeAll() { |
| | | INFO("MYH DEBUG HERE"); |
| | | #ifndef GB28181 |
| | | for (auto controller: m_controllers) { |
| | | controller.second->stop(); |
| | | } |
| | |
| | | delete controller.second; |
| | | } |
| | | m_controllers.clear(); |
| | | #else |
| | | for (auto controller: m_controllers_videoCapElem) { |
| | | controller.second->stop(); |
| | | } |
| | | for (auto controller: m_controllers_videoCapElem) { |
| | | controller.second->wait(); |
| | | delete controller.second; |
| | | } |
| | | m_controllers_videoCapElem.clear(); |
| | | #endif |
| | | INFO("MYH DEBUG HERE"); |
| | | |
| | | |
| | | m_imgRedisCRwLock.wrlock(); |
| | | for (auto controller: m_imgRedisControllers) { |
| | | controller.second->stop(); |
| | | } |
| | |
| | | controller.second->wait(); |
| | | delete controller.second; |
| | | } |
| | | m_controllers.clear(); |
| | | m_imgRedisControllers.clear(); |
| | | m_imgRedisCRwLock.unlock(); |
| | | |
| | | |
| | | m_currentCount = 0; |
| | |
| | | return m_currentCount; |
| | | } |
| | | |
| | | |
| | | //录取视频的RPC的接口函数 |
| | | ::std::string RtspAnalysManager::recordVideo(const ::std::string &name, const ::Ice::Current &) { |
| | | INFO("Record Video For: " << name); |
| | | ImageName_s_t nameSt = ImageName_s_t::fromString(name); |
| | | if (nameSt.Valid()) { |
| | | auto pCaptureElem = m_controllers.find(nameSt.m_camId); |
| | | if (pCaptureElem != m_controllers.end()) { |
| | | pCaptureElem->second->SaveVideo(name); |
| | | if (GB28181_Enable) { |
| | | auto pCaptureElem = m_controllers_videoCapElem.find(nameSt.m_camId); |
| | | if (pCaptureElem != m_controllers_videoCapElem.end()) { |
| | | //#todo ~~~~~~!!!!!!! 这里有bug 需要放开调试 |
| | | // pCaptureElem->second->SaveVideo(name); |
| | | } else { |
| | | ERR("Can not Find CamId " << nameSt.m_camId); |
| | | } |
| | | } else { |
| | | ERR("Can not Find CamId " << nameSt.m_camId); |
| | | auto pCaptureElem = m_controllers.find(nameSt.m_camId); |
| | | if (pCaptureElem != m_controllers.end()) { |
| | | pCaptureElem->second->SaveVideo(name); |
| | | } else { |
| | | ERR("Can not Find CamId " << nameSt.m_camId); |
| | | } |
| | | } |
| | | } else { |
| | | ERR("Record Video Failed:Name Not Valid Name: " << name); |
| | |
| | | |
| | | //保存视频到RtspImageRedis的队列,由RtspCaptureElement调用 |
| | | bool RtspAnalysManager::SaveImageToRedis(const std::string &camId, const std::string &imageName, const cv::Mat &img) { |
| | | INFO("MYH DEBUG HERE"); |
| | | INFO("MYH DEBUG HERE " << camId); |
| | | |
| | | // m_imgRedisCRwLock.rdlock(); |
| | | auto item = m_imgRedisControllers.find(camId); |
| | | if (item != m_imgRedisControllers.end()) { |
| | | INFO("Save Succeed Cam: " << camId << " ImageKey: " << imageName); |
| | |
| | | } else { |
| | | ERR("Save Failed Cam: " << camId << " ImageKey: " << imageName); |
| | | } |
| | | // m_imgRedisCRwLock.unlock(); |
| | | INFO("MYH DEBUG HERE"); |
| | | return true; |
| | | } |
| | |
| | | #include <map> |
| | | #include "RtspCaptureElement.h" |
| | | #include "RtspImageRedis.h" |
| | | #include <VideoServer/QiaoJia/DB/LDBTool.h> |
| | | #include "../GB28181DecoderModel/VideoCaptureElementWithRtp.h" |
| | | //#include <VideoCaptureElementWithRtp.h> |
| | | #include <QiaoJia/DB/LDBTool.h> |
| | | #include <basic/util/app/AppPreference.hpp> |
| | | #include "RtspAnalysServer.h" |
| | | //#include <GB28181DecoderModel/VideoCaptureElementWithRtp.h> |
| | | //#include <VideoToImageMulth/rpc/RtspAnalysServer.h> |
| | | |
| | | //using BASICGB28181::VideoCaptureElementWithRtp; |
| | | |
| | | //用来实现recordVideo的RPC的接口类 |
| | | class RtspAnalysManager :public ::RtspAnalys::RtspAnalysServer{ |
| | | class RtspAnalysManager : public ::RtspAnalys::RtspAnalysServer { |
| | | |
| | | public: |
| | | |
| | | RtspAnalysManager():m_maxCount(50), m_currentCount(0){ |
| | | m_lDBTool=new LDBTool; |
| | | RtspAnalysManager() : m_maxCount(50), m_currentCount(0) { |
| | | m_lDBTool = new LDBTool; |
| | | init(); |
| | | } |
| | | |
| | | RtspAnalysManager(LDBTool *_dbTool); |
| | | virtual ::std::string recordVideo(const ::std::string&, const ::Ice::Current& = ::Ice::emptyCurrent); |
| | | |
| | | virtual ::std::string recordVideo(const ::std::string &, const ::Ice::Current & = ::Ice::emptyCurrent); |
| | | |
| | | virtual ~RtspAnalysManager(); |
| | | |
| | | int addCamera(const std::string &, const std::string& rtsp); |
| | | int addCamera(const std::string &, const std::string &rtsp); |
| | | |
| | | int removeCamera(const std::string &); |
| | | |
| | |
| | | int getCurrentCamCount(); |
| | | |
| | | // 根据camId保存img到Redis,img的Key为imageName |
| | | bool SaveImageToRedis(const std::string& camId,const std::string& imageName,const cv::Mat& img); |
| | | bool SaveImageToRedis(const std::string &camId, const std::string &imageName, const cv::Mat &img); |
| | | |
| | | private: |
| | | void init(); |
| | | |
| | | private: |
| | | |
| | | RWLock m_imgRedisCRwLock; |
| | | |
| | | LDBTool *m_lDBTool; |
| | | |
| | | int m_GB28181_Enable; |
| | | |
| | | //保存CamID和RtspCaptureElement的映射关系 |
| | | std::map<std::string, RtspCaptureElement *> m_controllers; |
| | | |
| | | //保存CamID和VideoCaptureElementWithRtp的映射关系 |
| | | std::map<std::string, BASICGB28181::VideoCaptureElementWithRtp *> m_controllers_videoCapElem; |
| | | |
| | | //保存CamID和RtspImageRedisElement的映射关系 |
| | | std::map<std::string, RtspImageRedisElement*> m_imgRedisControllers; |
| | | std::map<std::string, RtspImageRedisElement *> m_imgRedisControllers; |
| | | //当前摄像头的数量 |
| | | int m_currentCount; |
| | | // 摄像头的最大数量 |
| | |
| | | #include <QString> |
| | | #include <QDateTime> |
| | | #include "RtspAnalysManager.h" |
| | | RtspCaptureElement::RtspCaptureElement(const std::string &path, const std::string& camId,int fps, int reopenTime, int gpuIndex,RtspAnalysManager* manager): |
| | | TimerElement(10),m_path(path),m_gpuIndex(gpuIndex), |
| | | m_reopenTime(reopenTime),m_camId(camId),m_pManager(manager){ |
| | | m_cutPath= appPref.getStringData("user.loop.absolute.path"); |
| | | |
| | | RtspCaptureElement::RtspCaptureElement(const std::string &path, const std::string &camId, int fps, int reopenTime, |
| | | int gpuIndex, RtspAnalysManager *manager) : |
| | | TimerElement(10), m_path(path), m_gpuIndex(gpuIndex), |
| | | m_reopenTime(reopenTime), m_camId(camId), m_pManager(manager) { |
| | | m_cutPath = appPref.getStringData("user.loop.absolute.path"); |
| | | |
| | | assert(!m_cutPath.empty()); |
| | | m_capture = new CvCapture_FFMPEG(m_camId); |
| | | } |
| | | |
| | | //定时抓取图片,通过将图片放入RtspImageRedisElement的队列中,来减少视频的丢帧 |
| | | void RtspCaptureElement::timerFunc() |
| | | { |
| | | void RtspCaptureElement::timerFunc() { |
| | | |
| | | bool ret = m_capture->grabFrame(); |
| | | if (!ret) { |
| | |
| | | cv::Mat copyMat; |
| | | img.copyTo(copyMat); |
| | | std::string imageName = m_capture->GetImageName(); |
| | | m_pManager->SaveImageToRedis(m_camId,imageName,copyMat); |
| | | m_pManager->SaveImageToRedis(m_camId, imageName, copyMat); |
| | | } |
| | | fireConnectors(); |
| | | } |
| | | |
| | | std::string RtspCaptureElement::MakeDir(const std::string &timeStamp) |
| | | { |
| | | std::string RtspCaptureElement::MakeDir(const std::string &timeStamp) { |
| | | std::string t_FilePath = m_cutPath; |
| | | |
| | | if (t_FilePath.back() != '/') { |
| | |
| | | char buf[24]; |
| | | QDateTime dt = QDateTime::fromString(QString::fromStdString(timeStamp), "yyyy-MM-dd hh:mm:ss:zzz"); |
| | | |
| | | std::string t_strTime=dt.toString("yyyyMMddhh").toStdString(); |
| | | std::string t_strTime = dt.toString("yyyyMMddhh").toStdString(); |
| | | // DBG("t_strTime="<<t_strTime); |
| | | t_FilePath.append(m_camId + "/" + t_strTime.substr(0, 6)+ "/" +t_strTime.substr(6, 2) + "/"); |
| | | t_FilePath.append(m_camId + "/" + t_strTime.substr(0, 6) + "/" + t_strTime.substr(6, 2) + "/"); |
| | | //YYYYMMDDHH |
| | | t_FilePath.append(t_strTime.substr(0,10)+ "/"); |
| | | t_FilePath.append(t_strTime.substr(0, 10) + "/"); |
| | | std::string t_cmd = "mkdir -p '"; |
| | | t_cmd.append(t_FilePath + "'"); |
| | | //#get path mkdir path |
| | |
| | | |
| | | return t_FilePath; |
| | | } |
| | | void RtspCaptureElement::SaveVideo(const std::string &strImageName) |
| | | { |
| | | INFO("SaveVideo: "<<strImageName); |
| | | std::string strTimeStamp= AppUtil::getTimeUSecString(); |
| | | std::string strPath=MakeDir(strTimeStamp); |
| | | m_capture->SaveVideoByImageName(strPath,strImageName); |
| | | |
| | | void RtspCaptureElement::SaveVideo(const std::string &strImageName) { |
| | | INFO("SaveVideo: " << strImageName); |
| | | std::string strTimeStamp = AppUtil::getTimeUSecString(); |
| | | std::string strPath = MakeDir(strTimeStamp); |
| | | m_capture->SaveVideoByImageName(strPath, strImageName); |
| | | } |
| | | |
| | | |
| | | void RtspCaptureElement::openVideo() |
| | | { |
| | | if(m_gpuIndex>=0){ |
| | | setenv("CUDA_VISIBLE_DEVICES", std::to_string(m_gpuIndex).c_str(),0); |
| | | void RtspCaptureElement::openVideo() { |
| | | if (m_gpuIndex >= 0) { |
| | | setenv("CUDA_VISIBLE_DEVICES", std::to_string(m_gpuIndex).c_str(), 0); |
| | | } |
| | | INFO("Open Video "<<m_path<<" GPU_Index: "<<m_gpuIndex); |
| | | m_capture->open(m_path.c_str(),m_gpuIndex>=0); |
| | | INFO("Open Video " << m_path << " GPU_Index: " << m_gpuIndex); |
| | | m_capture->open(m_path.c_str(), m_gpuIndex >= 0); |
| | | } |
| | | |
| | | void RtspCaptureElement::threadInitial() |
| | | { |
| | | void RtspCaptureElement::threadInitial() { |
| | | INFO("MYH DEBUG"); |
| | | openVideo(); |
| | | } |
| | | |
| | | void RtspCaptureElement::threadClosing() |
| | | { |
| | | void RtspCaptureElement::threadClosing() { |
| | | INFO("MYH DEBUG"); |
| | | m_capture->close(); |
| | | delete m_capture; |
| | | m_capture = nullptr; |
| | | } |
| | | |
| | | void RtspCaptureElement::SetVideoMinMaxSeconds(const int minSeconds, const int maxSeconds) |
| | | { |
| | | m_capture->SetMinMaxVideoSeconds(minSeconds,maxSeconds); |
| | | void RtspCaptureElement::SetVideoMinMaxSeconds(const int minSeconds, const int maxSeconds) { |
| | | m_capture->SetMinMaxVideoSeconds(minSeconds, maxSeconds); |
| | | } |
| | | |
| | |
| | | #include <opencv2/opencv.hpp> |
| | | #include "../StructureApp/HiredisTool.h" |
| | | #include <atomic> |
| | | |
| | | class RtspAnalysManager; |
| | | |
| | | struct CvCapture_FFMPEG; |
| | | |
| | | /** |
| | | * 使用ffmpeg封装的视频采集流水元素 |
| | | * 输入,rtsp地址或文件(mp4或avi)路径,输出opencv中的cv::Mat |
| | | * 支持GPU硬解码 |
| | | * 主要完成视频帧的获取以及向CvCapture_FFMPEG传送数据 |
| | | */ |
| | | class RtspCaptureElement: public TimerElement { |
| | | public: |
| | | RtspCaptureElement(const std::string& path,const std::string& camId, int fps = 30, int reOpenTime = -1, int gpuIndex = -1,RtspAnalysManager* manager= nullptr); |
| | | //保存视频接口,从RtspAnalysManager发起调用 |
| | | void SaveVideo(const std::string& strImageName); |
| | | /** |
| | | * 使用ffmpeg封装的视频采集流水元素 |
| | | * 输入,rtsp地址或文件(mp4或avi)路径,输出opencv中的cv::Mat |
| | | * 支持GPU硬解码 |
| | | * 主要完成视频帧的获取以及向CvCapture_FFMPEG传送数据 |
| | | */ |
| | | class RtspCaptureElement : public TimerElement { |
| | | public: |
| | | RtspCaptureElement(const std::string &path, const std::string &camId, int fps = 30, int reOpenTime = -1, |
| | | int gpuIndex = -1, RtspAnalysManager *manager = nullptr); |
| | | |
| | | //设置保存视频的最小和最大长度,单位是秒,实际的运行情况有一些差距,需要完善 |
| | | void SetVideoMinMaxSeconds(const int minSeconds,const int maxSeconds); |
| | | private: |
| | | //线程执行函数 |
| | | virtual void timerFunc() override; |
| | | //线程的一些变量初始化,线程启动的时候调用 |
| | | virtual void threadInitial() override; |
| | | //线程结束函数的时候调用,完成一些资源的释放 |
| | | virtual void threadClosing() override; |
| | | //打开视频 |
| | | void openVideo(); |
| | | //保存视频接口,从RtspAnalysManager发起调用 |
| | | void SaveVideo(const std::string &strImageName); |
| | | |
| | | //根据timeStamp创建路径 |
| | | std::string MakeDir(const std::string& timeStamp); |
| | | private: |
| | | //用来抓取视频的Ffmpeg的封装类 |
| | | CvCapture_FFMPEG* m_capture; |
| | | //保存视频流的路径,类似于rtsp://admin:a1234567@192.168.1.201:554/h264/ch2/main/av_stream |
| | | std::string m_path; |
| | | //设置保存视频的最小和最大长度,单位是秒,实际的运行情况有一些差距,需要完善 |
| | | void SetVideoMinMaxSeconds(const int minSeconds, const int maxSeconds); |
| | | |
| | | // Redis的工具类 |
| | | private: |
| | | //线程执行函数 |
| | | virtual void timerFunc() override; |
| | | |
| | | //线程的一些变量初始化,线程启动的时候调用 |
| | | virtual void threadInitial() override; |
| | | |
| | | //线程结束函数的时候调用,完成一些资源的释放 |
| | | virtual void threadClosing() override; |
| | | |
| | | //打开视频 |
| | | void openVideo(); |
| | | |
| | | //根据timeStamp创建路径 |
| | | std::string MakeDir(const std::string &timeStamp); |
| | | |
| | | private: |
| | | //用来抓取视频的Ffmpeg的封装类 |
| | | CvCapture_FFMPEG *m_capture; |
| | | //保存视频流的路径,类似于rtsp://admin:a1234567@192.168.1.201:554/h264/ch2/main/av_stream |
| | | std::string m_path; |
| | | |
| | | // Redis的工具类 |
| | | // HiredisTool m_redisTool; |
| | | |
| | | //对保存到Redis的图片进行计数 |
| | | std::atomic<int> m_picCount{0}; |
| | | //GPU的索引 |
| | | int m_gpuIndex; |
| | | //对保存到Redis的图片进行计数 |
| | | std::atomic<int> m_picCount{0}; |
| | | //GPU的索引 |
| | | int m_gpuIndex; |
| | | |
| | | //打开视频流失败的时候,sleep一段时间 |
| | | int m_reopenTime; |
| | | //打开视频流失败的时候,sleep一段时间 |
| | | int m_reopenTime; |
| | | |
| | | //摄像机ID |
| | | std::string m_camId; |
| | | //摄像机ID |
| | | std::string m_camId; |
| | | |
| | | //用来保存录像视频的路径 |
| | | std::string m_cutPath; |
| | | //用来保存录像视频的路径 |
| | | std::string m_cutPath; |
| | | |
| | | //几张图丢一张,目前是8张丢一张 |
| | | const int m_nPicsPickOne = 8; |
| | | //几张图丢一张,目前是8张丢一张 |
| | | const int m_nPicsPickOne = 8; |
| | | |
| | | RtspAnalysManager * m_pManager; |
| | | }; |
| | | RtspAnalysManager *m_pManager; |
| | | }; |
| | | |
| | | #endif // VIDEOCAPTUREELEMENT_H |
| | |
| | | #include <basic/util/file/FileUtil.h> |
| | | #include <basic/util/app/AppPreference.hpp> |
| | | #include <basic/util/app/AppConfig.h> |
| | | #include <basic/util/app/AppConfig.h> |
| | | |
| | | #include <GB28181Server.h> |
| | | #include <basic/util/net_config/net_config.h> |
| | | #include <DataManagerServer/vss/dao/VssLocalSettingTblSqliteDao.h> |
| | | |
| | | static void startManager(LDBTool *_dbTool) { |
| | | RtspAnalysManager rtspAnalysManager(_dbTool); |
| | |
| | | } |
| | | } |
| | | |
| | | std::string getLocalIp() { |
| | | unsigned char netmask_old[15] = {0}; |
| | | unsigned char gateway_old[15] = {0}; |
| | | unsigned char ip_old[15] = {0}; |
| | | |
| | | std::string net_ifname = appConfig.getStringProperty("netIfName"); |
| | | std::string str_ip; |
| | | |
| | | if (GetIpAddress(net_ifname.c_str(), ip_old)) { |
| | | std::string ip_old_temp((char *) ip_old); |
| | | str_ip = ip_old_temp; |
| | | } else { |
| | | // value["ipaddr"] = ""; |
| | | ERR("not get ip addr"); |
| | | } |
| | | assert(!str_ip.empty()); |
| | | return std::move(str_ip); |
| | | } |
| | | |
| | | /*** |
| | | * arg1 为-1时启用gb28181 |
| | | * @param argc |
| | | * @param argv |
| | | * @return |
| | | */ |
| | | int main(int argc, char **argv) { |
| | | std::cout << __DATE__ << " " << __TIME__ << std::endl; |
| | | SAVE_APP_ARGS |
| | |
| | | ENABLEGLOG(GET_STR_CONFIG("logPath").c_str()); |
| | | #endif |
| | | |
| | | int gindx = atoi(argv[1]) % 2; |
| | | if (argc < 4) { |
| | | assert("t_value.size()"); |
| | | } |
| | | |
| | | int arg1 = atoi(argv[1]); |
| | | |
| | | int gindx = abs(arg1) % 2; |
| | | int GB28181_Enable = abs(arg1) % 2; |
| | | DBG(gindx); |
| | | appPref.setIntData("GB28181_Enable", GB28181_Enable); |
| | | appPref.setLongData("gpu.index", gindx); |
| | | appPref.setIntData("show.image", 0); |
| | | |
| | | //todo |
| | | appPref.setIntData("CamStart", atoi(argv[1])); |
| | | appPref.setIntData("CamStart", arg1); |
| | | appPref.setIntData("CamStep", atoi(argv[2])); |
| | | appPref.setIntData("RpcServerPort", atoi(argv[3])); |
| | | if (GB28181_Enable) { |
| | | //#todo search from db |
| | | MysqlDBServerCfg mysqlDBServerCfg; |
| | | mysqlDBServerCfg.Host = getLocalIp(); |
| | | mysqlDBServerCfg.Port = 3306; |
| | | mysqlDBServerCfg.UserName = "root"; |
| | | mysqlDBServerCfg.Passwd = "123456"; |
| | | mysqlDBServerCfg.DBName = "EGEyesForVSS"; |
| | | mysqlDBServerCfg.DBConnCount = 5; |
| | | |
| | | LDBTool ldbTool; |
| | | BaseSqliteDao::setLDBTool(&ldbTool); |
| | | |
| | | //#todo search from db |
| | | Json::Value t_value; |
| | | { |
| | | LDBTool ldbTool; |
| | | BaseSqliteDao::setLDBTool(&ldbTool); |
| | | t_value = VssLocalSettingTblSqliteDao::instance()->findAllVssLocalSettingTblList(); |
| | | } |
| | | if (t_value.size() == 1 && t_value["data"].size() > 1) { |
| | | assert("t_value.size()"); |
| | | } |
| | | DBG(t_value["data"].begin()->toStyledString()); |
| | | auto &t_cfg = *t_value["data"].begin(); |
| | | GBServerCfg gbServerCfg; |
| | | gbServerCfg.SvrIp = t_cfg["ServerIp"].asString(); // 国标服务的ip地址 (本机的ip地址) |
| | | gbServerCfg.SvrPort = atoi(t_cfg["ServerPort"].asString().c_str());// 7060; // 国标服务监听的端口 |
| | | gbServerCfg.SvrPubID = t_cfg["ServerId"].asString();// "44120000002000000001"; // 国标服务器的ID |
| | | gbServerCfg.bMD5Auth = false; // 是否需要MD5加密 |
| | | gbServerCfg.UserName = t_cfg["UserAuthId"].asString();// "44120100002000000002"; // 国标服务的用户名 (下级设备注册的用户名) |
| | | gbServerCfg.Passwd = t_cfg["Password"].asString();// "123456"; // 国标服务的密码 (下级设备注册的密码) |
| | | gbServerCfg.SubScribeTime = 3600; // 订阅时间 如果为0 表示不订阅 |
| | | |
| | | SpinLock spinLock; |
| | | |
| | | bool running = false; |
| | | bool serinit = false; |
| | | auto func = [&] { |
| | | spinLock.lock(); |
| | | GB28181Server m_gbs; |
| | | m_gbs.setMysqlConnParam(mysqlDBServerCfg); |
| | | m_gbs.setGBServerParam(gbServerCfg); |
| | | DBG("initServer start before"); |
| | | running = true; |
| | | m_gbs.initServer(); |
| | | DBG("initServer start after"); |
| | | |
| | | spinLock.unlock(); |
| | | while (running) { |
| | | usleep(4000); |
| | | } |
| | | }; |
| | | |
| | | std::thread thd(func); |
| | | thd.detach(); |
| | | |
| | | usleep(400); |
| | | // ---------------------测试------------------------ |
| | | spinLock.lock(); |
| | | // if (!running) { |
| | | // ERR("running is false << DB init error"); |
| | | // exit(0); |
| | | // } |
| | | } |
| | | DBG("test start"); |
| | | |
| | | appPref.setStringData("user.loop.absolute.path", appConfig.getStringProperty("cutPath")); |
| | | IceRpcServer<RtspAnalysManager> server("RtspAnalysServer", appPref.getIntData("RpcServerPort"), "tcp"); |
| | |
| | | } |
| | | |
| | | void ImageDrawElement::darwProperty(cv::Mat &image, string key, string value, int x, int y) { |
| | | cv::putText(image, key + ": " + value, cv::Point(x, y), cv::HersheyFonts::FONT_HERSHEY_PLAIN, 1.5, |
| | | cv::Scalar(255, 255, 0), 2); |
| | | cv::putText(image, key + ": " + value, cv::Point(x, y), cv::HersheyFonts::FONT_HERSHEY_PLAIN, 4, |
| | | cv::Scalar(200, 120, 200), 3); |
| | | } |
| | | |
| | | void ImageDrawElement::processImage(cv::Mat &image) { |
| | |
| | | #include "ImageDrawElement.h" |
| | | #include "YoloRpcElement.h" |
| | | #include <basic/util/app/AppPreference.hpp> |
| | | #include <basic/util/opencv/CvUtil.h> |
| | | |
| | | class Controllor : public PipeController { |
| | | public: |
| | | Controllor(const int index, const std::string &rtsp) : m_videoCaptureElement(rtsp, 25, 1000, 0), |
| | | Controllor(const int index, const std::string &rtsp) : m_videoCaptureElement(rtsp, 25, -1, 0), |
| | | m_YoloRpcElement(std::to_string(index) + "YoloRpc") { |
| | | m_index = index; |
| | | m_rtsp = rtsp; |
| | |
| | | }); |
| | | |
| | | m_imageDrawElement.registerConnector([&] { |
| | | // ImageShowElement::showImage(std::to_string(m_index), *m_imageDrawElement.getImage()); |
| | | ImageShowElement::showImage(std::to_string(m_index), *m_imageDrawElement.getImage()); |
| | | |
| | | }); |
| | | m_videoCaptureElement.setOutPutInterval(3); |
| | |
| | | int m_index; |
| | | }; |
| | | |
| | | void darwProperty(cv::Mat &image, string key, string value, int x, int y) { |
| | | cv::putText(image, key + ": " + value, cv::Point(x, y), cv::HersheyFonts::FONT_HERSHEY_PLAIN, 1.5, |
| | | cv::Scalar(255, 255, 0), 2); |
| | | } |
| | | |
| | | //using namespace std; |
| | | int main(int argc, char *argv[]) { |
| | | SAVE_APP_ARGS |
| | | |
| | | int num = atoi(argv[1]); |
| | | std::string path(argv[2]); |
| | | int portNum = atoi(argv[3]); |
| | | // int num = atoi(argv[1]); |
| | | // std::string path(argv[2]); |
| | | // int portNum = atoi(argv[3]); |
| | | //yolo server |
| | | appPref.setStringData("yolo.proxy", "yoloServer"); |
| | | //#todo |
| | | appPref.setStringData("yolo.ip", ""); |
| | | appPref.setIntData("yolo.port", portNum); |
| | | appPref.setIntData("yolo.port", 10003); |
| | | // rpcClient(appPref.getStringData("yolo.proxy"), appPref.getStringData("yolo.ip"), appPref.getLongData("yolo.port"),"tcp"), |
| | | |
| | | for (int i = 0; i < num; i++) { |
| | | Controllor *_Controllor = new Controllor(i, path); |
| | | _Controllor->start(); |
| | | Controllor *_Controllor = new Controllor(1, "/home/bsk/210235C23NF187000045$2019-02-28-23-07-30_209850_210049.mp4"); |
| | | _Controllor->start(); |
| | | |
| | | getchar(); |
| | | |
| | | |
| | | |
| | | |
| | | YoloRpcElement m_YoloRpcElement("YoloRpc"); |
| | | ImageDrawElement m_imageDrawElement; |
| | | m_YoloRpcElement.start(); |
| | | m_imageDrawElement.start(); |
| | | auto img = cv::imread("/home/bsk/Desktop/wubao2.jpg"); |
| | | m_YoloRpcElement.setImage(img); |
| | | m_YoloRpcElement.submit(); |
| | | m_YoloRpcElement.registerConnector([&] { |
| | | }); |
| | | |
| | | sleep(2); |
| | | |
| | | auto res = m_YoloRpcElement.getLastScoreRects(); |
| | | |
| | | for (auto yoloObj: res) { |
| | | auto rect = CvUtil::zoomRect(yoloObj.rect, 1, 1); |
| | | //[{"x":1.5999756,"y":82.533325},{"x":1.5999756,"y":180.53333},{"x":61.599976,"y":175.53333},{"x":63.599976,"y":66.533325}] |
| | | //cv::rectangle(image, cv::Rect(4,328,252,480 ), cv::Scalar(0, 0, 255), 2); |
| | | cv::rectangle(img, rect, yoloObj.id >= 0 ? cv::Scalar(255, 0, 0) : cv::Scalar(0, 255, 255), 2); |
| | | int i = 0; |
| | | for (auto &property:yoloObj.properties) { |
| | | darwProperty(img, property.first, property.second, rect.x + rect.width, rect.y + 40 * i++); |
| | | } |
| | | } |
| | | cv::imwrite("img/test2.jpg", img); |
| | | cv::imshow("test", img); |
| | | // for (int i = 0; i < num; i++) { |
| | | // Controllor *_Controllor = new Controllor(i, path); |
| | | // _Controllor->start(); |
| | | // } |
| | | |
| | | // Controllor _Controllor(0, "/home/bsk/2.mp4"); |
| | | // _Controllor.start(); |
| | |
| | | if (trackingTrigger->triggerOnce(scoredRect)) { |
| | | trackingTrigger->getLastRect().properties["id"] = to_string(scoredRect.id); |
| | | trackingTrigger->getLastRect().properties["type"] = cocoData[obj.type]; |
| | | trackingTrigger->getLastRect().properties["score"] = to_string(scoredRect.score); |
| | | auto t_image = image(scoredRect.rect & cv::Rect(0, 0, image.cols, image.rows)).clone(); |
| | | triggerMats.push_back(t_image); |
| | | |
| | | } |
| | | } |
| | | trackingTrigger->triggerLine(); |