Design and Implementation of an Intelligent Log Diameter Grading and Sorting Line Based on Machine Vision

: In order to address the challenges posed by elevated manual labor costs and limited automation in traditional log diameter grading and sorting processes, this paper centers on the design and research of an intelligent log diameter grading and sorting line utilizing machine vision. The study focuses on logs with smaller diameters located in Fujian province, China. By analyzing production requirements, the study formulates the structure of the feeding, alignment, detection, and sorting zones to fulfill sorting functions. Using the YOLOv5 model, the system achieves accurate log end face positioning, and the diameter is computed through a designated algorithm. The operational process of the system is examined, and the control logic governing the production line is elucidated. Evaluating the practical performance of the production line, the study assesses the accuracy of diameter recognition, precision in grading, and operational efficiency. The results reveal that the absolute error in diameter detection for the sorting line averages 1.12 mm, with sorting accuracy exceeding 95%. The sorting line can automatically categorize logs with diameters ranging from 60 mm to 300 mm and lengths ranging from 2 m to 6 m, achieving an annual sorting capacity of 120,000 to 130,000 cubic meters. The research findings illustrate that the system fulfills the industry’s demands for log diameter grading and sorting, thereby enhancing economic efficiency for enterprises.


Introduction
Following the harvesting of timber in forestry operations, harvested logs are transported to sawmills for processing.With the rising cost of logs, diminishing supply, and an increasing demand for specialty products, sawmills globally are compelled to maximize the extraction of value from raw materials.Hence, sawmills worldwide have been actively exploring strategies to reduce raw material waste and enhance the yield from original logs [1].In order to minimize material waste, the pre-sorting of logs based on their diameter is an indispensable step for the majority of sawmills before processing begins [2].This step is pivotal in determining the specifications, quality, and suitability of the logs.Pre-sorting practices are widespread in southern Europe and eastern Canada, with over 95% of sawmills in countries such as Sweden implementing pre-sorting procedures.
However, most domestic enterprises in China still rely on traditional manual log diameter grading and sorting, a process fraught with numerous challenges.Given the vast quantity of harvested logs, manual measurements frequently lead to instances of under-detection and missed logs.Traditional manual measurements also require the collaboration of two to three individuals, with two tasked with measurements and one assigned to record keeping [3], demanding a considerable amount of manpower.Furthermore, the Chinese National Standards GB/T 144-2013 [4] for the size inspection of logs is intricate; for instance, in the case of the commonly encountered elliptical end face logs, the diameter measurement involves taking the short diameter through the center of the small end section, then vertically measuring the long diameter through the center of the short diameter (excluding bark thickness), and finally calculating the result according to the standard.In the face of a massive workload, workers often deviate from strict adherence to standards to ensure efficiency.The measurement methods, including the use of tape measures as measuring tools, are frequently not strictly in accordance with the standards.Consequently, the quality of tape measures used for measurement varies.As a result, the accuracy of log diameters cannot be guaranteed, leading to lower sorting precision [5].When measuring logs that are stacked at elevated heights, workers must ascend to potentially hazardous positions, posing both danger and physical strain.Following diameter measurements, different-sized logs must be individually coded and sorted, adding to the labor intensity and risk factor of the entire process.In frigid regions, these challenges are further intensified.Therefore, the development of automatic log detection and sorting equipment is of significant importance in improving the production efficiency of log sorting, reducing labor intensity, and mitigating safety risks.This presents a practical solution for the development of related industries.
Regarding research on automatic log sorting systems, both domestic and international scholars, as well as companies, have conducted relevant research.The log sorting line developed by Hekotek, an Estonia-based company, employs X-ray scanning technology for the efficient sorting of logs within the diameter range of 80-600 mm.The system achieves an average sorting speed of 20 logs per minute, with an annual sorting capacity ranging from 150,000 to 1.1 million cubic meters, and has been successfully deployed in multiple countries.Importantly, the company offers comprehensive solutions to ensure the adaptability of the production line to various extreme operational conditions [6].RewmaSawco, a Swedishbased company, has developed a comprehensive log sorting system that combines 3D scanners and X-ray technology.With its accompanying control system, this system increases customer output by 2% [7].Latvijas Finieris, a Latvia-based company, has designed a log sorting line using a 3D log scanner, capable of sorting logs with diameters ranging from 140 to 700 mm.The system achieves an average sorting speed of over twenty logs per minute [8].Nordautomation, a Finland-based company, has designed and delivered the world's longest log sorting line, with a length of up to 500 m and 126 sorting bins controlled by a combination of hydraulic and electric systems.The system achieves an average sorting speed of around twenty logs per minute [9].On the domestic front, Shandong Baishengyuan Group Co., Ltd.(Weihai, Shandong, China) has developed automatic log detection and sorting equipment.This equipment employs laser curtains for measuring log dimensions and automatic sorting and has reached an advanced level internationally [10].
Based on X-ray and 3D scanning technologies, scanning devices currently dominate the global market, and this technology is relatively mature.Many companies have adopted similar solutions, deployed in sawmills globally.Scanning devices can perform not only diameter detection but also projects such as heartwood content and edge density detection.However, their cost is high, typically reaching tens of thousands of dollars.Moreover, as sorting sites are often outdoors, the deployment and maintenance costs of these devices are also high.This paper applies machine vision and deep learning technology innovatively to log sorting equipment, aiming to explore the possibility of low-cost visual devices replacing traditional high-cost scanning detection devices.In comparison to scanning devices, the log detection work in this paper can be achieved with just one camera, at a cost of only around a thousand dollars.Although the scope of detection projects is limited, for the majority of practical enterprises, there is a strong demand for diameter detection only.Therefore, this low-cost and lightweight solution has greater advantages.With the rapid development of machine vision and deep learning technology, numerous papers and research results on log feature detection have emerged.Various log detections that were previously impossible with machine vision, such as defect detection, heartwood detection, edge detection, annual ring spacing, etc., have become possible.In the future, this equipment will continue to improve to achieve more detection goals, meeting the specific needs of enterprises with Forests 2024, 15, 387 3 of 20 special requirements for sorting standards.The innovative human-machine interface (HMI) of this design [11,12] allows integration with third-party software, websites, etc., enabling remote control capabilities for third-party applications such as mobile apps.

Requirements
To meet the practical production requirements and align with the enterprise's production needs, the design must address several key technical challenges: 1.
The sorting of timber diameters is mainly conducted based on the diameter at the small end, with a small portion involving a combination of diameter and length.This research exclusively focuses on detecting the small end diameter of timber.Therefore, it requires the implementation of an automated method for measuring timber diameter.
The measurement method must comply with national standards and meet production accuracy requirements.The enterprise has specified that the absolute error in diameter detection must not exceed 5 mm.

2.
Once the diameter of the timber is known, it is necessary to develop precise control algorithms to achieve the final sorting function, ensuring that timber of the same diameter class is directed to the same discharge outlet for subsequent transport.
The sorting accuracy needs to be controlled to be at or above 95%, and the sorting speed should reach 100 m 3 /8 h, equivalent to 25,000 m 3 /year, in accordance with the enterprise's requirements.

3.
This design must be compatible with sorting all types of timber collected at the deployment site.All timber has a uniform length of 6 m, and the diameter at the small end falls within the range of 60-300 mm. 4.
The sorting targets for this design are freshly felled timber; therefore, it will be extensively deployed at logging sites.Given the complex and variable environmental conditions in forest areas, a high level of robustness is required for the system to ensure that the entire equipment set can support continuous, high-intensity operation in adverse conditions.

5.
While ensuring all the aforementioned conditions, the design should prioritize making the equipment as lightweight as possible to reduce costs.Additionally, it should feature good human-machine interaction characteristics.
In addressing these technical challenges, the structure of the designed log diameter automatic sorting system is illustrated in Figure 1.This design comprises the feeding preparation zone, small end alignment zone, inclined transport zone, diameter measurement zone, monitoring unit, automatic sorting zone, and sorting storage zone.
Forests 2024, 15, x FOR PEER REVIEW 3 of 20 the future, this equipment will continue to improve to achieve more detection goals, meeting the specific needs of enterprises with special requirements for sorting standards.The innovative human-machine interface (HMI) of this design [11,12] allows integration with third-party software, websites, etc., enabling remote control capabilities for third-party applications such as mobile apps.

Requirements
To meet the practical production requirements and align with the enterprise's production needs, the design must address several key technical challenges: 1.The sorting of timber diameters is mainly conducted based on the diameter at the small end, with a small portion involving a combination of diameter and length.This research exclusively focuses on detecting the small end diameter of timber.Therefore, it requires the implementation of an automated method for measuring timber diameter.The measurement method must comply with national standards and meet production accuracy requirements.The enterprise has specified that the absolute error in diameter detection must not exceed 5 mm. 2. Once the diameter of the timber is known, it is necessary to develop precise control algorithms to achieve the final sorting function, ensuring that timber of the same diameter class is directed to the same discharge outlet for subsequent transport.The sorting accuracy needs to be controlled to be at or above 95%, and the sorting speed should reach 100 m 3 /8 h, equivalent to 25,000 m 3 /year, in accordance with the enterprise's requirements.3.This design must be compatible with sorting all types of timber collected at the deployment site.All timber has a uniform length of 6 m, and the diameter at the small end falls within the range of 60-300 mm. 4. The sorting targets for this design are freshly felled timber; therefore, it will be extensively deployed at logging sites.Given the complex and variable environmental conditions in forest areas, a high level of robustness is required for the system to ensure that the entire equipment set can support continuous, high-intensity operation in adverse conditions. 5.While ensuring all the aforementioned conditions, the design should prioritize making the equipment as lightweight as possible to reduce costs.Additionally, it should feature good human-machine interaction characteristics.
In addressing these technical challenges, the structure of the designed log diameter automatic sorting system is illustrated in Figure 1.This design comprises the feeding preparation zone, small end alignment zone, inclined transport zone, diameter measurement zone, monitoring unit, automatic sorting zone, and sorting storage zone.

System Design
In response to the aforementioned technical challenges, Figure 1 illustrates the structure of the designed automatic timber diameter sorting system.The system primarily comprises the loading zone, alignment zone, incline transportation zone, diameter detection zone, monitoring unit, automatic sorting zone, and material storage rack.

1.
Loading zone: this zone is designed to achieve uniform and orderly loading of timber through mechanical structures.

2.
Alignment zone: after passing through the loading zone, the timber is transported to the alignment zone.A machine vision approach is employed for diameter detection, requiring the capture of images of the small end face of the timber.Since depth information is needed to determine the actual size represented by a single pixel when calculating the diameter, the distance from the timber end face to the camera needs to be consistent.The purpose of this zone is to align the small end face of the timber for effective detection.Diameter measurement: following the aforementioned steps, logs are arranged neatly, with even spacing and aligned butts, entering the diameter measurement zone.This design innovatively incorporates a solution that combines machine vision with deep learning for diameter measurement.

3.
Diameter measurement zone: this zone is designed for timber end face detection and diameter calculation.4.
Automatic sorting zone: the design of this zone aims to automatically sort timber according to its diameter and within specified diameter ranges.

5.
Material storage rack: timber of the same diameter class, sorted in the automatic sorting zone, is stacked in the same material storage rack for convenient subsequent transportation.

Hardware Selection
Due to environmental influences and production requirements, the system requires robustness; therefore, the use of high-quality and stable hardware is indispensable.The hardware composition of this design is illustrated in Figure 2. Following principles of reliability and cost-effectiveness, the design adopts the Haiwell T60S0T programmable logic controller (PLC) [13,14] as the control core.Given the need for a large number of I/O ports in practical development, a digital input module H36DOT is equipped to expand the PLC ports.Additionally, two communication expansion modules S01RS are added to extend the host communication interface.The system is also equipped with an HMI display screen, model C10S-W, for human-machine interface development.

Wood Log End Face Detection Model and Diameter Calculation Based on YOLOv5
The development of an automatic sorting system for log diameter classification depends on high-precision diameter detection.In this research, we employ machine vision technology for diameter detection, using the ZED2i stereo camera as the image acquisition device.Due to the deployment of the equipment outdoors, the system is significantly in- The PLC in this design serves as the lower-level controller, responsible for overseeing overall equipment operation control.Diameter measurement is controlled by the upper-Forests 2024, 15, 387 5 of 20 level program, comprising an industrial computer and a binocular camera.After obtaining diameter data, the industrial computer communicates with the PLC by transmitting the diameter values.The coordinated operation of these components comprises the automatic control system of the device.
Apart from the upper-and lower-level controllers, there are various conveying mechanisms and hardware for executing actions, including motors, cylinders, sensors, etc.These components are made of high-quality steel to ensure stability and corrosion resistance.All cables undergo multiple layers of wrapping to reduce aging and the likelihood of damage, particularly from animals like rodents.The core controllers and electronic components are uniformly installed in an electrical control cabinet, which is situated in a dedicated control room.

Wood Log End Face Detection Model and Diameter Calculation Based on YOLOv5
The development of an automatic sorting system for log diameter classification depends on high-precision diameter detection.In this research, we employ machine vision technology for diameter detection, using the ZED2i stereo camera as the image acquisition device.Due to the deployment of the equipment outdoors, the system is significantly influenced by lighting conditions.Moreover, the wide field of view of the stereo camera poses challenges in threshold segmentation, making it susceptible to background interference and natural lighting effects, resulting in inaccurate segmentation of elliptical end faces.To address this issue, we establish a YOLOv5 object detection model [15][16][17][18][19] for rapid and accurate extraction of log end face contours.The exceptional performance of the YOLOv5 model depends heavily on the computational capabilities of the running device.YOLOv5s, known for its compact model size and fast computation speed, is often applied in scenarios where computational performance is limited or real-time detection is required [20].Therefore, we prioritize the use of YOLOv5s for testing purposes.

Construction of the Dataset
To construct the dataset for detecting timber end face contours, this research deployed equipment on-site and utilized a stereo camera system.A total of 5000 images of timber end faces were taken under diverse conditions, including varying shooting angles, depths, diameters, shapes, and lighting intensities.The images were taken at a resolution of 1920 × 1080 pixels in the JPG format.Figure 3 illustrates a subset of the collected images.

Wood Log End Face Detection Model and Diameter Calculation Based on YOLOv5
The development of an automatic sorting system for log diameter classification pends on high-precision diameter detection.In this research, we employ machine v technology for diameter detection, using the ZED2i stereo camera as the image acquis device.Due to the deployment of the equipment outdoors, the system is significantl fluenced by lighting conditions.Moreover, the wide field of view of the stereo cam poses challenges in threshold segmentation, making it susceptible to background inte ence and natural lighting effects, resulting in inaccurate segmentation of elliptical faces.To address this issue, we establish a YOLOv5 object detection model [15-19 rapid and accurate extraction of log end face contours.The exceptional performan the YOLOv5 model depends heavily on the computational capabilities of the runnin vice.YOLOv5s, known for its compact model size and fast computation speed, is o applied in scenarios where computational performance is limited or real-time detecti required [20].Therefore, we prioritize the use of YOLOv5s for testing purposes.

Construction of the Dataset
To construct the dataset for detecting timber end face contours, this research ployed equipment on-site and utilized a stereo camera system.A total of 5000 imag timber end faces were taken under diverse conditions, including varying shooting an depths, diameters, shapes, and lighting intensities.The images were taken at a resolu of 1920 × 1080 pixels in the JPG format.Figure 3 illustrates a subset of the collected im  In this research, we annotated the images using the LabelImg software (version 1.8.5), with a single class labeled as "Wood".Due to the relatively small size of the dataset, to mitigate information leakage and offer a more accurate reflection of the model's performance, the annotated images were randomly partitioned into training, validation, and test sets following the common ratio of 6:2:2.

Detection Model for Timber End Faces
This study requires the application of algorithmic models to detect timber contours in the diameter measurement region.Since the target for detection is limited to the end faces of timber, and these end faces have relatively large contours with distinct features, the YOLOv5s detection model is chosen for this purpose.This model comprises four components: the input stage (input), backbone network (backbone), neck network (neck), and output stage (head) [21].The input stage uses Mosaic data augmentation on the dataset images by randomly combining four different images of timber end faces to generate new composite images, thereby enhancing dataset diversity.The adaptive training sample selection (ATSS) algorithm automatically calculates anchor box parameters that are most suitable for the input image.Adaptive image scaling dynamically scales images to adapt to the varying scales of timber end face detection.
The preprocessed images of timber end faces are then fed into the backbone network, which mainly comprises the focus structure and cross stage partial (CSP) structure, effectively extracting features of timber end faces.The neck network combines the feature pyramid network (FPN) and path aggregation network (PAN), where FPN generates timber feature maps of different scales, and PAN fuses these feature maps to enhance the model's feature representation and perception capabilities.The output stage generates confidence scores, class probabilities, and bounding box coordinates for the detected timber end faces.

Analysis of Model Training Results
This paper uses three metrics to evaluate the model's detection performance: precision (P), recall (R), and mean average precision at an intersection over union (IOU) threshold of 0.5 (mAP@0.5).
where TP represents the count of timber end faces correctly identified by the model; FP represents instances where the model incorrectly identified non-timber end face objects; FN represents the number of timber end faces the model failed to recognize; AP i represents the detection accuracy for the specific class; and C represent the total number of classes.
In this research, we set the initial learning rate to 0.01, the number of training epochs to 200, the batch size to 32, and configure the input image size for the neural network as 384 × 384.The model is trained on the Windows 11 operating system, using an AMD Ryzen 7 5800H CPU, NVIDIA GeForce RTX 3050 GPU, and PyTorch version 2.1.0with CUDA 11.7, Python 3.9.13 as the training environment.Figure 4 illustrates the model's loss on the validation set.
As evident from Figure 4, the model shows a rapid decrease in loss in the first 60 epochs.By the time the training reaches 150 epochs, the loss stabilizes, indicating that the model has effectively converged.Figure 5 presents other detection performance metrics for the model.The accuracy, recall, and mean average precision show a significant increase in the initial 10 epochs, followed by a more gradual improvement, ultimately reaching 99.77%, 99.85%, and 99.80%, respectively.In testing, the YOLOv5s, compared to other models in the YOLOv5 series, offers the advantages of minimal size and the fastest detection As evident from Figure 4, the model shows a rapid decrease in loss in the first 60 epochs.By the time the training reaches 150 epochs, the loss stabilizes, indicating that the model has effectively converged.Figure 5 presents other detection performance metrics for the model.The accuracy, recall, and mean average precision show a significant increase in the initial 10 epochs, followed by a more gradual improvement, ultimately reaching 99.77%, 99.85%, and 99.80%, respectively.In testing, the YOLOv5s, compared to other models in the YOLOv5 series, offers the advantages of minimal size and the fastest detection speed.Therefore, the use of this model meets the requirements for timber end face contour detection in production environments, ensuring both accuracy and speed.

Diameter Detection
After aligning the small end of each log, the camera position is fixed, ensuring a constant distance from the end face of each log.Before initiating actual measurements, position a standard circular object with a known diameter at this fixed distance, capturing its image using the camera.Then, apply the Canny edge detection algorithm to obtain the  As evident from Figure 4, the model shows a rapid decrease in loss in the first 60 epochs.By the time the training reaches 150 epochs, the loss stabilizes, indicating that the model has effectively converged.Figure 5 presents other detection performance metrics for the model.The accuracy, recall, and mean average precision show a significant increase in the initial 10 epochs, followed by a more gradual improvement, ultimately reaching 99.77%, 99.85%, and 99.80%, respectively.In testing, the YOLOv5s, compared to other models in the YOLOv5 series, offers the advantages of minimal size and the fastest detection speed.Therefore, the use of this model meets the requirements for timber end face contour detection in production environments, ensuring both accuracy and speed.

Diameter Detection
After aligning the small end of each log, the camera position is fixed, ensuring a constant distance from the end face of each log.Before initiating actual measurements, position a standard circular object with a known diameter at this fixed distance, capturing its image using the camera.Then, apply the Canny edge detection algorithm to obtain the

Diameter Detection
After aligning the small end of each log, the camera position is fixed, ensuring a constant distance from the end face of each log.Before initiating actual measurements, position a standard circular object with a known diameter at this fixed distance, capturing its image using the camera.Then, apply the Canny edge detection algorithm to obtain the pixel size of its diameter (the number of pixels along its length).The real-world size of the standard object's diameter is subsequently divided by the pixel size, yielding the actual size corresponding to a single pixel at that distance.In the actual testing phase, after acquiring log end face contours through the YOLOv5 model, the contours are cropped from the larger image.Following a series of image preprocessing steps, apply the Canny edge detection algorithm once again to extract contour points of the log end face.Subsequently, employ the least squares method for ellipse fitting [22][23][24][25], obtaining pixel sizes corresponding to the major and minor axes.Finally, multiply these pixel sizes by the real-world size corresponding to a single pixel, resulting in the actual diameter of the log end face.The detection results are depicted in Figure 6.
size corresponding to a single pixel at that distance.In the actual testing phase, after acquiring log end face contours through the YOLOv5 model, the contours are cropped from the larger image.Following a series of image preprocessing steps, apply the Canny edge detection algorithm once again to extract contour points of the log end face.Subsequently, employ the least squares method for ellipse fitting [22][23][24][25], obtaining pixel sizes corresponding to the major and minor axes.Finally, multiply these pixel sizes by the real-world size corresponding to a single pixel, resulting in the actual diameter of the log end face.The detection results are depicted in Figure 6.At this stage, the obtained sizes represent the dimensions before debarking.However, aligning with standard results requires debarking adjustments.Bark thickness on timber is significantly influenced by spatial and climatic factors and their interactions [26].Additionally, it tends to increase with the diameter of the timber [27].Adjustments need to be made based on the individual dimensions and type of the timber to account for bark proportion or thickness within the specified range [28].The estimation of bark volume is closely tied to the value of the timber, making the accurate selection of the bark thickness estimation equation crucial [29].The bark calculation equation used in this research was provided by a local industry.Depending on the type of timber and relative tree height, the calculated bark value can be deduced.Subtracting the corresponding bark thickness from the obtained major and minor axes sizes yields the debarked diameter of the timber.
The applicability of this proposed solution for log diameter detection depends on the size of the log end within the camera's field of view.Successful detection can be achieved as long as the camera's field of view can encompass the entire log end.In widely used scanning devices, the scanning limits typically range from 60 mm to 1200 mm.Due to the significant increase in the cost of scanning devices with an expanded detection range, manufacturers often customize scanning equipment based on specific detection requirements.The machine vision detection solution employed in this study uses a binocular camera with a broad field of view.Furthermore, the field of view can be increased by adjusting the distance from the camera to the log end, enabling it to achieve a detection range comparable to scanning devices.While there may be a marginal decrease in detection accuracy, the equipment cost remains nearly unchanged.Consequently, this approach provides increased flexibility in adjusting the detection range according to specific needs without a substantial impact on equipment costs.
For timber with extremely irregular end face shapes or noticeable defects, and because they constitute a very small portion of the overall production, the standard diameter calculation method is complex and yields relatively low economic benefits.Therefore, these atypical timber specimens will be excluded in the subsequent sorting steps after detection, and their impact on diameter detection and sorting accuracy is not considered.At this stage, the obtained sizes represent the dimensions before debarking.However, aligning with standard results requires debarking adjustments.Bark thickness on timber is significantly influenced by spatial and climatic factors and their interactions [26].Additionally, it tends to increase with the diameter of the timber [27].Adjustments need to be made based on the individual dimensions and type of the timber to account for bark proportion or thickness within the specified range [28].The estimation of bark volume is closely tied to the value of the timber, making the accurate selection of the bark thickness estimation equation crucial [29].The bark calculation equation used in this research was provided by a local industry.Depending on the type of timber and relative tree height, the calculated bark value can be deduced.Subtracting the corresponding bark thickness from the obtained major and minor axes sizes yields the debarked diameter of the timber.
The applicability of this proposed solution for log diameter detection depends on the size of the log end within the camera's field of view.Successful detection can be achieved as long as the camera's field of view can encompass the entire log end.In widely used scanning devices, the scanning limits typically range from 60 mm to 1200 mm.Due to the significant increase in the cost of scanning devices with an expanded detection range, manufacturers often customize scanning equipment based on specific detection requirements.The machine vision detection solution employed in this study uses a binocular camera with a broad field of view.Furthermore, the field of view can be increased by adjusting the distance from the camera to the log end, enabling it to achieve a detection range comparable to scanning devices.While there may be a marginal decrease in detection accuracy, the equipment cost remains nearly unchanged.Consequently, this approach provides increased flexibility in adjusting the detection range according to specific needs without a substantial impact on equipment costs.
For timber with extremely irregular end face shapes or noticeable defects, and because they constitute a very small portion of the overall production, the standard diameter calculation method is complex and yields relatively low economic benefits.Therefore, these atypical timber specimens will be excluded in the subsequent sorting steps after detection, and their impact on diameter detection and sorting accuracy is not considered.

Prospects
The application of deep learning models not only enables accurate detection of timber end face contours and diameter measurement but also demonstrates excellent scalability.For instance, extracting tree rings from timber end faces, closely linked to the timber's strength, can serve as one of the criteria for timber sorting [30].Defect detection on timber end faces, affecting the strength and texture of the timber, is another potential application [31].Special types of timber, such as split wood or wood with detached small heads, Forests 2024, 15, 387 9 of 20 can trigger corresponding diameter calculation programs to determine standard diameter sizes.The integration of current machine vision and deep learning technologies enables the extraction of various features from timber end faces, facilitating the addition of desired feature detection algorithms based on specific requirements.For different tree species, training specific diameter detection models and bark thickness calculation models can enhance the precision of detection and measurement.Thus, the intelligent timber sorting solution based on machine vision demonstrates strong scalability.Through the development of software algorithms, a more comprehensive sorting process can be achieved without a significant increase in hardware costs, thereby reducing the development difficulty.

Production Line Design 2.5.1. Overall Control Logic
The designed production line in this design consists of four distinct zones, and the overall control logic is depicted in Figure 7.It can accomplish loading, alignment, diameter detection, and diameter-grade sorting functions.The following sections provide an explanation of the structure design and control logic for each zone of the production line.
timber end faces, affecting the strength and texture of the timber, is another po plication [31].Special types of timber, such as split wood or wood with detac heads, can trigger corresponding diameter calculation programs to determine diameter sizes.The integration of current machine vision and deep learning tec enables the extraction of various features from timber end faces, facilitating th of desired feature detection algorithms based on specific requirements.For diff species, training specific diameter detection models and bark thickness calculati can enhance the precision of detection and measurement.Thus, the intelligent tim solution based on machine vision demonstrates strong scalability.Through the de of software algorithms, a more comprehensive sorting process can be achieved wi nificant increase in hardware costs, thereby reducing the development difficulty.

Overall Control Logic
The designed production line in this design consists of four distinct zone overall control logic is depicted in Figure 7.It can accomplish loading, alignme ter detection, and diameter-grade sorting functions.The following sections p explanation of the structure design and control logic for each zone of the produ

Design and Control of Loading Zone
In the timber sorting yard, bulk loading of logs is typically carried out using forklifts, and the structure of the loading zone is shown in Figure 7.When a batch of logs is positioned at the front end of the material storage rack, the conveyor motor in the loading zone is activated.The four toggling structures of the alignment structure will be subjected to force on only one side.Due to the uneven force, the end that reaches first will be held in place until the other end also arrives.Both ends will then simultaneously lock into the four grooves of the toggling structure.At this moment, with the force evenly distributed, the structure toggles, allowing a log to pass through.Consequently, the originally inclined log is adjusted to a horizontal position.Subsequently, the logs continue to advance and encounter the hook-shaped wheel, which is a solid disc with hook-shaped grooves on both sides, as shown in Figure 8, structure 3. When a log reaches this point and encounters the curved surface, it is held in place until the hook-shaped wheel rotates into position, lifting the log.The grooves of the left and right hook-shaped wheels can catch and release one log at a time, and subsequent logs will be held by the circular arc surface until the next groove releases them.

Design and Control of Loading Zone
In the timber sorting yard, bulk loading of logs is typically carried out using forklifts, and the structure of the loading zone is shown in Figure 7.When a batch of logs is positioned at the front end of the material storage rack, the conveyor motor in the loading zone is activated.The four toggling structures of the alignment structure will be subjected to force on only one side.Due to the uneven force, the end that reaches first will be held in place until the other end also arrives.Both ends will then simultaneously lock into the four grooves of the toggling structure.At this moment, with the force evenly distributed, the structure toggles, allowing a log to pass through.Consequently, the originally inclined log is adjusted to a horizontal position.Subsequently, the logs continue to advance and encounter the hook-shaped wheel, which is a solid disc with hook-shaped grooves on both sides, as shown in Figure 8, structure 3. When a log reaches this point and encounters the curved surface, it is held in place until the hook-shaped wheel rotates into position, lifting the log.The grooves of the left and right hook-shaped wheels can catch and release one log at a time, and subsequent logs will be held by the circular arc surface until the next groove releases them.

Design and Control of Alignment Zone
After being captured by the hook-shaped wheel, the logs reach the alignment zone.Below the alignment wheel, in the alignment zone, there are two photoelectric sensors, one on the left and one on the right (through practical testing, it was found that having only one sensor may lead to missed triggers, especially when the difference in diameters between the small and large ends of the log is significant, hence sensors are set at both ends).When a log enters the alignment zone, the photoelectric sensor triggers, and the system recognizes that the log has entered the alignment zone.
Once within the alignment zone, the conveyor motor in the loading zone is turned off.Next, the alignment motor is activated.The alignment motor drives the alignment wheel to rotate to the left, causing the log to shift to the left for alignment.A pressure sensor is installed on the alignment side, and a baffle is externally attached to the pressure sensor.The baffle does not touch the sensor when there is no force applied.When the log moves to the far-left position, the baffle presses against the pressure sensor, triggering the pressure sensor, and the system determines that alignment is complete.The alignment motor stops, and the ramp motor starts.The chain on the ramp motor is equipped with equally spaced hook teeth, as shown in Figure 9, structure 1.When the hook teeth reach the position of the log, they can capture the log from the alignment zone.When neither the photoelectric sensor nor the pressure sensor is triggered, the system determines that the previous log has left, indicating that alignment is complete.At this point, the conveyor motor in the loading zone restarts, and the hook-shaped wheel captures the next log into the alignment zone, repeating the alignment process.To ensure efficiency, the ramp motor will not be turned off thereafter.

Design and Control of Alignment Zone
After being captured by the hook-shaped wheel, the logs reach the alignment zone.Below the alignment wheel, in the alignment zone, there are two photoelectric sensors, one on the left and one on the right (through practical testing, it was found that having only one sensor may lead to missed triggers, especially when the difference in diameters between the small and large ends of the log is significant, hence sensors are set at both ends).When a log enters the alignment zone, the photoelectric sensor triggers, and the system recognizes that the log has entered the alignment zone.
Once within the alignment zone, the conveyor motor in the loading zone is turned off.Next, the alignment motor is activated.The alignment motor drives the alignment wheel to rotate to the left, causing the log to shift to the left for alignment.A pressure sensor is installed on the alignment side, and a baffle is externally attached to the pressure sensor.The baffle does not touch the sensor when there is no force applied.When the log moves to the far-left position, the baffle presses against the pressure sensor, triggering the pressure sensor, and the system determines that alignment is complete.The alignment motor stops, and the ramp motor starts.The chain on the ramp motor is equipped with equally spaced hook teeth, as shown in Figure 9, structure 1.When the hook teeth reach the position of the log, they can capture the log from the alignment zone.When neither the photoelectric sensor nor the pressure sensor is triggered, the system determines that the previous log has left, indicating that alignment is complete.At this point, the conveyor motor in the loading zone restarts, and the hook-shaped wheel captures the next log into the alignment zone, repeating the alignment process.To ensure efficiency, the ramp motor will not be turned off thereafter.

Design and Control of Diameter Detection Zone
As the log is transported by the ramp motor to the highest point of the ramp, it will drop onto the platform in the diameter detection zone.The structure of the detection zone is shown in Figure 10.The conveyor motor in this zone is in a normally open state, and the log advances along with the transfer chain on the conveyor platform.At the diameter detection platform, there is a photoelectric sensor, and the camera is mounted approximately 1 m behind the photoelectric sensor.When the log reaches this point, the sensor triggers.After a minimal delay (to allow the log to reach the center of the image), a photograph is captured.Subsequently, the timber end face image is sent to the upper computer.The pre-trained YOLOv5s model on the upper computer performs contour extraction on the image, followed by running a diameter calculation program, which can complete the diameter calculation within 1 s.Once the diameter size is obtained, the upper computer sends the diameter data to the PLC using the Modbus communication protocol [32,33].
The transmission and handling of diameter data utilize a first-in-first-out (FIFO) sequential queue algorithm [34].Upon receiving the first diameter data, the PLC stores these data at the front of the queue and increments the rear pointer by one position.Each time new data are received, they are stored in the register at the address pointed to by the rear pointer.At this point, the diameter data of the logs are arranged in the queue in the same order as the logs on the equipment.Subsequently, the logs continue to be transported forward, moving out of the measurement zone.

Design and Control of Diameter Detection Zone
As the log is transported by the ramp motor to the highest point of the ramp, it will drop onto the platform in the diameter detection zone.The structure of the detection zone is shown in Figure 10.The conveyor motor in this zone is in a normally open state, and the log advances along with the transfer chain on the conveyor platform.

Design and Control of Diameter Detection Zone
As the log is transported by the ramp motor to the highest point of the ramp, it will drop onto the platform in the diameter detection zone.The structure of the detection zone is shown in Figure 10.The conveyor motor in this zone is in a normally open state, and the log advances along with the transfer chain on the conveyor platform.At the diameter detection platform, there is a photoelectric sensor, and the camera is mounted approximately 1 m behind the photoelectric sensor.When the log reaches this point, the sensor triggers.After a minimal delay (to allow the log to reach the center of the image), a photograph is captured.Subsequently, the timber end face image is sent to the upper computer.The pre-trained YOLOv5s model on the upper computer performs contour extraction on the image, followed by running a diameter calculation program, which can complete the diameter calculation within 1 s.Once the diameter size is obtained, the upper computer sends the diameter data to the PLC using the Modbus communication protocol [32,33].
The transmission and handling of diameter data utilize a first-in-first-out (FIFO) sequential queue algorithm [34].Upon receiving the first diameter data, the PLC stores these data at the front of the queue and increments the rear pointer by one position.Each time new data are received, they are stored in the register at the address pointed to by the rear pointer.At this point, the diameter data of the logs are arranged in the queue in the same order as the logs on the equipment.Subsequently, the logs continue to be transported forward, moving out of the measurement zone.At the diameter detection platform, there is a photoelectric sensor, and the camera is mounted approximately 1 m behind the photoelectric sensor.When the log reaches this point, the sensor triggers.After a minimal delay (to allow the log to reach the center of the image), a photograph is captured.Subsequently, the timber end face image is sent to the upper computer.The pre-trained YOLOv5s model on the upper computer performs contour extraction on the image, followed by running a diameter calculation program, which can complete the diameter calculation within 1 s.Once the diameter size is obtained, the upper computer sends the diameter data to the PLC using the Modbus communication protocol [32,33].
The transmission and handling of diameter data utilize a first-in-first-out (FIFO) sequential queue algorithm [34].Upon receiving the first diameter data, the PLC stores these data at the front of the queue and increments the rear pointer by one position.Each time new data are received, they are stored in the register at the address pointed to by the rear pointer.At this point, the diameter data of the logs are arranged in the queue in the same order as the logs on the equipment.Subsequently, the logs continue to be transported forward, moving out of the measurement zone.After moving out of the measurement zone, the timber enters the sorting zone, which consists of multiple individual sorting sections, as illustrated in Figure 11.Each sorting section has movable flaps on both the left and right sides, each connected to a cylinder.When the cylinder moves, it pushes the flaps upward at an angle.Additionally, each sorting section is equipped with a photoelectric sensor, and there is a rectangular hole cut in front of the sensor, through which the triggering light beam is emitted.As the timber moves with the transfer chain in the middle of the sorting section, when the timber reaches the position of the sensor in a sorting section, the sensor at that location is triggered.At this point, the PLC dequeues the data at the front of the queue storing the diameter of the timber, based on the first-in-first-out principle.This diameter datapoint corresponds to the diameter of the current timber.The PLC then compares this diameter datapoint with the diameter range set by the user for the current section.For example, if the lower limit and upper limit values for the diameter range on the left side of sorting section one are X1 mm and X2 mm, respectively, then if the diameter of the current timber is within the [X1, X2] interval, it meets the sorting condition.Since the photoelectric sensor is triggered by the end face, after a certain delay, when the middle position of the timber reaches the location of the cylinder, the sorting action is triggered.The cylinder pushes the flap, and the timber is pushed down.The left cylinder moves to push the timber to the left stacking area of this section, and the right cylinder does the same on the right side.Each sorting section can perform sorting for two diameter grades.
the diameter range set by the user for the current section.For example, if the lower limit and upper limit values for the diameter range on the left side of sorting section one are X1 mm and X2 mm, respectively, then if the diameter of the current timber is within the [X1, X2] interval, it meets the sorting condition.Since the photoelectric sensor is triggered by the end face, after a certain delay, when the middle position of the timber reaches the location of the cylinder, the sorting action is triggered.The cylinder pushes the flap, and the timber is pushed down.The left cylinder moves to push the timber to the left stacking area of this section, and the right cylinder does the same on the right side.Each sorting section can perform sorting for two diameter grades.
If the diameter of the timber does not meet the diameter range on both ends of that section, the PLC will create a second queue of the same size.When the timber triggers the photoelectric sensor for sorting section two, the second queue will also undergo dequeuing in a first-in-first-out manner.If it still does not meet the diameter requirements for section two, the data will be enqueued into a new queue for that section, and so on, until the last section.In summary, each sorting section has a corresponding sequential queue.When the photoelectric sensor of a section is triggered, the value from the queue of that section is dequeued, and a comparison with the set values is made.This algorithm efficiently links diameter recognition and automatic sorting functions.
There is no diameter range set on the right side of the last sorting section.When the timber reaches this section and triggers the photoelectric sensor, if it still does not meet the diameter requirements set on the left side, the cylinder will act to push the timber to the right.The timber piled on this side consists of logs that do not fall within the set diameter ranges or those that were recognized incorrectly.This allows for additional sorting to improve sorting accuracy.It is worth mentioning that the photoelectric sensor for each section is triggered by the end of the timber, and a suitable delay needs to be set.Only then, if a sorting action is triggered, can the timber be smoothly pushed down by the cylinder.At this point, the automatic sorting of the timber is achieved, and the entire sorting process is completed.If the diameter of the timber does not meet the diameter range on both ends of that section, the PLC will create a second queue of the same size.When the timber triggers the photoelectric sensor for sorting section two, the second queue will also undergo dequeuing in a first-in-first-out manner.If it still does not meet the diameter requirements for section two, the data will be enqueued into a new queue for that section, and so on, until the last section.In summary, each sorting section has a corresponding sequential queue.When the photoelectric sensor of a section is triggered, the value from the queue of that section is dequeued, and a comparison with the set values is made.This algorithm efficiently links diameter recognition and automatic sorting functions.
There is no diameter range set on the right side of the last sorting section.When the timber reaches this section and triggers the photoelectric sensor, if it still does not meet the diameter requirements set on the left side, the cylinder will act to push the timber to the right.The timber piled on this side consists of logs that do not fall within the set diameter ranges or those that were recognized incorrectly.This allows for additional sorting to improve sorting accuracy.It is worth mentioning that the photoelectric sensor for each section is triggered by the end of the timber, and a suitable delay needs to be set.Only then, if a sorting action is triggered, can the timber be smoothly pushed down by the cylinder.At this point, the automatic sorting of the timber is achieved, and the entire sorting process is completed.

Analysis of Production Line Speed
This section addresses the coordination issues identified through practical testing, analyzing, and adjusting the speeds of various sections of the production line.The meanings of all symbols used in this section's formulae can be found in Table 1.When a log completes small end alignment and enters the alignment zone, the interval ∆x between two logs when each row of hooks on the ramp chain picks up a log is equal to the distance (∆x 2 ) between two rows of hooks, where ∆x 2 is a predetermined value established during the design.Practical testing revealed that if the motor power for all sections of the production line is set to the maximum, when logs enter the final sorting step, the spacing between two logs becomes too small, resulting in collisions that prevent proper sorting.Specifically, when logs transition from the alignment zone to the detection zone, the spacing between two logs is insufficient.As a result, when entering the sorting zone, the preceding log has not completely left the connection zone, and the next log enters prematurely.To address this issue, adjustments to the motor power are required.The two logs entering the sorting zone will be connected end to end, preventing any collision if the forward speed of logs in the sorting zone is v 4 , assuming all logs have the same length L avg , and when the following condition is satisfied: ) The distance between two rows of toothed hooks in the sloped transport zone v 3 The forward speed of logs in the diameter detection zone at the maximum power of the motor ∆x 3 The gap between adjacent logs in the diameter detection zone v 4 The forward speed of logs in the automated sorting zone at the maximum power of the motor ∆x 4 The gap between adjacent logs in the automated sorting zone T d The time taken for logs to fall from the diameter detection zone to the automated sorting zone

L avg
The length of all logs (assuming they are equal) T s The time required for the actuation and reset of the cylinder

L max
The actual longest log in practice (typically not exceeding 6.5 m; for the purpose of this paper, it is considered as 7 m) T Motor torque Here, v 3 represents the log forward speed in the detection zone at maximum motor power, ∆x 3 is the spacing between two logs in the detection zone, and T d is the time it takes for a log to fall from the detection zone to the sorting zone.As the actual log lengths are unequal, L max is used instead of L avg .Thus, Equation ( 5) is replaced with: In practice, when the sorting conditions are met, the sorting zone activates the cylinder to raise the barrier, pushing the log down, and then retracts.During this action, if the next log is too close, it may get caught in the raised barrier.Therefore, there needs to be a sufficiently large spacing ∆x 4 between the two logs in the sorting zone.Consequently, Equation ( 9) is optimized as follows: Forests 2024, 15, 387 14 of 20 where T s is the time required for the cylinder to actuate and reset.From Equations ( 5), (7), and ( 8), it can be deduced that v 2 needs to satisfy the following equation: From Equation (10), it can be inferred that the log transfer v 2 at the ramp must be less than a certain value.The power of the ramp motor should be adjusted to the maximum value that satisfies the conditions of the formula for converting motor speed to power: where P is the motor power, T is the torque, and n is the speed.At this point, the power of other motors can also be set to their maximum values.Through a series of derivations, it can be found that during the design, if the distance ∆x 2 between the two rows of hooks on the ramp satisfies Equation ( 12), it is unnecessary to decrease the power of the ramp motor, allowing for an increase in the overall operating speed of the production line: Through practical testing and verification, lowering the power of the motor at the ramp as required results in the smooth and stable operation of the entire production line.

An Analysis of Sorting Accuracy and Efficiency
This production line has been deployed in the sorting facility situated in Jiangle County, Fujian Province, China.The following tests were carried out at this sorting facility.In terms of sorting accuracy, this study included 10 sets of raw logs, each comprising 10 individual logs.Each log was randomly selected and measured manually for diameter using a high-quality tape measure following measurement standards.The diameter of each log, along with its identification number, was recorded on labels, and these labels were securely affixed to the non-measured end using push pins.The measured diameter at this point was considered the standard actual diameter.
Subsequently, sorting tests were conducted using the production line based on the assigned identification numbers, and the automatically recognized diameter values were recorded on the human-machine interface.After each sorting session, the measured diameter recorded on the label of each log in the storage rack was compared with the set diameter range for that storage rack.If the measured diameter was within the specified range, it was considered a successful sorting.Each storage rack represented a diameter grade, and the diameter range for this test is presented in Table 2.The results of one set of tests are presented in Table 3, with all diameter values rounded to the nearest value after debarking.The testing was conducted in the morning on a summer day, with a temperature of 35 • C and ample natural light during the testing period.
From Tables 2 and 3, the obtained sorting results demonstrate relative accuracy, with an absolute error ranging from 1 to 2 mm and a relative error of less than 3%.During this test, there was one sorting failure observed.Upon analyzing the failed sorting, it was found that the failure occurred because the diameter of the wood was close to the threshold values of two diameter classes.Owing to the presence of errors, there was a misjudgment of the diameter class, as shown in the 9th set of data in Table 3, where the wood of Specification 3 was misidentified as Specification 2. A total of ten sets of these small-scale tests were conducted, and the results are presented in Table 4.
where MAE stands for mean absolute error, ARE stands for average relative error, k represents the total number of experiments, E i is the absolute error for the i-th set, δ i is the relative error for the i-th set, PRE denotes the sorting accuracy, n is the number of successfully sorted logs, and N is the total number of logs sorted.From Table 4, it is evident that out of a total of 100 wood tests, 98 woods were successfully sorted, and the occasional failures were attributed to the reasons mentioned earlier.Through calculations, the absolute error range in log diameter identification ranged between 0.8 and 1.4 mm, with an average absolute error of 1.12 mm and a maximum average relative error of 1.21%.This accuracy meets the enterprise's requirement of being within 3%, achieving a sorting accuracy rate of 98%.The actual diameters in the experimental data were manually measured and calculated in accordance with national standards.This measurement process is time consuming and requires a significant amount of manpower, resulting in high labor costs.However, to maintain speed, workers may at times opt to measure the diameter of the end face directly based on subjective feelings, introducing high subjectivity and randomness.In this non-standardized and rapidly conducted manual measurement process involving high-intensity repetitive work, the accuracy of diameter measurement cannot be guaranteed, leading to lower sorting accuracy.In contrast, the implemented device can achieve accurate diameter identification according to national standards while ensuring high accuracy in diameter class sorting.
Following the determination of sorting accuracy, a statistical analysis of the sorting efficiency for this design was performed.The efficiency testing consisted of 10 groups, each lasting for 10 min.In the continuously running production line, timing began as the first log entered the feeding area, and counting started as the first log was pushed down.The testing concluded after the production line had operated continuously for ten minutes, and the count included all logs pushed down during this period.Each test group was separated by intervals, and the logs sorted in each group were stacked together to avoid confusion among different groups.Logs for testing were randomly selected for loading.After completing the tests, the diameters of the logs automatically identified were recorded.Subsequently, the correctness of the identified diameters was verified using a manual tape measure.In cases where sorting errors occurred, the correct diameter value obtained from the tape measure was used for volume calculation during the sorting process.The volume sorted in 10 min on the production line was then calculated, and the volume sorted per eight hours was extrapolated.The testing site remained the deployment location of the production line, with a temperature of 25 • C during testing.The tests were conducted in the afternoon in autumn, with sufficient natural light, ensuring no impact on the detection process.The statistical results of sorting efficiency are presented in Table 5.The lengths of the sorted wood in the aforementioned cases were all 6 m, with diameters ranging from 60 to 300 mm.To facilitate volume calculation, a uniform log diameter of 200 mm was chosen.As shown in Table 5, the sorting efficiency achieves a rate surpassing 490 m 3 /8 h, far surpassing the enterprise's requirement of 100 m 3 /8 h and meeting practical production needs.When calculated based on 250 working days per year, the annual sorting volume can reach 120,000-130,000 m 3 .Because it is in its initial development, there are some design imperfections, and there are coordination issues among the various parts of the equipment.Therefore, motor power has been appropriately decreased, and certain delays have been set to ensure the smoothness and stability of the operation.With calculations conducted under ideal conditions and maximum motor efficiency, the annual sorting volume can exceed 1,500,000 m 3 .This level of efficiency is comparable to foreign sorting efficiency.Calculated from the data in Table 5, the sorting time for each log (6 m) ranges from 7 to 8 s, whereas traditional manual sorting, from manually measuring the diameter

Limitations and Future Prospects of the Study
With the continuous development of the timber market, an increasing number of sawmills aim to achieve greater economic benefits by expanding their considerations beyond merely sorting logs based on diameter.Additional features of logs, such as tree species, grain patterns, heartwood percentage, sapwood percentage, color, etc., are becoming crucial factors.Currently, our design is limited to the identification of log diameters, lacking recognition techniques for other features, resulting in a relatively narrow sorting criterion.However, the current trend in log feature detection, particularly based on deep learning, has shown significant advancements, achieving the robust detection of various characteristics.
In the future, the design will draw inspiration from these studies by incorporating additional deep learning models into the detection algorithm to enhance the variety of detected features.Furthermore, this research will optimize the control system and introduce a log management database.This database will document all detected features, creating a "profile" for each log based on defects, tree species, grain patterns, and other characteristics.Sawmills can easily retrieve logs with the desired features by referencing these "profiles." For machine vision, natural light and other environmental factors present the greatest interference.The current detection area of this design is exposed to natural conditions, with only a few structures, such as sheds and sunshades, for protection and adjustment.While supplementary lighting can enable detection throughout working hours, changes in the deployment environment can easily disrupt the detection process.In the future, this study will install a protective shell in the detection area and establish a constant light source within the shell to maintain the stability of the detection environment.
Due to the commonality of log diameters below 300 mm in the test region, the structural design of the production line is suitable for small-and medium-sized logs, with limited adaptability to larger logs that may require structural optimization.This design has attracted attention from several domestic enterprises in China, including some port sorting yards that primarily handle large-diameter timber imported globally.Collaborations

Limitations and Future Prospects of the Study
With the continuous development of the timber market, an increasing number of sawmills aim to achieve greater economic benefits by expanding their considerations beyond merely sorting logs based on diameter.Additional features of logs, such as tree species, grain patterns, heartwood percentage, sapwood percentage, color, etc., are becoming crucial factors.Currently, our design is limited to the identification of log diameters, lacking recognition techniques for other features, resulting in a relatively narrow sorting criterion.However, the current trend in log feature detection, particularly based on deep learning, has shown significant advancements, achieving the robust detection of various characteristics.
In the future, the design will draw inspiration from these studies by incorporating additional deep learning models into the detection algorithm to enhance the variety of detected features.Furthermore, this research will optimize the control system and introduce a log management database.This database will document all detected features, creating a "profile" for each log based on defects, tree species, grain patterns, and other characteristics.Sawmills can easily retrieve logs with the desired features by referencing these "profiles." For machine vision, natural light and other environmental factors present the greatest interference.The current detection area of this design is exposed to natural conditions, with only a few structures, such as sheds and sunshades, for protection and adjustment.While supplementary lighting can enable detection throughout working hours, changes in the deployment environment can easily disrupt the detection process.In the future, this study will install a protective shell in the detection area and establish a constant light source within the shell to maintain the stability of the detection environment.
Due to the commonality of log diameters below 300 mm in the test region, the structural design of the production line is suitable for small-and medium-sized logs, with limited adaptability to larger logs that may require structural optimization.This design has attracted attention from several domestic enterprises in China, including some port sorting yards that primarily handle large-diameter timber imported globally.Collaborations have been initiated.Future efforts will focus on designing a solution tailored to the sorting of large-diameter logs.

1.
This study designed an automated log diameter grading sorting line capable of sorting logs with a diameter ranging from 60 to 300 mm and a length ranging from 2 to 6 m.The sorting line achieved a sorting accuracy exceeding 95%, with a sorting efficiency of 490 m 3 /8 h and an annual sorting volume ranging from 120,000 to 130,000 m 3 .2.
This study constructed a log end detection model using YOLOv5, which achieved an accuracy of 99.77%, a recall rate of 99.85%, and a mean average precision of 99.80% in identifying log end faces.

3.
This study proposed and validated a diameter detection solution combining machine vision and deep learning.The average absolute error of the detection results was 1.12 mm, with a maximum average relative error of 1.21%.Detection in low-light environments can be achieved through supplementary lighting.4.
This stud implemented a machine vision solution in the sorting line, replacing the existing scanning device approach.While meeting production needs, this alternative considerably reduced equipment production, deployment, and maintenance costs.It is a preferred choice for enterprises with sorting requirements limited to log diameters.For enterprises with broader detection needs, there is still the possibility of additional feature development.

Figure 5 .
Figure 5. Performance metrics of the trained model.

Figure 5 .
Figure 5. Performance metrics of the trained model.

Figure 5 .
Figure 5. Performance metrics of the trained model.

Forests 5 .
Design and Control of Automatic Sorting Zone

Table 3 .
Single group sorting results record table.

Table 4 .
Statistical summary of multiple sorting results.