From 160eddddc4e265d5ee59a38797c30720bf46cd7c Mon Sep 17 00:00:00 2001
From: AlexeyAB <alexeyab84@gmail.com>
Date: Sun, 27 May 2018 13:53:42 +0000
Subject: [PATCH] Minor fix
---
src/yolo_console_dll.cpp | 40 +++++++++++++++++++++++++++++-----------
1 files changed, 29 insertions(+), 11 deletions(-)
diff --git a/src/yolo_console_dll.cpp b/src/yolo_console_dll.cpp
index 3bd1246..2eca267 100644
--- a/src/yolo_console_dll.cpp
+++ b/src/yolo_console_dll.cpp
@@ -11,10 +11,15 @@
#ifdef _WIN32
#define OPENCV
+#define GPU
#endif
// To use tracking - uncomment the following line. Tracking is supported only by OpenCV 3.x
-#define TRACK_OPTFLOW
+//#define TRACK_OPTFLOW
+
+//#include "C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v9.1\include\cuda_runtime.h"
+//#pragma comment(lib, "C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v9.1/lib/x64/cudart.lib")
+//static std::shared_ptr<image_t> device_ptr(NULL, [](void *img) { cudaDeviceReset(); });
#include "yolo_v2_class.hpp" // imported functions from DLL
@@ -23,19 +28,21 @@
#include "opencv2/core/version.hpp"
#ifndef CV_VERSION_EPOCH
#include "opencv2/videoio/videoio.hpp"
-#define OPENCV_VERSION CVAUX_STR(CV_VERSION_MAJOR)""CVAUX_STR(CV_VERSION_MINOR)""CVAUX_STR(CV_VERSION_REVISION)
+#define OPENCV_VERSION CVAUX_STR(CV_VERSION_MAJOR)"" CVAUX_STR(CV_VERSION_MINOR)"" CVAUX_STR(CV_VERSION_REVISION)
#pragma comment(lib, "opencv_world" OPENCV_VERSION ".lib")
+#ifdef TRACK_OPTFLOW
#pragma comment(lib, "opencv_cudaoptflow" OPENCV_VERSION ".lib")
#pragma comment(lib, "opencv_cudaimgproc" OPENCV_VERSION ".lib")
#pragma comment(lib, "opencv_core" OPENCV_VERSION ".lib")
#pragma comment(lib, "opencv_imgproc" OPENCV_VERSION ".lib")
#pragma comment(lib, "opencv_highgui" OPENCV_VERSION ".lib")
+#endif // TRACK_OPTFLOW
#else
#define OPENCV_VERSION CVAUX_STR(CV_VERSION_EPOCH)""CVAUX_STR(CV_VERSION_MAJOR)""CVAUX_STR(CV_VERSION_MINOR)
#pragma comment(lib, "opencv_core" OPENCV_VERSION ".lib")
#pragma comment(lib, "opencv_imgproc" OPENCV_VERSION ".lib")
#pragma comment(lib, "opencv_highgui" OPENCV_VERSION ".lib")
-#endif
+#endif // CV_VERSION_EPOCH
class track_kalman {
public:
@@ -219,9 +226,9 @@
int main(int argc, char *argv[])
{
- std::string names_file = "data/voc.names";
- std::string cfg_file = "cfg/yolo-voc.cfg";
- std::string weights_file = "yolo-voc.weights";
+ std::string names_file = "data/coco.names";
+ std::string cfg_file = "cfg/yolov3.cfg";
+ std::string weights_file = "yolov3.weights";
std::string filename;
if (argc > 4) { //voc.names yolo-voc.cfg yolo-voc.weights test.mp4
@@ -270,6 +277,7 @@
std::vector<bbox_t> result_vec, thread_result_vec;
detector.nms = 0.02; // comment it - if track_id is not required
std::atomic<bool> consumed, videowrite_ready;
+ bool exit_flag = false;
consumed = true;
videowrite_ready = true;
std::atomic<int> fps_det_counter, fps_cap_counter;
@@ -357,15 +365,16 @@
t_detect = std::thread([&]() {
auto current_image = det_image;
consumed = true;
- while (current_image.use_count() > 0) {
- auto result = detector.detect_resized(*current_image, frame_size, thresh, false); // true
+ while (current_image.use_count() > 0 && !exit_flag) {
+ auto result = detector.detect_resized(*current_image, frame_size.width, frame_size.height,
+ thresh, false); // true
++fps_det_counter;
std::unique_lock<std::mutex> lock(mtx);
thread_result_vec = result;
consumed = true;
cv_detected.notify_all();
if (detector.wait_stream) {
- while (consumed) cv_pre_tracked.wait(lock);
+ while (consumed && !exit_flag) cv_pre_tracked.wait(lock);
}
current_image = det_image;
}
@@ -405,6 +414,7 @@
if (key == 'f') show_small_boxes = !show_small_boxes;
if (key == 'p') while (true) if(cv::waitKey(100) == 'p') break;
if (key == 'e') extrapolate_flag = !extrapolate_flag;
+ if (key == 27) { exit_flag = true; break; }
if (output_video.isOpened() && videowrite_ready) {
if (t_videowrite.joinable()) t_videowrite.join();
@@ -424,10 +434,12 @@
}
#endif
}
+ exit_flag = true;
if (t_cap.joinable()) t_cap.join();
if (t_detect.joinable()) t_detect.join();
if (t_videowrite.joinable()) t_videowrite.join();
std::cout << "Video ended \n";
+ break;
}
else if (file_ext == "txt") { // list of image files
std::ifstream file(filename);
@@ -445,12 +457,18 @@
}
else { // image file
cv::Mat mat_img = cv::imread(filename);
+
+ auto start = std::chrono::steady_clock::now();
std::vector<bbox_t> result_vec = detector.detect(mat_img);
- result_vec = detector.tracking_id(result_vec); // comment it - if track_id is not required
+ auto end = std::chrono::steady_clock::now();
+ std::chrono::duration<double> spent = end - start;
+ std::cout << " Time: " << spent.count() << " sec \n";
+
+ //result_vec = detector.tracking_id(result_vec); // comment it - if track_id is not required
draw_boxes(mat_img, result_vec, obj_names);
cv::imshow("window name", mat_img);
- cv::waitKey(3); // 3 or 16ms
show_console_result(result_vec, obj_names);
+ cv::waitKey(0);
}
#else
//std::vector<bbox_t> result_vec = detector.detect(filename);
--
Gitblit v1.10.0