ZED 3D Camera support added to ./uselib (yolo_console_cpp.exe) example

This commit is contained in:
AlexeyAB
2019-03-18 02:48:52 +03:00
parent 7a854302ef
commit b6e15f1656
65 changed files with 1324 additions and 662 deletions

View File

@ -250,8 +250,6 @@ LIB_API std::vector<bbox_t> Detector::detect(image_t img, float thresh, bool use
#endif
//std::cout << "net.gpu_index = " << net.gpu_index << std::endl;
//float nms = .4;
image im;
im.c = img.c;
im.data = img.data;
@ -305,6 +303,9 @@ LIB_API std::vector<bbox_t> Detector::detect(image_t img, float thresh, bool use
bbox.obj_id = obj_id;
bbox.prob = prob;
bbox.track_id = 0;
bbox.x_3d = NAN;
bbox.y_3d = NAN;
bbox.z_3d = NAN;
bbox_vec.push_back(bbox);
}
@ -379,3 +380,70 @@ LIB_API std::vector<bbox_t> Detector::tracking_id(std::vector<bbox_t> cur_bbox_v
return cur_bbox_vec;
}
LIB_API bool Detector::send_json_http(std::vector<bbox_t> cur_bbox_vec, std::vector<std::string> obj_names, int frame_id, std::string filename, int timeout, int port)
{
//int timeout = 400000;
//int port = 8070;
//send_json(local_dets, local_nboxes, l.classes, demo_names, frame_id, demo_json_port, timeout);
std::string send_str;
char *tmp_buf = (char *)calloc(1024, sizeof(char));
if (!filename.empty()) {
sprintf(tmp_buf, "{\n \"frame_id\":%d, \n \"filename\":\"%s\", \n \"objects\": [ \n", frame_id, filename);
}
else {
sprintf(tmp_buf, "{\n \"frame_id\":%d, \n \"objects\": [ \n", frame_id);
}
send_str = tmp_buf;
free(tmp_buf);
for (auto & i : cur_bbox_vec) {
char *buf = (char *)calloc(2048, sizeof(char));
sprintf(buf, " {\"class_id\":%d, \"name\":\"%s\", \"absolute_coordinates\":{\"center_x\":%d, \"center_y\":%d, \"width\":%d, \"height\":%d}, \"confidence\":%f",
i.obj_id, obj_names[i.obj_id], i.x, i.y, i.w, i.h, i.prob);
//sprintf(buf, " {\"class_id\":%d, \"name\":\"%s\", \"relative_coordinates\":{\"center_x\":%f, \"center_y\":%f, \"width\":%f, \"height\":%f}, \"confidence\":%f",
// i.obj_id, obj_names[i.obj_id], i.x, i.y, i.w, i.h, i.prob);
send_str += buf;
if (!isnan(i.z_3d)) {
sprintf(buf, "\n , \"coordinates_in_meters\":{\"x_3d\":%.2f, \"y_3d\":%.2f, \"z_3d\":%.2f}",
i.x_3d*100, i.y_3d, i.z_3d);
send_str += buf;
}
send_str += "}\n";
free(buf);
}
//send_str += "\n ] \n}, \n";
send_str += "\n ] \n}";
send_json_custom(send_str.c_str(), port, timeout);
return true;
}
void *Detector::get_cuda_context()
{
#ifdef GPU
int old_gpu_index;
cudaGetDevice(&old_gpu_index);
if (cur_gpu_id != old_gpu_index)
cudaSetDevice(cur_gpu_id);
void *cuda_context = cuda_get_context();
if (cur_gpu_id != old_gpu_index)
cudaSetDevice(old_gpu_index);
return cuda_context;
#else // GPU
return NULL;
#endif // GPU
}