Most coastal trash comes from land. To prevent and control ocean pollution, it should be handled using sources that can maintain a clean ocean and improve the marine ecological environment. The proposed system can be used to inspect riverbanks and identify garbage on riverbanks. This waste can then be cleaned up before flowing into the sea. In this study, we utilized an unmanned aerial vehicle (UAV) to inspect riverbanks and applied path planning and obstacle avoidance to enhance the efficiency of UAV performance and ensure good adaptability in a complicated environment. Since most rivers in the middle and upper sections of the study area are rough and meandering, path planning was first addressed so that the drone could use the shortest path and less energy to perform the inspection task. Branches frequently protrude from the riverbank on both sides. Therefore, an instant obstacle avoidance algorithm was added to avoid various obstacles. Path planning was based on an Improved Particle Swarm Optimization (IPSO). A fuzzy system was added to the IPSO to adjust the parameters that could shorten the planned path. The Artificial Potential Field (APF) was applied for real-time dynamic obstacle avoidance. The proposed UAV system could be used to perform riverbank inspection successfully.