# Performance Optimization of Object Tracking Algorithms in OpenCV on GPUs
###### Abstract  
Machine-learning-based computer vision is increasingly versatile and being leveraged by a wide range of smart devices. Due to the limited performance/energy budget of computing units in smart devices, the careful implementation of computer vision algorithms is critical. In this paper, we analyze the performance bottleneck of two well-known computer vision algorithms for object tracking: object detection and optical flow in the Open-source Computer Vision library (OpenCV). Based on our in-depth analysis of their implementation, we found the current implementation fails to utilize Open Computing Language (OpenCL) accelerators (e.g., GPUs). Based on the analysis, we propose several optimization strategies and apply them to the OpenCL implementation of object tracking algorithms. Our evaluation results demonstrate the performance of the object detection is improved by up to 86% and the performance of the optical flow by up to 10%. We believe our optimization strategies can be applied to other computer vision algorithms implemented in OpenCL.  
GPU; OpenCL; OpenCV; optimization; kernel occupancy +
Footnote †: journal: Applied Sciences  
profiling results showed that the application's performance deteriorates owing to (1) failure to efficiently utilize GPU resources and (2) kernel call overhead when operating many kernels with short execution times sequentially.  
This paper proposes techniques to improve the performance of object tracking algorithms in OpenCV. Especially, we focused on object detection and optical flow algorithms. Object detection is an important step to track objects [15; 16; 17]. However, using only object detection causes poor accuracy in tracking moving objects. Therefore, previous studies applied optical flow techniques to object detection for increasing the tracking accuracy of moving objects [1; 2].  
For the performance optimization, we analyzed two object detection algorithms and one optical flow algorithm. Based on the analysis, the paper presents two optimization techniques. The first is allowing the OpenCL kernel to maximize the device's parallelism by optimizing GPU occupancy and adjusting the number of work-items. The second technique reduces the cost of OpenCL API calls and data transfers by avoiding unnecessary kernel calls.  
The proposed techniques were applied to two GPU computing environments: an accelerated processing unit (APU) in which the CPU and GPU share the main memory, and a discrete GPU, whose memory is separate from the CPU's main memory. Our experiments show that the proposed optimization techniques improve the throughput of the object detection algorithms by up to 73% and 86% on the APU and the discrete GPU, respectively. In addition, our method to remove unnecessary kernel calls achieves 10% performance improvement.  
Our contributions are as follows. First, we analyzed OpenCV's object tracking algorithms running on parallel computing devices in terms of hardware level and investigated major factors affecting the algorithm's performance. Next, we propose efficient schemes to better utilize the hardware resources of a parallel computing device for each object tracking algorithm: remapping variables, increasing global work size, and kernel merging. Finally, by applying the proposed schemes to OpenCV's object tracking algorithms, we showed performance improvement per each scheme and analyzed them at the hardware usage level.  
This paper is organized as follows. Section 2 describes the background, previous studies related to our work, and our motivation with the profiling results of the target algorithms. Then, in Section 3, we analyze the OpenCV object tracking algorithms: object detection with Haar/LBP classifiers and Farneback optical flow. Based on the analysis, Section 4 introduces optimization methods for object tracking algorithms in OpenCV. Section 5 demonstrates and analyzes the performance improvements gained by our optimization methods. Finally, Section 6 presents the conclusions of this paper with future work.