Add opencv script, modified macro, add opencv section into readme
Signed-off-by: Micaela Verucchi <micaela.verucchi@unimore.it>
This commit is contained in:
@@ -4,6 +4,7 @@ The main goal of this project is to exploit NVIDIA boards as much as possible to
|
|||||||
|
|
||||||
## Index
|
## Index
|
||||||
* [Dependencies](#dependencies)
|
* [Dependencies](#dependencies)
|
||||||
|
* [About OpenCV](#about-opencv)
|
||||||
* [How to compile this repo](#how-to-compile-this-repo)
|
* [How to compile this repo](#how-to-compile-this-repo)
|
||||||
* [Workflow](#workflow)
|
* [Workflow](#workflow)
|
||||||
* [How to export weights](#how-to-export-weights)
|
* [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
|
* OPENCV 4.1
|
||||||
* yaml-cpp 0.5.2 (sudo apt install libyaml-cpp-dev)
|
* 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
|
## How to compile this repo
|
||||||
Build with cmake. If using Ubuntu 18.04 a new version of cmake is needed (1.15 or above).
|
Build with cmake. If using Ubuntu 18.04 a new version of cmake is needed (1.15 or above).
|
||||||
```
|
```
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ private:
|
|||||||
|
|
||||||
float *target_coords;
|
float *target_coords;
|
||||||
|
|
||||||
#ifdef OPENCV_CUDA
|
#ifdef OPENCV_CUDACONTRIB
|
||||||
float *mean_d;
|
float *mean_d;
|
||||||
float *stddev_d;
|
float *stddev_d;
|
||||||
#else
|
#else
|
||||||
|
|||||||
@@ -17,7 +17,7 @@
|
|||||||
|
|
||||||
#include "tkdnn.h"
|
#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 {
|
namespace tk { namespace dnn {
|
||||||
|
|
||||||
@@ -37,7 +37,7 @@ class DetectionNN {
|
|||||||
|
|
||||||
cv::Scalar colors[256];
|
cv::Scalar colors[256];
|
||||||
|
|
||||||
#ifdef OPENCV_CUDA
|
#ifdef OPENCV_CUDACONTRIB
|
||||||
cv::cuda::GpuMat bgr[3];
|
cv::cuda::GpuMat bgr[3];
|
||||||
cv::cuda::GpuMat imagePreproc;
|
cv::cuda::GpuMat imagePreproc;
|
||||||
#else
|
#else
|
||||||
|
|||||||
@@ -91,7 +91,7 @@ bool CenternetDetection::init(const std::string& tensor_path, const int n_classe
|
|||||||
|
|
||||||
checkCuda( cudaMallocHost(&target_coords, 4 * K *sizeof(float)) );
|
checkCuda( cudaMallocHost(&target_coords, 4 * K *sizeof(float)) );
|
||||||
|
|
||||||
#ifdef OPENCV_CUDA
|
#ifdef OPENCV_CUDACONTRIB
|
||||||
|
|
||||||
checkCuda( cudaMalloc(&mean_d, 3 * sizeof(float)) );
|
checkCuda( cudaMalloc(&mean_d, 3 * sizeof(float)) );
|
||||||
checkCuda( cudaMalloc(&stddev_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;
|
// step_t = end_t;
|
||||||
}
|
}
|
||||||
sz_old = sz;
|
sz_old = sz;
|
||||||
#ifdef OPENCV_CUDA
|
#ifdef OPENCV_CUDACONTRIB
|
||||||
cv::cuda::GpuMat im_Orig;
|
cv::cuda::GpuMat im_Orig;
|
||||||
cv::cuda::GpuMat imageF1_d, imageF2_d;
|
cv::cuda::GpuMat imageF1_d, imageF2_d;
|
||||||
|
|
||||||
|
|||||||
@@ -160,7 +160,7 @@ bool MobilenetDetection::init(const std::string& tensor_path, const int n_classe
|
|||||||
|
|
||||||
generate_ssd_priors(specs, N_SSDSPEC);
|
generate_ssd_priors(specs, N_SSDSPEC);
|
||||||
|
|
||||||
#ifndef OPENCV_CUDA
|
#ifndef OPENCV_CUDACONTRIB
|
||||||
checkCuda(cudaMallocHost(&input, sizeof(dnnType) * netRT->input_dim.tot()));
|
checkCuda(cudaMallocHost(&input, sizeof(dnnType) * netRT->input_dim.tot()));
|
||||||
#endif
|
#endif
|
||||||
checkCuda(cudaMalloc(&input_d, sizeof(dnnType) * netRT->input_dim.tot()));
|
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)
|
void MobilenetDetection::preprocess(cv::Mat &frame)
|
||||||
{
|
{
|
||||||
#ifdef OPENCV_CUDA
|
#ifdef OPENCV_CUDACONTRIB
|
||||||
//move original image on GPU
|
//move original image on GPU
|
||||||
cv::cuda::GpuMat orig_img, frame_nomean;
|
cv::cuda::GpuMat orig_img, frame_nomean;
|
||||||
orig_img = cv::cuda::GpuMat(frame);
|
orig_img = cv::cuda::GpuMat(frame);
|
||||||
|
|||||||
@@ -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);
|
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()));
|
checkCuda(cudaMallocHost(&input, sizeof(dnnType)*netRT->input_dim.tot()));
|
||||||
#endif
|
#endif
|
||||||
checkCuda(cudaMalloc(&input_d, sizeof(dnnType)*netRT->input_dim.tot()));
|
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)
|
void Yolo3Detection::preprocess(cv::Mat &frame)
|
||||||
{
|
{
|
||||||
#ifdef OPENCV_CUDA
|
#ifdef OPENCV_CUDACONTRIB
|
||||||
cv::cuda::GpuMat orig_img, img_resized;
|
cv::cuda::GpuMat orig_img, img_resized;
|
||||||
orig_img = cv::cuda::GpuMat(frame);
|
orig_img = cv::cuda::GpuMat(frame);
|
||||||
cv::cuda::resize(orig_img, img_resized, cv::Size(netRT->input_dim.w, netRT->input_dim.h));
|
cv::cuda::resize(orig_img, img_resized, cv::Size(netRT->input_dim.w, netRT->input_dim.h));
|
||||||
|
|||||||
Reference in New Issue
Block a user