With the rapid increase in thevolume of music, digital processing of music has become an inevitable trend. Melody reflects the main ideas of music, melody extraction has wide application in computer music production, music retrieval and classification, and humming recognition and other fields. In this paper, a music melody extraction algorithm is proposed for polyphonic music based on adaptive harmonic superposition. A saliency function is first constructed by adaptive harmonic superposition through the preprocess of harmonic percussive source separation and the change of compression factor by discriminating the minimum stable variance of fundamental frequency. Then, random forest model is used to voice detection in the fundamental frequency segment constructed by the saliency function. Combining the frequency with maximum significance to get the melody sequence of music. Experiments show that the results obtained from the MIR 1K data set are significantly improved in the case of high signal to noise ratio.