When multi-dynamic target UAVs escape, the uncertainty of the formation method and the external environment causes difficulties in rounding them up, so suitable solutions are needed to improve the roundup success rate. However, traditional methods can generally only enable the encirclement of a single target, and when the target is scattered and escaping, this will lead to encirclement failure due to the inability to sufficiently allocate UAVs for encirclement. Therefore, in this paper, a real-time roundup and dynamic allocation algorithm for multiple dynamic targets is proposed. A real-time dynamic obstacle avoidance model is established for the roundup problem, drawing on the artificial potential field function. For the escape problem of the rounding process, an optimal rounding allocation strategy is established by drawing on the linear matching method. The algorithm in this paper simulates the UAV in different obstacle environments to round up dynamic targets with different escape methods. The results show that the algorithm is able to achieve the rounding up of multiple dynamic targets in a UAV and obstacle scenario with random initial positions, and the task UAV, which is able to avoid obstacles, can be used in other algorithms for real-time rounding up and dynamic allocation. The results show that the algorithm is able to achieve the rounding up of multi-dynamic targets in scenarios with a random number of UAVs and obstacles with random locations. It results in a 50% increase in the rounding efficiency and a 10-fold improvement in the formation success rate. And the mission UAV is able to avoid obstacles, which can be used in other algorithms for real-time roundup and dynamic allocation.