Anomalies between the platform doors and train seriously threaten the safe operation of intercity railway train, and therefore, accurately selecting the appropriate time for anomaly detection in elaborate process of train access is vital. However, the scarcity of data samples, disadvantage of anomaly reconstruction, and unreliable reconstruction errors pose challenges to image reconstruction-based anomaly detection methods. To address these issues, this study proposes a method based on train predeparture key frame extraction and patch-level unsupervised network using image inpainting. The key frame extraction is designed to extract the key frame to assist subsequent detection by tracking the motion state of train door and converting states into the switching door signals. An unsupervised network, which named image-inpainting anomaly detection network (IADN), based on image-inpainting autoencoder (AE), local abnormal information enhancement, and global-attentive reconstruction error (GARE), is proposed for anomaly classification and localization. The network utilizes an image-inpainting AE based on masking strategy and dual-channel structure to reconstruct normal images and solve the anomaly reconstruction problem. Afterward, it proposes local abnormal information enhancement and GARE to enhance the difference between inputs and reconstructions to improve the accuracy. The proposed method is tested on the intercity railway risk space anomaly dataset, and the anomaly classification AUC, localization precision, and recall achieve 99.32%, 97.45%, and 96.29%, respectively, which outperforms state-of-the-art methods.