An RGB-D SLAM (simultaneous localization and mapping) algorithm based on semi-direct visual odometry is proposed. By using the advantages of both the direct method and the traditional feature-based method, and combining with robust back-end optimization and closed-loop detection, the localization and mapping accuracy of the algorithm in complex environments is effectively improved. At the localization stage, the initial pose of camera is estimated by the direct method, which is further optimized by matching the features and minimizing the reprojection error. By selecting map points and optimizing the posture output strategy, it can deal with the problems of low-texture, illumination change, moving objects and so on. In addition, the algorithm has the ability of global relocation. A new key frame selection strategy is proposed for back-end optimization, that maintains two separate key frames in parallel, i.e. the local key frames selected by the direct method, and the global key frames selected by the feature-based method. These key frame are optimized in sliding window and feature map respectively. The algorithm improves the global consistency of SLAM through closed-loop detection and optimization on the global key frames. The experimental results based on standard datasets and real scenes show that the performance of the proposed algorithm is better than the main RGB-D SLAM algorithms in many real scenes, and it has strong robustness to the environments with low-texture and moving objects.