Faced with the problem of poor anti-interference ability of star map recognition technology, in order to improve its anti-interference ability and achieve higher attitude measurement accuracy, this article proposes a star map recognition method based on binary search trees. Star sensors and gyroscopes are combined to solve the problem of the poor real-time performance of star sensors, optimizing the Extended Kalman Filtering (EKF) algorithm. This improves attitude output accuracy and formulates corresponding attitude measurement schemes considering the situation where the star sensor is not visible. The results showed that the improved star pattern recognition algorithm had better adaptability and robustness than the rasterization algorithm, with a high recognition success rate of 95.6% when the star sensor field of view was 3°*3°, while the rasterization algorithm cannot recognize small fields of view. The recognition success rate of the algorithm was 98.6% when the standard deviation of magnitude noise was 2.0 pixels, which was 15.4% higher than the rasterization algorithm. Unlike the EKF algorithm, the optimized EKF algorithm had a higher attitude output accuracy, with an average error of about 0.000 211°; compared to before optimization, it has increased by 93.43%. In the attitude measurement scheme, the relative attitude angle measurement error was small, and the maximum attitude measurement error in the rolling angle direction was 1.8 × 10−3°. This paper adopts a method to achieve high-precision satellite attitude measurement with good adaptability, which can be applied in complex space missions.