As UAVs (Unmanned Aerial Vehicle) being widely used in remote sensing of agriculture resources and many other areas, the security of UAVs flying at a low altitude is getting more and more serious. This paper studies on the problem of obstacle avoidance while the UAV cruises at low altitude for agriculture sensing. Two kinds of obstacles are taken into account. A rapid obstacle-avoidance algorithm with adding a compensation waypoint is proposed for the avoidance of static obstacles; and a real-time method with dynamic information of navigation status and flying control sequence is proposed for tackling dynamic obstacles. Based on the sharing obstacle avoidance information, UAVs optimize their flight paths dynamically. Simulation results show that UAVs can avoid both static and dynamic kinds of obstacles quickly and their heading angles have a good convergence effect after flying over obstacles which can save much more energy for UAVs.