From 1216e8bb748e6e69cb59a1a2e1d7e64ca6d1b384 Mon Sep 17 00:00:00 2001 From: Davide Sapienza Date: Wed, 21 Jul 2021 16:14:53 +0200 Subject: [PATCH] Add camera calibration file reading for demo3d and demoTracker. Some minor fixes. Signed-off-by: Davide Sapienza --- demo/demo/demo3D.cpp | 43 ++++++++++---------- demo/demo/demoTracker.cpp | 46 +++++++++++----------- docs/demo.md | 12 ++++-- include/tkDNN/pluginsRT/DeformableConvRT.h | 2 +- include/tkDNN/utils.h | 7 ++++ scripts/test_all_tests.sh | 3 +- src/utils.cpp | 19 ++++++++- 7 files changed, 83 insertions(+), 49 deletions(-) diff --git a/demo/demo/demo3D.cpp b/demo/demo/demo3D.cpp index 90d4bfb..e7f909e 100644 --- a/demo/demo/demo3D.cpp +++ b/demo/demo/demo3D.cpp @@ -31,27 +31,31 @@ int main(int argc, char *argv[]) { if(argc > 2) input = argv[2]; - char ntype = 'c'; + std::string calib_params = ""; if(argc > 3) - ntype = argv[3][0]; - int n_classes = 3; + calib_params = argv[3]; + char ntype = 'c'; if(argc > 4) - n_classes = atoi(argv[4]); - int n_batch = 1; + ntype = argv[4][0]; + int n_classes = 3; if(argc > 5) - n_batch = atoi(argv[5]); - bool show = true; + n_classes = atoi(argv[5]); + int n_batch = 1; if(argc > 6) - show = atoi(argv[6]); - float conf_thresh=0.3; + n_batch = atoi(argv[6]); + + bool show = true; if(argc > 7) - conf_thresh = atof(argv[7]); + show = atoi(argv[7]); + float conf_thresh=0.3; + if(argc > 8) + conf_thresh = atof(argv[8]); if(n_batch < 1 || n_batch > 64) FatalError("Batch dim not supported"); if(!show) - SAVE_RESULT = true; + SAVE_RESULT = true; tk::dnn::CenternetDetection3D cnet; @@ -66,15 +70,14 @@ int main(int argc, char *argv[]) { FatalError("Network type not allowed (3rd parameter)\n"); } std::vector calibs; - // cv::Mat calib = cv::Mat::zeros(cv::Size(3,3), CV_32F); - // calib.at(0,0) = 864.1243196486207;// * 512.0;//884.081444212;//864.1243196486207 * 512.0;// 633.0; - // calib.at(0,2) = 726.7271690557819;// * 512.0;//0.0;//726.7271690557819 * 512.0;// 0.0; //w/2 - // calib.at(1,1) = 883.6552349216504;// * 512.0;//884.081444212;//883.6552349216504 * 512.0;// 633.0; - // calib.at(1,2) = 506.8548506986564;// * 512.0;//0.0;//506.8548506986564 * 512.0;// 0.0; //h/2 - // calibs.push_back(calib); - // calibs.push_back(calib); - // calibs.push_back(calib); - // calibs.push_back(calib); + if(!calib_params.empty() && calib_params!="NULL") { + std::cout<<"calib_params: "<init(net, n_classes, n_batch, conf_thresh, calibs); gRun = true; diff --git a/demo/demo/demoTracker.cpp b/demo/demo/demoTracker.cpp index ad6e204..797eb1b 100644 --- a/demo/demo/demoTracker.cpp +++ b/demo/demo/demoTracker.cpp @@ -31,29 +31,32 @@ int main(int argc, char *argv[]) { if(argc > 2) input = argv[2]; - char ntype = 'c'; + std::string calib_params = ""; if(argc > 3) - ntype = argv[3][0]; - int n_classes = 3; + calib_params = argv[3]; + char ntype = 'c'; if(argc > 4) - n_classes = atoi(argv[4]); - int n_batch = 1; + ntype = argv[4][0]; + int n_classes = 3; if(argc > 5) - n_batch = atoi(argv[5]); - bool show = true; + n_classes = atoi(argv[5]); + int n_batch = 1; if(argc > 6) - show = atoi(argv[6]); - float conf_thresh=0.3; + n_batch = atoi(argv[6]); + bool show = true; if(argc > 7) - conf_thresh = atof(argv[7]); - bool t3d = true; + show = atoi(argv[7]); + float conf_thresh=0.3; if(argc > 8) - t3d = atoi(argv[8]); + conf_thresh = atof(argv[8]); + bool t3d = true; + if(argc > 9) + t3d = atoi(argv[9]); if(n_batch < 1 || n_batch > 64) FatalError("Batch dim not supported"); if(!show) - SAVE_RESULT = true; + SAVE_RESULT = true; tk::dnn::CenterTrack ctrack; @@ -68,15 +71,14 @@ int main(int argc, char *argv[]) { FatalError("Network type not allowed (3rd parameter)\n"); } std::vector calibs; - // cv::Mat calib = cv::Mat::zeros(cv::Size(3,3), CV_32F); - // calib.at(0,0) = 864.1243196486207;// * 512.0;//884.081444212;//864.1243196486207 * 512.0;// 633.0; - // calib.at(0,2) = 726.7271690557819;// * 512.0;//0.0;//726.7271690557819 * 512.0;// 0.0; //w/2 - // calib.at(1,1) = 883.6552349216504;// * 512.0;//884.081444212;//883.6552349216504 * 512.0;// 633.0; - // calib.at(1,2) = 506.8548506986564;// * 512.0;//0.0;//506.8548506986564 * 512.0;// 0.0; //h/2 - // calibs.push_back(calib); - // calibs.push_back(calib); - // calibs.push_back(calib); - // calibs.push_back(calib); + if(!calib_params.empty() && calib_params!="NULL") { + std::cout<<"calib_params: "<init(net, n_classes, n_batch, conf_thresh, t3d, calibs); gRun = true; diff --git a/docs/demo.md b/docs/demo.md index 1ac1695..00e84c3 100644 --- a/docs/demo.md +++ b/docs/demo.md @@ -77,12 +77,15 @@ To run the 3D object detection demo follow these steps (example with CenterNet b ``` rm dla34_cnet3d_fp32.rt # be sure to delete(or move) old tensorRT files ./test_dla34_cnet3d # run the yolo test (is slow) -./demo3D dla34_cnet3d_fp32.rt ../demo/yolo_test.mp4 c +./demo3D dla34_cnet3d_fp32.rt ../demo/yolo_test.mp4 NULL c ``` The demo3D program takes the same parameters of the demo program: ``` -./demo3D +./demo3D ``` +where + +* ```calibration-file``` is the camera calibration file (opencv format). It is important that the file contains entry "camera_matrix" with sub-entry "rows", "cols", "data". If you do not want to pass the calibration file, pass "NULL" instead. ### Object Detection and Tracking @@ -90,16 +93,17 @@ To run the 3D object detection & tracking demo follow these steps (example with ``` rm dla34_ctrack_fp32.rt # be sure to delete(or move) old tensorRT files ./test_dla34_ctrack # run the yolo test (is slow) -./demoTracker dla34_ctrack_fp32.rt ../demo/yolo_test.mp4 c +./demoTracker dla34_ctrack_fp32.rt ../demo/yolo_test.mp4 NULL c ``` The demoTracker program takes the same parameters of the demo program: ``` -./demoTracker <2D/3D-flag> +./demoTracker <2D/3D-flag> ``` where +* ```calibration-file``` is the camera calibration file (opencv format). It is important that the file contains entry "camera_matrix" with sub-entry "rows", "cols", "data". If you do not want to pass the calibration file, pass "NULL" instead. * ```<2D/3D-flag>``` if set to 0 the demo will be in the 2D mode, while if set to 1 the demo will be in the 3D mode (Default is 1 - 3D mode). ### FP16 inference diff --git a/include/tkDNN/pluginsRT/DeformableConvRT.h b/include/tkDNN/pluginsRT/DeformableConvRT.h index 5cb2bab..711198f 100644 --- a/include/tkDNN/pluginsRT/DeformableConvRT.h +++ b/include/tkDNN/pluginsRT/DeformableConvRT.h @@ -30,7 +30,7 @@ public: height_ones = (i_h + 2 * ph - (1 * (kh - 1) + 1)) / sh + 1; width_ones = (i_w + 2 * pw - (1 * (kw - 1) + 1)) / sw + 1; dim_ones = i_c * kh * kw * 1 * height_ones * width_ones; - std::cout< #include + #ifdef __linux__ #include +#include +#include +#include + +#include #endif #include @@ -131,6 +137,7 @@ void matrixMulAdd( cublasHandle_t handle, dnnType* srcData, dnnType* dstData, void getMemUsage(double& vm_usage_kb, double& resident_set_kb); void printCudaMemUsage(); void removePathAndExtension(const std::string &full_string, std::string &name); +void readCalibrationMatrix(const std::string& path, cv::Mat& calib_mat); static inline bool isCudaPointer(void *data) { cudaPointerAttributes attr; return cudaPointerGetAttributes(&attr, data) == 0; diff --git a/scripts/test_all_tests.sh b/scripts/test_all_tests.sh index 5a3a725..b45745e 100644 --- a/scripts/test_all_tests.sh +++ b/scripts/test_all_tests.sh @@ -91,10 +91,11 @@ do #test_net csresnext50-panet-spp_berkeley test_net resnet101_cnet test_net dla34_cnet + test_net dla34_cnet3d test_net mobilenetv2ssd test_net mobilenetv2ssd512 test_net bdd-mobilenetv2ssd - test_net dla34_cnet3d_track + test_net dla34_ctrack done echo "If errors occured, check logfile $out_file" diff --git a/src/utils.cpp b/src/utils.cpp index fa6458f..4b3bbb0 100644 --- a/src/utils.cpp +++ b/src/utils.cpp @@ -240,4 +240,21 @@ void removePathAndExtension(const std::string &full_string, std::string &name){ name = name.substr(previous, current); // std::cout<<"full string: "<(); + int cols = config["camera_matrix"]["cols"].as(); + + cv::Mat calib = cv::Mat(cv::Size(rows, cols), CV_32F); + float *vals = (float *)calib.data; + + for(int i=0; i < config["camera_matrix"]["data"].size(); ++i ) + vals[i] = config["camera_matrix"]["data"][i].as(); + + calib_mat = calib; + +}