mirror of
https://github.com/pjreddie/darknet.git
synced 2023-08-10 21:13:14 +03:00
merge changes
This commit is contained in:
@ -22,24 +22,18 @@ extern "C" {
|
||||
|
||||
#define FRAMES 3
|
||||
|
||||
static Detector* detector;
|
||||
//static std::unique_ptr<Detector> detector;
|
||||
//static Detector* detector = NULL;
|
||||
static std::unique_ptr<Detector> detector;
|
||||
|
||||
int init(const char *configurationFilename, const char *weightsFilename, int gpu) {
|
||||
std::string configurationFilenameString;
|
||||
configurationFilenameString = configurationFilename;
|
||||
std::string weightsFilenameString;
|
||||
weightsFilenameString = weightsFilename;
|
||||
|
||||
detector = new Detector(configurationFilenameString, weightsFilenameString, 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) {
|
||||
std::string filenameString;
|
||||
filenameString = filename;
|
||||
|
||||
std::vector<bbox_t> detection = detector->detect(filenameString);
|
||||
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();
|
||||
@ -60,8 +54,9 @@ int detect_mat(const uint8_t* data, const size_t data_length, bbox_t_container &
|
||||
}
|
||||
|
||||
int dispose() {
|
||||
detector->~Detector();
|
||||
//detector.reset();
|
||||
//if (detector != NULL) delete detector;
|
||||
//detector = NULL;
|
||||
detector.reset();
|
||||
return 1;
|
||||
}
|
||||
|
||||
@ -88,7 +83,7 @@ YOLODLL_API Detector::Detector(std::string cfg_filename, std::string weight_file
|
||||
wait_stream = 0;
|
||||
int old_gpu_index;
|
||||
#ifdef GPU
|
||||
check_cuda( cudaGetDevice(&old_gpu_index) );
|
||||
check_cuda(cudaGetDevice(&old_gpu_index));
|
||||
#endif
|
||||
|
||||
detector_gpu_ptr = std::make_shared<detector_gpu_t>();
|
||||
@ -125,7 +120,7 @@ YOLODLL_API Detector::Detector(std::string cfg_filename, std::string weight_file
|
||||
for (j = 0; j < l.classes; ++j) detector_gpu.track_id[j] = 1;
|
||||
|
||||
#ifdef GPU
|
||||
check_cuda( cudaSetDevice(old_gpu_index) );
|
||||
check_cuda(cudaSetDevice(old_gpu_index));
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -139,7 +134,7 @@ YOLODLL_API Detector::~Detector()
|
||||
|
||||
free(detector_gpu.avg);
|
||||
for (int j = 0; j < FRAMES; ++j) free(detector_gpu.predictions[j]);
|
||||
for (int j = 0; j < FRAMES; ++j) if(detector_gpu.images[j].data) free(detector_gpu.images[j].data);
|
||||
for (int j = 0; j < FRAMES; ++j) if (detector_gpu.images[j].data) free(detector_gpu.images[j].data);
|
||||
|
||||
int old_gpu_index;
|
||||
#ifdef GPU
|
||||
@ -187,8 +182,8 @@ static image load_image_stb(char *filename, int channels)
|
||||
for (k = 0; k < c; ++k) {
|
||||
for (j = 0; j < h; ++j) {
|
||||
for (i = 0; i < w; ++i) {
|
||||
int dst_index = i + w*j + w*h*k;
|
||||
int src_index = k + c*i + c*w*j;
|
||||
int dst_index = i + w * j + w * h*k;
|
||||
int src_index = k + c * i + c * w*j;
|
||||
im.data[dst_index] = (float)data[src_index] / 255.;
|
||||
}
|
||||
}
|
||||
@ -226,7 +221,7 @@ YOLODLL_API std::vector<bbox_t> Detector::detect(image_t img, float thresh, bool
|
||||
int old_gpu_index;
|
||||
#ifdef GPU
|
||||
cudaGetDevice(&old_gpu_index);
|
||||
if(cur_gpu_id != old_gpu_index)
|
||||
if (cur_gpu_id != old_gpu_index)
|
||||
cudaSetDevice(net.gpu_index);
|
||||
|
||||
net.wait_stream = wait_stream; // 1 - wait CUDA-stream, 0 - not to wait
|
||||
@ -294,7 +289,7 @@ YOLODLL_API std::vector<bbox_t> Detector::detect(image_t img, float thresh, bool
|
||||
}
|
||||
|
||||
free_detections(dets, nboxes);
|
||||
if(sized.data)
|
||||
if (sized.data)
|
||||
free(sized.data);
|
||||
|
||||
#ifdef GPU
|
||||
@ -330,9 +325,9 @@ YOLODLL_API std::vector<bbox_t> Detector::tracking_id(std::vector<bbox_t> cur_bb
|
||||
for (size_t m = 0; m < cur_bbox_vec.size(); ++m) {
|
||||
bbox_t const& k = cur_bbox_vec[m];
|
||||
if (i.obj_id == k.obj_id) {
|
||||
float center_x_diff = (float)(i.x + i.w/2) - (float)(k.x + k.w/2);
|
||||
float center_y_diff = (float)(i.y + i.h/2) - (float)(k.y + k.h/2);
|
||||
unsigned int cur_dist = sqrt(center_x_diff*center_x_diff + center_y_diff*center_y_diff);
|
||||
float center_x_diff = (float)(i.x + i.w / 2) - (float)(k.x + k.w / 2);
|
||||
float center_y_diff = (float)(i.y + i.h / 2) - (float)(k.y + k.h / 2);
|
||||
unsigned int cur_dist = sqrt(center_x_diff*center_x_diff + center_y_diff * center_y_diff);
|
||||
if (cur_dist < max_dist && (k.track_id == 0 || dist_vec[m] > cur_dist)) {
|
||||
dist_vec[m] = cur_dist;
|
||||
cur_index = m;
|
||||
@ -343,7 +338,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(),
|
||||
[&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){
|
||||
if (cur_index >= 0 && track_id_absent) {
|
||||
cur_bbox_vec[cur_index].track_id = i.track_id;
|
||||
cur_bbox_vec[cur_index].w = (cur_bbox_vec[cur_index].w + i.w) / 2;
|
||||
cur_bbox_vec[cur_index].h = (cur_bbox_vec[cur_index].h + i.h) / 2;
|
||||
|
Reference in New Issue
Block a user