| | |
| | | #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); |
| | | } |
| | | |
| | |
| | | } |
| | | |
| | | 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(); |