diff --git a/CMakeLists.txt b/CMakeLists.txt index 1ae4289..0e75e3b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -159,6 +159,9 @@ target_link_libraries(map_demo tkDNN) add_executable(demo demo/demo/demo.cpp) target_link_libraries(demo tkDNN) +add_executable(demo3D demo/demo/demo3D.cpp) +target_link_libraries(demo3D tkDNN) + #------------------------------------------------------------------------------- # Install #------------------------------------------------------------------------------- diff --git a/demo/demo/demo3D.cpp b/demo/demo/demo3D.cpp new file mode 100644 index 0000000..e838395 --- /dev/null +++ b/demo/demo/demo3D.cpp @@ -0,0 +1,103 @@ +#include +#include +#include /* srand, rand */ +#include +#include + +#include "CenternetDetection3D.h" + +bool gRun; +bool SAVE_RESULT = false; + +void sig_handler(int signo) { + std::cout<<"request gateway stop\n"; + gRun = false; +} + +int main(int argc, char *argv[]) { + + std::cout<<"detection\n"; + signal(SIGINT, sig_handler); + + + std::string net = "dla34_cnet3d_fp32.rt"; + if(argc > 1) + net = argv[1]; + std::string input = "../demo/yolo_test.mp4"; + if(argc > 2) + input = argv[2]; + char ntype = 'c'; + if(argc > 3) + ntype = argv[3][0]; + int n_classes = 3; + if(argc > 4) + n_classes = atoi(argv[4]); + + tk::dnn::CenternetDetection3D cnet; + + tk::dnn::DetectionNN3D *detNN; + + switch(ntype) + { + case 'c': + detNN = &cnet; + break; + default: + FatalError("Network type not allowed (3rd parameter)\n"); + } + + detNN->init(net, n_classes); + + gRun = true; + + cv::VideoCapture cap(input); + if(!cap.isOpened()) + gRun = false; + else + std::cout<<"camera started\n"; + + cv::VideoWriter resultVideo; + if(SAVE_RESULT) { + int w = cap.get(cv::CAP_PROP_FRAME_WIDTH); + int h = cap.get(cv::CAP_PROP_FRAME_HEIGHT); + resultVideo.open("result.mp4", cv::VideoWriter::fourcc('M','P','4','V'), 30, cv::Size(w, h)); + } + + cv::Mat frame; + cv::Mat dnn_input; + cv::namedWindow("detection", cv::WINDOW_NORMAL); + + std::vector detected_bbox; + + while(gRun) { + cap >> frame; + if(!frame.data) { + break; + } + + // this will be resized to the net format + dnn_input = frame.clone(); + + //inference + detNN->update(dnn_input); + frame = detNN->draw(frame); + + cv::imshow("detection", frame); + cv::waitKey(1); + if(SAVE_RESULT) + resultVideo << frame; + } + + std::cout<<"detection end\n"; + double mean = 0; + + std::cout<stats.begin(), detNN->stats.end())<<" ms\n"; + std::cout<<"Max: "<<*std::max_element(detNN->stats.begin(), detNN->stats.end())<<" ms\n"; + for(int i=0; istats.size(); i++) mean += detNN->stats[i]; mean /= detNN->stats.size(); + std::cout<<"Avg: "<