CTU-IIG / kcf

Kernelized Correlation Filter tracker
13 stars 6 forks source link

GPU-accelerated HoG calculation #37

Open wentasah opened 5 years ago

wentasah commented 5 years ago

Currently, HoG calculation is the perfomance bottlenect. Try to accelerate it on GPU, perhaps with the implementation from OpenCV: https://docs.opencv.org/3.4.3/d5/d33/structcv_1_1HOGDescriptor.html

Shanigen commented 5 years ago

I was only able to implement CPU version of HOG extraction function in OpenCV (f995b64). As for the CUDA version of the HOG from OpenCV. I was not able to make it work on Tegra and neither on my desktop PC. The problem is probably the wrong version of OpenCV. I am also not sure how it is currently with memory management, if cv::Mat's in the tracker are currently using the memory class you implemented or if it is necessary to copy data from cv::Mat to cv::Cuda::GpuMat. I ask you if you could test this piece of code on your board if your version of OpenCV is newer.

cv::Ptr<cv::cuda::HOG> cuda_hog = cuda::HOG::create(win_size, block_size, block_stride, cell_size, 9);

cv::cuda::GpuMat image;
cv::cuda::GpuMat descriptor;

image.upload(src);

cuda_hog->compute(image_alpha, descriptor);

This code should go to KCF_Tracker::hog function that I implemented, where it replaces:

   cv::HOGDescriptor hog(win_size, block_size, block_stride, cell_size, 9, 1, -1, cv::HOGDescriptor::L2Hys, clip);
   hog.compute(input_hog, descs);

There will be additional modifications needed for the output in the CUDA version of HOG, but now I would like just to test if you can run and compile the code with cv::cuda::HOG.

wentasah commented 5 years ago

Regarding OpenCV: I think that OpenCV must be compiled with CUDA support, i.e. cmake -DUSE_CUDA=ON. Do you use such a version? If not try to recompile OpenCV with it. Unfortunately, I cannot try it on my board, because it's not working since last jetpack update.

Memory management: I didn't do anything with cv::Mat's memory management. Only ComplexMat uses memory via DynMem class. So you can do whatever is supported by plain OpenCV with cv::Mat.

wentasah commented 5 years ago

Any progress?