# Log Volume Measurement and Counting Based on Improved Cascade Mask R-CNN and Deep SORT
## 1 Introduction
While bounding box-based object detection models excel in rapidly and accurately identifying log bounding boxes, techniques like the Hough transform or ellipse fitting are still employed for subsequent log end dimension measurements to determine end diameters [23], which may impact the overall measurement accuracy. To overcome the limitations of the Hough transform, [PERSON] introduced an enhanced detection network called YOLACT_WOOD, based on YOLACT [24]. This network effectively provides accurate log contours and rapid detection capabilities. The results demonstrate a 2.6% improvement in the Intersection over Union (IoU) for masks, with a true detection rate of 96.61% for logs [25]. Furthermore, mask-based detection models have gained significant attention in the field of log detection [26; 27]. [PERSON] also integrated Res2 Net and PAFPN into the backbone network for Mask R-CNN to enhance log contour segmentation, achieving improvements of 2.0%, 1.2%, and 4.4% for small, medium, and large logs, respectively, while maintaining a wood volume calculation error within 1% [28]. In another approach, [PERSON] developed a handheld device for measuring log end diameters, utilizing the Solov2 model for log contour detection and pose estimation to accurately calculate dimensions. The measurement error for log diameter was found to range from \(-\)0.54 cm to 0.61 cm [29]. Instance segmentation-based object detection algorithms can mitigate the accuracy loss typically associated with secondary detection of log contours. However, in complex detection scenarios, the feature extraction capability of the backbone network may face challenges. Moreover, object detectors trained with low Intersection over Union (IoU) thresholds, such as 0.5, often result in noisy detections. As a result, when detecting large stacks of logs, current log end detection models may still overlook some smaller objects, complicating accurate detection and segmentation efforts. The object detection model can quickly identify log ends and count logs within a single image. However, capturing all log stacks in one image poses a challenge. Whenmultiple logs are present, each detected log may appear relatively small, leading to missed detections and negatively affecting counting accuracy. To address this issue, we employ the Deep SORT [30] object tracking algorithm to identify and statistically track logs across consecutive image frames. The Deep SORT-based tracking model has been successfully applied in agriculture and forestry. For instance, [PERSON] utilized the ShuffleNetV2 and BiFPN architectures as the backbone for the YOLOv5s model to detect tomatoes at different growth stages, and subsequently employed Deep SORT to track and count these tomatoes, achieving a high level of accuracy [31]. Similarly, [PERSON] implemented Deep SORT alongside an enhanced CenterNet to track and count cotton seedlings, resulting in an R\({}^{2}\) value of 0.967 and a root mean square error (RMSE) of 0.394 [32]. These studies inspire our research on counting large-scale log stacks. In this paper, we present an enhanced Cascade Mask R-CNN method for detecting log ends. Using the detection information, we then measure log volume and perform statistical log counting through integration with the Deep SORT algorithm. Our contributions can be summarized as follows:  
1. We proposed an improved Cascade Mask R-CNN model that incorporates an attention mechanism into the feature fusion components of the ResNet and FPN networks. It serves to bolster the network's capability for extracting log features. 2. We integrated the improved Cascade Mask R-CNN model with Deep SORT to track and count large log stacks. 3. We achieved the automated calculation of log volume in accordance with Chinese wood measurement standards, using depth information from a binocular stereo camera and achieving a low error.