From 743e767dce87abd3d688afafd324d6faa8cafed6 Mon Sep 17 00:00:00 2001 From: danil_e71 Date: Thu, 15 Oct 2020 15:37:41 +0300 Subject: [PATCH] add support mat ptr --- include/yolo_v2_class.hpp | 4 +++- src/yolo_v2_class.cpp | 17 +++++++++++++++-- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/include/yolo_v2_class.hpp b/include/yolo_v2_class.hpp index 360c3320bc7..6b11ce341d8 100644 --- a/include/yolo_v2_class.hpp +++ b/include/yolo_v2_class.hpp @@ -58,7 +58,8 @@ struct bbox_t_container { extern "C" LIB_API int init(const char *configurationFilename, const char *weightsFilename, int gpu); extern "C" LIB_API int detect_image(const char *filename, bbox_t_container &container); -extern "C" LIB_API int detect_mat(const uint8_t* data, const size_t data_length, bbox_t_container &container); +extern "C" LIB_API int detect_image_mat(const uint8_t* data, const size_t data_length, bbox_t_container &container); +extern "C" LIB_API int detect_mat(const void *mat, bbox_t_container &container); extern "C" LIB_API int dispose(); extern "C" LIB_API int get_device_count(); extern "C" LIB_API int get_device_name(int gpu, char* deviceName); @@ -1050,3 +1051,4 @@ class track_kalman_t #endif // __cplusplus #endif // YOLO_V2_CLASS_HPP + diff --git a/src/yolo_v2_class.cpp b/src/yolo_v2_class.cpp index 93812e7fabe..5b81c573da5 100644 --- a/src/yolo_v2_class.cpp +++ b/src/yolo_v2_class.cpp @@ -41,7 +41,7 @@ int detect_image(const char *filename, bbox_t_container &container) return detection.size(); } -int detect_mat(const uint8_t* data, const size_t data_length, bbox_t_container &container) { +int detect_image_mat(const uint8_t* data, const size_t data_length, bbox_t_container &container) { #ifdef OPENCV std::vector vdata(data, data + data_length); cv::Mat image = imdecode(cv::Mat(vdata), 1); @@ -55,6 +55,18 @@ int detect_mat(const uint8_t* data, const size_t data_length, bbox_t_container & #endif // OPENCV } +int detect_mat(const void *mat, bbox_t_container &container) { +#ifdef OPENCV + cv::Mat *mat_img = (cv::Mat*)mat; + std::vector detection = detector->detect(*mat_img); + 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; @@ -430,4 +442,5 @@ void *Detector::get_cuda_context() #else // GPU return NULL; #endif // GPU -} \ No newline at end of file +} +