This study was aimed at investigating the location of gastric cancer by using a gastroscope image based on an artificial intelligence algorithm for gastric cancer and the effect of ultrasonic-guided nerve block combined with general anesthesia on patients undergoing gastric cancer surgery. A total of 160 patients who were undergoing gastric cancer surgery from March 2019 to March 2021 were collected as the research objects, and the convolutional neural network (CNN) algorithm was used to segment the gastroscope image of gastric cancer. The patients were randomly divided into a simple general anesthesia group of 80 cases and a transversus abdominis plane block combined with rectus abdominis sheath block combined with the general anesthesia group of 80 cases. Then, compare the systolic blood pressure (SBP), diastolic blood pressure (DBP), and heart rate (HR) at the four time points T0, T1, T2, and T3. The times of analgesic drug use within 48 hours after operation and postoperative adverse reactions were recorded. The visual analog scale (VAS) scores were also recorded at 4 h, 12 h, 24 h, and 48 h. The results show that the image quality after segmentation is good: the accuracy of tumor location is 75.67%, which is similar to that of professional endoscopists. Compared with the general anesthesia group, the transversus abdominis plane block combined with the rectus sheath block combined with the general anesthesia group had fewer anesthetics, and the difference was statistically significant (P < 0.05). Compared with the general anesthesia group, SBP, DBP, and HR were significantly reduced at T1, T2, and T3 in the transverse abdominis plane block combined with rectus sheath block and general anesthesia group (P < 0.05). Compared with the simple general anesthesia group, the VAS scores of the transversus abdominis plane block combined with rectus sheath block combined with the general anesthesia group decreased at 4 h, 12 h, and 24 h after surgery, and the difference was statistically significant (P < 0.05). The number of analgesics used in transversus abdominis plane block combined with the rectus sheath block combined with the general anesthesia group within 48 hours after operation was significantly less than that in the general anesthesia group, and the difference was statistically significant (P < 0.05). The average incidence of adverse reactions in the nerve block combined with the general anesthesia group was 2.5%, which was lower than the average incidence of 3.75% in the general anesthesia group. In summary, the CNN algorithm can accurately segment the lesions in the ultrasonic images of gastric cancer, which was convenient for doctors to make a more accurate judgment on the lesions, and provided a basis for the preoperative examination of radical gastrectomy for gastric cancer. Ultrasonic-guided nerve block combined with general anesthesia can effectively improve the analgesic effect of radical gastrectomy for gastric cancer, reduced intraoperative and postoperative adverse reactions and analgesic drug dosage, and had a good effect on postoperative recovery of patients. The combined application of these two methods can further improve the precision treatment of gastric cancer patients and accelerate postoperative recovery.