diff --git a/README.md b/README.md index 64089cb..570c89e 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,7 @@ The main goal of this project is to exploit NVIDIA boards as much as possible to ## Index * [Dependencies](#dependencies) +* [About OpenCV](#about-opencv) * [How to compile this repo](#how-to-compile-this-repo) * [Workflow](#workflow) * [How to export weights](#how-to-export-weights) @@ -23,6 +24,13 @@ This branch works on every NVIDIA GPU that supports the dependencies: * OPENCV 4.1 * yaml-cpp 0.5.2 (sudo apt install libyaml-cpp-dev) +## About OpenCV +To compile and install OpenCV4 with contrib us the script ```install_OpenCV4.sh```. It will download and compile OpenCV in Download folder. +``` +bash install_OpenCV4.sh +``` +When using openCV not compiled with contrib, comment the definition of OPENCV_CUDACONTRIBCONTRIB in include/tkDNN/DetectionNN.h. When commented, the preprocessing of the networks is computed on the CPU, otherwise on the GPU. In the latter case some milliseconds are saved in the end-to-end latency. + ## How to compile this repo Build with cmake. If using Ubuntu 18.04 a new version of cmake is needed (1.15 or above). ``` diff --git a/include/tkDNN/CenternetDetection.h b/include/tkDNN/CenternetDetection.h index 8a63a8b..94e87e3 100644 --- a/include/tkDNN/CenternetDetection.h +++ b/include/tkDNN/CenternetDetection.h @@ -43,7 +43,7 @@ private: float *target_coords; - #ifdef OPENCV_CUDA + #ifdef OPENCV_CUDACONTRIB float *mean_d; float *stddev_d; #else diff --git a/include/tkDNN/DetectionNN.h b/include/tkDNN/DetectionNN.h index 8a1bbcd..101e75d 100644 --- a/include/tkDNN/DetectionNN.h +++ b/include/tkDNN/DetectionNN.h @@ -17,7 +17,7 @@ #include "tkdnn.h" -#define OPENCV_CUDA //if OPENCV has been compiled with CUDA and contrib. +#define OPENCV_CUDACONTRIB //if OPENCV has been compiled with CUDA and contrib. namespace tk { namespace dnn { @@ -37,7 +37,7 @@ class DetectionNN { cv::Scalar colors[256]; -#ifdef OPENCV_CUDA +#ifdef OPENCV_CUDACONTRIB cv::cuda::GpuMat bgr[3]; cv::cuda::GpuMat imagePreproc; #else diff --git a/src/CenternetDetection.cpp b/src/CenternetDetection.cpp index 1924ad5..c9cfa76 100644 --- a/src/CenternetDetection.cpp +++ b/src/CenternetDetection.cpp @@ -91,7 +91,7 @@ bool CenternetDetection::init(const std::string& tensor_path, const int n_classe checkCuda( cudaMallocHost(&target_coords, 4 * K *sizeof(float)) ); -#ifdef OPENCV_CUDA +#ifdef OPENCV_CUDACONTRIB checkCuda( cudaMalloc(&mean_d, 3 * sizeof(float)) ); checkCuda( cudaMalloc(&stddev_d, 3 * sizeof(float)) ); @@ -177,7 +177,7 @@ void CenternetDetection::preprocess(cv::Mat &frame) // step_t = end_t; } sz_old = sz; -#ifdef OPENCV_CUDA +#ifdef OPENCV_CUDACONTRIB cv::cuda::GpuMat im_Orig; cv::cuda::GpuMat imageF1_d, imageF2_d; diff --git a/src/MobilenetDetection.cpp b/src/MobilenetDetection.cpp index 23ffba6..4c6ff8a 100644 --- a/src/MobilenetDetection.cpp +++ b/src/MobilenetDetection.cpp @@ -160,7 +160,7 @@ bool MobilenetDetection::init(const std::string& tensor_path, const int n_classe generate_ssd_priors(specs, N_SSDSPEC); -#ifndef OPENCV_CUDA +#ifndef OPENCV_CUDACONTRIB checkCuda(cudaMallocHost(&input, sizeof(dnnType) * netRT->input_dim.tot())); #endif checkCuda(cudaMalloc(&input_d, sizeof(dnnType) * netRT->input_dim.tot())); @@ -209,7 +209,7 @@ bool MobilenetDetection::init(const std::string& tensor_path, const int n_classe void MobilenetDetection::preprocess(cv::Mat &frame) { -#ifdef OPENCV_CUDA +#ifdef OPENCV_CUDACONTRIB //move original image on GPU cv::cuda::GpuMat orig_img, frame_nomean; orig_img = cv::cuda::GpuMat(frame); diff --git a/src/Yolo3Detection.cpp b/src/Yolo3Detection.cpp index c1d86e8..654b5db 100644 --- a/src/Yolo3Detection.cpp +++ b/src/Yolo3Detection.cpp @@ -30,7 +30,7 @@ bool Yolo3Detection::init(const std::string& tensor_path, const int n_classes) { } dets = tk::dnn::Yolo::allocateDetections(tk::dnn::Yolo::MAX_DETECTIONS, classes); -#ifndef OPENCV_CUDA +#ifndef OPENCV_CUDACONTRIB checkCuda(cudaMallocHost(&input, sizeof(dnnType)*netRT->input_dim.tot())); #endif checkCuda(cudaMalloc(&input_d, sizeof(dnnType)*netRT->input_dim.tot())); @@ -50,7 +50,7 @@ bool Yolo3Detection::init(const std::string& tensor_path, const int n_classes) { void Yolo3Detection::preprocess(cv::Mat &frame) { -#ifdef OPENCV_CUDA +#ifdef OPENCV_CUDACONTRIB cv::cuda::GpuMat orig_img, img_resized; orig_img = cv::cuda::GpuMat(frame); cv::cuda::resize(orig_img, img_resized, cv::Size(netRT->input_dim.w, netRT->input_dim.h));