Merge pull request #4762 from adujardin/zedsdk_3_support

Adding support for ZED SDK 3.0 (with 2.8 support maintained)
pull/4907/head
Alexey 5 years ago committed by GitHub
commit a67a3d7880
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 8
      Makefile
  2. 70
      src/yolo_console_dll.cpp

@ -5,7 +5,8 @@ OPENCV=0
AVX=0 AVX=0
OPENMP=0 OPENMP=0
LIBSO=0 LIBSO=0
ZED_CAMERA=0 ZED_CAMERA=0 # ZED SDK 3.0 and above
ZED_CAMERA_v2_8=0 # ZED SDK 2.X
# set GPU=1 and CUDNN=1 to speedup on GPU # set GPU=1 and CUDNN=1 to speedup on GPU
# set CUDNN_HALF=1 to further speedup 3 x times (Mixed-precision on Tensor Cores) GPU: Volta, Xavier, Turing and higher # set CUDNN_HALF=1 to further speedup 3 x times (Mixed-precision on Tensor Cores) GPU: Volta, Xavier, Turing and higher
@ -124,8 +125,13 @@ endif
ifeq ($(ZED_CAMERA), 1) ifeq ($(ZED_CAMERA), 1)
CFLAGS+= -DZED_STEREO -I/usr/local/zed/include CFLAGS+= -DZED_STEREO -I/usr/local/zed/include
ifeq ($(ZED_CAMERA_v2_8), 1)
LDFLAGS+= -L/usr/local/zed/lib -lsl_core -lsl_input -lsl_zed LDFLAGS+= -L/usr/local/zed/lib -lsl_core -lsl_input -lsl_zed
#-lstdc++ -D_GLIBCXX_USE_CXX11_ABI=0 #-lstdc++ -D_GLIBCXX_USE_CXX11_ABI=0
else
LDFLAGS+= -L/usr/local/zed/lib -lsl_zed
#-lstdc++ -D_GLIBCXX_USE_CXX11_ABI=0
endif
endif endif
OBJ=image_opencv.o http_stream.o gemm.o utils.o dark_cuda.o convolutional_layer.o list.o image.o activations.o im2col.o col2im.o blas.o crop_layer.o dropout_layer.o maxpool_layer.o softmax_layer.o data.o matrix.o network.o connected_layer.o cost_layer.o parser.o option_list.o darknet.o detection_layer.o captcha.o route_layer.o writing.o box.o nightmare.o normalization_layer.o avgpool_layer.o coco.o dice.o yolo.o detector.o layer.o compare.o classifier.o local_layer.o swag.o shortcut_layer.o activation_layer.o rnn_layer.o gru_layer.o rnn.o rnn_vid.o crnn_layer.o demo.o tag.o cifar.o go.o batchnorm_layer.o art.o region_layer.o reorg_layer.o reorg_old_layer.o super.o voxel.o tree.o yolo_layer.o gaussian_yolo_layer.o upsample_layer.o lstm_layer.o conv_lstm_layer.o scale_channels_layer.o sam_layer.o OBJ=image_opencv.o http_stream.o gemm.o utils.o dark_cuda.o convolutional_layer.o list.o image.o activations.o im2col.o col2im.o blas.o crop_layer.o dropout_layer.o maxpool_layer.o softmax_layer.o data.o matrix.o network.o connected_layer.o cost_layer.o parser.o option_list.o darknet.o detection_layer.o captcha.o route_layer.o writing.o box.o nightmare.o normalization_layer.o avgpool_layer.o coco.o dice.o yolo.o detector.o layer.o compare.o classifier.o local_layer.o swag.o shortcut_layer.o activation_layer.o rnn_layer.o gru_layer.o rnn.o rnn_vid.o crnn_layer.o demo.o tag.o cifar.o go.o batchnorm_layer.o art.o region_layer.o reorg_layer.o reorg_old_layer.o super.o voxel.o tree.o yolo_layer.o gaussian_yolo_layer.o upsample_layer.o lstm_layer.o conv_lstm_layer.o scale_channels_layer.o sam_layer.o

@ -24,9 +24,17 @@
#ifdef OPENCV #ifdef OPENCV
#ifdef ZED_STEREO #ifdef ZED_STEREO
#include <sl_zed/Camera.hpp> #include <sl/Camera.hpp>
#if ZED_SDK_MAJOR_VERSION == 2
#define ZED_STEREO_2_COMPAT_MODE
#endif
#undef GPU // avoid conflict with sl::MEM::GPU
#ifdef ZED_STEREO_2_COMPAT_MODE
#pragma comment(lib, "sl_core64.lib") #pragma comment(lib, "sl_core64.lib")
#pragma comment(lib, "sl_input64.lib") #pragma comment(lib, "sl_input64.lib")
#endif
#pragma comment(lib, "sl_zed64.lib") #pragma comment(lib, "sl_zed64.lib")
float getMedian(std::vector<float> &v) { float getMedian(std::vector<float> &v) {
@ -92,6 +100,7 @@ std::vector<bbox_t> get_3d_coordinates(std::vector<bbox_t> bbox_vect, cv::Mat xy
return bbox3d_vect; return bbox3d_vect;
} }
#ifdef ZED_STEREO_2_COMPAT_MODE
cv::Mat slMat2cvMat(sl::Mat &input) { cv::Mat slMat2cvMat(sl::Mat &input) {
// Mapping between MAT_TYPE and CV_TYPE // Mapping between MAT_TYPE and CV_TYPE
int cv_type = -1; int cv_type = -1;
@ -125,6 +134,41 @@ cv::Mat slMat2cvMat(sl::Mat &input) {
} }
return cv::Mat(input.getHeight(), input.getWidth(), cv_type, input.getPtr<sl::uchar1>(sl::MEM_CPU)); return cv::Mat(input.getHeight(), input.getWidth(), cv_type, input.getPtr<sl::uchar1>(sl::MEM_CPU));
} }
#else
cv::Mat slMat2cvMat(sl::Mat &input) {
// Mapping between MAT_TYPE and CV_TYPE
int cv_type = -1;
switch (input.getDataType()) {
case sl::MAT_TYPE::F32_C1:
cv_type = CV_32FC1;
break;
case sl::MAT_TYPE::F32_C2:
cv_type = CV_32FC2;
break;
case sl::MAT_TYPE::F32_C3:
cv_type = CV_32FC3;
break;
case sl::MAT_TYPE::F32_C4:
cv_type = CV_32FC4;
break;
case sl::MAT_TYPE::U8_C1:
cv_type = CV_8UC1;
break;
case sl::MAT_TYPE::U8_C2:
cv_type = CV_8UC2;
break;
case sl::MAT_TYPE::U8_C3:
cv_type = CV_8UC3;
break;
case sl::MAT_TYPE::U8_C4:
cv_type = CV_8UC4;
break;
default:
break;
}
return cv::Mat(input.getHeight(), input.getWidth(), cv_type, input.getPtr<sl::uchar1>(sl::MEM::CPU));
}
#endif
cv::Mat zed_capture_rgb(sl::Camera &zed) { cv::Mat zed_capture_rgb(sl::Camera &zed) {
sl::Mat left; sl::Mat left;
@ -136,7 +180,11 @@ cv::Mat zed_capture_rgb(sl::Camera &zed) {
cv::Mat zed_capture_3d(sl::Camera &zed) { cv::Mat zed_capture_3d(sl::Camera &zed) {
sl::Mat cur_cloud; sl::Mat cur_cloud;
#ifdef ZED_STEREO_2_COMPAT_MODE
zed.retrieveMeasure(cur_cloud, sl::MEASURE_XYZ); zed.retrieveMeasure(cur_cloud, sl::MEASURE_XYZ);
#else
zed.retrieveMeasure(cur_cloud, sl::MEASURE::XYZ);
#endif
return slMat2cvMat(cur_cloud).clone(); return slMat2cvMat(cur_cloud).clone();
} }
@ -334,13 +382,21 @@ int main(int argc, char *argv[])
#ifdef ZED_STEREO #ifdef ZED_STEREO
sl::InitParameters init_params; sl::InitParameters init_params;
init_params.depth_minimum_distance = 0.5; init_params.depth_minimum_distance = 0.5;
#ifdef ZED_STEREO_2_COMPAT_MODE
init_params.depth_mode = sl::DEPTH_MODE_ULTRA; init_params.depth_mode = sl::DEPTH_MODE_ULTRA;
init_params.camera_resolution = sl::RESOLUTION_HD720;// sl::RESOLUTION_HD1080, sl::RESOLUTION_HD720 init_params.camera_resolution = sl::RESOLUTION_HD720;// sl::RESOLUTION_HD1080, sl::RESOLUTION_HD720
init_params.coordinate_units = sl::UNIT_METER; init_params.coordinate_units = sl::UNIT_METER;
//init_params.sdk_cuda_ctx = (CUcontext)detector.get_cuda_context();
init_params.sdk_gpu_id = detector.cur_gpu_id;
init_params.camera_buffer_count_linux = 2; init_params.camera_buffer_count_linux = 2;
if (file_ext == "svo") init_params.svo_input_filename.set(filename.c_str()); if (file_ext == "svo") init_params.svo_input_filename.set(filename.c_str());
#else
init_params.depth_mode = sl::DEPTH_MODE::ULTRA;
init_params.camera_resolution = sl::RESOLUTION::HD720;// sl::RESOLUTION::HD1080, sl::RESOLUTION::HD720
init_params.coordinate_units = sl::UNIT::METER;
if (file_ext == "svo") init_params.input.setFromSVOFile(filename.c_str());
#endif
//init_params.sdk_cuda_ctx = (CUcontext)detector.get_cuda_context();
init_params.sdk_gpu_id = detector.cur_gpu_id;
if (filename == "zed_camera" || file_ext == "svo") { if (filename == "zed_camera" || file_ext == "svo") {
std::cout << "ZED 3D Camera " << zed.open(init_params) << std::endl; std::cout << "ZED 3D Camera " << zed.open(init_params) << std::endl;
if (!zed.isOpened()) { if (!zed.isOpened()) {
@ -407,7 +463,13 @@ int main(int argc, char *argv[])
detection_data = detection_data_t(); detection_data = detection_data_t();
#ifdef ZED_STEREO #ifdef ZED_STEREO
if (use_zed_camera) { if (use_zed_camera) {
while (zed.grab() != sl::SUCCESS) std::this_thread::sleep_for(std::chrono::milliseconds(2)); while (zed.grab() !=
#ifdef ZED_STEREO_2_COMPAT_MODE
sl::SUCCESS
#else
sl::ERROR_CODE::SUCCESS
#endif
) std::this_thread::sleep_for(std::chrono::milliseconds(2));
detection_data.cap_frame = zed_capture_rgb(zed); detection_data.cap_frame = zed_capture_rgb(zed);
detection_data.zed_cloud = zed_capture_3d(zed); detection_data.zed_cloud = zed_capture_3d(zed);
} }

Loading…
Cancel
Save