Utilizing machine vision technology based on YOLOv5, a six-axis robot can quickly identify and classify targets. However, when the YOLOv5 model is used for the recognition and grasping of small workpieces, issues such as low precision and missed detections frequently occur. This paper proposes an enhanced object recognition algorithm, integrating a CBAM attention module and an improved loss function into YOLOv5 to control the hand–eye coordination of the six-axis robot during grasping. The CBAM attention module is incorporated into the backbone network of YOLOv5 to enhance its feature extraction capabilities, while the original loss function is modified to accelerate convergence and improve regression accuracy. An experimental platform for six-axis robot hand–eye coordination grasping was built, and grasping experiments were conducted. The proposed method significantly improves the robot’s grasping accuracy, with a 99.59% mAP0.5 and a 90.83% successful grasping rate, effectively addressing the challenges of low accuracy and missed detections in traditional systems.