From 04c0c4fdf84bb7b9e89604e8b9a6079016d5968c Mon Sep 17 00:00:00 2001
From: Alexey <AlexeyAB@users.noreply.github.com>
Date: Wed, 04 Jul 2018 16:06:41 +0000
Subject: [PATCH] Merge pull request #1132 from tinohager/master

---
 src/yolo_v2_class.cpp |   38 ++++++++++++++++++++++++++++++++++++++
 1 files changed, 38 insertions(+), 0 deletions(-)

diff --git a/src/yolo_v2_class.cpp b/src/yolo_v2_class.cpp
index faaf8d1..4df9be5 100644
--- a/src/yolo_v2_class.cpp
+++ b/src/yolo_v2_class.cpp
@@ -22,6 +22,44 @@
 
 #define FRAMES 3
 
+//static Detector* detector = NULL;
+static std::unique_ptr<Detector> detector;
+
+int init(const char *configurationFilename, const char *weightsFilename, int gpu) 
+{
+    detector.reset(new Detector(configurationFilename, weightsFilename, gpu));
+    return 1;
+}
+
+int detect_image(const char *filename, bbox_t_container &container) 
+{
+    std::vector<bbox_t> detection = detector->detect(filename);
+    for (size_t i = 0; i < detection.size() && i < C_SHARP_MAX_OBJECTS; ++i)
+        container.candidates[i] = detection[i];
+    return detection.size();
+}
+
+int detect_mat(const uint8_t* data, const size_t data_length, bbox_t_container &container) {
+#ifdef OPENCV
+    std::vector<char> vdata(data, data + data_length);
+    cv::Mat image = imdecode(cv::Mat(vdata), 1);
+
+    std::vector<bbox_t> detection = detector->detect(image);
+    for (size_t i = 0; i < detection.size() && i < C_SHARP_MAX_OBJECTS; ++i)
+        container.candidates[i] = detection[i];
+    return detection.size();
+#else
+    return -1;
+#endif	// OPENCV
+}
+
+int dispose() {
+	//if (detector != NULL) delete detector;
+	//detector = NULL;
+    detector.reset();
+    return 1;
+}
+
 #ifdef GPU
 void check_cuda(cudaError_t status) {
 	if (status != cudaSuccess) {

--
Gitblit v1.10.0