The automatic acquisition of crop information can promote the rapid development of precision agriculture. Tomatoes, as a representative greenhouse crop, can demonstrate their growth status and overall health could be exhibited by measuring the diameters of their main stems. Automated measurement of the diameters of the trunk stems can not only reduce labor costs, but also enhance efficiency, thereby facilitating the improvement of tomato cultivation and planting management. Therefore, this study proposes a novel method based on an instance segmentation algorithm combined with RGB-D data to measure the diameter of a tomato trunk. First, we utilize the improved YOLOv8-seg to acquire the masks and bounding boxes of the buds and stems. Namely, we replace the SPPF module with Soft-SPPF to enhance the model’s capability to extract multi-scale features. Additionally, we improve the neck layer using cross-stage and weighted feature fusion to enhance the feature fusion effect. Then, we design a method to calculate the diameter of the tomato trunk by utilizing the instance segmentation results and depth information. Specifically, we first obtain the measurement point and the ROI (Region of Interest) to be measured by identifying the intersection between the bounding box of the bud and the straight line fitted by the stem mask in an image. We then filter out irrelevant depth information using the mask within the ROI, optimize the coordinate values of the measurement point, and calculate the main stem diameter. The results demonstrate that the measurements obtained in this study have a RMSE (Root Mean Square Error) of 1.5 mm and a MAPE (Mean Absolute Percentage Error) of 12.37 % compared with the manual measurements. Compared with the method based on object detection, the direct acquisition of contour information for the target instances by the instance segmentation algorithm reduces the algorithmic complexity of the subsequent processing. The proposed method can offer precise and reliable information on the diameter of the main stem of a tomato in real-world scenarios. It can be extended to other types of crops in greenhouses.