A method for extracting the left and right ear roots of group-raised pigs

By using video data acquisition device and rotation target detection model in a group health pig environment, combined with polar coordinate system method, accurate detection and accurate identification of pig ear roots is achieved, and the problem of low temperature measurement accuracy in the prior art is solved.

CN119229357BActive Publication Date: 2025-04-01ZHEJIANG UNIV
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202411769058.2
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-12-04
Publication Date
2025-04-01
Estimated Expiration
2044-12-04

AI Technical Summary

Technical Problem

The prior art is difficult to accurately identify and extract the temperature of the pig ear roots in the environment of group health pigs, and the temperature measurement accuracy is not high, so it is impossible to achieve accurate detection of the ear roots of the pig individuals.

Method used

The pig video data acquisition device is used to collect video data in real time, and the tag data set is constructed through image extraction and label addition, and the rotation object detection YOLOv8-OBB model is trained to identify the position and category of the ear root site, and the polar coordinate system method is used to optimize the identification results.

Benefits of technology

It realizes accurate detection of ear roots of group health pigs and accurate identification of left and right ear root categories, improving the position accuracy of ear root predictive frame and the identification accuracy of left and right ear root categories.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119229357B_ABST
    Figure CN119229357B_ABST
Patent Text Reader

Abstract

The present invention discloses a method for extracting the left and right ear bases of group-raised pigs. The method comprises: building a pig video data acquisition device and collecting video data of group-raised pigs in real time, adding ear base labels after image extraction, then constructing a label data set and dividing it into a training set and a verification set, and then training a pig ear base recognition model; obtaining the ear base position of group-raised pigs and the image after the left and right ear base categories are recognized through the trained model, and then optimizing the left and right ear base categories using the polar coordinate system method, and finally realizing the extraction of the left and right ear bases of group-raised pigs. The method of the present invention can improve the position accuracy of the ear base prediction frame, and optimize the model recognition using the polar coordinate system method, which can improve the recognition accuracy of the left and right ear base categories. The present invention can be applied to the detection of the ear base of individual pigs in a pig group-raising environment, and can further provide an application basis for the accurate monitoring of the body temperature of group-raised pigs and the identification of individual pigs.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The invention relates to a method for extracting ear roots, and relates to the technical field of target detection, in particular to a method for extracting left and right ear roots of group-raised pigs. Background Art

[0002] With the development of pig farming, large-scale, intensive and intelligent farming methods are widely used in the industry. In the farming process, the health of pigs is very important. The body temperature of pigs is an important indicator of their health status. Timely and accurate monitoring of the body temperature of pigs can effectively prevent diseases and improve farming efficiency and quality.

[0003] In recent years, infrared thermal imaging technology, as a non-contact body surface temperature measurement method, has been widely used in the fields of livestock and poultry body temperature detection and disease diagnosis. This method uses a combination of deep learning and machine vision. It collects pig images through a camera to build a data set, trains a deep learning model to detect the area of ​​interest for pig temperature measurement, and extracts the thermal image to use the temperature value of the area of ​​interest as the pig body temperature. The temperature of the ear root is the part of the pig's body surface that is most closely related to the rectal temperature. In the study of infrared thermal imaging to detect pig body temperature, the ear root is very suitable as the area of ​​interest for pig temperature measurement, so the application of deep learning models to accurately extract the pig ear root has become an important research topic.

[0004] The existing method uses a handheld infrared thermal imager to shoot the ear base of a single pig's head, collect image data of the ear base of the pig, and then use a deep learning target detection algorithm to identify the ear base, and finally extract the temperature value of the ear base in the thermal image. This method is time-consuming and labor-intensive and cannot achieve individual ear base identification of pigs in a group-raising environment, and its intelligence level is insufficient. Another method uses a thermal imager to take a bird's-eye view of the pigpen, perform target detection on the head of group-raised pigs, and then extract the temperature of the pig head in the thermal image. This method uses a vertical box to detect the head, which is prone to include background pixels and has more noise points, and its temperature measurement accuracy is not as good as directly detecting the ear base. Summary of the invention

[0005] In order to solve the problems existing in the background technology, the present invention provides a method for extracting the left and right ear roots of group-raised pigs. The method of the present invention can achieve accurate detection of the ear roots of group-raised pigs and accurate identification of the left and right ear roots.

[0006] The technical solution adopted by the present invention is:

[0007] The method for extracting the left and right ear roots of group-raised pigs of the present invention comprises:

[0008] Step S1: Set up a pig video data acquisition device in the breeding room and monitoring room of group-raised pigs, use the pig video data acquisition device to collect video data of the group-raised pigs in real time, add ear base part labels after image extraction to the video data of the group-raised pigs, and obtain a number of pig label images, thereby constructing a label data set, and divide the label data set into a training set and a verification set according to a preset ratio.

[0009] Step S2: constructing a pig ear base part recognition model in the pig video data acquisition device, inputting a training set and a validation set into the pig ear base part recognition model for training, and obtaining a trained pig ear base part recognition model.

[0010] Step S3: input the group-raised pig image to be identified into the trained pig ear base part recognition model for processing. After processing, the pig ear base part recognition model outputs the group-raised pig image with the ear base position and the left and right ear base categories identified.

[0011] Step S4: Use the polar coordinate system method to optimize the left and right ear root categories in the group-raised pig image identified in step S3 to obtain optimized left and right ear root categories. Finally, the pig video data acquisition device extracts the left and right ear root parts of the group-raised pigs according to the ear root parts in the group-raised pig image identified in step S3 and the left and right ear root categories optimized in step S4.

[0012] In the step S1, the pig video data acquisition device includes a camera, a fiber optic transceiver, an optical fiber, a switch, a hard disk recorder and a network monitoring computer. The camera is connected to the fiber optic transceiver through a network cable, the fiber optic transceiver is connected to the switch through an optical fiber, and the switch, the hard disk recorder and the network monitoring computer are connected in turn through the network cable; the camera and the fiber optic transceiver are installed in the cultivation room of group-raised pigs, and the camera is downward facing the group-raised pigs in the cultivation room; the camera is a dual-spectrum camera, and the camera collects infrared spectrum and visible spectrum video data of group-raised pigs in real time, and then stores them in the hard disk recorder after passing through the fiber optic transceiver, the optical fiber and the switch in turn, and finally views and processes them in the network monitoring computer. The installation position of the camera is located above the drinking trough of the pig pen, and the pig pen is photographed from a bird's-eye view to ensure that all pigs in the pig pen are within the field of view. The camera can specifically use a Hikvision infrared thermal imager to monitor and shoot the daily behavior activities of all pigs in the cultivation room.

[0013] In the step S1, the video data of group-raised pigs is subjected to frame extraction at intervals to obtain pig image frames in various scenes, thereby completing image extraction; for each extracted pig image frame, the ear root of each pig in the pig image frame is marked with a rectangular frame, and the coordinates of the four vertex corners of each rectangular frame and the left and right ear categories of the ear root are marked, thereby obtaining a number of pig label images. It is necessary to select typical frame images, and various scenes include no pigs, a single pig, multiple pigs, complete shooting of the left and right ears of the pigs, incomplete shooting of the left and right ears of the pigs, etc., and the number of images in each scene is basically the same. If there are too many images in the same scene, they need to be deleted.

[0014] In the step S2, the pig ear base part recognition model adopts the rotation target detection YOLOv8-OBB (You Only Look Once version 8-Oriented Bounding Box) model.

[0015] In the step S2, the training set and the validation set are input into the pig ear base part recognition model for training, so as to iteratively generate the weight parameters of the pig ear base part recognition model, and the weight parameters are back-propagated to the pig ear base part recognition model to iteratively update the model hyperparameters in the pig ear base part recognition model until the optimal weight parameters are reached, thereby obtaining a trained pig ear base part recognition model.

[0016] In the step S3, the positions of the ear roots of group-raised pigs outputted after processing by the pig ear root position recognition model and the group-raised pig images after the left and right ear root categories are identified, and the positions of the ear roots of the group-raised pigs are marked by their own prediction boxes. The information of each prediction box includes the coordinates of the four vertex corners, and the ear root positions in each prediction box correspond to the respective left and right ear categories.

[0017] In step S4, the process of optimizing the left and right ear root categories in the identified group-reared pig images using the polar coordinate system is as follows:

[0018] Step S4.1: According to the coordinates of the four vertices of each prediction box in the group-raised pig image after the ear base position and the left and right ear base category identification, the center point coordinates of each prediction box are obtained, and the prediction boxes are matched according to the center point coordinates of each prediction box to pair the prediction boxes of the left and right ear bases of each pig.

[0019] Step S4.2: For every two paired prediction frames, the two prediction frames are in an eight-shaped shape, and the sides of the two prediction frames that are farthest from each other in the two eight-shaped prediction frames are determined as edge lines according to the coordinates of the four vertices of the two prediction frames; the ear base of the raw pig is in an eight-shaped shape, and the prediction frames of each pair of ear base parts are also in an eight-shaped shape.

[0020] Step S4.3: For each pair of prediction boxes, extend the edge lines of the two prediction boxes and intersect them. Take the intersection of the two prediction box edge lines as the origin and draw a polar coordinate system. In the polar coordinate system, obtain the level coordinates of the center points of the two prediction boxes, and then obtain the angle difference between the center points of the two prediction boxes. i , according to the angle difference i Determine the left and right categories of the ear base in the two prediction frames; repeat the steps to traverse all paired ear base prediction frames to complete the left and right ear base category recognition.

[0021] The left and right ear root position recognition method can re-confirm and correct the left ear root position and right ear root position categories for each pair of ear root position prediction frames to eliminate the left and right ear root position category errors predicted by the ear root position recognition model.

[0022] In the step S4.1, for each two prediction frames at the base of the ears, the center distance of the two prediction frames is obtained using the Euclidean distance according to the center point coordinates of the two prediction frames. When the center distance of the two prediction frames is within the preset center distance threshold range, the two prediction frames are matched until the prediction frames at each base of the ears are matched. Generally, the two prediction frames with the smallest center distance can be matched as paired prediction frames.

[0023] In the step S4.2, according to the coordinates of the four vertices of the two prediction boxes, firstly, the four vertices in the first prediction box are matched with the four vertices in the second prediction box, and a pair of vertices closest to the two prediction boxes are determined as base points. For each base point in the prediction box, the vertices closest to and farthest from the base point among the other three vertices in the prediction box are determined, and the line connecting the vertices closest to and farthest from the base point is the edge line of the prediction box.

[0024] In step S4.3, according to the angle difference i Determine the left and right categories of the ear roots in the two prediction boxes as follows:

[0025] When the angle difference between the center points of the two predicted boxes i When the angle is less than 180°, the prediction box with the smaller center point angle is used as the prediction box for the left ear, and the other prediction box with the larger center point angle is used as the prediction box for the right ear.

[0026] When the angle difference between the center points of the two predicted boxes i When the angle is greater than 180°, the prediction box with the larger center point angle is used as the prediction box for the left ear, and the other prediction box with the smaller center point angle is used as the prediction box for the right ear.

[0027] The method of the present invention takes the direction of the head of the live pig as the origin direction of the polar coordinate system. The pigs standing in different positions in the image can be regarded as rotating around the head, and a polar coordinate system is established for each pig. The method transforms the pixel coordinates of the original rectangular coordinate system into the angle coordinates of the polar coordinate system, and according to the characteristic that the coordinate values ​​of the polar coordinates contain angles, the angle difference is used to determine the left and right ear roots.

[0028] The method of the present invention can use a directional rotation prediction frame to predict the ear base position of pigs in a pig group-raising environment. The directional rotation prediction frame can accurately fit the left and right ear base positions of each pig, and through the pairing of the left and right ear base position prediction frames and the identification of the left and right ear base position categories, the model recognition method is optimized using the polar coordinate system method to achieve the identification of the left and right ear base positions of individual pigs, thereby realizing the identification of the left and right ear base positions of different individual pigs, laying a foundation for subsequent pig body temperature detection, and having very important application value in the fields of ear base target detection of group-raised pigs and infrared thermal imaging temperature measurement of group-raised pigs.

[0029] The beneficial effects of the present invention are:

[0030] The method of the present invention detects the ear base of pigs based on the model of the directional rotation prediction frame, which can improve the position accuracy of the ear base prediction frame. The model recognition method is optimized by the polar coordinate system method, which can improve the recognition accuracy of the left and right ear base categories, and can accurately identify the left and right ear bases of different individual pigs. The present invention can be applied to the detection of the ear base of individual pigs in a pig group-raising environment, and further provides an application basis for the accurate monitoring of the body temperature of group-raised pigs and the identification of individual pigs. BRIEF DESCRIPTION OF THE DRAWINGS

[0031] Figure 1 It is a schematic diagram of the pig video data acquisition system of the present invention;

[0032] Figure 2 It is a flow chart of the method for extracting the left and right ear roots of group-reared pigs of the present invention;

[0033] Figure 3 This is a result diagram of the extraction of the left and right ear roots of group-raised pigs according to the present invention;

[0034] Figure 4 It is a confusion matrix diagram of the prediction results of the pig ear root position recognition model of the present invention on the test set;

[0035] Figure 5 It is a schematic diagram of determining the categories of left and right ear roots by using the polar coordinate system method for identifying the left and right ear roots of pigs according to the present invention;

[0036] Figure 6 This is a schematic diagram of an example of extracting the left and right ear roots of group-raised pigs according to the present invention;

[0037] In the picture: 1. Camera, 2. Network cable, 3. Fiber optic transceiver, 4. Optical fiber, 5. Switch, 6. Hard disk recorder, 7. Network monitoring computer. DETAILED DESCRIPTION

[0038] The present invention is further described in detail below with reference to the accompanying drawings and specific embodiments.

[0039] like Figure 2 As shown, the specific implementation process of the method for extracting the left and right ear roots of group-raised pigs of the present invention is as follows:

[0040] First, build the following in the breeding room and monitoring room of group pigs: Figure 1 The pig video data acquisition device shown in the figure includes a camera 1, a fiber optic transceiver 3, an optical fiber 4, a switch 5, a hard disk recorder 6 and a network monitoring computer 7. The camera 1 is connected to the fiber optic transceiver 3 via a network cable 2, the fiber optic transceiver 3 is connected to the switch 5 via an optical fiber 4, and the switch 5, the hard disk recorder 6 and the network monitoring computer 7 are connected in sequence via the network cable 2; the camera 1 and the fiber optic transceiver 3 are installed in a breeding room for group-raised pigs, and the camera 1 is downward facing the group-raised pigs in the breeding room; the camera 1 specifically adopts a Hikvision infrared thermal imager, model Hikvision temperature measurement dual-spectrum tube camera DS-2TD2636B-13 / P, the thermal imaging resolution of the camera 1 is 384×288, and the visible light resolution is 2688×1520. The camera 1 collects infrared spectrum and visible spectrum video data of group-raised pigs in real time, and then stores them in the hard disk recorder 6 after passing through the optical fiber transceiver 3, optical fiber 4 and switch 5 in sequence. The model of the hard disk recorder 6 is DS-7608N-I3-V3, which can store videos in multiple channels and multiple disk slots, and obtain infrared spectrum and visible spectrum video data of pigs at the same time, and finally view and process them in the network monitoring computer 7. The installation position of the camera 1 is located above the drinking trough of the pig pen in the breeding room. The horizontal and vertical field of view of the camera 1 are 28.8° and 21.6°, and the pig pen is photographed from a top-down angle to ensure that all pigs in the pig pen are within the field of view. The camera 1 monitors and shoots the daily behavior activities of all 20 pigs in the breeding room, and collects video data 24 hours a day. The collection period is 5 to 6 months of the normal breeding period of pigs from piglets to fattening pigs.

[0041] Then, a pig video data acquisition device is used to collect video data of group-raised pigs in real time, so as to produce and divide the data set. The video data of group-raised pigs is subjected to frame extraction at intervals to obtain pig image frames in various scenes, and then complete image extraction. Typical frame images need to be selected. Various scenes include no pigs, a single pig, multiple pigs, complete shooting of the left and right ears of the pigs, incomplete shooting of the left and right ears of the pigs, and the number of images of each scene is basically the same. If there are too many images in the same scene, they need to be deleted. There should be pigs with different postures and numbers in the image, so that the data set contains more information; for each extracted pig image frame, the ear root of each pig in the pig image frame is marked with a rectangular frame, and the coordinates of the four vertex corners of each rectangular frame and the left and right ear categories of the ear root are marked, so as to obtain several pig label images and construct them into a label data set, and then the label data set is divided into a training set, a validation set and a test set in a ratio of 8:1:1. The training set and the validation set are used to train to obtain the optimal model parameters, and the test set is used to evaluate the trained model and verify the performance of the optimal model parameters. In the specific implementation, ro-labelimg annotation software is used for annotation. The ear root is the connection between the pig ear and the pig body. When annotating, try to make the annotation box parallel to the ear root line, including the ear root line and the left and right areas. The added labels are in xml format. According to the needs of the deep learning model, the format needs to be converted to txt format that can be recognized by the YOLOv8-OBB model.

[0042] A pig ear base position recognition model is constructed in the network monitoring computer 7 of the pig video data acquisition device. The pig ear base position recognition model adopts the rotating target detection YOLOv8-OBB model. The data set, model structure configuration file and training and prediction script terminal commands need to be set in advance to prepare for the training model; the model directly predicts the ear base position of the pig in the image through an end-to-end mode and generates a prediction result.

[0043] The YOLOv8-OBB model directly predicts the ear base of the pig in the image through an end-to-end mode and generates a prediction result. The YOLOv8-OBB model consists of the Backbone module, the Neck module, and the Head module; the Backbone part is the backbone network responsible for feature extraction, the CBS module is a combination of convolution, pooling, and activation functions, and the Backbone module uses C2f as the basic building block to extract feature maps. The C2f module, as a basic building block, has a residual connection and a bottleneck structure; the Neck module enhances the feature representation capability by fusing feature maps from different stages of the Backbone, including the spatial pyramid pooling SPPF module for pooling operations at different scales, including the Concat module , splicing feature maps of different scales together, including the Upsample module, which changes the size of the feature map by upsampling; the Head module is responsible for the final pig ear base detection and classification task, and the model outputs three prediction results of different sizes, including a detection head, a classification head, and an angle head, all of which are composed of two CBS modules and a separate Conv2d convolutional layer; the OBB model is a modification of the Head module, adding an angle head to predict the rotation angle of the feature map, which can identify the pig ear base at different angles in the image. The corresponding directional rotation prediction box generated by the OBB model is called the ear base prediction box. The dataset label uses a directional rotation annotation box, which is different from the traditional horizontal annotation box; when using a directional rotation annotation box, you need to manually adjust the rotation angle and size of the annotation box so that the narrow directional rotation annotation box fits the pig ear base exactly.

[0044] The training set and validation set were input into the pig ear base part recognition model for training, and the hyperparameters such as the number of iterations in the training process were set to 300, the batch size was 16, and the initial learning rate was 0.01. The hyperparameters were optimized through 300 rounds of iterations and back propagation to achieve the best training effect. After training, the optimal weight parameter file was generated, which can be used for subsequent model prediction, and finally the trained pig ear base part recognition model was obtained.

[0045] The test set is input into the trained pig ear base position recognition model for processing, and the optimal weight parameter model obtained through training is used on the test set. After processing, the pig ear base position recognition model outputs the ear base position of group-raised pigs in each image and the group-raised pig images after left and right ear base category recognition. The positions of the ear bases of group-raised pigs in the image are marked by their own prediction boxes. The information of each prediction box includes the coordinates of the four vertex corners. The ear bases in each prediction box correspond to the respective left and right ear categories. There are generally i There are ear root prediction boxes, each with a , b , c ,d Four vertices. Figure 3 As shown in the figure, the left and right ear bases of group-raised pigs are extracted by the pig ear base identification model, which contains multiple ear base prediction frames. The directional and rotated ear base prediction frames fit the direction and size of the pig ear base very well. Figure 4 As shown in the figure, this is the confusion matrix of the pig ear base recognition model for the test set prediction results. The test set has a total of 254 left ear L samples with a prediction accuracy of 89%; there are 256 right ear R samples with an accuracy of 87.5%.

[0046] Finally, the polar coordinate system method is used to optimize the left and right ear root categories in the identified group-raised pig images. The specific implementation process is as follows:

[0047] First, according to the coordinates of the four vertices of each prediction box in the group-raised pig image after the ear base position and the left and right ear base category identification, the center point coordinates of each prediction box are obtained, and the prediction boxes are matched according to the center point coordinates of each prediction box to pair the prediction boxes of the left and right ear bases of each pig. For every two prediction boxes at the ear base, the center distance of the two prediction boxes is obtained based on the center point coordinates of the two prediction boxes. When the center distance of the two prediction boxes is within the preset center distance threshold range, the two prediction boxes are matched until the prediction boxes at each ear base are matched. In general, the two prediction boxes with the smallest center distance can be matched as paired prediction boxes. In the specific implementation, the four vertices of the prediction box of one ear base and the four vertices of the prediction box of another ear base are taken as point sets, and the distance between the eight points of the two point sets is calculated. Here, Euclidean distance is used as the distance measurement method, and each distance value is stored in the form of a two-dimensional matrix. The index value (0, 1, 2, 3) of each row of the two-dimensional matrix is ​​the index value of the four vertices of the first prediction box, and the index value (0, 1, 2, 3) of each column is the index value of the four vertices of the second prediction box. Take out the minimum distance value in the two-dimensional matrix L min , then the minimum distance value L min The index value of the corresponding row is the vertex of the prediction box of the first ear root. P Index value of 1, minimum distance value L min The index value of the corresponding column is the vertex of the predicted box of the second ear root. P Index value 2, two vertices P 1 and P 2 is the vertex with the shortest distance between the prediction boxes of the two ear roots, which is called the base point.

[0048] When pairing the left and right ear roots of pigs, since the predicted ear roots are independent of each other, there is no connection between the prediction frames of each ear root. Therefore, the left and right ear root prediction frames belonging to the same pig need to be matched together. The minimum center distance of the ear root prediction frames is used to pair the left and right ear roots of pigs. The center distance of the left and right ear root prediction frames of each pair of group-raised pigs is less than the preset T Pixel, preset T The pixel is determined by the number of pixels between the center of the left and right ears of the pig in the image. T Generally, it is 150 pixels. If the pairing is unsuccessful, the pig ear root prediction box exists alone, indicating that one ear root of the pig is missed by the other paired ear root; the possible errors in the categories of the paired left and right ear root prediction boxes include: swapping the left and right ear categories, two left ear roots, or two right ear roots.

[0049] For every two paired prediction frames, the two prediction frames are in the shape of a figure eight. According to the coordinates of the four vertices of the two prediction frames, first determine the four vertices in the first prediction frame to match with the four vertices in the second prediction frame, and determine the pair of vertices closest to the two prediction frames as the base point. For the base point in each prediction frame, determine the vertices closest to and farthest from the base point among the other three vertices in the prediction frame. The line connecting the vertices closest to and farthest from the base point is the edge line of the prediction frame. The ear roots of raw pigs are in the shape of a figure eight, and the prediction frames for each pair of ear roots are also in the shape of a figure eight. In specific implementation, calculate the distance between the four vertices of the prediction frame at the first ear root and the base point. P 1Nearest Vertex P 1min , calculate the distance base point within the four vertices of the prediction box of the second ear root P 2 nearest vertex P 2min ; Change the minimum value to the maximum value, and take the maximum distance value L max ; Calculate the distance base point within the four vertices of the prediction box of the first ear root P 1Furthest vertex P 1max , calculate the distance base point within the four vertices of the second ear root prediction box P 2Furthest Vertex P 2max ; The vertex P 1min and vertices P 1max The lines and vertices of P 2min and vertices P 2max The connecting lines are used as the outer edge lines of the prediction boxes of the two ear roots.

[0050] For every two paired prediction boxes, extend the edge lines of the two prediction boxes and intersect them. Take the intersection of the two prediction box edge lines as the origin and draw a polar coordinate system. In the polar coordinate system, obtain the level coordinates of the center points of the two prediction boxes, and then obtain the angle difference of the center points of the two prediction boxes. i , according to the angle difference i Determine the left and right categories of the ear roots in the two prediction frames; in specific implementation, first use the intersection of the edge lines of the two prediction frames as the origin ( x 0, y 0), and draw the polar coordinate system to obtain the polar coordinates of the center points of the two prediction boxes as ( r 1, i 1) ( r 2, i 2) to obtain the angle difference between the center points of the two prediction boxes i =| i 1- i 2|. Repeat the steps to traverse the prediction boxes of all paired ear roots to complete the classification of left and right ear roots.

[0051] According to the angle difference i Determine the left and right categories of the ear roots in the two prediction frames. When the angle difference between the center points of the two prediction frames is i When the center angle difference of the two prediction frames is less than 180°, the prediction frame with the smaller center angle is used as the prediction frame for the left ear, and the prediction frame with the larger center angle is used as the prediction frame for the right ear. i When the angle is greater than 180°, the prediction box with the larger center point angle is used as the prediction box for the left ear, and the other prediction box with the smaller center point angle is used as the prediction box for the right ear.

[0052] After the determination is completed, the optimized left and right ear root categories are obtained, such as Figure 5 As shown in the figure, the left and right ear roots of the pig are extracted according to the polar coordinate system method. The outer edge line of the figure eight shape of the ear root prediction frame is drawn with a thick solid line, and the intersection of the extended lines of the outer edge line of the figure eight shape is used as the polar coordinate system. The center point of the ear root prediction frame is a solid point. The polar coordinate system method of the present invention is used to identify the identified left and right ear root prediction frames, and it can be confirmed that the polar coordinates of the center points of the two ear root prediction frames are respectively length r 1=251.4 and angle i 1 = 20.7° and length r 2 = 245.2 and angle i 2=353.4°, the angle difference between the two center points can be obtained i =|20.7°-353.4°|=332.7°, then determine the angle difference between the two center points iThe value of i >180°, and i 2> i 1, so the second prediction box is the prediction box of the left ear root, and the first prediction box is the prediction box of the right ear root.

[0053] The left and right ear root identification method can identify the left and right because the intersection of the outer edge lines of the eight-shaped ear root prediction frame (the origin of the polar coordinate system) is always in the direction of the pig's head, so it can be understood that the ear root prediction frame of pigs in different postures and positions rotates around their respective heads. Due to rotation invariance, the relative positions of left and right can be determined through the polar coordinate system. And the ear root frame is generally in the shape of an eight, so the center points of the ear root prediction frame will not be on the same line, and the angle difference between them will not be equal to 180°.

[0054] The group-raised pig image to be identified is processed using the method of the present invention, such as Figure 6 As shown in the figure, from top to bottom are the original image, the YOLOv8-OBB detection result, the polar coordinate system to determine the left and right ear root categories, and the pig ear root location recognition algorithm result. In the figure, after the left and right ear roots of each pig are determined according to the polar coordinate system method, the polar coordinates of the center points of the prediction boxes of the two ear roots can be confirmed. The polar coordinates of the center points of the prediction boxes of the two ear roots of one pig are respectively the length r 3 = 122.6 and angle i 3 = 112.1° and length r 4 = 124.0 and angle i 4=52.8°, the angle difference between the two center points can be obtained i =|112.1°-52.8°|=59.3°, then determine the angle difference between the two center points i The value of i <180°, and i 3> i 4, so the first prediction box is the right ear root prediction box, and the second prediction box is the left ear root prediction box. Finally, the live pig video data acquisition device realizes the extraction of the left and right ear root parts of group-raised live pigs according to the identified ear root position in the group-raised live pig image and the optimized left and right ear root categories. It can be seen that the present invention can accurately determine the left and right ear categories of live pigs after optimization by the polar coordinate method. The left and right ear root part recognition method can re-confirm and correct the left and right ear root part categories for each pair of ear root part prediction frames to eliminate the left and right ear root part category errors predicted by the ear root part recognition model.

[0055] The present invention uses a polar coordinate system to facilitate determining the direction of a rotating object, because the origin of the polar coordinate system is always near the pig's head. When the pig stands in different orientations, it can be regarded as the pig's body rotating around the head; that is, the two ear bases in different standing orientations also rotate around the pig's head. On this basis, the pig's ear base prediction frame is detected according to the model, and then the polar coordinate value of the center point of the pig's ear base prediction frame is calculated. The left and right are determined based on the angular difference of the polar coordinate values, thereby achieving accurate left and right judgment of the polar coordinate system.

Claims

1. A method for extracting the left and right ear roots of group-raised pigs, characterized in that: include: Step S1: a live pig video data acquisition device is set up in a breeding room and a monitoring room of group-raised live pigs, and video data of the group-raised live pigs are collected in real time using the live pig video data acquisition device. After image extraction, ear base labels are added to the video data of the group-raised live pigs to obtain a number of live pig label images, thereby constructing a label data set, and dividing the label data set into a training set and a validation set according to a preset ratio; Step S2: constructing a pig ear base part recognition model in the pig video data acquisition device, inputting the training set and the verification set into the pig ear base part recognition model for training to obtain a trained pig ear base part recognition model; Step S3: inputting the group-raised pig image to be identified into the trained pig ear base position recognition model for processing, and the pig ear base position recognition model outputs the group-raised pig image after the ear base position of the group-raised pig and the left and right ear base categories are identified after processing; Step S4: using the polar coordinate system method to optimize the left and right ear root categories in the group-raised pig image identified in step S3, and obtain the optimized left and right ear root categories. Finally, the pig video data acquisition device extracts the left and right ear root parts of the group-raised pigs according to the ear root part positions in the group-raised pig image identified in step S3 and the left and right ear root categories optimized in step S4. The pig ear root recognition model uses the rotating target detection YOLOv8-OBB model; In step S4, the process of optimizing the left and right ear root categories in the identified group-reared pig images using the polar coordinate system is as follows: Step S4.1: according to the coordinates of the four vertices of each prediction frame in the group-raised pig image after the ear base position and the left and right ear base category identification, the center point coordinates of each prediction frame are obtained, and the prediction frames are matched according to the center point coordinates of each prediction frame to pair the prediction frames of the left and right ear base of each pig; Step S4.2: for every two paired prediction boxes, the two prediction boxes are in an eight-shaped shape, and the edges of the two prediction boxes that are farthest from each other in the two prediction boxes in the eight-shaped shape are determined as edge lines according to the coordinates of the four vertices of the two prediction boxes; Step S4.3: For each pair of prediction boxes, extend the edge lines of the two prediction boxes and intersect them. Take the intersection of the two prediction box edge lines as the origin and draw a polar coordinate system. In the polar coordinate system, obtain the level coordinates of the center points of the two prediction boxes, and then obtain the angle difference between the center points of the two prediction boxes. θ , according to the angle difference θ Determine the left and right categories of the ear base in the two predicted boxes.

2. The method for extracting the left and right ear roots of group-raised pigs according to claim 1, characterized in that: In the step S1, the pig video data acquisition device comprises a camera (1), an optical fiber transceiver (3), an optical fiber (4), a switch (5), a hard disk video recorder (6) and a network monitoring computer (7); the camera (1) is connected to the optical fiber transceiver (3) via a network cable (2); the optical fiber transceiver (3) is connected to the switch (5) via an optical fiber (4); the switch (5), the hard disk video recorder (6) and the network monitoring computer (7) are connected in sequence via the network cable (2); the camera (1) and the optical fiber transceiver (3) are installed in a breeding room for group-reared pigs, and the camera (1) is directed downward toward the group-reared pigs in the breeding room; The camera (1) is a dual-spectrum camera. The camera (1) collects infrared spectrum and visible spectrum video data of group-raised pigs in real time, and then stores the data in a hard disk recorder (6) through an optical fiber transceiver (3), an optical fiber (4) and a switch (5) in sequence, and finally views and processes the data in a network monitoring computer (7).

3. The method for extracting the left and right ear roots of group-raised pigs according to claim 1, characterized in that: In the step S1, the video data of group-raised pigs is subjected to a frame extraction operation at intervals to obtain pig image frames in various scenes, thereby completing image extraction; for each extracted pig image frame, the ear base of each pig in the pig image frame is marked with a rectangular frame, and the coordinates of the four vertex corners of each rectangular frame and the left and right ear categories of the ear base are marked, thereby obtaining a number of pig label images.

4. The method for extracting the left and right ear roots of group-raised pigs according to claim 1, characterized in that: In the step S2, the training set and the validation set are input into the pig ear base part recognition model for training, so as to iteratively generate the weight parameters of the pig ear base part recognition model, and the weight parameters are back-propagated to the pig ear base part recognition model to iteratively update the model hyperparameters in the pig ear base part recognition model until the optimal weight parameters are reached, thereby obtaining a trained pig ear base part recognition model.

5. The method for extracting the left and right ear roots of group-raised pigs according to claim 1, characterized in that: In the step S3, the positions of the ear roots of group-raised pigs outputted after processing by the pig ear root position recognition model and the group-raised pig images after the left and right ear root categories are identified, and the positions of the ear roots of the group-raised pigs are marked by their own prediction boxes. The information of each prediction box includes the coordinates of the four vertex corners, and the ear root positions in each prediction box correspond to the respective left and right ear categories.

6. The method for extracting the left and right ear roots of group-raised pigs according to claim 1, characterized in that: In the step S4.1, for every two prediction frames at the base of the ears, the center distance of the two prediction frames is obtained using the Euclidean distance based on the center point coordinates of the two prediction frames. When the center distance of the two prediction frames is within the preset center distance threshold range, the two prediction frames are matched until the prediction frames at each base of the ears are matched.

7. The method for extracting the left and right ear roots of group-raised pigs according to claim 1, characterized in that: In the step S4.2, according to the coordinates of the four vertices of the two prediction boxes, firstly, the four vertices in the first prediction box are matched with the four vertices in the second prediction box, and a pair of vertices closest to the two prediction boxes are determined as base points. For each base point in the prediction box, the vertices closest to and farthest from the base point among the other three vertices in the prediction box are determined, and the line connecting the vertices closest to and farthest from the base point is the edge line of the prediction box.

8. The method for extracting the left and right ear roots of group-raised pigs according to claim 1, characterized in that: In step S4.3, according to the angle difference θ Determine the left and right categories of the ear roots in the two prediction boxes as follows: When the angle difference between the center points of the two predicted boxes θ When the angle is less than 180°, the prediction box with the smaller center point angle is used as the prediction box for the left ear, and the other prediction box with the larger center point angle is used as the prediction box for the right ear. When the angle difference between the center points of the two predicted boxes θ When the angle is greater than 180°, the prediction box with the larger center point angle is used as the prediction box for the left ear, and the other prediction box with the smaller center point angle is used as the prediction box for the right ear.

Citation Information

Patent Citations

  • Anchor-frame-free remote sensing image rotating target detection method

    CN113468968A

  • Pig group body temperature automatic detection method based on cross-modal feature fusion

    CN118115849A