diff --git a/include/yolo_v2_class.hpp b/include/yolo_v2_class.hpp index 74e1c116..b6bea64a 100644 --- a/include/yolo_v2_class.hpp +++ b/include/yolo_v2_class.hpp @@ -1,15 +1,15 @@ #pragma once #ifdef LIB_EXPORTS #if defined(_MSC_VER) -#define LIB_EXPORTS __declspec(dllexport) +#define LIB_API __declspec(dllexport) #else -#define LIB_EXPORTS __attribute__((visibility("default"))) +#define LIB_API __attribute__((visibility("default"))) #endif #else #if defined(_MSC_VER) -#define LIB_EXPORTS __declspec(dllimport) +#define LIB_API #else -#define LIB_EXPORTS +#define LIB_API #endif #endif @@ -45,12 +45,12 @@ struct bbox_t_container { #include "opencv2/imgproc/imgproc_c.h" // C #endif // OPENCV -extern "C" LIB_EXPORTS int init(const char *configurationFilename, const char *weightsFilename, int gpu); -extern "C" LIB_EXPORTS int detect_image(const char *filename, bbox_t_container &container); -extern "C" LIB_EXPORTS int detect_mat(const uint8_t* data, const size_t data_length, bbox_t_container &container); -extern "C" LIB_EXPORTS int dispose(); -extern "C" LIB_EXPORTS int get_device_count(); -extern "C" LIB_EXPORTS int get_device_name(int gpu, char* deviceName); +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 dispose(); +extern "C" LIB_API int get_device_count(); +extern "C" LIB_API int get_device_name(int gpu, char* deviceName); class Detector { std::shared_ptr detector_gpu_ptr; @@ -60,18 +60,18 @@ public: float nms = .4; bool wait_stream; - LIB_EXPORTS Detector(std::string cfg_filename, std::string weight_filename, int gpu_id = 0); - LIB_EXPORTS ~Detector(); + LIB_API Detector(std::string cfg_filename, std::string weight_filename, int gpu_id = 0); + LIB_API ~Detector(); - LIB_EXPORTS std::vector detect(std::string image_filename, float thresh = 0.2, bool use_mean = false); - LIB_EXPORTS std::vector detect(image_t img, float thresh = 0.2, bool use_mean = false); - static LIB_EXPORTS image_t load_image(std::string image_filename); - static LIB_EXPORTS void free_image(image_t m); - LIB_EXPORTS int get_net_width() const; - LIB_EXPORTS int get_net_height() const; - LIB_EXPORTS int get_net_color_depth() const; + LIB_API std::vector detect(std::string image_filename, float thresh = 0.2, bool use_mean = false); + LIB_API std::vector detect(image_t img, float thresh = 0.2, bool use_mean = false); + static LIB_API image_t load_image(std::string image_filename); + static LIB_API void free_image(image_t m); + LIB_API int get_net_width() const; + LIB_API int get_net_height() const; + LIB_API int get_net_color_depth() const; - LIB_EXPORTS std::vector tracking_id(std::vector cur_bbox_vec, bool const change_history = true, + LIB_API std::vector tracking_id(std::vector cur_bbox_vec, bool const change_history = true, int const frames_story = 10, int const max_dist = 150); std::vector detect_resized(image_t img, int init_w, int init_h, float thresh = 0.2, bool use_mean = false) @@ -613,13 +613,13 @@ public: /* // C - wrappers - LIB_EXPORTS void create_detector(char const* cfg_filename, char const* weight_filename, int gpu_id); - LIB_EXPORTS void delete_detector(); - LIB_EXPORTS bbox_t* detect_custom(image_t img, float thresh, bool use_mean, int *result_size); - LIB_EXPORTS bbox_t* detect_resized(image_t img, int init_w, int init_h, float thresh, bool use_mean, int *result_size); - LIB_EXPORTS bbox_t* detect(image_t img, int *result_size); - LIB_EXPORTS image_t load_img(char *image_filename); - LIB_EXPORTS void free_img(image_t m); + LIB_API void create_detector(char const* cfg_filename, char const* weight_filename, int gpu_id); + LIB_API void delete_detector(); + LIB_API bbox_t* detect_custom(image_t img, float thresh, bool use_mean, int *result_size); + LIB_API bbox_t* detect_resized(image_t img, int init_w, int init_h, float thresh, bool use_mean, int *result_size); + LIB_API bbox_t* detect(image_t img, int *result_size); + LIB_API image_t load_img(char *image_filename); + LIB_API void free_img(image_t m); #ifdef __cplusplus } // extern "C" @@ -628,7 +628,7 @@ static std::shared_ptr c_detector_ptr; static std::vector c_result_vec; void create_detector(char const* cfg_filename, char const* weight_filename, int gpu_id) { - c_detector_ptr = std::make_shared(cfg_filename, weight_filename, gpu_id); + c_detector_ptr = std::make_shared(cfg_filename, weight_filename, gpu_id); } void delete_detector() { c_detector_ptr.reset(); } diff --git a/src/image.h b/src/image.h index 15731333..67743964 100644 --- a/src/image.h +++ b/src/image.h @@ -32,10 +32,10 @@ image crop_image(image im, int dx, int dy, int w, int h); image random_crop_image(image im, int w, int h); image random_augment_image(image im, float angle, float aspect, int low, int high, int size); void random_distort_image(image im, float hue, float saturation, float exposure); -//LIB_EXPORTS image resize_image(image im, int w, int h); +//LIB_API image resize_image(image im, int w, int h); void fill_image(image m, float s); void letterbox_image_into(image im, int w, int h, image boxed); -//LIB_EXPORTS image letterbox_image(image im, int w, int h); +//LIB_API image letterbox_image(image im, int w, int h); image resize_min(image im, int min); image resize_max(image im, int max); void translate_image(image m, float s); @@ -48,7 +48,7 @@ void exposure_image(image im, float sat); void distort_image(image im, float hue, float sat, float val); void saturate_exposure_image(image im, float sat, float exposure); void hsv_to_rgb(image im); -//LIB_EXPORTS void rgbgr_image(image im); +//LIB_API void rgbgr_image(image im); void constrain_image(image im); void composite_3d(char *f1, char *f2, char *out, int delta); int best_3d_shift_r(image a, image b, int min, int max); @@ -70,13 +70,13 @@ void show_image_collapsed(image p, char *name); void print_image(image m); -//LIB_EXPORTS image make_image(int w, int h, int c); +//LIB_API image make_image(int w, int h, int c); image make_random_image(int w, int h, int c); image make_empty_image(int w, int h, int c); image float_to_image(int w, int h, int c, float *data); image copy_image(image p); image load_image(char *filename, int w, int h, int c); -//LIB_EXPORTS image load_image_color(char *filename, int w, int h); +//LIB_API image load_image_color(char *filename, int w, int h); image **load_alphabet(); //float get_pixel(image m, int x, int y, int c); @@ -87,7 +87,7 @@ float bilinear_interpolate(image im, float x, float y, int c); image get_image_layer(image m, int l); -//LIB_EXPORTS void free_image(image m); +//LIB_API void free_image(image m); void test_resize(char *filename); #endif diff --git a/src/yolo_v2_class.cpp b/src/yolo_v2_class.cpp index a8710600..388f2eed 100644 --- a/src/yolo_v2_class.cpp +++ b/src/yolo_v2_class.cpp @@ -100,7 +100,7 @@ struct detector_gpu_t { unsigned int *track_id; }; -LIB_EXPORTS Detector::Detector(std::string cfg_filename, std::string weight_filename, int gpu_id) : cur_gpu_id(gpu_id) +LIB_API Detector::Detector(std::string cfg_filename, std::string weight_filename, int gpu_id) : cur_gpu_id(gpu_id) { wait_stream = 0; int old_gpu_index; @@ -147,7 +147,7 @@ LIB_EXPORTS Detector::Detector(std::string cfg_filename, std::string weight_file } -LIB_EXPORTS Detector::~Detector() +LIB_API Detector::~Detector() { detector_gpu_t &detector_gpu = *static_cast(detector_gpu_ptr.get()); layer l = detector_gpu.net.layers[detector_gpu.net.n - 1]; @@ -171,21 +171,21 @@ LIB_EXPORTS Detector::~Detector() #endif } -LIB_EXPORTS int Detector::get_net_width() const { +LIB_API int Detector::get_net_width() const { detector_gpu_t &detector_gpu = *static_cast(detector_gpu_ptr.get()); return detector_gpu.net.w; } -LIB_EXPORTS int Detector::get_net_height() const { +LIB_API int Detector::get_net_height() const { detector_gpu_t &detector_gpu = *static_cast(detector_gpu_ptr.get()); return detector_gpu.net.h; } -LIB_EXPORTS int Detector::get_net_color_depth() const { +LIB_API int Detector::get_net_color_depth() const { detector_gpu_t &detector_gpu = *static_cast(detector_gpu_ptr.get()); return detector_gpu.net.c; } -LIB_EXPORTS std::vector Detector::detect(std::string image_filename, float thresh, bool use_mean) +LIB_API std::vector Detector::detect(std::string image_filename, float thresh, bool use_mean) { std::shared_ptr image_ptr(new image_t, [](image_t *img) { if (img->data) free(img->data); delete img; }); *image_ptr = load_image(image_filename); @@ -214,7 +214,7 @@ static image load_image_stb(char *filename, int channels) return im; } -LIB_EXPORTS image_t Detector::load_image(std::string image_filename) +LIB_API image_t Detector::load_image(std::string image_filename) { char *input = const_cast(image_filename.data()); image im = load_image_stb(input, 3); @@ -229,14 +229,14 @@ LIB_EXPORTS image_t Detector::load_image(std::string image_filename) } -LIB_EXPORTS void Detector::free_image(image_t m) +LIB_API void Detector::free_image(image_t m) { if (m.data) { free(m.data); } } -LIB_EXPORTS std::vector Detector::detect(image_t img, float thresh, bool use_mean) +LIB_API std::vector Detector::detect(image_t img, float thresh, bool use_mean) { detector_gpu_t &detector_gpu = *static_cast(detector_gpu_ptr.get()); network &net = detector_gpu.net; @@ -322,7 +322,7 @@ LIB_EXPORTS std::vector Detector::detect(image_t img, float thresh, bool return bbox_vec; } -LIB_EXPORTS std::vector Detector::tracking_id(std::vector cur_bbox_vec, bool const change_history, +LIB_API std::vector Detector::tracking_id(std::vector cur_bbox_vec, bool const change_history, int const frames_story, int const max_dist) { detector_gpu_t &det_gpu = *static_cast(detector_gpu_ptr.get());