The decline of Drosophila climbing behavior is one of the common phenomena of Drosophila aging. The so-called negative geotaxis refers to the natural upward climbing behavior of Drosophila melanogaster after it oscillates to the bottom of the test tube. The strength of climbing ability is regarded as the index of aging change of D. melanogaster. At present, many laboratories use the percentage of 10 fruit flies climbing a specific height in 5 s as a general indicator of the climbing ability of fruit flies. This group research index ignores the climbing performance of a single fruit fly, and the climbing height belongs to the concept of vertical distance in physics, which cannot truly and effectively reflect the concept of curve distance in the actual climbing process of fruit flies. Therefore, based on the image processing algorithm, we added an experimental method to draw the climbing trajectory of a single fruit fly. By comparing the differences in climbing behavior of fruit flies under different sex, group or single, oscillation condition or rotation inversion condition, we can find that the K-Nearest Neighbor target detection algorithm has good applicability in fruit fly climbing experiment, and the climbing ability of fruit flies decreases with age. Under the same experimental conditions, the climbing ability of female fruit flies was greater than that of male fruit flies. The climbing track