Artificial pigment is a common food additive in cream products. If added in excess, it will do harm to human body. At present, there is no research on the detection of cream pigment by Near Infrared (NIR) spectroscopy. In this paper, a method based on random forest was applied to determine the indigotine in cream. Weighting in the experiments was accomplished using analytical balances with precision as low as 0.0001 g. The NIR spectra data of cream with different concentration of indigotine were recorded. The original spectra was pretreated by SG smoothing, mean centering and second derivative. Random forest was applied to establish a quantitative analysis model for cream pigment content, and multiple evaluation criteria were selected to comprehensively evaluate the model. The R2 was 0.9402, RMSEP was 0.2509 and RPD was 4.0893. Consequently, NIR spectroscopy, combined with data pretreatments and random forest model, was confirmed to be an interesting tool for non-destructive evaluation of pigment content in cream.