A feature point selection and measurement method for visual measurement of pig body size
Through the SimpleBaselines feature point detection algorithm with fusion attention mechanism and the feature point evaluation algorithm designed by deep neural network, combined with affine transformation, the problem of the pig body ruler being unable to measure when pig body ruler is high and the pig body ruler being dense in the existing technology is solved, and the accurate measurement of the pig body ruler is achieved.
Patent Information
- Application Number
- CN202210538688.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-05-18
- Publication Date
- 2025-04-29
- Estimated Expiration
- 2042-05-18
AI Technical Summary
The existing automatic measurement technology of pig body rulers has the problem of high requirements for pig body shape and inability to measure pig body rulers when pig herds are too dense.
The SimpleBaselines feature point detection algorithm with fusion attention mechanism is used to detect feature points on pigs in the image, design pig feature points and use deep neural network to design pig feature point evaluation algorithm. Combining data of equipment installation angle and other data, pig body ruler data is obtained through affine transformation.
Accurate measurement of pig body rulers is achieved, and the situation where pig body shape is not straight and the pig herd is dense, improving the accuracy and efficiency of measurement.
Smart Images

Figure CN114973321B_ABST
Abstract
Description
Technical Field
[0001] The invention relates to the technical fields of computer vision, image processing and livestock breeding, and in particular to a method for selecting and measuring feature points for visual measurement of pig body size. Background Art
[0002] Developing a large-scale, intensive, and intelligent modern pig farming management model is the only way to improve breeding production efficiency and reduce the cost per pig. Existing pig farms still rely mainly on manual inspections, growth, and apparent health status of pigs during the production process, with high rates of false detection and missed detection, which cannot meet the needs of large-scale production and epidemic prevention. Research on automatic measurement of pig body size during pig farming has important research significance for the intelligent realization of pig production processes and the improvement of breeding levels.
[0003] At present, the measurement of pig body size in my country mainly stays in the manual measurement stage, and the application of automatic measurement technology of pig body size without manual measurement is less. For these two methods, manual measurement will have problems such as low measurement efficiency, insufficient accuracy, and the risk of human-pig infection; for the automatic measurement technology of pig body size, there are mainly two types of methods for measurement. The first type is to use an algorithm to extract the outline of livestock, and then use envelopes and other methods to extract body size information. The other type is to use equipment such as depth cameras to extract livestock point clouds, and then calculate the livestock body size based on the point cloud. Although these methods can calculate the body size of livestock well, they also have great limitations. The first type has the problem of requiring a more suitable shooting angle, the livestock posture is straight, and the livestock cannot be too dense. The second type has the problem of high equipment requirements and the livestock cannot be too dense. In view of the above problems, the present invention proposes a feature point detection algorithm that integrates the attention mechanism to detect feature points of pigs in the image, and uses the feature points on the pigs as the basis for measuring the body size of pigs.
[0004] In the past, feature point detection technology was mostly used for human posture estimation. Attention mechanism is one of the research hotspots in the field of deep learning in recent years. It assigns different weights to different parts of the model to extract more important and critical information, optimize the model and obtain more accurate predictions. Integrating the attention mechanism into the SimpleBaselines feature point detection algorithm to detect feature points of pigs in images can provide a reference for pig body size measurement.
[0005] Aiming at the problem of measuring the body size of pigs in pig houses, the present invention adopts target detection technology to separate individual pigs, designs pig feature points and uses the SimpleBaselines algorithm integrated with attention mechanism to identify the pig feature points, designs a pig feature point evaluation algorithm to evaluate whether the pig posture and body size information can be measured, and finally obtains the pig body size data according to data such as the equipment installation angle by using affine transformation and other calculations, thereby solving the problems in the current automatic pig body size measurement technology, such as high requirements on the pig posture and inability to measure the pig body size when the pig group is too dense. Summary of the invention
[0006] To solve the above problems, the present invention discloses a feature point selection and measurement method for visual measurement of pig body size. The technical problems to be solved by the present invention are: first, individual images of pigs in a pig house are extracted and pig feature points are designed based on the body size measurement method; second, the pig feature points are well detected and identified and an algorithm is performed on the feature points; third, a pig body size calculation method is proposed based on the pig house installation equipment information and the identified pig feature points.
[0007] In order to solve the above technical problems and achieve the purpose of the present invention, the technical solution adopted by the present invention is as follows:
[0008] A method for selecting and measuring characteristic points of visually measuring the body size of a live pig comprises the following steps:
[0009] Step S1, build image acquisition equipment in the pig house, set up guide rails and inspection equipment in the pig house, install a camera on the inspection equipment, connect to the host through a switch to collect images, use Zhang Zhengyou camera calibration method to correct radial distortion, and measure the position information of the installed equipment in the pig house.
[0010] Step S2: Obtain the collected images to construct a pig breeding dataset, input the dataset into YOLOv5 (You Only Look Once version 5), extract image feature information through the backbone network, obtain the detection bounding box of the pigs from the features, and thus separate the pigs individually from the image.
[0011] Step S3: Based on a large number of statistical tests, the feature points on the pig's body are designed. Based on the SimpleBaselines algorithm, the attention mechanism is integrated into it to obtain the feature point information of the pig in the image, and the feature point coordinates in the image containing only a single individual pig are restored to the collected pig house breeding environment image.
[0012] Step S4: design a pig feature point evaluation algorithm based on a deep neural network, whose input is the identified feature point coordinates, and the output is whether the pig posture and body size information can be measured through the image.
[0013] Step S5, using affine transformation to transform the captured image of the pig house breeding environment into a perspective of shooting from directly above, and transforming the coordinates of the pig feature points to the coordinates of the corresponding points in the image after the affine transformation.
[0014] Step S6: Calculate the body size of the pig based on the obtained coordinate information of the pig feature points in the image, combined with the equipment installation angle, height, length and other information.
[0015] Further, the specific process of step S1 is as follows:
[0016] Step S11, setting up a guide rail above the aisle inside the pig house, installing a patrol machine that can move laterally, and installing a camera on the patrol machine to collect images of the pig pens on one side of the pig house;
[0017] Step S12: Calculate the camera distortion parameters according to the Zhang Zhengyou camera calibration method to obtain the distortion parameter k in the third-order formula of radial distortion. 1 , k 2 , k 3 , and then correct the image according to the radial distortion formula, where (x, y) is the pixel coordinate in the image before correction, is the corresponding pixel coordinate after correction:
[0018]
[0019]
[0020] Step S13: Use a network cable to connect the inspection equipment and the camera to the switch, and then pull the network cable from the switch to connect to the host placed outside the pig house. The inspection equipment and the camera can be controlled by the host to collect corresponding image data.
[0021] Further, the specific process of step S2 is as follows:
[0022] Step S21, label the collected images with labelme, select each pig with a box, and save the labeled file in json format. Convert the labeled file of each image to a txt file with corresponding information, and input it into YOLOv5 as a data set for training together with the image;
[0023] Step S22: extract the pig identification frame in the image after YOLOv5 detection, and calculate the pig identification frame based on the coordinates of the upper left corner of the frame (x 0 ,y 0 ) and size (h, w) to crop a single pig in the image for subsequent feature point detection.
[0024] Furthermore, the YOLOv5 in steps S21 and S22 is a single-stage target detection algorithm: after the image is input into YOLOv5, the image features are first preliminarily extracted through the backbone network, and then three features of different sizes are calculated based on the preliminarily extracted features and used to detect pigs of different sizes in the image.
[0025] Furthermore, the backbone network of YOLOv5 in steps S21 and S22 is mainly composed of downsampling, residual structure and spatial pyramid pooling operations. The pig house collected images are input into the backbone network calculation to extract feature maps of three sizes. The FPN (Feature Pyramid Network) and PAN (Perceptual Adversarial Network) structures are respectively used on the feature maps of these three sizes to finally obtain the prediction results. The FPN structure refers to the fusion of the feature layer with a smaller area with the feature layer with a larger area by upsampling, and the PAN structure is the opposite of FPN, and the feature layer information with a larger area is fused with the feature layer with a smaller area by downsampling.
[0026] Further, the specific process of step S3 is as follows:
[0027] Step S31, select more than 100 pigs from the image, use edge detection, centroid algorithm, envelope curve and other methods to obtain multiple feature points on the pig's body, perform statistics and tests, and select the feature points with higher frequency that can be used for pig body size calculation from a variety of pig feature points. Thus, the design selects six points, namely, the left and right ear roots, the left and right front legs, the center of the shoulder blade, and the base of the tail, as pig feature points to characterize the pig's feature information, and then to calculate the pig's body size. The left ear root and the right ear root are recorded as point 1 and point 2, the left front leg and the right front leg are recorded as point 3 and point 4, the base of the tail is point 5, and the center of the shoulder blade is recorded as point 6.
[0028] Step S32: Input the individual pig image obtained in step S22 into SimpleBaselines integrated with the attention mechanism, extract features through the backbone network, and then use deconvolution to obtain a heat map. After obtaining feature points from the heat map, the coordinates of the pig feature points in the input image can be obtained by using radial transformation. The coordinates of points 1 to 6 are expressed as (x 1 ,y 1 ),(x 2 ,y 2 ),(x 3 ,y 3 ),(x 4 ,y 4 ),(x 5 ,y 5 ),(x 6 ,y6 );
[0029] Step S33: According to the coordinates and size of the pig detection frame before cropping obtained in step S22, the coordinates of the feature points obtained in step S32 are restored to obtain the coordinates of the feature points in the original image before cropping, which can be expressed as (x i +x 0 ,y i +y 0 ),i=1~6.
[0030] Furthermore, the attention mechanism in step S32 is a function structure used in the neural network algorithm. By assigning different weights to different parts of the model, more important and critical information is extracted from it, and the model is optimized to obtain more accurate predictions. Adding it to the algorithm can significantly improve the algorithm detection accuracy in single environment scenarios such as pig houses.
[0031] Furthermore, SimpleBaselines in step S32 is a feature point detection algorithm with a simple structure and high accuracy. The image input is extracted by a backbone network composed of a residual network. The obtained features are deconvolved three times and finally a 1×1 convolution is performed to obtain an output tensor, also called a heat map. The coordinates of the feature points in each heat map can be obtained by calculation, and then the coordinates of the feature points in the input image can be obtained by affine transformation.
[0032] Further, the specific steps of step S4 are as follows:
[0033] Step S41, based on the deep neural network, a pig feature point evaluation algorithm is designed, which is composed of multiple fully connected layers. The algorithm input is the coordinates of the 6 feature points identified by the feature point recognition algorithm. If a feature point in the image is not identified, the coordinates of the point are set to (0,0). The algorithm output includes three items. The first item is the posture of the pig, including straight, bent, side-lying, etc.; the second item is whether the pig's body length can be measured, and the output is 1 for measurable and 0 for unmeasurable; the third item is whether the pig's body width can be measured, and the output is 1 for measurable and 0 for unmeasurable.
[0034] Further, the specific steps of step S5 are as follows:
[0035] Step S51, select the four corners of the pig pen boundary in the collected pig house image as reference points, and transform these four points to the four corner points of a rectangle of size (H, W) through affine transformation, so that the image angle is converted to a top-down angle. The affine transformation can be obtained by the formula (x′, y′, z′) T =M(x,y,z) TRepresents, where M represents a 3×3 matrix. Four points are selected in the image before transformation, and the matrix M is calculated according to the preset coordinates of these four points in the transformed image.
[0036] Step S52, calculate the coordinates (x″) of the transformed feature points in the new image according to the calculated matrix M i ,y″ i ), i = 1 to 6, and the calculation method is as follows:
[0037] (x′ i ,y′ i ,z) T =M(x i ,y i ,1) T
[0038] (x″ i ,y″ i )=(x′ i / z,y′ i / z)
[0039] Further, the specific steps of step S6 are as follows:
[0040] Step S61: Measure the height H between the camera installation horizontal plane and the ground cam , the average height H of the pigs in the pig pen is obtained by manual measurement pig , measure the actual length and width of a pig pen (H col ,W col ), then the actual body length of the pig is D l and body width D w It can be obtained by calculation, where the width of the pig's body can be calculated by the distance between the left and right front legs of the pig (point 3, point 4), and the body length of the pig can be expressed as the distance from the midpoint of the left and right ear roots (the midpoint of point 1 and point 2, let it be point 7) to the center of the shoulder blade (point 6) plus the length from point 6 to the base of the tail (point 5), as shown in the formula:
[0041]
[0042]
[0043] (III) Beneficial effects
[0044] Compared with the prior art, the present invention provides a method for selecting and measuring characteristic points for visual measurement of pig body size, which has the following beneficial effects:
[0045] 1. The feature point selection and measurement method for visual measurement of pig body size of the present invention is based on traditional pig body size measurement, and statistics and tests are performed according to different feature points on the bodies of a large number of pigs. Six feature points, namely, the left and right ear roots, the left and right front legs, the center of the shoulder blade, and the tail root are designed. The characteristic parts of the pig can be better characterized according to the feature point information, which can solve the problem that the body length of the pig cannot be measured when the body is bent.
[0046] 2. The feature point selection and measurement method for visual measurement of pig body size of the present invention adopts a method that combines target detection and feature point recognition, and innovates the image algorithm. In this way, the characteristic information of the pig can be quickly identified, thereby calculating the body size length of the pig in different postures.
[0047] 3. A feature point evaluation algorithm is designed in the feature point selection and measurement method for visual measurement of pig body size of the present invention, so that the posture of pigs in different postures and whether the body size measurement can be specifically evaluated through the identified feature points, so that the body size measurement of pigs is not limited to the pigs in an upright standing posture.
[0048] 4. The feature point selection and measurement method for visual measurement of pig body size of the present invention integrates the attention mechanism into the algorithm before using the SimpleBaselines algorithm to identify the feature points of pigs, which can effectively reduce the feature point recognition error when the lighting conditions are dark, the pigs are densely packed, and the pigs are in a bent angle posture. BRIEF DESCRIPTION OF THE DRAWINGS
[0049] Figure 1 is a flow chart of the overall method of the present invention;
[0050] Figure 2 This is a schematic diagram of the equipment installation in the pig house of the present invention, in which H cam H is the camera installation height pig It is the height of pigs in the breeding pig house;
[0051] Figure 3 This is the YOLOv5 network structure diagram;
[0052] Figure 4 These are the characteristic points of the pigs designed and selected in the present invention, wherein point 1 and point 2 are the left and right ear roots, point 3 and point 4 are the left and right front legs, point 5 is the tail root, point 6 is the center of the shoulder blade, and point 7 is the midpoint of the left and right ear roots.
[0053] Figure 5 This is a schematic diagram of the SimpleBaselines network structure that incorporates the attention mechanism;
[0054] Figure 6 It is a schematic diagram of the structure of the pig feature point evaluation algorithm;
[0055] Figure 7 Schematic diagram of affine transformation of the collected pig house image in the present invention, wherein the affine transformation is performed according to the correspondence between the points A, B, C, D and the points A′, B′, C′, D′ before and after the transformation. col With W col is the actual length and width of the pig pen, H and W are the pixel sizes of the length and width of the pig pen in the image after affine transformation;
[0056] Figure 8 It is a schematic diagram of the transformation of the pig feature points detected in the present invention when the image is affine transformed, wherein the distance between point 7′ and point 6′ plus the distance between point 6′ and point 5′ can be added to obtain the body length of the pig, and the distance between point 3′ and point 4′ is the body width of the pig. DETAILED DESCRIPTION
[0057] The present invention is further explained below in conjunction with the accompanying drawings and specific embodiments. It should be understood that the following specific embodiments are only used to illustrate the present invention and are not used to limit the scope of the present invention. It should be noted that the words "front", "rear", "left", "right", "upper" and "lower" used in the following description refer to directions in the accompanying drawings, and the words "inner" and "outer" refer to directions toward or away from the geometric center of a specific component, respectively.
[0058] Figure 1 This is a flow chart of a method for measuring pig body size based on YOLOv5 target detection and Simple Baselines feature point detection. The present invention is further described below in conjunction with the accompanying drawings and embodiments.
[0059] Example 1
[0060] The specific implementation is:
[0061] Step 1: Install rails, inspection equipment, cameras and other equipment in the pig house, and measure the height H of the installed camera from the ground. cam , measured the average height H of the pigs in the pig house pig .
[0062] Step 2: Use the equipment installed in the pig house to collect images and use Zhang Zhengyou's camera calibration method to correct radial distortion. Input the images into the YOLOv5 algorithm to detect pigs, and segment individual pigs from the images based on the detection results. YOLOv5 is a single-stage target detection algorithm. The algorithm can obtain the coordinates and size of the pig recognition box by inputting the pig house image.
[0063] Step 3: Crop the pig house image according to the pig identification frame detected by YOLOv5 to obtain individual pig images. Design pig feature points based on a large number of statistical tests, and then use labelme software to annotate the image based on the designed pig feature points to obtain a json annotation file.
[0064] Step 4: The annotated file and the pig image are input into the SimpleBaselines algorithm that integrates the attention mechanism for training. After the training is completed, the coordinates of the feature points of the input pig image can be obtained through the algorithm.
[0065] Step 5: Design the network structure of the pig feature point evaluation algorithm, input the identified feature point coordinates, and output whether the pig posture information and body size information can be measured.
[0066] Step 6: According to the coordinates of the pig identification frame in step 2, the obtained image feature point coordinates are converted to the original image, and then the image is affine transformed according to the four corner points of the pig pen in the image to obtain a bird's-eye view image, and the coordinates of the corresponding points of the feature points in the bird's-eye view image are obtained according to the affine transformation formula.
[0067] Step 7. Calculate the length and width of the pig based on the camera installation height, the average height of the pig, the coordinates of the pig's characteristic points and other data.
[0068] The equipment installed in the pig house in step 1 is shown in the figure Figure 2 As shown in the figure, the specific process of installing the equipment includes: setting up a guide rail bracket on the ceiling of the pig house, then setting up a guide rail on the bracket, placing the inspection equipment on the guide rail, and fixing the camera equipment on the inspection equipment. The inspection equipment and the camera are connected to the switch through a network cable, and then the switch is connected to the host outside the pig house through the network cable, and the inspection equipment and the camera are controlled by the host. The collected image is calculated according to the camera distortion parameter k of Zhang Zhengyou's camera calibration method 1 , k 2 , k 3 , correct the image, where (x, y) is the pixel coordinate in the image before correction, is the corresponding pixel coordinate after correction:
[0069]
[0070]
[0071] The YOLOv5 network structure of step 2 is as follows Figure 3As shown in the figure, the YOLOv5 pig detection process includes: first, the pig house image is converted to 640×640×3 size and input into the backbone network to extract features; then, the three sets of features with sizes of 80×80×256, 40×40×256, and 20×20×512 are subjected to FPN and PAN operations to obtain outputs of three sizes, and finally, non-maximum suppression is used to obtain the recognition frame coordinates (x 0 ,y 0 ) and size (h,w).
[0072] The design and selection of feature points in step 3 requires selecting more than 100 pigs from the image, using edge detection, centroid algorithm, envelope curve and other methods to obtain multiple feature points on the pigs' bodies, and then statistically analyzing and testing them to select the feature points with higher frequency that can be used for calculating the pigs' body size. The design selects the six points of the left and right ear roots, left and right front legs, shoulder blade center, and tail root as the pig feature points to characterize the pig feature information, such as Figure 4 shown.
[0073] The step 3 of cropping the image and marking the pig feature points includes: taking a pig detected by YOLOv5 in the pig house image as an example, the coordinates of the upper left corner of the pig's identification box are calculated as (x 0 ,y 0 ), the length and width of the frame are (h, w), and based on these two data, a single pig image can be cropped out of the image; then follow Figure 4 The pig feature points shown are used to annotate the image using labelme software to obtain a json annotation file.
[0074] In the fourth step, the SimpleBaselines algorithm training data with the fusion attention mechanism is used to identify the characteristic points of the pigs in the image, which includes: firstly, the SimpleBaselines algorithm network structure with the fusion attention mechanism is constructed as follows: Figure 5As shown in the figure, an attention module is added to each residual network structure in the backbone network part of the SimpleBaselines algorithm; then the SimpleBaselines algorithm with fusion attention mechanism is used for training, the pig image is first converted to 192×256×3 size, and input into the backbone network part with fusion attention mechanism to obtain a feature layer with size of 6×8×2048, and then after three deconvolution operations in the upsampling part, a heat map with size of 48×64×6 is obtained. According to the 6 heat maps obtained here, the coordinates of the 6 feature points on the pig in each heat map can be calculated, and then the coordinates of the feature points in the input image can be obtained by affine transformation. These six feature points can be recorded as point 1, point 2, point 3, point 4, point 5, and point 6, and their coordinates in the image can be recorded as (x 1 ,y 1 ),(x 2 ,y 2 ),(x 3 ,y 3 ),(x 4 ,y 4 ),(x 5 ,y 5 ),(x 6 ,y 6 ).
[0075] The pig feature point evaluation algorithm in step 5 is composed of multiple fully connected layers, and the output layer includes three units, one of which is composed of a softmax function for evaluating the pig's posture, and the other two units are composed of sigmoid functions for evaluating whether the body size information can be measured. The algorithm input is the coordinates of the 6 feature points identified by the feature point recognition algorithm. If a feature point in the image is not identified, the coordinates of the point are set to (0,0). The algorithm output includes three items. The first item is the pig's posture, including straight, bent, side-lying, etc.; the second item is whether the pig's body length can be measured, and the output is 1 for measurable and 0 for unmeasurable; the third item is whether the pig's body width can be measured, and the output is 1 for measurable and 0 for unmeasurable.
[0076] The step 6 of converting the feature point coordinates to the original image includes: converting the feature point coordinates to the original image according to the upper left corner coordinates (x 0 ,y 0 ) can calculate the coordinates of the feature points in the original image (x i ,y i ), i = 1 to 6, where x i =x i +x 0 ,y i =y i +y 0 ,i=1~6.
[0077] In step 6, the image is affine transformed to obtain a top-view image and calculate the coordinates of the feature points, including: Figure 6 As shown in the figure, the four corners of the pig pen in the pig house image are selected and recorded as points A, B, C, and D respectively, and the actual length and width of the pig pen are measured as (H col ,W col ), the four points after transformation are recorded as points A', B', C', D', and the four points after transformation form a rectangle with length and width (H, W). The affine transformation formula is as follows:
[0078] (x′,y′,z′) T =M(x,y,z) T
[0079]
[0080] According to the correspondence between points A, B, C, D and points A′, B′, C′, D′, the matrix M is obtained, and then the coordinates (x″) of the feature points in the image after affine transformation can be calculated. i ,y″ i ),i=1~6:
[0081] (x′ i ,y′ i ,z) T =M(x i ,y i ,1) T
[0082] (x″ i ,y″ i )=(x′ i / z,y′ i / z)
[0083] In step 7, the calculation of the length and width of the pigs according to the camera installation height, the average height of the pigs, the coordinates of the characteristic points of the pigs and other data includes: Figure 7 The figure shows the changes of feature points after the image is affine transformed. At this time, the width of the pig is the distance between point 3' and point 4', and the length of the pig is the distance between point 7' and point 6', the midpoint of point 1' and point 2', plus the distance between point 6' and point 5'. According to the length and width of the rectangle formed by points A', B', C', and D', the real length corresponding to each horizontal pixel and vertical pixel in the image can be calculated. Finally, according to the camera installation height and the height of the pig, the pig's body length D can be calculated. l and body width D w Size, as follows:
[0084]
[0085]
[0086] The technical means disclosed in the scheme of the present invention are not limited to the technical means disclosed in the above-mentioned implementation mode, but also include technical schemes composed of any combination of the above technical features.
Claims
1. A method for selecting and measuring characteristic points for visual measurement of pig body size, characterized in that: The following steps are involved: Step S1, set up guide rails and inspection equipment in the pig house, install a camera on the inspection equipment, and connect it to the host through a switch to collect images; Step S2, obtaining the collected images to construct a pig breeding image dataset, inputting the images into YOLOv5, extracting the image feature information through the backbone network, and obtaining the coordinates of the upper left corner of the pig detection bounding box in the image and the length and width through convolution calculation of the feature information, thereby separating the pigs from the image; Step S3, designing pig feature points based on a large number of statistical tests, based on the SimpleBaselines algorithm, integrating the attention mechanism, obtaining the feature point information of the pigs in the image, and restoring the feature point coordinates in the image containing only a single individual pig to the collected pig house breeding environment image according to the coordinates of the upper left corner of the pig detection bounding box; Step S4, designing a pig feature point evaluation algorithm based on a deep neural network, wherein the input is the identified feature point coordinates, and the output is whether the pig posture and body size information can be measured through the image; Step S5, using affine transformation to transform the captured pig house breeding environment image into a perspective of shooting from directly above, and transforming the coordinates of the pig feature points to the coordinates of the corresponding points in the image after the affine transformation; Step S6, calculating the body size of the pig according to the obtained coordinate information of the pig feature points in the image, combined with the equipment installation angle, height and length information; The specific steps of step S3 are as follows: Step S31, selecting more than 100 pigs from the image, using edge detection, centroid algorithm, and envelope method to obtain multiple feature points on the pigs' bodies, performing statistics and testing, and selecting the feature points with a higher frequency of occurrence for pig body size calculation from the multiple pig feature points; thus, the six points of left and right ear roots, left and right front legs, shoulder blade center, and tail root are selected as pig feature points for characterizing pig feature information, and then used for pig body size calculation; the left ear root and the right ear root are recorded as point 1 and point 2, the left front leg and the right front leg are recorded as point 3 and point 4, the tail root is point 5, and the shoulder blade center is recorded as point 6; Step S32, input the individual pig image obtained in step S22 into SimpleBaselines integrated with the attention mechanism, extract features through the backbone network, and then use deconvolution to obtain a heat map. After obtaining the feature points from the heat map, use affine transformation to obtain the coordinates of the pig feature points in the input image. The coordinates of point 1 to point 6 are expressed as (x1, y1), (x2, y2), (x3, y3), (x4, y4), (x5, y5), (x6, y6). Compared with the traditional pig body measurement method, the selection of the center point 6 of the pig's back shoulder blade allows the body length of pigs in a bent posture when standing or lying flat to be measured. Step S33: According to the coordinates and size of the pig detection frame before cropping obtained in step S22, the coordinates of the feature points obtained in step S32 are restored to obtain the coordinates of the feature points in the original image before cropping, which is expressed as (x i +x0,y i +y0),i=1~6; The specific steps of step S4 are as follows: Step S41, based on the deep neural network, a pig feature point evaluation algorithm is designed, and the algorithm is composed of multiple layers of fully connected layers; the algorithm input is the coordinates of 6 feature points identified by the feature point recognition algorithm. If a feature point in the image is not identified, the coordinates of the point are set to (0,0); the algorithm output includes three items, the first item is the pig posture, including straight, bent, and side-lying posture; the second item is whether the pig's body length can be measured, and the output is 1 for measurable and 0 for unmeasurable; the third item is whether the pig's body width can be measured, and the output is 1 for measurable and 0 for unmeasurable.
2. According to claim 1, a method for selecting and measuring characteristic points for visual measurement of pig body size, Features: The specific steps of step S1 are as follows: Step S11, setting up a guide rail above the aisle inside the pig house, installing a patrol machine that can move laterally, installing a camera on the patrol machine, and collecting images of the pig pens on one side of the pig house; Step S12: Calculate the camera distortion parameters according to the Zhang Zhengyou camera calibration method, find the distortion parameters k1, k2, k3 in the third-order formula of radial distortion, and then correct the image according to the radial distortion formula, where (x, y) is the pixel coordinate in the image before correction. is the corresponding pixel coordinate after correction: Step S13: Use a network cable to connect the inspection equipment and the camera to the switch, and then pull the network cable from the switch to connect to the host placed outside the pig house. The inspection equipment and the camera are controlled by the host to collect corresponding image data.
3. The method for selecting and measuring characteristic points for visual measurement of pig body size according to claim 1, characterized in that: The specific steps of step S2 are as follows: Step S21, label the collected images using labelme, select each pig using a box, and save the labeled file in json format; Convert the annotation file to a txt text file with corresponding information, and form a data set together with the image to input into YOLOv5 for training; Step S22: extract the pig detection frame of the image, and intercept a single pig image in the image according to the coordinates (x0, y0) and size (h, w) of the detection frame for subsequent feature point detection.
4. The method for selecting and measuring characteristic points for visual measurement of pig body size according to claim 3, characterized in that: The YOLOv5 in steps S21 and S22 is a single-stage target detection algorithm. YOLOv5 includes three parts: a backbone network, a neck network, and a head network. Its input is an image of size 640×640×3. After the image is processed by the three parts of the algorithm, three sizes of recognition results are output. Finally, the pig recognition frame in the image is obtained by maximum value suppression.
5. The method for selecting and measuring characteristic points for visual measurement of pig body size according to claim 1, characterized in that: The specific steps of step S5 are as follows: Step S51, Zhang Zhengyou's calibration method originally has a tangential distortion for correcting non-parallel images, but considering that the angle between the camera and the image of the farmed pigs is difficult to determine, an affine transformation is used here to replace the tangential distortion; the four corners of the pig pen boundary are selected as reference points in the collected farmed pig house image, and these four points are transformed into the four corner points of a rectangle of size (H, W) through an affine transformation, so that the image angle is converted to a top-down angle; the affine transformation is calculated by the formula (x ′ ,y ′ ,z ′ ) T =M(x,y,z) T Indicates, where M represents a 3×3 matrix. Four points are selected in the image before transformation, and the matrix M is calculated according to the pre-set coordinates of these four points in the transformed image. Step S52: Calculate the coordinates (x i ″ ,y i ″ ), i = 1 to 6, and the calculation method is as follows: (x i ′ ,y i ′ ,z) T =M(x i ,y i ,1) T (x i ″ ,y i ″ )=(x i ′ / z,y i ′ / z)。 6. The method for selecting and measuring characteristic points for visual measurement of pig body size according to claim 1, characterized in that: The specific steps of step S6 are as follows: Step S61: Measure the height H between the camera installation horizontal plane and the ground cam , the average height H of the pigs in the pig pen is obtained by manual measurement pig , measure the actual length and width of the pig pen (H col ,W col ), then the actual body length of the pig is D l and body width D w It is calculated by the following formula, where the pig's body width is calculated by the distance between the left and right front legs of the pig, i.e., points 3 and 4. The pig's body length is expressed as the distance from the midpoint of the left and right ear roots to the center point 6 of the shoulder blade plus the length from point 6 to the base of the tail, point 5, where the midpoint of the left and right ear roots is set as point 7:
Citation Information
Patent Citations
License plate feature point detection method based on deep learning
CN112464750A
Group pig body size measuring method based on stacked hourglass network
CN114120359A