Self-adaptive cattle neck clamping control method and system based on visual identification

By using visual recognition technology and closed-loop adjustment, precise positioning and adaptive clamping of the cow's neck were achieved, solving the problems of low clamping accuracy and poor stability in existing technologies, and improving work efficiency and safety.

CN121926136APending Publication Date: 2026-04-28SHANDONG HUACHEN HYDRAULIC TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
SHANDONG HUACHEN HYDRAULIC TECH CO LTD
Filing Date
2026-01-22
Publication Date
2026-04-28

AI Technical Summary

Technical Problem

Existing cattle neck clamping technology cannot achieve precise positioning and adaptive clamping based on the individual characteristics of cattle, resulting in low clamping accuracy, poor stability, easy damage to cattle, and low work efficiency.

Method used

An adaptive clamping control method for cattle neck based on vision recognition is adopted. Multi-view image data of cattle are obtained through vision recognition technology, a world coordinate system is constructed, the neck reference point is extracted, and closed-loop adjustment is achieved by combining pressure sensor to dynamically adapt the clamping force.

Benefits of technology

It achieves precise positioning and adaptive clamping of the cattle's neck, improving operational efficiency, reducing stress response in cattle, and enhancing the stability and safety of clamping.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121926136A_ABST
    Figure CN121926136A_ABST
Patent Text Reader

Abstract

The invention relates to the technical field of farming and pasture breeding, in particular to a cattle neck self-adaptive clamping control method and system based on visual identification, and the method is used for enclosing a neck clamping device. The method comprises the following steps: obtaining a pixel actual mapping relation based on a standard calibration plate image, constructing a world coordinate system, obtaining cattle multi-view image data, and obtaining a cattle neck clamping data set; processing the multi-view image data to obtain an effective contour image which retains the complete contour of the cattle; positioning a neck datum point by using a feature point matching algorithm, and determining world coordinates of the neck datum point according to a pixel actual distance mapping relation; according to the world coordinates of the neck datum point, target control parameters of driving of a driving assembly are determined, wherein the target control parameters comprise the advancing distance of the neck clamping mechanism in the first direction and the advancing distance of the neck clamping mechanism in the second direction. The problems that accurate positioning and self-adaptive clamping of the neck cannot be achieved based on the individual characteristics of the cattle, so that the clamping precision is low, the stability is poor, the cattle is prone to being damaged, and the working efficiency is low are solved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of agricultural and livestock breeding technology, and in particular to a method and system for adaptive clamping control of cattle necks based on visual recognition. Background Technology

[0002] In livestock farming, disease prevention and control, and breed improvement, it is often necessary to restrain cattle by their necks to perform procedures such as vaccination, temperature checks, blood collection, and ear tagging. The accuracy and stability of the neck restraint directly affect operational efficiency, safety, and the degree of stress response in cattle. Therefore, neck restraint devices have become a key piece of equipment in livestock operations.

[0003] Existing technologies for clamping cattle necks mostly employ manual-assisted positioning or mechanized clamping methods with fixed parameters. Manual-assisted positioning relies on the operator's experience to judge the cattle's neck position and manually control the clamping mechanism. This is not only labor-intensive and inefficient, but can also lead to the cattle struggling due to improper operation, posing safety risks to personnel or causing injury and discomfort to the cattle. Mechanized clamping methods with fixed parameters pre-set uniform clamping positions and strokes, failing to consider individual differences in cattle size, neck position, etc., and cannot achieve adaptive adjustment. This results in clamps that are too loose to meet fixation requirements or too tight, damaging the cattle's neck tissue. Furthermore, this method lacks positioning guidance during the clamping process, reducing the stability and reliability of the clamping.

[0004] In summary, the core technical problem with existing technologies is that they cannot achieve precise neck positioning and adaptive clamping based on the individual characteristics of cattle, resulting in low clamping accuracy, poor stability, easy damage to cattle, and low operational efficiency. Therefore, there is a need for an adaptive clamping control method and system that can accurately identify the neck position of cattle and adapt to cattle of different sizes. Summary of the Invention

[0005] This application provides a vision-based adaptive clamping control method and system for cattle necks, which solves the problem in the prior art that it is impossible to achieve accurate positioning and adaptive clamping of the neck based on the individual characteristics of cattle. It achieves the effect of accurately identifying the position of the cattle neck and adapting to cattle of different sizes.

[0006] In a first aspect, this application provides a vision-based adaptive clamping control method for cattle necks, used in a neck-clamping device. The neck-clamping device includes: a conveyor belt for carrying and transporting cattle; a double-side plate clamping mechanism for lateral positioning of the cattle's torso; a neck clamping mechanism driven by a drive component for clamping the cattle's neck; and a front door and a rear door located at both ends of the enclosure device. The drive component is configured to drive the neck clamping mechanism to move linearly at least along a first direction and a second direction. The first direction is parallel to the tangent direction of the conveying path, and the second direction is perpendicular to the bearing plane of the conveying mechanism. The method includes the following steps: S1. Obtain a first position signal and a second position signal, and output a closing signal to the rear door and a conveyor signal to the conveyor belt in sequence according to the first position signal. Output a stop signal to the conveyor belt in sequence according to the second position signal and output a counter-approach signal to the double-side plate clamping mechanism. The first position signal is the signal that the cow has reached the first position, and the second position signal is the signal that the cow has reached the second position. S2. Obtain the actual pixel mapping relationship based on the standard calibration plate image, construct a world coordinate system, obtain multi-view image data of cattle, and process the multi-view image data to obtain an effective contour image that retains the complete contour of the cattle; S3. Extract the cattle contour features based on the effective contour image, obtain the cattle length data, height data, and width data according to the cattle contour features, locate the neck reference point using a feature point matching algorithm, and determine the world coordinates of the neck reference point according to the actual pixel distance mapping relationship. S4. Determine the target control parameters for driving the drive assembly based on the world coordinates of the neck reference point. The target control parameters include controlling the travel distance of the neck clamping mechanism in the first direction and the travel distance in the second direction.

[0007] Further, acquiring the first position signal and the second position signal includes: S1.1 When a cow is detected entering the first position and generates an occlusion signal for a preset duration, a valid first position signal is generated; when a cow is detected reaching the second position and generates an occlusion signal for a preset duration, a valid second position signal is generated.

[0008] Furthermore, the step of obtaining the actual pixel mapping relationship based on the standard calibration board image and constructing a world coordinate system includes: S2.1 The standard calibration plate is set on the neck clamping device and parallel to the conveyor belt bearing plane. The calibration image dataset is processed to extract the corner features of the calibration plate in each frame image. The mapping relationship of the actual distance between pixels is calculated by matching the corner coordinates, and the calibration coefficient is solved. The calculation formula is: Where k is the actual distance calibration coefficient of the pixel. The actual straight-line distance between two adjacent corner points is preset on the standard calibration plate. To determine the pixel distance between two adjacent corner points in an image; S2.2 Construct an OXY two-dimensional world coordinate system with the center point of the second position as the origin O. The X-axis is set along the first direction and points downstream of the conveying path as the positive direction. The Y-axis is set along the second direction and points away from the bearing plane as the positive direction.

[0009] Furthermore, the step of acquiring multi-view image data of cattle and processing the multi-view image data to obtain an effective contour image that preserves the complete outline of the cattle includes: S2.3 Acquire the side profile image, trunk front view image, and head and neck side view image of the cattle to form multi-view image data; S2.4 Invoke the preset image preprocessing algorithm to process the multi-view image data, and sequentially perform Gaussian filtering for noise reduction, grayscale conversion, edge enhancement and threshold segmentation operations to extract the complete outline of the cow and obtain an effective outline image that retains the complete outline of the cow and key feature points.

[0010] Furthermore, the processing of the multi-view image data includes: S2.4.1 Perform Gaussian filtering on the acquired color multi-view images to filter out random noise and environmental interference noise. The filter kernel size is set to 3×3, and the filtering formula is as follows: Where G(x,y) is the weight value at position (x,y) in the filter kernel, σ is the preset Gaussian standard deviation, and x and y are the relative coordinates of the pixels in the filter kernel. The denoised color image is obtained through this filtering operation. S2.4.2 Converts the denoised color image to a grayscale image, preserving the brightness features of the cattle outlines and reducing the amount of data processing. The conversion formula is as follows: ,in, Let R(x,y) be the gray value of the (x,y) pixel in the grayscale image, and let G(x,y) and B(x,y) be the red, green, and blue channel pixel values ​​of the (x,y) pixel in the color image, respectively. S2.5.3 uses a fusion of the Sobel and Canny operators to extract the edges of cattle, and calculates the horizontal gradient using the Sobel operator. and vertical gradient The formula for calculating the fusion gradient is: A preliminary edge image is obtained, and the preliminary edge image is input into the Canny operator for edge thinning and connection to obtain a continuous and complete edge image of the cow. S2.4.4 Based on the grayscale histogram of the cattle edge image, the Otsu adaptive threshold segmentation algorithm is used to determine the segmentation threshold, the edge image is binarized, the complete contour of the cattle is extracted, and an effective contour image is obtained.

[0011] Further, the step of extracting cattle contour features based on the effective contour image, obtaining cattle length, height, and width data based on the cattle contour features, locating the neck reference point using a feature point matching algorithm, and determining the world coordinates of the neck reference point based on the actual pixel distance mapping relationship includes: S3.1 Based on the effective contour image, the YOLO object detection algorithm is called to identify the contour region of the cow and extract the complete set of contour pixel coordinates of the cow; S3.2 From the set of contour pixel coordinates, filter out the nose tip feature points, rump feature points, lowest hoof feature points, and widest feature points on both sides of the torso of the cow, and convert the pixel distance between the feature points into the actual physical distance according to the calibration coefficient. S3.3 uses the preset SIFT feature point matching algorithm to locate the neck reference point from the effective contour image corresponding to the detailed side view image of the cow's head and neck. Combining the actual pixel distance mapping relationship and the world coordinate system, the pixel coordinates of the neck reference point are converted into world coordinates.

[0012] Furthermore, the step of converting the pixel coordinates of the neck reference point into world coordinates by combining the actual pixel distance mapping relationship and the world coordinate system includes: S3.3.1 Using the SIFT feature point matching algorithm, the head-neck connection points are extracted from the effective contour image of the detailed side view image of the cattle's head and neck. Connection point between neck and torso Among them, the head-neck connection point is the natural connection position between the lower jawbone and the neck of the cow, and the neck-body connection point is the natural connection position between the front of the scapula and the neck of the cow. S3.3.2 Head-neck connection point Connection point between neck and torso Using the midpoint between the two points as a reference, calculate the midpoint as the neck clamping reference point, and its pixel coordinates are... The calculation uses the following formula: ,in, The pixel x-coordinate of the neck reference point. The pixel ordinate of the neck reference point; S3.3.3 Based on the calibration coefficient k and the constructed OXY two-dimensional world coordinate system, the pixel coordinates of the neck reference point are... Convert to world coordinates The conversion formula is: ,in, Here are the world coordinates for the top-left pixel of the head and neck detail side view image. The pixel coordinates are the top-left corner pixels of the side view image of the head and neck details.

[0013] Further, determining the target control parameters for driving the drive component based on the world coordinates of the neck reference point includes: S4.1 Obtain the initial position coordinates of the neck clamping mechanism in the OXY two-dimensional world coordinate system. ,in, The initial coordinates of the neck clamping mechanism along the first direction. The initial coordinates of the neck clamping mechanism along the second direction; S4.2 Based on the world coordinates of the neck reference point and the initial position coordinates Calculate the target control parameters of the driving component, and the travel distance in the first direction. Distance traveled in the second direction The calculation formula is: ; S4.3 converts the corrected target control parameters into pulse drive signals recognizable by the drive component, and sends the drive signals to the drive component, causing the drive component to drive the neck clamping mechanism to move along the first direction. Distance, precise movement along the second direction distance.

[0014] Furthermore, the neck clamping mechanism has a curved portion, and a pressure sensor is provided on the curved portion. During the clamping action, the neck clamping mechanism includes: S5.1 acquires the clamping pressure signal; S5.2 compares the actual clamping pressure with the preset pressure threshold. If the pressure deviation exceeds the preset allowable range, it outputs an adjustment signal to the drive component to dynamically adjust the clamping pressure and displacement.

[0015] Secondly, a vision-based adaptive clamping control system for cattle necks, characterized in that it utilizes the method described in claims 1-9, comprising: The position signal processing module is configured to acquire a first position signal and a second position signal, and output a closing signal to the rear door and a conveyor signal to the conveyor belt in sequence according to the first position signal, and output a stop signal to the conveyor belt in sequence according to the second position signal, and output a counter-approach signal to the double-side plate clamping mechanism. The first position signal is the signal that the cow has reached the first position, and the second position signal is the signal that the cow has reached the second position. The image processing module is configured to obtain the actual pixel mapping relationship based on the standard calibration plate image, construct a world coordinate system, acquire multi-view image data of cattle, and process the multi-view image data to obtain an effective contour image that retains the complete outline of the cattle. The neck reference point localization module is configured to extract cattle contour features based on the effective contour image, obtain cattle length data, height data, and width data according to the cattle contour features, locate the neck reference point using a feature point matching algorithm, and determine the world coordinates of the neck reference point according to the actual pixel distance mapping relationship. The parameter determination module is configured to determine the target control parameters for driving the drive component based on the world coordinates of the neck reference point. The target control parameters include controlling the travel distance of the neck clamping mechanism in a first direction and the travel distance in a second direction.

[0016] Thirdly, the present invention provides a computer-readable storage medium storing a plurality of instructions adapted for loading and execution by a processor of a terminal device of the aforementioned vision-based adaptive clamping control method for cattle necks.

[0017] Fourthly, the present invention provides a terminal device, including a processor and a computer-readable storage medium, wherein the processor is used to implement various instructions; the computer-readable storage medium is used to store multiple instructions, the instructions being adapted to be loaded and executed by the processor to provide the aforementioned vision recognition-based adaptive clamping control method for cattle necks.

[0018] One or more technical solutions provided in the embodiments of this application have at least the following technical effects or advantages: 1. By employing timing control technology for the first and second position signals, replacing the traditional manual-assisted positioning method, this technology effectively solves the problems of high labor intensity, low work efficiency, and significant influence of human factors on positioning accuracy in existing technologies. This achieves automated and precise positioning and posture regularization before cattle clamping, improving work efficiency and positioning consistency while reducing personnel safety risks. Furthermore, by using a standard calibration board to obtain the actual pixel mapping relationship and construct a world coordinate system, combined with multi-view image acquisition and fusion preprocessing technology, and utilizing the YOLO algorithm to extract contour features and the SIFT algorithm to locate the neck reference point and complete the conversion from pixel coordinates to world coordinates, this technology effectively solves the problems of fixed-parameter mechanized clamping being unable to adapt to individual differences in cattle size and inaccurate neck positioning in existing technologies. This achieves precise neck positioning based on individual cattle characteristics, providing accurate coordinates for subsequent adaptive clamping and ensuring the accuracy of the clamping position.

[0019] 2. By employing a technology that calculates target control parameters based on the world coordinates of the neck reference point and the initial coordinates of the clamping mechanism, and converts these parameters into pulse drive signals to control the movement of the drive components, and by incorporating a bending section and pressure sensor in the neck clamping mechanism to achieve closed-loop adjustment through comparison of the collected clamping pressure signal with a preset threshold, this technology effectively solves the problems of existing technologies where clamping force and clamping position cannot be adaptively adjusted, and where clamping is too loose or too tight, leading to injury to cattle or unstable fixation. This achieves adaptive and precise clamping of the cattle's neck, balancing clamping stability and cattle safety, reducing stress response in cattle, and improving cattle comfort. Attached Figure Description

[0020] Figure 1 This is a schematic diagram of the neck-blocking clamping device in Embodiment 1 of this application; Figure 2 This is a left view of the neck-blocking clamping device in Embodiment 1 of this application; Figure 3 This is a front view of the neck-blocking clamping device in Embodiment 1 of this application; Figure 4 This is a flowchart of the method in Embodiment 1 of this application; Figure 5 This is a structural block diagram of the module in Embodiment 2 of this application.

[0021] Among them, 1. Neck clamping device; 2. Conveyor belt; 3. Double side plate clamping mechanism; 4. Neck clamping mechanism; 5. Front door; 6. Rear door; 7. Front safety bar; 8. Rear safety bar. Detailed Implementation

[0022] The embodiments of this application aim to solve the technical problems in the prior art that the neck cannot be accurately positioned and adaptively clamped based on the individual characteristics of cattle, resulting in low clamping accuracy, poor stability, easy damage to cattle, and low work efficiency.

[0023] To address the aforementioned core technical challenges, the overall technical solution provided in this embodiment is as follows: a collaborative control architecture combining visual recognition technology with timing control and closed-loop adjustment is employed. Position sensors collect cattle position signals and transmit them via timing control. The clamping mechanism's actions are then controlled to ensure proper cattle posture. Standard calibration and multi-view image processing are used to obtain individual cattle characteristics and precise coordinates of the neck reference point. Based on these coordinates, the clamping mechanism's driving parameters are calculated and combined with pressure feedback to achieve adaptive clamping. Ultimately, the entire process of cattle neck clamping is automated and precise.

[0024] The core mechanism of this technical solution is as follows: taking the coordination of positioning, recognition and control as the core, firstly, the automatic positioning and posture constraint of the cattle before clamping are completed by the timing control of the first and second position signals. Then, the mapping relationship between pixels and actual distance is established by visual calibration. Combined with multi-algorithm fusion image processing technology, the contour features of the cattle are extracted and the neck reference point is accurately located. Subsequently, the coordinate calculation is converted into the driving command of the clamping mechanism. Finally, the clamping force is dynamically adjusted by relying on the closed-loop feedback of the pressure sensor to ensure that the technical features form an effective synergy to solve the core problem.

[0025] The above technical solution can effectively overcome the shortcomings of low efficiency of manual positioning and poor adaptability of fixed parameter clamping in the existing technology, realize adaptive and precise clamping of cattle neck, improve work efficiency and operation safety, reduce stress response of cattle, and meet the needs of modern animal husbandry for efficient, precise and safe clamping.

[0026] To better understand the above technical solutions, the following will provide a detailed explanation of the technical solutions in conjunction with the accompanying drawings and specific implementation methods.

[0027] Example 1 Reference Figure 2 , Figure 3 and Figure 4 This embodiment presents a vision-based adaptive clamping control method for cattle necks, used in a neck-clamping device. The neck-clamping device includes: a conveyor belt for carrying and transporting cattle; a double-side plate clamping mechanism for lateral positioning of the cattle's torso; a neck clamping mechanism driven by a drive component for clamping the cattle's neck; and front and rear doors located at both ends of the enclosure device. The drive component is configured to drive the neck clamping mechanism to move linearly at least along a first direction and a second direction. The first direction is parallel to the tangent direction of the conveying path, and the second direction is perpendicular to the bearing plane of the conveying mechanism. The main body of the device is made of stainless steel frame, and the conveyor belt is made of non-slip rubber. The conveying speed can be steplessly adjusted within the range of 0.3-0.8m / s. The drive end of the conveyor belt is equipped with a servo motor, and the servo motor is connected to the controller through a pulse signal line to achieve precise control of the conveying speed.

[0028] The dual-side plate clamping mechanism includes two symmetrically arranged clamping plates made of aluminum alloy. A flexible rubber buffer layer can be attached to the inside of the plates to avoid damaging the cattle. Each clamping plate is equipped with an independent electric push rod as a driving component. The electric push rod is fixed to the outside of the frame and is connected to the controller signal. It can receive opposing approach / separation signals to achieve synchronous action.

[0029] The neck clamping mechanism includes two symmetrical arc-shaped clamping arms, the arc shape of which is adapted to the physiological curve of the bovine neck. Pressure sensors are embedded in the inner side of the clamping arms. The neck clamping mechanism is connected to the drive component through a linear module. The drive component includes an X-axis servo slide (corresponding to the first direction) and a Y-axis servo slide (corresponding to the second direction). The drive component is electrically connected to the controller and can receive pulse drive signals to achieve bidirectional linear motion.

[0030] In the door structure, both the front and rear doors use stainless steel frames and are equipped with DC geared motors (model: ZGA37RG) as drive components. Limit switches are installed on both sides of the door, and these switches are connected to the controller signal to provide feedback on the door's closed position. Additionally, a protective pressure bar is installed on the door, which is pressed down by an electric push rod to improve safety.

[0031] Regarding the visual acquisition components, three industrial cameras are arranged axially in sequence to form a multi-view acquisition array: the first camera (side view acquisition) is fixed on the outside of the frame at the entrance of the device, with an installation height of 1800mm, horizontally facing the second position, and the shooting angle is 45° with the conveyor belt bearing plane, used to acquire the side profile image of the cattle; the second camera (front view acquisition) is fixed on the frame directly above the core clamping area of ​​the device, with an installation height of 2200mm, vertically facing the conveyor belt bearing plane, used to acquire the front view image of the cattle's torso; the third camera (head and neck acquisition) is fixed on the frame near the front door side of the core clamping area of ​​the device, with an installation height of 1600mm, horizontally facing the direction of the cattle's head, and the shooting angle is 30° with the conveyor belt bearing plane, used to acquire the side view image of the cattle's head and neck; each camera is equipped with a supplementary lighting device, which is triggered synchronously with the camera, and the intensity of the supplementary lighting can be adjusted by the controller.

[0032] Regarding the position detection components, diffuse reflection photoelectric sensors are installed at both the first and second positions. The sensor model is E3Z-D61. The first sensor is fixed on the frame column 50cm outside the entrance of the device, with an installation height of 800mm. The detection direction is perpendicular to the conveyor belt direction, and it is used to detect whether the cattle have reached the first position. The second sensor is fixed on the frame column at the entrance of the core clamping area of ​​the device, with an installation height of 800mm. The detection direction is consistent with the conveyor belt direction, and it is used to detect whether the cattle have reached the second position.

[0033] The control core uses a PLC controller as the control core. The controller integrates an Ethernet interface and establishes signal connections with components such as servo motors, electric linear actuators, DC geared motors, industrial cameras, photoelectric sensors, and pressure sensors through an industrial Ethernet bus, so as to realize centralized control of signal acquisition and command output.

[0034] Reference Figure 1 The method includes the following steps: S1. Obtain a first position signal and a second position signal, and output a closing signal to the rear door and a conveyor signal to the conveyor belt in sequence according to the first position signal. Output a stop signal to the conveyor belt in sequence according to the second position signal and output a counter-approach signal to the double-side plate clamping mechanism. The first position signal is the signal that the cow has reached the first position, and the second position signal is the signal that the cow has reached the second position. Signal transmission uses the Profinet industrial Ethernet protocol. Closing signals, conveying signals, stop signals, and approaching signals are all digital signals. Before starting, the front door needs to be closed and the rear door opened. After the controller outputs a closing signal, the rear door drive motor starts, causing the door to close. When the limit switch detects that the door is closed and sends a feedback signal, the controller starts a timing delay program. The timing interval for actions based on the first position signal is set to 1.5 seconds. That is, after the rear door closes, a conveying signal is output to the conveyor belt servo motor 1.5 seconds later, controlling the conveyor belt to start at a preset speed of 0.5 m / s. This ensures the enclosure space is completely sealed before transporting the cattle, preventing them from escaping. After receiving the second position signal, the controller outputs a stop signal to the conveyor belt servo motor, which then executes a braking program. When the conveyor belt speed drops to 0 m / s, the controller initiates another timing delay program. The timing interval for the action based on the second position signal is set to 2.0s; that is, after the conveyor belt comes to a complete stop, a 2.0s delay is set before the controller outputs a counter-approach signal to the electric push rod of the double-side plate clamping mechanism. This controls the two clamping plates to synchronously approach inwards at a speed of 50 mm / s until the clamping plates are in contact with the cow's torso. The contact pressure is fed back through the electric push rod current; when the current reaches 1.5A, the approach stops, achieving lateral positioning of the cow's torso and ensuring the stability of subsequent visual acquisition and clamping actions. The first position signal indicates the cow has reached the first position, and the second position signal indicates the cow has reached the second position.

[0035] Further, acquiring the first position signal and the second position signal includes: S1.1 When a cow is detected entering the first position and generates an occlusion signal for a preset duration, a valid first position signal is generated; when a cow is detected reaching the second position and generates an occlusion signal for a preset duration, a valid second position signal is generated.

[0036] Both the first and second sensors are connected to the digital input interface of the PLC controller. When the first sensor detects that a cow has entered the first position and generates an obstruction signal for a preset duration, the controller determines that the cow has stably reached the first position and generates a valid first position signal. When the second sensor detects that a cow has reached the second position and generates an obstruction signal for a preset duration, the controller determines that the cow has stably reached the clamping operation area and generates a valid second position signal. The preset duration is calculated using the following formula to ensure signal validity and avoid false triggering: Where t is the preset duration (in seconds), d is the detection spot diameter of the photoelectric sensor (in meters), and v is the preset conveyor speed (in meters per second). In this embodiment, the detection spot diameter d = 0.05 meters, and the preset conveyor speed v = 0.5 meters per second. Substituting these values ​​into the formula yields 0.4 seconds. This means that the controller only determines a signal to be valid when the duration of the obstruction signal reaches 0.4 seconds. This effectively filters out momentary false triggers caused by factors such as cattle limb movement and environmental obstructions, ensuring the reliability of position detection.

[0037] S2. Obtain the actual pixel mapping relationship based on the standard calibration plate image, construct a world coordinate system, obtain multi-view image data of cattle, and process the multi-view image data to obtain an effective contour image that retains the complete contour of the cattle; This step is achieved through the collaboration of the three industrial cameras and PLC controllers mentioned above. The image acquisition and preprocessing tasks are completed by the image processing module integrated into the controller, and the data transmission adopts the CameraLink interface protocol to ensure the real-time performance and integrity of image data transmission.

[0038] The process of obtaining the actual pixel mapping relationship based on the standard calibration board image and constructing a world coordinate system includes: S2.1 The standard calibration plate is set on the neck clamping device and parallel to the conveyor belt bearing plane. The calibration image dataset is processed to extract the corner features of the calibration plate in each frame image. The mapping relationship of the actual distance between pixels is calculated by matching the corner coordinates, and the calibration coefficient is solved. The calculation formula is: Where k is the actual distance calibration coefficient of the pixel. The actual straight-line distance between two adjacent corner points is preset on the standard calibration plate. To determine the pixel distance between two adjacent corner points in an image; A checkerboard standard calibration board is adopted, with a board size of 300mm × 225mm and a checkerboard unit size of 25mm × 25mm. The calibration board is positioned at the second position of the neck clamping device via a magnetic fixing base, ensuring that the plane of the calibration board is parallel to the conveyor belt bearing plane. The controller sends synchronous acquisition commands to three industrial cameras and supplementary lighting components. Each camera acquires images of the calibration board from five preset angles, including 0°, 15°, 30°, -15°, and -30°, with the camera's optical axis perpendicular to the plane of the calibration board as the 0° reference. Five frames are acquired for each angle, forming a calibration image dataset containing 75 frames, which is then transmitted to the controller's image buffer unit. The controller calls Zhang Zhengyou's calibration algorithm to process the calibration image dataset. The corner features of the calibration board in each frame are extracted using a sub-pixel corner detection algorithm, achieving a corner detection accuracy of 0.1 pixels. The correspondence between image pixels and actual space is established through corner coordinate matching, the mapping relationship of actual pixel distance is calculated, and the calibration coefficient k is solved. The value is 25mm. In this embodiment, the calibration coefficient k = 0.125mm / pixel is finally obtained by averaging multiple frames of images. This coefficient is stored in the controller parameter library for subsequent conversion between pixel coordinates and world coordinates.

[0039] S2.2 Construct an OXY two-dimensional world coordinate system with the center point of the second position as the origin O. The X-axis is set along the first direction and points downstream of the conveying path as the positive direction. The Y-axis is set along the second direction and points away from the bearing plane as the positive direction.

[0040] A laser positioning device is used to locate the center point of the second position, which is set as the origin O, constructing an OXY two-dimensional world coordinate system. The X-axis is set along the first direction, pointing downstream of the conveying path as the positive direction, with a range of -500mm to 1500mm; the Y-axis is set along the second direction, pointing away from the bearing plane as the positive direction, with a range of 0mm to 1200mm. The positioning accuracy of the coordinate system is calibrated using calibration coefficients to ensure that the deviation between the coordinate values ​​and the actual spatial position is ≤0.2mm. The controller stores the coordinate system parameters, including the origin position, axis direction, range, and calibration coefficient relationships, in the system configuration file for subsequent neck reference point coordinate transformation.

[0041] The process of acquiring multi-view image data of cattle and processing the multi-view image data to obtain an effective contour image that preserves the complete outline of the cattle includes: S2.3 Acquire the side profile image, trunk front view image, and head and neck side view image of the cattle to form multi-view image data; After receiving the second position signal output by S1, the controller sends a synchronous acquisition command to the three industrial cameras after a 0.5s delay, ensuring the cattle's posture is stable before starting image acquisition. The supplementary lighting is simultaneously activated to a 600 lux intensity to avoid the impact of glare from the cattle's fur on image quality. Specifically, the first camera (side-view acquisition) captures the side profile image of the cattle, the second camera (front-view acquisition) captures a frontal view image facing the cattle, and the third camera (head and neck acquisition) captures a side view image of the cattle's head and neck. The acquisition parameters for all three cameras are uniformly set as follows: image resolution 2592×1944 pixels, frame rate 15fps, exposure time 50ms, and image format BMP lossless format. The acquired three-channel image data are synchronously transmitted to the controller's image processing module to form multi-view image data.

[0042] S2.4 Invoke the preset image preprocessing algorithm to process the multi-view image data, and sequentially perform Gaussian filtering for noise reduction, grayscale conversion, edge enhancement and threshold segmentation operations to extract the complete outline of the cow and obtain an effective outline image that retains the complete outline of the cow and key feature points.

[0043] The controller calls a preset image preprocessing algorithm to process the multi-view image data synchronously and in parallel, sequentially performing Gaussian filtering for noise reduction, grayscale conversion, edge enhancement, and threshold segmentation to extract the complete outline of the cattle, obtaining an effective outline image that retains the complete outline of the cattle and key feature points (nose, rump, head-neck junction, etc.), providing high-quality image data for subsequent outline feature extraction.

[0044] The processing of the multi-view image data includes: S2.4.1 Perform Gaussian filtering on the acquired color multi-view images to filter out random noise and environmental interference noise. The filter kernel size is set to 3×3, and the filtering formula is as follows: Where G(x,y) is the weight value at position (x,y) in the filter kernel, σ is the preset Gaussian standard deviation, and x and y are the relative coordinates of the pixels in the filter kernel. The denoised color image is obtained through this filtering operation. In this embodiment, the filter kernel size is set to 3×3. This size can ensure the denoising effect while avoiding over-filtering that would cause image edge blurring. The preset Gaussian standard deviation σ=1.2, x and y are the relative coordinates of the pixels in the filter kernel, with values ​​ranging from -1, 0, to 1. The image is then subjected to weighted smoothing through this filtering operation to obtain the denoised color image.

[0045] S2.4.2 Converts the denoised color image to a grayscale image, preserving the brightness features of the cattle outlines and reducing the amount of data processing. The conversion formula is as follows: ,in, Let R(x,y) be the gray value of the (x,y) pixel in the grayscale image, and let G(x,y) and B(x,y) be the red, green, and blue channel pixel values ​​of the (x,y) pixel in the color image, respectively. S2.4.3 uses a fusion of the Sobel and Canny operators to extract the edges of the cattle, and calculates the horizontal gradient using the Sobel operator. and vertical gradient The formula for calculating the fusion gradient is: A preliminary edge image is obtained, and the preliminary edge image is input into the Canny operator for edge thinning and connection to obtain a continuous and complete edge image of the cow. A preliminary edge image is obtained; then the preliminary edge image is input into the Canny operator for edge refinement and connection. The high threshold of the Canny operator is set to 80, the low threshold is set to 40, and the ratio of high to low threshold is 2:1. This ratio can effectively connect broken edges and suppress false edges, and finally obtain a continuous and complete edge image of cattle.

[0046] It should be noted that the Sobel operator detects image edges based on first-order differential operations. Its core principle is to perform sliding convolution on the image using a preset convolution kernel, calculating the gray-level gradient of pixels in the horizontal and vertical directions. A larger gradient magnitude indicates more prominent edge features. This embodiment uses a 3×3 convolution kernel. The horizontal gradient is obtained through convolution operations. and vertical gradient .

[0047] The Canny operator employs a multi-step edge detection strategy. Its core principle is to eliminate false edges through non-maximum suppression and detect broken edges using a double threshold, ultimately obtaining continuous and complete edges. In this embodiment, the specific parameters and implementation steps of the Canny operator are: Gaussian smoothing preprocessing; gradient calculation based on the Sobel operator. , The process involves: determining the edge direction; non-maximum suppression, comparing the gradient magnitude of the current pixel with that of its neighboring pixels along the edge direction, retaining pixels with local maxima, and discarding non-edge pixels; dual threshold detection, setting a high threshold of 80 and a low threshold of 40, with a high / low threshold ratio of 2:1. This ratio was determined through testing with a large number of cattle image samples, effectively balancing edge connectivity and pseudo-edge suppression. Pixels with gradient magnitudes greater than the high threshold are considered strong edges, those less than the low threshold are considered non-edges, and those in between are considered valid edges if connected to strong edges through connectivity analysis; edge connectivity, integrating valid edge pixels to obtain a continuous and complete cattle edge image. It should be understood that the above content regarding the Sobel and Canny operators is existing technology and common practice in this field, and is also common knowledge to those skilled in the art. The main improvement of this application is not the algorithm itself, but rather the use of it to obtain a continuous and complete cattle edge image. All of the above content belongs to existing technology, and those skilled in the art should know its principles and methods.

[0048] S2.4.4 Based on the grayscale histogram of the cattle edge image, the Otsu adaptive threshold segmentation algorithm is used to determine the segmentation threshold, the edge image is binarized, the complete contour of the cattle is extracted, and an effective contour image is obtained.

[0049] The edge image is binarized according to the determined segmentation threshold. The binarization rule is as follows: when the pixel gray value is greater than the segmentation threshold, it is determined to be a foreground pixel of the cow outline and is assigned a value of 255 (white); when the pixel gray value is less than or equal to the segmentation threshold, it is determined to be a background pixel and is assigned a value of 0 (black). The complete outline of the cow is extracted through binarization, and an effective outline image that retains the complete outline of the cow and key feature points is obtained.

[0050] S3. Extract the cattle contour features based on the effective contour image, obtain the cattle length data, height data, and width data according to the cattle contour features, locate the neck reference point using a feature point matching algorithm, and determine the world coordinates of the neck reference point according to the actual pixel distance mapping relationship. This step is executed by the image processing module of the PLC controller. The effective contour image is transmitted to the feature data buffer of the controller by step S2. Data retrieval adopts memory mapping to ensure the real-time performance of data reading. During contour feature extraction and coordinate transformation, the controller establishes an association call with the world coordinate system parameter library and calibration coefficient library mentioned above to ensure parameter consistency.

[0051] The process of extracting cattle contour features based on the effective contour image, obtaining cattle length, height, and width data based on the cattle contour features, locating the neck reference point using a feature point matching algorithm, and determining the world coordinates of the neck reference point based on the actual pixel distance mapping relationship includes: S3.1 Based on the effective contour image, the YOLO object detection algorithm is called to identify the contour region of the cattle and extract the complete contour pixel coordinate set of the cattle. The algorithm confidence threshold is set to 0.85 and the non-maximum suppression threshold is set to 0.4. The algorithm filters out background interference pixels such as the enclosure device frame and the ground, and accurately extracts the complete contour pixel coordinate set of the cattle. The coordinate set is stored in the feature database of the controller in the form of a two-dimensional array. The array index corresponds one-to-one with the pixel position, providing a data basis for subsequent feature point screening.

[0052] This embodiment can use YOLOv5s, which adopts a network structure of input layer, backbone network, neck network, and prediction layer. The backbone network (C2f module + SPPF module) extracts multi-scale features of the image, the neck network (FPN + PAN structure) realizes feature fusion, and the prediction layer outputs the bounding box coordinates, confidence and class probability of the target. It can realize end-to-end target detection and contour localization, and has the advantages of fast detection speed and high accuracy of small target recognition, which is suitable for the real-time detection needs in livestock scenarios.

[0053] This embodiment is adapted and optimized as follows: Dataset construction: For the containment device scenario of this application, an image dataset containing cattle of different breeds and sizes is constructed. This embodiment provides an image dataset of calves, fattening cattle, and adult cows under different lighting conditions, with a total of 8000 sample images collected. The dataset is divided into training set, validation set, and test set in a 7:2:1 ratio. The dataset is expanded by random cropping, flipping, brightness adjustment, etc., to improve the model's generalization ability. Model training parameters: The number of training iterations is set to 300 rounds, the initial learning rate is 0.01, the learning rate is adjusted using a cosine annealing strategy, the weight decay coefficient is 0.0005, and the batch size is set to 16. Inference parameter settings: The algorithm confidence threshold is set to 0.85, which is determined through validation set testing. This effectively filters background interference such as the ground and device frame. The non-maximum suppression threshold is set to 0.4 to remove overlapping detection boxes and ensure the uniqueness of the contour region.

[0054] Contour extraction implementation: The optimized YOLOv5s algorithm is used to identify and output the minimum bounding rectangle of the cow. Based on the bounding box, the cow region in the effective edge image is cropped, background interference pixels are filtered out, and the complete contour pixel coordinate set of the cow is extracted. The coordinate set is stored in the feature database of the controller in the form of a two-dimensional array, where the row index corresponds to the pixel ordinate and the column index corresponds to the pixel abscissa, providing a data foundation for subsequent feature point selection.

[0055] This embodiment uses YOLOv5s as the core algorithm model for cattle contour recognition. It is a lightweight one-stage object detection architecture that balances detection speed and accuracy, and is suitable for the real-time requirements of containment device scenarios. The model is divided into four main modules: input layer, backbone feature extraction network, feature fusion network, and detection output layer. The layer structure, activation function, and functional details of each module are as follows: The input layer's core function is to perform image preprocessing and adaptive fitting, laying the foundation for subsequent feature extraction. Its specific layer structure and operations are as follows: The collected cattle images were adaptively scaled to 640×640 pixels, and a letterbox filling strategy was used to maintain the aspect ratio of the images and avoid distortion. During the training phase, four random sample images were stitched together, including random scaling, cropping, flipping, and color gamut transformation, to improve the model's generalization ability to cattle of different sizes. Based on the cattle outline annotation boxes in this dataset, three sets of anchor box sizes are automatically calculated to replace manual setting and adapt to different cattle body shape features; the normalization layer normalizes pixel values ​​from [0,255] to [0,1], reducing the impact of numerical range on training.

[0056] The backbone network's core function is to extract multi-scale features from images and distinguish the cow's outline from the background. Its core layer structure and activation function are as follows: The basic convolutional module (Conv) consists of a convolutional layer (Conv2d) and a batch normalization layer (BN) + SiLU activation function. The stride / kernel size of the convolutional layer can be set as needed. The initial layer has a 6×6 convolutional kernel and a stride of 2. It uses the SiLU activation function, which can avoid gradient vanishing and improve feature extraction accuracy compared to ReLU. The C2f module (feature fusion unit) serves as the core layer of the Backbone, consisting of two Conv modules and multiple Bottleneck units. Each Bottleneck unit contains two Conv modules (1×1 convolution for dimensionality reduction + 3×3 convolution for dimensionality increase), with SiLU activation function for all modules. In this embodiment, the Backbone contains four C2f modules, which output feature maps at scales of 80×80, 40×40, and 20×20, respectively, adapting to multi-scale recognition of calves and adult cows. The SPPF module (Spatial Pyramid Pooling Layer) pools the 20×20 feature map output by the last C2f module using four pooling kernels of different sizes (5×5, 9×9, 13×13), and then concatenates and merges them to enhance the model's ability to extract global features of cattle outlines. After pooling, the number of channels is still adjusted through the Conv module (SiLU activation).

[0057] The Feature Fusion Network (Neck) fuses multi-scale features output from the Backbone to improve the contour recognition accuracy of cattle of different sizes. It adopts a bidirectional fusion structure of FPN (top-down) and PAN (bottom-up): FPN layer: Upsample the 20×20 feature map output by SPPF to 40×40, concatenate it with the 40×40 feature map output by Backbone, and then fuse it through SiLU activation in the C2f module; continue to upsample to 80×80, concatenate it with the 80×80 feature map output by Backbone, and fuse it through the C2f module; PAN layer: The 80×80 fused feature map is downsampled, i.e., 3×3 convolution with stride 2, downsampled to 40×40, and concatenated with the 40×40 feature map of the FPN layer, and then fused by the C2f module; it is further downsampled to 20×20, concatenated with the 20×20 feature map output by SPPF, and then fused by the C2f module; All C2f modules use SiLU as their activation function to ensure gradient continuity during feature fusion.

[0058] The core function of the detection output layer (Head) is to output the bounding box, confidence score, and category of cattle outlines, including calves, fattening cattle, and adult cows, using a decoupled head structure. Decoupled convolutional layers: The three scale feature maps output by Neck are input into two parallel Conv modules respectively. The Conv modules also use SiLU activation. One set is responsible for regressing the bounding box coordinates, and the other set is responsible for predicting the confidence and class. Output layer: The prediction results are output through a linear layer. Each scale feature map corresponds to 3 anchor boxes. The output dimension is H×W×3×(4+1+3) (4 is the bounding box coordinates, 1 is the confidence score, and 3 is the number of classes: calf / fattening cattle / adult cow). Loss function: CIoULoss is used to calculate bounding box loss, BCEWithLogitsLoss is used to calculate confidence loss, and CrossEntropyLoss is used to calculate class loss. The total loss is the weighted sum of the three.

[0059] It should be understood that the above YOLOv5s algorithm is existing technology and conventional technology in this field. The main improvement of this application is not the algorithm itself, but the use of it to identify the outline region of cattle and extract the complete outline pixel coordinate set of cattle. All of the above content belongs to existing technology, and those skilled in the art should know its principles and methods.

[0060] S3.2 From the set of contour pixel coordinates, filter out the nose tip feature points, rump feature points, lowest hoof feature points, and widest feature points on both sides of the torso of the cow, and convert the pixel distance between the feature points into the actual physical distance according to the calibration coefficient. The specific filtering rules are as follows: the nose tip feature point is the minimum horizontal coordinate point at the front of the contour; the rump feature point is the maximum horizontal coordinate point at the rear of the contour; the lowest point feature point of the hoof is the maximum vertical coordinate point at the bottom of the contour; and the feature points at the widest points on both sides of the torso are the extreme horizontal coordinate points in the left-right direction of the contour. After filtering, the pixel distance between each feature point is converted into the actual physical distance according to the calibration coefficient k. The conversion formula is as follows: ; ; ; Where L is the actual length of the cow, in millimeters (mm); H is the actual height of the cow, in millimeters (mm); and W is the actual width of the cow, in millimeters (mm). , These are the pixel coordinates of the corresponding feature points captured by the first industrial camera. , These are the pixel coordinates of the feature points captured by the first industrial camera; Corresponding to the rightmost and leftmost coordinates collected by the second industrial camera, in this embodiment, through verification with multiple sets of cattle data, individual parameters of cattle of different sizes can be accurately obtained, providing a differentiated basis for subsequent adaptive clamping.

[0061] S3.3 uses the preset SIFT feature point matching algorithm to locate the neck reference point from the effective contour image corresponding to the detailed side view image of the cow's head and neck. Combining the actual pixel distance mapping relationship and the world coordinate system, the pixel coordinates of the neck reference point are converted into world coordinates.

[0062] Using a pre-defined SIFT feature point matching algorithm, the neck reference point is located from the effective contour image corresponding to the detailed side view image of the cow's head and neck. The SIFT algorithm parameters are set as follows: 6 layers of the difference of Gaussian pyramid, 0.03 key point detection threshold, and 128-dimensional feature vector. This parameter configuration improves the stability and anti-interference ability of feature point matching. Combining the actual pixel distance mapping relationship obtained in step S2 and the constructed OXY two-dimensional world coordinate system, the pixel coordinates of the neck reference point are converted into world coordinates. The error in the conversion process is calibrated by calibration coefficients.

[0063] The process of converting the pixel coordinates of the neck reference point to world coordinates by combining the actual pixel distance mapping relationship and the world coordinate system includes: S3.3.1 Using the SIFT feature point matching algorithm, the head-neck connection points are extracted from the effective contour image of the detailed side view image of the cattle's head and neck. Connection point between neck and torso Among them, the head-neck connection point is the natural connection position between the lower jawbone and the neck of the cow, and the neck-body connection point is the natural connection position between the front of the scapula and the neck of the cow. Using the SIFT feature point matching algorithm, the head-neck connection point P1 and the neck-to-body connection point P2 are extracted from the effective contour image corresponding to the detailed side view image of the cow's head and neck captured by the third industrial camera. The head-neck connection point is identified as the curvature abrupt change point of the contour below the cow's mandible, and the neck-to-body connection point is identified as the curvature abrupt change point of the contour in front of the cow's scapula. Feature vector matching using the SIFT algorithm eliminates interference factors such as cow hair and wrinkles, ensuring the uniqueness and accuracy of the extracted feature points. The coordinates of the extracted feature points are stored in the neck positioning parameter cache of the controller.

[0064] S3.3.2 Head-neck connection point Connection point between neck and torso Using this as a reference, the midpoint between the two points is calculated as the neck clamping reference point. This midpoint represents the physiologically safe clamping area of ​​the cattle's neck, preventing damage to the trachea, blood vessels, and nerve tissue during clamping. Its pixel coordinates are... The calculation uses the following formula: ,in, The pixel x-coordinate of the neck reference point. The pixel ordinate of the neck reference point is calculated. After the calculation is completed, the controller verifies the validity of the coordinate. If the coordinate is within the outline of the cow's neck, it is determined to be a valid reference point; otherwise, the feature point extraction process is re-executed. S3.3.3 Based on the calibration coefficient k and the constructed OXY two-dimensional world coordinate system, the pixel coordinates of the neck reference point are... Convert to world coordinates The conversion formula is: ,in, Here are the world coordinates for the top-left pixel of the head and neck detail side view image. The pixel coordinates are the top-left corner pixels of the side view image of the head and neck details.

[0065] S4. Determine the target control parameters for driving the drive assembly based on the world coordinates of the neck reference point. The target control parameters include controlling the travel distance of the neck clamping mechanism in the first direction and the travel distance in the second direction.

[0066] This step is executed by the drive control module of the PLC controller. The world coordinates of the neck reference point are transmitted to the controller's drive parameter buffer area via step S3. The drive components employ the X-axis servo slide and Y-axis servo slide described above. It should be understood that the servo slide is existing technology and conventional technique in this field. The main improvement of this application is not the servo slide itself, but rather the use of the servo slide to move the neck clamping mechanism to the position of the cow's neck. Similarly, the above content is all existing technology, and those skilled in the art should understand its principles and methods. The opposing movement of the neck clamping mechanism can be achieved by a cylinder.

[0067] The step of determining the target control parameters for driving the drive component based on the world coordinates of the neck reference point includes: S4.1 Obtain the initial position coordinates of the neck clamping mechanism in the OXY two-dimensional world coordinate system. ,in, The initial coordinates of the neck clamping mechanism along the first direction. The initial coordinates of the neck clamping mechanism along the second direction; The initial position coordinates are acquired by a displacement sensor integrated into the servo slide. Before each operation, the controller sends a reset command to drive the neck clamping mechanism back to the mechanical origin. The displacement sensor acquires the coordinates at this time as the initial position coordinates and stores them in the controller's drive parameter library.

[0068] S4.2 Based on the world coordinates of the neck reference point and the initial position coordinates Calculate the target control parameters of the driving component, and the travel distance in the first direction. Distance traveled in the second direction The calculation formula is: ; To compensate for displacement errors caused by mechanical transmission backlash, the controller calls a preset linear compensation model to correct the calculation results. The compensation formula is as follows: In the formula, ΔX′ and ΔY′ are the corrected target travel distances, and a and b are the transmission clearance compensation coefficients. In this embodiment, the values ​​are a=0.002 and b=0.0015, and the displacement control error after compensation is ≤0.05mm. In this embodiment, the world coordinates of the neck reference point obtained in step S3 are substituted. =105mm, =600mm and initial coordinates =−100mm, =400mm, calculated as follows: After compensation and correction, ΔX′=205.41mm and ΔY′=200.3mm are obtained. The corrected parameters are stored in the output command buffer of the controller.

[0069] S4.3 converts the corrected target control parameters into pulse drive signals recognizable by the drive component, and sends the drive signals to the drive component, causing the drive component to drive the neck clamping mechanism to move along the first direction. Distance, precise movement along the second direction distance.

[0070] The corrected target control parameters are converted into pulse drive signals recognizable by the drive component. These drive signals are then sent to the drive component, causing it to drive the neck clamping mechanism to travel a distance ΔX in the first direction and a precise distance ΔY in the second direction. The pulse equivalent of the servo slide is set to a pulse, meaning that for every pulse signal output, the slide travels 0.01 mm. The formula for calculating the number of pulses is: ,in, The number of pulses in the first direction. The number of pulses in the second direction; substituting the corrected parameters, we can calculate... =20541 pulses, =20030 pulses. The controller adopts a "pulse + direction" signal output mode, sending pulse and direction signals to the servo driver of the drive component. The signal transmission uses a differential signal format, which has strong anti-interference capability. The action sequence of the drive component is set as follows: first, it moves along the first direction to the target position. After the slide's position detection switch feeds back the position signal, it then moves along the second direction to the target position, avoiding interference between the two directions. When the neck clamping mechanism reaches the target position, the controller sends a clamping preparation signal to the neck clamping mechanism to complete the precise positioning of the neck and provide position assurance for subsequent adaptive clamping actions.

[0071] The neck clamping mechanism forms a curved section, and the neck clamping mechanism adopts the symmetrical arc-shaped clamping arm described above. The curved section of the arc-shaped clamping arm is adapted to the physiological curve of the bovine neck. Three sets of pressure sensors are evenly embedded inside the curved section. The sensors are evenly spaced along the axial direction of the curved section to ensure comprehensive acquisition of the clamping pressure distribution. The pressure sensors are connected to the analog input interface of the PLC controller. The signal transmission is filtered and amplified by the signal conditioning module to ensure the stability and accuracy of the pressure signal.

[0072] A pressure sensor is provided on the curved portion, and the neck clamping mechanism performs the clamping action as follows: S5.1 acquires the clamping pressure signal. The pressure sensor's detection range is set to 0-100N, detection accuracy to ±0.5N, and sampling frequency to 50Hz. After the neck clamping mechanism receives the clamping preparation signal and initiates the clamping action, the controller synchronously triggers the pressure sensor's data acquisition process, acquiring pressure data from three sensors in real time and transmitting it to the controller's pressure feedback module. The controller performs mean filtering on the three sets of acquired pressure data to eliminate signal distortion caused by instantaneous pressure fluctuations. The formula for calculating the average actual clamping pressure after filtering is as follows: in, This represents the average actual clamping pressure (unit: N). , , The pressure values ​​(unit: N) collected by three sets of pressure sensors are used as the basis for subsequent comparison and adjustment, and are stored in the feedback parameter cache of the controller.

[0073] S5.2 compares the actual clamping pressure with the preset pressure threshold. If the pressure deviation exceeds the preset allowable range, it outputs an adjustment signal to the drive component to dynamically adjust the clamping pressure and displacement.

[0074] The preset pressure threshold is adaptively matched based on the cattle's body size parameters. The specific setting rule is as follows: Based on the cattle width data W obtained in step S3, the preset pressure threshold is determined using the following formula. ,in, Here, is the preset pressure threshold (unit: N), c is the width coefficient (c = 0.08 N / mm in this embodiment), d is the base pressure value (d = 15 N in this embodiment), and W is the actual width of the cow (unit: mm); the preset allowable pressure deviation range is... This range ensures both effective clamping and fixation, while also preventing excessive pressure that could damage the cattle's neck tissue.

[0075] The formula for calculating the deviation between the actual clamping pressure and the preset threshold is: ,in, Pressure deviation (unit: N); when When the pressure is deemed too high, the controller outputs a reverse adjustment signal; when When the pressure is too low, the controller outputs a positive adjustment signal; when When the pressure is deemed acceptable, the current clamping state is maintained.

[0076] The control signal is generated using a PID control algorithm to ensure a smooth control process without overshoot. The PID control formula is as follows: Where u(k) is the adjusted output signal at time k (unit: V). This is a scaling factor, used in this embodiment. =0.8, The integral coefficient is used in this embodiment. =0.05, These are the differential coefficients, in this embodiment... =0.1, Let k be the pressure deviation at time k. The pressure deviation at time k-1.

[0077] The controller converts the PID regulation output signal into a pulse regulation signal that the drive component can recognize and sends it to the drive component of the neck clamping mechanism. The timing of the regulation action is set as follows: first, the displacement of the clamping mechanism along the second direction is finely adjusted based on the regulation signal. If the pressure deviation is still not eliminated, the displacement along the first direction is finely adjusted to avoid the adjustment action causing the neck clamping to shift. Until the pressure deviation falls into the preset allowable range, the controller stops outputting the regulation signal, locks the current clamping parameters, and completes the adaptive clamping adjustment.

[0078] In this embodiment, if the cow width W = 600mm obtained in step S3, the preset pressure threshold is calculated by substituting it into the formula. The preset allowable range is [60N, 66N]; if the three sets of pressure data collected at a certain moment are The actual average clamping pressure Pressure deviation The controller generates a reverse adjustment signal through a PID algorithm, which drives the servo slide to move the clamping mechanism back slightly until the average pressure stabilizes at 64N and the deviation is eliminated.

[0079] The technical solutions described in the embodiments of this application have at least the following technical effects or advantages: By employing photoelectric sensors and time-series control technology for cattle positioning, the first and second position signals are accurately collected through diffuse reflection photoelectric sensors. The rear door closing, conveyor belt starting and stopping, and the double-side plate clamping mechanism are controlled sequentially according to preset time intervals, replacing the traditional manual positioning method. Therefore, it effectively solves the problems of high labor intensity, low work efficiency, and significant influence of human factors on positioning accuracy in existing technologies. This achieves automated, standardized, and regularized posture before cattle clamping, improving work efficiency and positioning consistency, while avoiding the safety risks of direct contact between manual operation and cattle.

[0080] By employing visual recognition technologies such as standard calibration board calibration, multi-view industrial camera acquisition, and multi-algorithm fusion image processing, and establishing a mapping relationship between pixels and actual distances through the Zhang Zhengyou calibration algorithm, combined with multi-view image acquisition from three industrial cameras, and using Gaussian filtering, Sobel-Canny edge enhancement fusion, Otsu threshold segmentation, and YOLO and SIFT feature point matching algorithms, this technology effectively solves the problems of existing technologies being unable to adapt to individual differences in the body size of different cattle and insufficient neck positioning accuracy. This enables accurate extraction of cattle contour features and high-precision positioning of neck reference points, providing millimeter-level precise coordinates for subsequent adaptive clamping and ensuring the accuracy and adaptability of the clamping position.

[0081] By employing control technologies such as servo slide drive, coordinate difference calculation, and transmission clearance compensation, the target travel distance is calculated based on the world coordinates of the neck reference point and the initial coordinates of the clamping mechanism. The mechanical transmission error is corrected through a linear compensation model, and the parameters are converted into pulse signals to drive the servo slide action. Therefore, the problems of low displacement control accuracy of the clamping mechanism and mechanical error affecting the positioning effect in the existing technology are effectively solved. This enables precise displacement control of the neck clamping mechanism along the first and second directions, ensuring that the clamping mechanism can accurately reach the target clamping position and laying the foundation for stable clamping.

[0082] By employing pressure feedback technology with multiple pressure sensors, adaptive threshold matching, and PID closed-loop regulation, and by evenly distributing pressure sensors at the curved part of the neck clamping mechanism, and adaptively matching preset pressure thresholds based on cattle width data, the clamping pressure and displacement are dynamically adjusted through a PID algorithm. This effectively solves the problems of uncontrollable clamping pressure and excessively loose or tight clamping in existing technologies, thereby achieving adaptive flexible clamping of the cattle's neck. It balances the clamping and fixation effect with the cattle's physiological safety, significantly reduces cattle stress response, and improves the overall operational reliability and stability of the equipment, meeting the high-efficiency operational needs of modern large-scale livestock farming.

[0083] Finally, the usage instructions are as follows: Initial gate preparation: Open the rear gate, close the front gate, and simultaneously close the front safety lever to guide the cattle into the containment device.

[0084] Enclosure of the enclosure space: After the cattle enter, the back door is closed and the rear safety lever is engaged, forming an enclosed enclosure space.

[0085] Conveyor belt positioning: Activate the conveyor belt under the cattle's feet to transport the cattle to the preset working position at the front of the device.

[0086] Lateral centering clamping with double side plates: Control the two side plates to move towards the center and clamp the cattle to the center of the device to prevent the cattle from moving left and right.

[0087] Visual recognition of body shape: Activate the visual acquisition system to identify and acquire body shape data such as the length, height, and width of the cattle.

[0088] Neck clamping mechanism positioning and clamping: The neck position is calculated based on the height and length data of the cattle, and the neck clamping mechanism is controlled to adjust forward and backward and up and down to the target position to complete the precise clamping of the neck.

[0089] Operating access opened: By opening the front safety lever and front door, operators can carry out operations such as vaccination and blood collection on cattle.

[0090] Cattle body inspection and reset: The protective bars on the side panels can be opened to inspect the cattle body; after the operation is completed, release the neck clamping mechanism and the two side panels in sequence, open the front door and the front safety lever, and the cattle will exit from the front door, or the conveyor belt can be reversed to send the cattle out from the rear door, and all parts will be reset to their initial state.

[0091] Example 2 Reference Figure 5 Secondly, a vision-based adaptive clamping control system for cattle necks includes: The position signal processing module is configured to acquire a first position signal and a second position signal, and output a closing signal to the rear door and a conveyor signal to the conveyor belt in sequence according to the first position signal, and output a stop signal to the conveyor belt in sequence according to the second position signal, and output a counter-approach signal to the double-side plate clamping mechanism. The first position signal is the signal that the cow has reached the first position, and the second position signal is the signal that the cow has reached the second position. The image processing module is configured to obtain the actual pixel mapping relationship based on the standard calibration plate image, construct a world coordinate system, acquire multi-view image data of cattle, and process the multi-view image data to obtain an effective contour image that retains the complete outline of the cattle. The neck reference point localization module is configured to extract cattle contour features based on the effective contour image, obtain cattle length data, height data, and width data according to the cattle contour features, locate the neck reference point using a feature point matching algorithm, and determine the world coordinates of the neck reference point according to the actual pixel distance mapping relationship. The parameter determination module is configured to determine the target control parameters for driving the drive component based on the world coordinates of the neck reference point. The target control parameters include controlling the travel distance of the neck clamping mechanism in a first direction and the travel distance in a second direction.

[0092] A computer-readable storage medium storing a plurality of instructions adapted for loading and execution by a processor of a terminal device, the aforementioned vision-based adaptive clamping control method for cattle necks.

[0093] A terminal device includes a processor and a computer-readable storage medium, the processor being configured to implement various instructions; the computer-readable storage medium being configured to store multiple instructions adapted for loading and execution by the processor of the aforementioned vision-based adaptive clamping control method for cattle necks.

[0094] Those skilled in the art will understand that embodiments of the present invention can be provided as methods, systems, or computer program products. Therefore, the present invention can take the form of a completely hardware embodiment, a completely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, the present invention can take the form of a computer program product embodied on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.

[0095] This invention is described with reference to flowchart illustrations and / or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of the invention. It will be understood that each block of the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, special-purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, generate instructions for implementing the flowchart illustrations and / or block diagrams. Figure 1 One or more processes and / or boxes Figure 1 A device that provides the functions specified in one or more boxes.

[0096] These computer program instructions may also be stored in a computer-readable storage medium that can direct a computer or other programmable data processing device to function in a particular manner, such that the instructions stored in the computer-readable storage medium produce an article of manufacture including instruction means, which are implemented in a process Figure 1 One or more processes and / or boxes Figure 1 The function specified in one or more boxes.

[0097] These computer program instructions may also be loaded onto a computer or other programmable data processing equipment to cause a series of operational steps to be performed on the computer or other programmable equipment to produce a computer-implemented process, thereby providing instructions that execute on the computer or other programmable equipment for implementing the process. Figure 1 One or more processes and / or boxes Figure 1 The steps of the function specified in one or more boxes.

[0098] Although preferred embodiments of the invention have been described, those skilled in the art, upon learning the basic inventive concept, can make other changes and modifications to these embodiments. Therefore, the appended claims are intended to be interpreted as including both the preferred embodiments and all changes and modifications falling within the scope of the invention.

[0099] Obviously, those skilled in the art can make various modifications and variations to this invention without departing from the scope of the invention. The spirit and scope of the invention are as follows: Thus, if these modifications and variations of the invention fall within the scope of the claims of the invention and their equivalents, the invention is also intended to include these modifications and variations.

Claims

1. A vision-based adaptive neck clamping control method for cattle, used in a neck-locking clamping device, characterized in that, The neck-clamping device includes: a conveyor belt for carrying and transporting cattle; a double-side plate clamping mechanism for laterally positioning the cattle's torso; a neck clamping mechanism driven by a drive assembly for clamping the cattle's neck; and a front door and a rear door located at both ends of the enclosure device. The drive assembly is configured to drive the neck clamping mechanism to move linearly at least along a first direction and a second direction. The first direction is parallel to the tangent direction of the conveying path, and the second direction is perpendicular to the bearing plane of the conveying mechanism. The method includes the following steps: Acquire a first position signal and a second position signal. Based on the first position signal, output a closing signal to the rear door and a conveyor signal to the conveyor belt in sequence. Based on the second position signal, output a stop signal to the conveyor belt in sequence and output a counter-approach signal to the double-side plate clamping mechanism in sequence. The first position signal is the signal that the cow has reached the first position and the second position signal is the signal that the cow has reached the second position. The actual pixel mapping relationship is obtained based on the standard calibration plate image, and a world coordinate system is constructed to obtain multi-view image data of cattle. The multi-view image data is then processed to obtain an effective contour image that retains the complete outline of the cattle. Based on the effective contour image, the contour features of the cattle are extracted, the neck reference point is located using a feature point matching algorithm, and the world coordinates of the neck reference point are determined according to the actual pixel distance mapping relationship. The target control parameters for driving the drive assembly are determined based on the world coordinates of the neck reference point. The target control parameters include controlling the travel distance of the neck clamping mechanism in a first direction and the travel distance in a second direction.

2. The adaptive clamping control method for cattle necks based on visual recognition according to claim 1, characterized in that, The acquisition of the first position signal and the second position signal includes: When a cow is detected entering the first position and generates an occlusion signal that lasts for a preset duration, a valid first position signal is generated. When a cow is detected reaching the second position and generates an occlusion signal that lasts for a preset duration, a valid second position signal is generated.

3. The adaptive clamping control method for cattle necks based on visual recognition according to claim 1, characterized in that, The process of obtaining the actual pixel mapping relationship based on the standard calibration board image and constructing a world coordinate system includes: The standard calibration plate is set on the neck clamping device and parallel to the conveyor belt bearing plane. The calibration image dataset is processed to extract the corner features of the calibration plate in each frame image. The mapping relationship of the actual distance of pixels is calculated by matching the corner coordinates to solve the calibration coefficient. With the center point of the second position as the origin O, construct an OXY two-dimensional world coordinate system. The X-axis is set along the first direction and points downstream of the conveying path as the positive direction. The Y-axis is set along the second direction and points away from the bearing plane as the positive direction.

4. The adaptive clamping control method for cattle necks based on visual recognition according to claim 3, characterized in that, The process of acquiring multi-view image data of cattle and processing the multi-view image data to obtain an effective contour image that preserves the complete outline of the cattle includes: Acquire images of the cattle's side profile, front view of the torso, and side view of the head and neck to form multi-view image data; The preset image preprocessing algorithm is invoked to process the multi-view image data, sequentially performing Gaussian filtering for noise reduction, grayscale conversion, edge enhancement, and threshold segmentation operations to extract the complete outline of the cow, resulting in an effective outline image that retains the complete outline of the cow and key feature points.

5. The adaptive clamping control method for cattle necks based on visual recognition according to claim 4, characterized in that, The processing of the multi-view image data includes: A Gaussian filter is applied to the acquired color multi-view images to filter out random noise and environmental interference noise. The filtering formula is as follows: Where G(x,y) is the weight value at position (x,y) in the filter kernel, σ is the preset Gaussian standard deviation, and x and y are the relative coordinates of the pixels in the filter kernel. The denoised color image is obtained through this filtering operation. The denoised color image is converted to a grayscale image, preserving the brightness features of the cattle outline and reducing the amount of data processing. The Sobel and Canny operators are fused to extract the edges of the cattle, and the horizontal gradient is calculated using the Sobel operator. and vertical gradient The gradient fusion calculation is performed to obtain a preliminary edge image. The preliminary edge image is then input into the Canny operator for edge thinning and connection to obtain a continuous and complete cattle edge image. Based on the grayscale histogram of the cattle edge image, the Otsu adaptive threshold segmentation algorithm is used to determine the segmentation threshold, and the edge image is binarized to extract the complete outline of the cattle, thus obtaining an effective outline image.

6. The adaptive clamping control method for cattle necks based on visual recognition according to claim 1, characterized in that, The neck reference point is located using a feature point matching algorithm, and the world coordinates of the neck reference point are determined based on the actual pixel distance mapping relationship, including: Based on the effective contour image, the YOLO object detection algorithm is called to identify the contour region of the cattle and extract the complete set of contour pixel coordinates of the cattle. From the set of outline pixel coordinates, the nose tip feature points, rump feature points, lowest hoof feature points, and widest feature points on both sides of the torso feature points of the cow are selected. Based on the calibration coefficient, the pixel distance between the feature points is converted into the actual physical distance. Using the pre-defined SIFT feature point matching algorithm, the neck reference point is located from the effective contour image corresponding to the detailed side view image of the cow's head and neck. Combining the actual pixel distance mapping relationship and the world coordinate system, the pixel coordinates of the neck reference point are converted into world coordinates.

7. The adaptive clamping control method for cattle necks based on visual recognition according to claim 6, characterized in that, The process of converting the pixel coordinates of the neck reference point to world coordinates by combining the actual pixel distance mapping relationship and the world coordinate system includes: Using the SIFT feature point matching algorithm, head-neck connection points and neck-body connection points are extracted from the effective contour images of detailed side view images of cattle heads and necks. The head-neck connection point is the natural connection position between the lower jawbone and the neck of the cattle, and the neck-body connection point is the natural connection position between the front of the scapula and the neck of the cattle. Using the head-neck connection point and the neck-to-body connection point as references, calculate the midpoint between the two as the neck clamping reference point; Based on the calibration coefficients and the constructed OXY two-dimensional world coordinate system, the pixel coordinates of the neck reference point are converted into world coordinates.

8. The adaptive clamping control method for cattle necks based on visual recognition according to claim 1, characterized in that, The step of determining the target control parameters for driving the drive component based on the world coordinates of the neck reference point includes: Obtain the initial position coordinates of the neck clamping mechanism in the OXY two-dimensional world coordinate system. ,in, The initial coordinates of the neck clamping mechanism along the first direction. The initial coordinates of the neck clamping mechanism along the second direction; Based on the world coordinates of the neck reference point and the initial position coordinates, the target control parameters of the drive component, the travel distance in the first direction, and the travel distance in the second direction are calculated. The corrected target control parameters are converted into pulse drive signals that can be recognized by the drive component, and the drive signals are sent to the drive component so that the drive component drives the neck clamping mechanism to travel a distance in the first direction and a precise distance in the second direction.

9. The adaptive clamping control method for cattle necks based on visual recognition according to claim 1, characterized in that, The neck clamping mechanism has a curved portion, and a pressure sensor is provided on the curved portion. During the clamping action, the neck clamping mechanism includes: Acquire clamping pressure signal; The actual clamping pressure is compared with the preset pressure threshold. If the pressure deviation exceeds the preset allowable range, an adjustment signal is output to the drive component to dynamically adjust the clamping pressure and displacement.

10. A vision-based adaptive clamping control system for cattle necks, characterized in that, The method according to claims 1-9 includes: The position signal processing module is configured to acquire a first position signal and a second position signal, and output a closing signal to the rear door and a conveyor signal to the conveyor belt in sequence according to the first position signal, and output a stop signal to the conveyor belt in sequence according to the second position signal, and output a counter-approach signal to the double-side plate clamping mechanism. The first position signal is the signal that the cow has reached the first position, and the second position signal is the signal that the cow has reached the second position. The image processing module is configured to obtain the actual pixel mapping relationship based on the standard calibration plate image, construct a world coordinate system, acquire multi-view image data of cattle, and process the multi-view image data to obtain an effective contour image that retains the complete outline of the cattle. The neck reference point localization module is configured to extract cattle contour features based on the effective contour image, obtain cattle length data, height data, and width data according to the cattle contour features, locate the neck reference point using a feature point matching algorithm, and determine the world coordinates of the neck reference point according to the actual pixel distance mapping relationship. The parameter determination module is configured to determine the target control parameters for driving the drive component based on the world coordinates of the neck reference point. The target control parameters include controlling the travel distance of the neck clamping mechanism in a first direction and the travel distance in a second direction.