From 99221e4721a1246883465c2b52fbff14eb9aaa7a Mon Sep 17 00:00:00 2001
From: pans <pansen626@sina.com>
Date: 星期六, 30 三月 2019 12:12:02 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/yangwu1.3' into yangwu1.3
---
QiaoJiaSystem/YoloServer/DnDetect.h | 89 ++++++++++++++++++++++++++++++++++++--------
1 files changed, 73 insertions(+), 16 deletions(-)
diff --git a/QiaoJiaSystem/YoloServer/DnDetect.h b/QiaoJiaSystem/YoloServer/DnDetect.h
index 3718aed..fc1a37c 100644
--- a/QiaoJiaSystem/YoloServer/DnDetect.h
+++ b/QiaoJiaSystem/YoloServer/DnDetect.h
@@ -1,26 +1,83 @@
#ifndef DNDETECT_H
#define DNDETECT_H
#define GPU
+
#include <darknet.h>
#include <opencv2/opencv.hpp>
-class DnDetect
-{
-public:
- DnDetect(const int gpuIndex);
- virtual ~DnDetect();
+#include <thread>
- std::vector<cv::Rect2f> detect(cv::Mat&);
-private:
- image matToImg(cv::Mat& RefImg);
+namespace DnDetect {
-private:
- network *m_net;
- float m_thresh;
- float m_hier_thresh;
- float m_nms;
- char **names;
+ class ClockTimer {
+ public:
+ ClockTimer(const std::string &flag, int nMscTimeout = 0) {
+ timeval time;
+ gettimeofday(&time, nullptr);
+ m_start = time.tv_sec * 1000000 + time.tv_usec;
+ m_flag = flag;
+ m_nMscTimeout = nMscTimeout;
+ }
- image **alphabet;
-};
+ ~ClockTimer() {
+ timeval time1;
+ gettimeofday(&time1, nullptr);
+ double end = time1.tv_sec * 1000000 + time1.tv_usec;
+ int n = (end - m_start) / 1000;
+ if (0 >= m_nMscTimeout) {
+// std::cout << m_flag << ">> Time elapsed: " << n << "ms" << std::endl;
+ INFO(m_flag << ">> Time elapsed: " << n << "ms");
+ } else if (n >= m_nMscTimeout) {
+// std::cout << m_flag << ">> Time out: " << n << "ms" << std::endl;
+ INFO(m_flag << ">> Time out: " << n << "ms");
+ }
+ }
+
+ private:
+ double m_start;
+ std::string m_flag;
+ int m_nMscTimeout;
+ };
+
+ struct Rect {
+ float left;
+ float top;
+ float right;
+ float bottom;
+ };
+
+ struct YoloObjInfo {
+ int type;
+ float prob;
+ Rect rcObj;
+ };
+
+ class DnDetect {
+ public:
+ DnDetect(const int gpuIndex);
+
+ virtual ~DnDetect();
+
+ std::vector<YoloObjInfo> detect(cv::Mat &);
+
+ private:
+ image matToImg(cv::Mat &RefImg);
+
+ static int init(void *arg);
+
+ private:
+ network *m_net;
+ float m_thresh;
+ float m_hier_thresh;
+ float m_nms;
+ char **names;
+ image **alphabet;
+
+ std::mutex dataMtx;
+
+ bool m_bInitThd;
+ std::thread m_thdInit;
+ };
+}
+
#endif
--
Gitblit v1.8.0