diff --git a/CMakeLists.txt b/CMakeLists.txt index b366416..5e5d60b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -18,7 +18,7 @@ if(DEBUG) endif() if(TKDNN_PATH) - message("SET TKDNN_PATH:"${TKDNN_PATH}) + message("SET TKDNN_PATH:${TKDNN_PATH}") add_definitions(-DTKDNN_PATH="${TKDNN_PATH}") else() add_definitions(-DTKDNN_PATH="${CMAKE_CURRENT_SOURCE_DIR}") @@ -51,11 +51,11 @@ find_package(Eigen3 REQUIRED) message("Eigen DIR: " ${EIGEN3_INCLUDE_DIR}) include_directories(${EIGEN3_INCLUDE_DIR}) -find_package(OpenCV REQUIRED) +find_package(OpenCV 4.5 REQUIRED) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DOPENCV") -# if(OpenCV_CUDA_VERSION) -# add_compile_definitions(OPENCV_CUDACONTRIB) -# endif() +if(OpenCV_CUDA_VERSION) + add_compile_definitions(OPENCV_CUDACONTRIB) +endif() # gives problems in cross-compiling, probably malformed cmake config find_package(yaml-cpp REQUIRED) @@ -71,7 +71,7 @@ include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include ${CUDA_INCLUDE_DIRS} ${O add_library(tkDNN SHARED ${tkdnn_SRC}) target_link_libraries(tkDNN ${tkdnn_LIBS}) -#static +#static #add_library(tkDNN_static STATIC ${tkdnn_SRC}) #target_link_libraries(tkDNN_static ${tkdnn_LIBS}) @@ -163,7 +163,7 @@ target_link_libraries(seg_demo tkDNN) # Install #------------------------------------------------------------------------------- #if (CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) -# set (CMAKE_INSTALL_PREFIX "${CMAKE_BINARY_DIR}/install" +# set (CMAKE_INSTALL_PREFIX "${CMAKE_BINARY_DIR}/install" # CACHE PATH "default install path" FORCE) #endif() message("install dir:" ${CMAKE_INSTALL_PREFIX}) diff --git a/include/tkDNN/DetectionNN.h b/include/tkDNN/DetectionNN.h index a8c81f7..6711ebf 100644 --- a/include/tkDNN/DetectionNN.h +++ b/include/tkDNN/DetectionNN.h @@ -3,10 +3,10 @@ #include #include -#include +#include #ifdef __linux__ #include -#endif +#endif #include #include "utils.h" @@ -17,7 +17,7 @@ #include "tkdnn.h" -//#define OPENCV_CUDACONTRIB //if OPENCV has been compiled with CUDA and contrib. +#define OPENCV_CUDACONTRIB //if OPENCV has been compiled with CUDA and contrib. #ifdef OPENCV_CUDACONTRIB #include @@ -37,7 +37,7 @@ class DetectionNN { cv::Scalar colors[256]; - int nBatches = 1; + int nBatches = 2; #ifdef OPENCV_CUDACONTRIB cv::cuda::GpuMat bgr[3]; @@ -57,11 +57,11 @@ class DetectionNN { virtual void preprocess(cv::Mat &frame, const int bi=0) = 0; /** - * This method postprocess the output of the NN to obtain the correct - * boundig boxes. - * + * This method postprocess the output of the NN to obtain the correct + * boundig boxes. + * * @param bi batch index - * @param mAP set to true only if all the probabilities for a bounding + * @param mAP set to true only if all the probabilities for a bounding * box are needed, as in some cases for the mAP calculation */ virtual void postprocess(const int bi=0,const bool mAP=false) = 0; @@ -79,25 +79,25 @@ class DetectionNN { ~DetectionNN(){}; /** - * Method used to initialize the class, allocate memory and compute + * Method used to initialize the class, allocate memory and compute * needed data. - * + * * @param tensor_path path to the rt file of the NN. * @param n_classes number of classes for the given dataset. * @param n_batches maximum number of batches to use in inference * @return true if everything is correct, false otherwise. */ virtual bool init(const std::string& tensor_path, const int n_classes=80, const int n_batches=1, const float conf_thresh=0.3) = 0; - + /** * This method performs the whole detection of the NN. - * + * * @param frames frames to run detection on. * @param cur_batches number of batches to use in inference - * @param save_times if set to true, preprocess, inference and postprocess times + * @param save_times if set to true, preprocess, inference and postprocess times * are saved on a csv file, otherwise not. * @param times pointer to the output stream where to write times - * @param mAP set to true only if all the probabilities for a bounding + * @param mAP set to true only if all the probabilities for a bounding * box are needed, as in some cases for the mAP calculation */ void update(std::vector& frames, const int cur_batches=1, bool save_times=false, std::ofstream *times=nullptr, const bool mAP=false){ @@ -107,14 +107,14 @@ class DetectionNN { FatalError("A batch size greater than nBatches cannot be used"); originalSize.clear(); - if(TKDNN_VERBOSE) printCenteredTitle(" TENSORRT detection ", '=', 30); + if(TKDNN_VERBOSE) printCenteredTitle(" TENSORRT detection ", '=', 30); { TKDNN_TSTART for(int bi=0; bi& frames) { @@ -155,11 +155,11 @@ class DetectionNN { std::string det_class; int baseline = 0; float font_scale = 0.5; - int thickness = 2; + int thickness = 2; for(int bi=0; bi #include #include -#ifdef __linux__ +#ifdef __linux__ #include #endif @@ -17,7 +17,7 @@ #include "tkdnn.h" -// #define OPENCV_CUDACONTRIB //if OPENCV has been compiled with CUDA and contrib. +#define OPENCV_CUDACONTRIB //if OPENCV has been compiled with CUDA and contrib. #ifdef OPENCV_CUDACONTRIB #include @@ -57,11 +57,11 @@ class DetectionNN3D { virtual void preprocess(cv::Mat &frame, const int bi=0) = 0; /** - * This method postprocess the output of the NN to obtain the correct - * boundig boxes. - * + * This method postprocess the output of the NN to obtain the correct + * boundig boxes. + * * @param bi batch index - * @param mAP set to true only if all the probabilities for a bounding + * @param mAP set to true only if all the probabilities for a bounding * box are needed, as in some cases for the mAP calculation */ virtual void postprocess(const int bi=0,const bool mAP=false) = 0; @@ -69,7 +69,7 @@ class DetectionNN3D { public: int classes = 0; float confThreshold = 0.3; /*threshold on the confidence of the boxes*/ - + std::vector detected3D; /*bounding boxes in output*/ std::vector> batchDetected; /*bounding boxes in output*/ std::vector pre_stats, stats, post_stats, visual_stats; /*keeps track of inference times (ms)*/ @@ -79,29 +79,29 @@ class DetectionNN3D { ~DetectionNN3D(){}; /** - * Method used to initialize the class, allocate memory and compute + * Method used to initialize the class, allocate memory and compute * needed data. - * + * * @param tensor_path path to the rt file of the NN. * @param n_classes number of classes for the given dataset. * @param n_batches maximum number of batches to use in inference. * @return true if everything is correct, false otherwise. */ - virtual bool init(const std::string& tensor_path, const int n_classes=3, const int n_batches=1, + virtual bool init(const std::string& tensor_path, const int n_classes=3, const int n_batches=1, const float conf_thresh=0.3, const std::vector& k_calibs=std::vector()) = 0; /** * This method performs the whole detection of the NN. - * + * * @param frames frames to run detection on. * @param cur_batches number of batches to use in inference. - * @param save_times if set to true, preprocess, inference and postprocess times + * @param save_times if set to true, preprocess, inference and postprocess times * are saved on a csv file, otherwise not. * @param times pointer to the output stream where to write times. - * @param mAP set to true only if all the probabilities for a bounding + * @param mAP set to true only if all the probabilities for a bounding * box are needed, as in some cases for the mAP calculation. */ - void update(std::vector& frames, const int cur_batches=1, bool save_times=false, + void update(std::vector& frames, const int cur_batches=1, bool save_times=false, std::ofstream *times=nullptr, const bool mAP=false){ if(save_times && times==nullptr) FatalError("save_times set to true, but no valid ofstream given"); @@ -109,17 +109,17 @@ class DetectionNN3D { FatalError("A batch size greater than nBatches cannot be used"); originalSize.clear(); - if(TKDNN_VERBOSE) printCenteredTitle(" TENSORRT detection ", '=', 30); + if(TKDNN_VERBOSE) printCenteredTitle(" TENSORRT detection ", '=', 30); { TKDNN_TSTART for(int bi=0; bi& frames){}; - + }; }}