Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add support mat ptr #6838

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion include/yolo_v2_class.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -1050,3 +1051,4 @@ class track_kalman_t
#endif // __cplusplus

#endif // YOLO_V2_CLASS_HPP

17 changes: 15 additions & 2 deletions src/yolo_v2_class.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<char> vdata(data, data + data_length);
cv::Mat image = imdecode(cv::Mat(vdata), 1);
Expand All @@ -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<bbox_t> 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;
Expand Down Expand Up @@ -430,4 +442,5 @@ void *Detector::get_cuda_context()
#else // GPU
return NULL;
#endif // GPU
}
}