Added include/darknet.h

This commit is contained in:
AlexeyAB
2019-01-06 23:51:38 +03:00
parent c56931dd75
commit 3ff5084590
30 changed files with 1823 additions and 308 deletions

View File

@ -25,13 +25,13 @@ extern "C" {
//static Detector* detector = NULL;
static std::unique_ptr<Detector> detector;
int init(const char *configurationFilename, const char *weightsFilename, int gpu)
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)
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)
@ -100,7 +100,7 @@ struct detector_gpu_t {
unsigned int *track_id;
};
YOLODLL_API Detector::Detector(std::string cfg_filename, std::string weight_filename, int gpu_id) : cur_gpu_id(gpu_id)
LIB_EXPORTS 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;
@ -119,7 +119,7 @@ YOLODLL_API Detector::Detector(std::string cfg_filename, std::string weight_file
network &net = detector_gpu.net;
net.gpu_index = cur_gpu_id;
//gpu_index = i;
char *cfgfile = const_cast<char *>(cfg_filename.data());
char *weightfile = const_cast<char *>(weight_filename.data());
@ -147,7 +147,7 @@ YOLODLL_API Detector::Detector(std::string cfg_filename, std::string weight_file
}
YOLODLL_API Detector::~Detector()
LIB_EXPORTS Detector::~Detector()
{
detector_gpu_t &detector_gpu = *static_cast<detector_gpu_t *>(detector_gpu_ptr.get());
layer l = detector_gpu.net.layers[detector_gpu.net.n - 1];
@ -171,21 +171,21 @@ YOLODLL_API Detector::~Detector()
#endif
}
YOLODLL_API int Detector::get_net_width() const {
LIB_EXPORTS int Detector::get_net_width() const {
detector_gpu_t &detector_gpu = *static_cast<detector_gpu_t *>(detector_gpu_ptr.get());
return detector_gpu.net.w;
}
YOLODLL_API int Detector::get_net_height() const {
LIB_EXPORTS int Detector::get_net_height() const {
detector_gpu_t &detector_gpu = *static_cast<detector_gpu_t *>(detector_gpu_ptr.get());
return detector_gpu.net.h;
}
YOLODLL_API int Detector::get_net_color_depth() const {
LIB_EXPORTS int Detector::get_net_color_depth() const {
detector_gpu_t &detector_gpu = *static_cast<detector_gpu_t *>(detector_gpu_ptr.get());
return detector_gpu.net.c;
}
YOLODLL_API std::vector<bbox_t> Detector::detect(std::string image_filename, float thresh, bool use_mean)
LIB_EXPORTS std::vector<bbox_t> Detector::detect(std::string image_filename, float thresh, bool use_mean)
{
std::shared_ptr<image_t> image_ptr(new image_t, [](image_t *img) { if (img->data) free(img->data); delete img; });
*image_ptr = load_image(image_filename);
@ -196,7 +196,7 @@ static image load_image_stb(char *filename, int channels)
{
int w, h, c;
unsigned char *data = stbi_load(filename, &w, &h, &c, channels);
if (!data)
if (!data)
throw std::runtime_error("file not found");
if (channels) c = channels;
int i, j, k;
@ -214,7 +214,7 @@ static image load_image_stb(char *filename, int channels)
return im;
}
YOLODLL_API image_t Detector::load_image(std::string image_filename)
LIB_EXPORTS image_t Detector::load_image(std::string image_filename)
{
char *input = const_cast<char *>(image_filename.data());
image im = load_image_stb(input, 3);
@ -229,14 +229,14 @@ YOLODLL_API image_t Detector::load_image(std::string image_filename)
}
YOLODLL_API void Detector::free_image(image_t m)
LIB_EXPORTS void Detector::free_image(image_t m)
{
if (m.data) {
free(m.data);
}
}
YOLODLL_API std::vector<bbox_t> Detector::detect(image_t img, float thresh, bool use_mean)
LIB_EXPORTS std::vector<bbox_t> Detector::detect(image_t img, float thresh, bool use_mean)
{
detector_gpu_t &detector_gpu = *static_cast<detector_gpu_t *>(detector_gpu_ptr.get());
network &net = detector_gpu.net;
@ -259,7 +259,7 @@ YOLODLL_API std::vector<bbox_t> Detector::detect(image_t img, float thresh, bool
im.w = img.w;
image sized;
if (net.w == im.w && net.h == im.h) {
sized = make_image(im.w, im.h, im.c);
memcpy(sized.data, im.data, im.w*im.h*im.c * sizeof(float));
@ -294,8 +294,8 @@ YOLODLL_API std::vector<bbox_t> Detector::detect(image_t img, float thresh, bool
box b = dets[i].bbox;
int const obj_id = max_index(dets[i].prob, l.classes);
float const prob = dets[i].prob[obj_id];
if (prob > thresh)
if (prob > thresh)
{
bbox_t bbox;
bbox.x = std::max((double)0, (b.x - b.w / 2.)*im.w);
@ -322,7 +322,7 @@ YOLODLL_API std::vector<bbox_t> Detector::detect(image_t img, float thresh, bool
return bbox_vec;
}
YOLODLL_API std::vector<bbox_t> Detector::tracking_id(std::vector<bbox_t> cur_bbox_vec, bool const change_history,
LIB_EXPORTS std::vector<bbox_t> Detector::tracking_id(std::vector<bbox_t> cur_bbox_vec, bool const change_history,
int const frames_story, int const max_dist)
{
detector_gpu_t &det_gpu = *static_cast<detector_gpu_t *>(detector_gpu_ptr.get());
@ -357,7 +357,7 @@ YOLODLL_API std::vector<bbox_t> Detector::tracking_id(std::vector<bbox_t> cur_bb
}
}
bool track_id_absent = !std::any_of(cur_bbox_vec.begin(), cur_bbox_vec.end(),
bool track_id_absent = !std::any_of(cur_bbox_vec.begin(), cur_bbox_vec.end(),
[&i](bbox_t const& b) { return b.track_id == i.track_id && b.obj_id == i.obj_id; });
if (cur_index >= 0 && track_id_absent){