The pushing robot working in the complex farming environment encounters several problems. For example, the precision of its navigation path extraction is low, and its working quality is greatly affected by the weather. In view of this, a method of farm operation path extraction based on machine vision is proposed in this study in order to solve the problems above and realize the autonomous and intelligent operation of the robot. First of all, the RGB images of the working area in front of the robot are obtained by using an RGB camera installed on the machine. Then, the collected images are preprocessed by means of sky removal, denoising and grayscale transformation. After that, the image is segmented to obtain the front fence, feed belt and ground data. Finally, the navigation path is obtained by extracting the features of the feed belt. The test results show that the absolute deviation of the pushing robot at different initial lateral distances is less than ±15 cm, and the deviation between the actual navigation route and the target route is within the expected range. The absolute value of the maximum lateral deviation in five test areas is 8.9 cm, and the absolute value of the average maximum lateral deviation is 7.6 cm. These experimental results show that the pushing robot can work stably without disturbing the feeding of cows. Particle swarm optimization is used to optimize the parameters of the PID and find the optimal parameters. This makes the system balanced and more responsive. Through this test, it is found that the initial direction of the robot will have a certain impact on the path production and tracking efficiency, and this effect is more significant when the robot changes the working area or turns. In which case, the trajectory of the robot should be in such a way that it immediately faces the next row at a small angular deviation, thus ensuring smoother motion. The method proposed in this study can provide support for the automatic navigation of pushing robots in dairy farms.