From 99e809737f6b54509727f3cef9c0e1021c0f1298 Mon Sep 17 00:00:00 2001 From: Davide Sapienza Date: Tue, 3 Mar 2020 17:30:35 +0100 Subject: [PATCH] Move multiple demo files into one Signed-off-by: Davide Sapienza --- CMakeLists.txt | 14 +--- demo/demo/demo.cpp | 138 +++++++++++++++++++++++++++++++++++ demo/demo/demo_centernet.cpp | 88 ---------------------- demo/demo/demo_mobilenet.cpp | 88 ---------------------- demo/demo/demo_yolo3.cpp | 88 ---------------------- 5 files changed, 140 insertions(+), 276 deletions(-) create mode 100644 demo/demo/demo.cpp delete mode 100644 demo/demo/demo_centernet.cpp delete mode 100644 demo/demo/demo_mobilenet.cpp delete mode 100644 demo/demo/demo_yolo3.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 421e53a..0a765a4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -115,18 +115,8 @@ target_link_libraries(test_dla34_cnet tkDNN) add_executable(test_rtinference tests/test_rtinference/rtinference.cpp) target_link_libraries(test_rtinference tkDNN) -add_executable(yolo3_demo demo/demo/demo_yolo3.cpp) -target_link_libraries(yolo3_demo tkDNN) - -add_executable(centernet_demo demo/demo/demo_centernet.cpp) -target_link_libraries(centernet_demo tkDNN) - -add_executable(mobilenet_demo demo/demo/demo_mobilenet.cpp) -target_link_libraries(mobilenet_demo tkDNN) - -add_executable(map_demo demo/demo/map.cpp) -target_link_libraries(map_demo tkDNN) - +add_executable(demo demo/demo/demo.cpp) +target_link_libraries(demo tkDNN) #------------------------------------------------------------------------------- # Install diff --git a/demo/demo/demo.cpp b/demo/demo/demo.cpp new file mode 100644 index 0000000..a5a9d1a --- /dev/null +++ b/demo/demo/demo.cpp @@ -0,0 +1,138 @@ +#include +#include +#include /* srand, rand */ +#include +#include + +#include "CenternetDetection.h" +#include "MobilenetDetection.h" +#include "Yolo3Detection.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); + + + char *net = "yolo3_berkeley.rt"; + if(argc > 1) + net = argv[1]; + char *input = "../demo/yolo_test.mp4"; + if(argc > 2) + input = argv[2]; + char ntype = 'y'; + if(argc > 3) + ntype = argv[3][0]; + + tk::dnn::Yolo3Detection yolo; + tk::dnn::CenternetDetection cnet; + tk::dnn::MobilenetDetection mbnet; + switch(ntype) + { + case 'y': + yolo.init(net); + break; + case 'c': + cnet.init(net); + break; + case 'm': + mbnet.init(net); + break; + default: + FatalError("Network type not allowed (3rd parameter)\n"); + } + + 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(); + // TODO: async infer + switch(ntype) + { + case 'y': + yolo.update(dnn_input); + frame = yolo.draw(frame); + break; + case 'c': + cnet.update(dnn_input); + frame = cnet.draw(dnn_input); + break; + case 'm': + mbnet.update(dnn_input); + frame = mbnet.draw(); + break; + default: + FatalError("Network type not allowed!\n"); + } + + cv::imshow("detection", frame); + cv::waitKey(1); + if(SAVE_RESULT) + resultVideo << frame; + } + + std::cout<<"detection end\n"; + double mean = 0; + switch(ntype) + { + case 'y': + std::cout< -#include -#include /* srand, rand */ -#include -#include -#include "utils.h" - -#include -#include -#include -#include - -#include "CenternetDetection.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); - - - char *net = "resnet101_cnet.rt"; - if(argc > 1) - net = argv[1]; - char *input = "../demo/yolo_test.mp4"; - if(argc > 2) - input = argv[2]; - - tk::dnn::CenternetDetection cnet; - cnet.init(net); - - 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); - - while(gRun) { - cap >> frame; - if(!frame.data) { - break; - } - - // this will be resized to the net format - dnn_input = frame.clone(); - // TODO: async infer - cnet.update(dnn_input); - // draw dets - frame = cnet.draw(dnn_input); - - cv::imshow("detection", frame); - cv::waitKey(1); - if(SAVE_RESULT) - resultVideo << frame; - } - - std::cout<<"detection end\n"; - - - std::cout< -#include -#include /* srand, rand */ -#include -#include - - -#include "MobilenetDetection.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); - - char *net = "mobilenetv2ssd.rt"; - if (argc > 1) - net = argv[1]; - char *input = "../demo/yolo_test.mp4"; - if (argc > 2) - input = argv[2]; - - tk::dnn::MobilenetDetection mbnet; - mbnet.init(net); - - 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); - - while (gRun) - { - cap >> frame; - if (!frame.data) - { - break; - } - - // this will be resized to the net format - dnn_input = frame.clone(); - // TODO: async infer - mbnet.update(dnn_input); - // draw dets - frame = mbnet.draw(); - - cv::imshow("detection", frame); - cv::waitKey(1); - if (SAVE_RESULT) - resultVideo << frame; - } - - std::cout << "detection end\n"; - - std::cout << COL_GREENB << "\n\nTime stats:\n"; - std::cout << "Min: " << *std::min_element(mbnet.stats.begin(), mbnet.stats.end()) << " ms\n"; - std::cout << "Max: " << *std::max_element(mbnet.stats.begin(), mbnet.stats.end()) << " ms\n"; - double mean = 0; - for (int i = 0; i < mbnet.stats.size(); i++) - mean += mbnet.stats[i]; - mean /= mbnet.stats.size(); - std::cout << "Avg: " << mean << " ms\n" - << COL_END; - return 0; -} diff --git a/demo/demo/demo_yolo3.cpp b/demo/demo/demo_yolo3.cpp deleted file mode 100644 index 0abcc2c..0000000 --- a/demo/demo/demo_yolo3.cpp +++ /dev/null @@ -1,88 +0,0 @@ -#include -#include -#include /* srand, rand */ -#include -#include -#include "utils.h" - -#include -#include -#include -#include - -#include "Yolo3Detection.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); - - - char *net = "yolo3_berkeley.rt"; - if(argc > 1) - net = argv[1]; - char *input = "../demo/yolo_test.mp4"; - if(argc > 2) - input = argv[2]; - - tk::dnn::Yolo3Detection yolo; - yolo.init(net); - - 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); - - while(gRun) { - cap >> frame; - if(!frame.data) { - break; - } - - // this will be resized to the net format - dnn_input = frame.clone(); - // TODO: async infer - yolo.update(dnn_input); - - frame = yolo.draw(frame); - - cv::imshow("detection", frame); - cv::waitKey(1); - if(SAVE_RESULT) - resultVideo << frame; - } - - std::cout<<"detection end\n"; - - - std::cout<