© 2021 Elsevier LtdOne of the main issues about safety in human-robot interaction is the distance calculation between robot and human. The acquisition of real-time distance information between robot and human allows the robot to modify its motion to ensure safety. This paper presents a real-time distance calculation framework that enables safe human-robot interaction. The human is tracked by an RGB-D sensor, and the joint positions of the human are acquired from the skeletal tracking algorithm. The representation of the robot and the human are formed by capsules to simplify and speed up the distance calculation. The distance calculation is implemented by using the GJK (Gilbert-Johnson-Keerthi) algorithm. The framework is validated by simulations and real experiments to show the efficiency of the framework. The results demonstrate the applicability of the framework for safe human-robot interaction applications.