Automated Measurement of Heart Girth for Pigs Using Two Kinect Depth Sensors

The heart girth parameter is an important indicator reflecting the growth and development of pigs that provides critical guidance for the optimization of healthy pig breeding. To overcome the heavy workloads and poor adaptability of traditional measurement methods currently used in pig breeding, this paper proposes an automated pig heart girth measurement method using two Kinect depth sensors. First, a two-view pig depth image acquisition platform is established for data collection; the two-view point clouds after preprocessing are registered and fused by feature-based improved 4-Point Congruent Set (4PCS) method. Second, the fused point cloud is pose-normalized, and the axillary contour is used to automatically extract the heart girth measurement point. Finally, this point is taken as the starting point to intercept the circumferential perpendicular to the ground from the pig point cloud, and the complete heart girth point cloud is obtained by mirror symmetry. The heart girth is measured along this point cloud using the shortest path method. Using the proposed method, experiments were conducted on two-view data from 26 live pigs. The results showed that the heart girth measurement absolute errors were all less than 4.19 cm, and the average relative error was 2.14%, which indicating a high accuracy and efficiency of this method.


Introduction
The body size parameters of pigs are important indices for healthy pig breeding [1]. They not only directly reflect the growth and development of pigs, but also are closely related to production performance, health status and meat quality [2,3]. Simple linear calibration equation using heart girth and body length as independent variables can also be used to predict the body weight of pigs [4]. Therefore, the accurate measurement of pig size parameters is important for optimizing pig breeding and management [5]. The traditional method of measuring livestock body size is via manual tape measurement. On the one hand, this method is easily affected by the subjectivity of the person performing the measurement and external environmental factors, and it is not suitable for large-scale breeding operations [6]. On the other hand, contact measurements can produce a stress response in livestock, affect their growth and development, and reduce animal health and welfare [7]. As an alternative, non-contact body measurements of livestock through machine vision technology can effectively overcome the disadvantages of traditional measurement methods and improve measurement efficiency [8].
(1) We built a two-view pig depth image acquisition platform. The 4PCS method is improved according to the physical characteristics of the pig and the geometric characteristics of the two-view area to realize the registration of the top-and side-view pig point clouds. (2) In the process of measurement, a method for automatically extracting heart girth measurement point and a method measures pig heart girth along the point cloud using the shortest path method are proposed.

Platform Construction and Data Acquisition
In October 2019, we used two Kinect depth sensors (Microsoft Corporation, Beijing, China) to acquire depth images of 26 pigs at the Tianpeng Xingwang Farm in Beijing. These pigs were two breeds, pure Large White and pure Landrace. At the experimental pig house, there is an automatic feeding system for the pigs. Pigs enter the automatic feeding system for feeding every day following their own feeding routines. The whole feeding system is composed of two parts: an individual Sensors 2020, 20, 3848 3 of 20 information collection channel and a feeding area. After a pig enters the feeding system, it is weighed in the individual information collection channel and then proceeds to the feeding area. The individual information collection channel is approximately 1.10 m long, 0.60 m wide and 0.80 m high. Only one pig can pass through this channel at a time. A data acquisition platform was built on the basis of this channel, as shown in Figure 1. The experimental platform included an RFID reader, two Kinect V2 sensors (Microsoft Corporation, Beijing, China) and two computers connected to and controlling the platform.  Since the effective sight distance of the Kinect V2 is 0.5-4.5 m, to capture multiple complete pig depth images and reduce the impact of environmental factors on the Kinect sensors (Microsoft Corporation, Beijing, China), the Kinect sensor used to collect the top-view images was placed approximately 1.10 m above the channel based on the results of preliminary tests, and this Kinect sensor was aligned with the central axis of the channel. The Kinect sensor for collecting side-view images was placed at a distance of 0.63 m from the ground and approximately 0.94 m from the channel fence. With these dimensions, the best data acquisition effect was achieved.
After a pig entered the channel, the entrance and exit gates were closed to ensure that there would be only one pig in the channel. After the current pig's ear tag was acquired by the RFID reader, the two Kinect sensors (resolution: 512 × 424 pixels) simultaneously began to collect top-view and side-view depth images, with a frame rate of 30 frames per second. Each collected depth image was Since the effective sight distance of the Kinect V2 is 0.5-4.5 m, to capture multiple complete pig depth images and reduce the impact of environmental factors on the Kinect sensors (Microsoft Corporation, Beijing, China), the Kinect sensor used to collect the top-view images was placed approximately 1.10 m above the channel based on the results of preliminary tests, and this Kinect sensor was aligned with the central axis of the channel. The Kinect sensor for collecting side-view images was placed at a distance Sensors 2020, 20, 3848 4 of 20 of 0.63 m from the ground and approximately 0.94 m from the channel fence. With these dimensions, the best data acquisition effect was achieved.
After a pig entered the channel, the entrance and exit gates were closed to ensure that there would be only one pig in the channel. After the current pig's ear tag was acquired by the RFID reader, the two Kinect sensors (resolution: 512 × 424 pixels) simultaneously began to collect top-view and side-view depth images, with a frame rate of 30 frames per second. Each collected depth image was associated with a time stamp to enable the frame synchronization of the pig images acquired from the two views in order to facilitate subsequent pig point cloud registration.

Data Preprocessing
Pig depth images collected simultaneously from the top and side views are shown in Figure 2a,b. Due to the complex environment of the farm, in addition to the pig data, the original data collected by the Kinect sensors include data from complex background objects such as the weight scale, railings and ground. Consequently, it was necessary to extract the pig data from this complex background. The specific steps of the extraction process are as follows: (1) Background images (Figure 2c,d) acquired from the top and side views were used as masks, and the background difference method [30] was applied to extract the foreground of each collected image to isolate the pig depth image and convert it into a point cloud, as shown in Figure 3a,b. (2) Pass-through filtering was used to filter out non-interesting background points from the original pig body point cloud. (3) Point cloud downsampling can reduce redundant data and improve measurement efficiency.
Voxel grid filtering was used to downsampling of the pig point cloud. (4) The neighbourhood average distance threshold method was used to dynamically remove outliers from the pig body surface. (5) Euclidean clustering segmentation [31] was used to segment the point cloud. The cluster with the largest number of points in the clustering results was taken as the pig point cloud, as shown in Figure 3c,d. (6) Due to occlusion by the railings, some parts of each pig point cloud were missing, producing nonrigid deformations. The CloudCompare software was used to remove the corresponding deformed boundary data for subsequent registration and measurement.
Sensors 2020, 20, x FOR PEER REVIEW 4 of 21 associated with a time stamp to enable the frame synchronization of the pig images acquired from the two views in order to facilitate subsequent pig point cloud registration.

Data Preprocessing
Pig depth images collected simultaneously from the top and side views are shown in Figure 2a and b. Due to the complex environment of the farm, in addition to the pig data, the original data collected by the Kinect sensors include data from complex background objects such as the weight scale, railings and ground. Consequently, it was necessary to extract the pig data from this complex background. The specific steps of the extraction process are as follows: (1) Background images (Figures 2c,d) acquired from the top and side views were used as masks, and the background difference method [30] was applied to extract the foreground of each collected image to isolate the pig depth image and convert it into a point cloud, as shown in Figure 3a,b. (2) Pass-through filtering was used to filter out non-interesting background points from the original pig body point cloud. (3) Point cloud downsampling can reduce redundant data and improve measurement efficiency.
Voxel grid filtering was used to downsampling of the pig point cloud. (4) The neighbourhood average distance threshold method was used to dynamically remove outliers from the pig body surface. (5) Euclidean clustering segmentation [31] was used to segment the point cloud. The cluster with the largest number of points in the clustering results was taken as the pig point cloud, as shown in Figures 3c,d. (6) Due to occlusion by the railings, some parts of each pig point cloud were missing, producing nonrigid deformations. The CloudCompare software was used to remove the corresponding deformed boundary data for subsequent registration and measurement.  Top-view depth image of the individual information collection channel acquired with no pig in the channel; (d) Side-view depth image of the individual information collection channel acquired with no pig in the channel.

Registration Two-View Pig Point Clouds with Feature-Based Improved 4PCS Method
The top-view point cloud and side-view point cloud collected synchronously (as shown in Figure 4a) are two independent point clouds in different coordinate system. The top-view point cloud mainly reflects the information of the pig's back, while the side-view point cloud mainly reflects the information of one side of the pig's body, so it is impossible to directly measure the pig heart girth. Therefore, we need to perform the registration of two point clouds to form a complete pig point cloud and provide conditions for subsequent pig heart girth measurement. The top-view point cloud and side-view point cloud collected synchronously (as shown in Figure 4a) are two independent point clouds in different coordinate system. The top-view point cloud mainly reflects the information of the pig's back, while the side-view point cloud mainly reflects the information of one side of the pig's body, so it is impossible to directly measure the pig heart girth. Therefore, we need to perform the registration of two point clouds to form a complete pig point cloud and provide conditions for subsequent pig heart girth measurement.
At present, the most widely used point cloud registration method is the iterative closest point (ICP) algorithm [32,33], which requires only simple calculations and offers high registration accuracy. However, the registration accuracy depends on the initial relative pose of the two input point clouds. Furthermore, the ICP algorithm requires sufficient overlap between the two point clouds to be registered. Therefore, for point cloud registration, coarse registration of the two-view point clouds to be registered is usually performed first, and then the ICP algorithm is used for fine registration. For the pig point clouds of interest in this study, there are large differences in position and pose between the top-and side-view point clouds of the same pig, and the coincidence rate between points in the two point clouds is low. If the 4-Point Congruent Set (4PCS) method [34,35] of coarse registration were to be used directly, registration would easily fail. Therefore, the regions of the two point clouds that are to be registered must first be extracted by considering the body features of a pig; specifically, regions with rich information in the form of boundary features as well as ear and tail features are used as the registration regions. Thus, the performance of the 4PCS algorithm is improved, and the ICP algorithm can subsequently be used to achieve the registration of the two-view pig point clouds, as shown in Figure 4.   At present, the most widely used point cloud registration method is the iterative closest point (ICP) algorithm [32,33], which requires only simple calculations and offers high registration accuracy. However, the registration accuracy depends on the initial relative pose of the two input point clouds. Furthermore, the ICP algorithm requires sufficient overlap between the two point clouds to be registered. Therefore, for point cloud registration, coarse registration of the two-view point clouds to be registered is usually performed first, and then the ICP algorithm is used for fine registration. For the pig point clouds of interest in this study, there are large differences in position and pose between the top-and side-view point clouds of the same pig, and the coincidence rate between points in the two point clouds is low. If the 4-Point Congruent Set (4PCS) method [34,35] of coarse registration were to be used directly, registration would easily fail. Therefore, the regions of the two point clouds that are to be registered must first be extracted by considering the body features of a pig; specifically, regions with rich information in the form of boundary features as well as ear and tail features are used as the registration regions. Thus, the performance of the 4PCS algorithm is improved, and the ICP algorithm can subsequently be used to achieve the registration of the two-view pig point clouds, as shown in

Extraction of Registration Regions from Two-View Pig Point Clouds
The difference between the initial positions and poses of the pig point clouds collected from the top view and the side view is large, and the overlap rate of these point clouds is low, as shown in Figure 4a. The side-view point cloud is partially missing due to barrier occlusion, and the edges of the missing regions show some nonrigid deformations, which increase the difficulty of registration. If the registration of the two-view point clouds were to be carried out directly, there would be too many invalid registration pairs, resulting in low registration accuracy or even failure. Due to the influence of the sensor angles and the pig's own characteristics, it is impossible to directly locate the overlapping regions. From an analysis of spatial geometry, it can be seen that the upper part of the side-view contour of any object exists and is unique in its top-view contour [36]. Thus, there is a unique correspondence between the back contour of the side-view pig point cloud and the top-view pig point cloud, as shown in Figure 4b; therefore, the contour of the pig's back from the side-view point cloud is used as one of the regions P to be registered. The pig contour is extracted, and the details of the contour extraction method are shown in the Appendix A. Take the maximum and minimum values of the pig contour in the y-axis direction, y max and y min , and extract the point cloud consisting of y ∈ y min , y min + (y max − y min )/4 as the back profile of the pig from the side-view point cloud.
It is very important to find corresponding point pairs in point cloud registration process, which directly affects the accuracy of point cloud registration. The larger the curvature change, the richer the feature information is, the easier to match the corresponding points accurately [37]. The principal component analysis (PCA) [38] method is used to calculate the curvature at each point in the top-and side-view point clouds, as shown in Figure 4c. It can be seen from this figure that the back curvature of a pig is relatively uniform, the curvature change is small, the associated feature information is relatively weak. If only the back information were to be used for registration, the corresponding points were easy to match wrong, leading to low registration accuracy and even registration failure. By contrast, the curvature values of the ears and tail of a pig are significantly larger than those of the back, and the curvature changes obviously, providing more characteristic information, which is helpful to accurately find the corresponding point and improve the registration accuracy. We rank the unordered side-view points of the pigs in order of curvature value from large to small. Because the curvature values in the ear and tail regions are larger than those in other regions, we can extract the ear and tail regions by extracting the first M (set M = 500) points ordered in this way from the side-view pig point cloud. The extracted ear and tail regions of the side-view pig point cloud are then combined with the back contour from the side-view pig point cloud as the region P to be registered.
If we directly regard the top-view point cloud as the target point cloud Q, when the pig's posture is good and the trunk is relatively straight, the point cloud acquired from the right side of the body can be easily registered with the left. Therefore, we divide the top-view pig point cloud into left and right parts along the central axis of the body and take only the side corresponding to the side-view point cloud as the target point cloud Q to reduce registration errors. Considering that there is often slight bending or turning of the pig's body, the point cloud representing the pig's back is divided into three parts: hip, trunk and head, as shown in Figure 4d. The central axis of each part is identified individually. Then this axis is used to extract this part of top-view point cloud which corresponds with the side-view point cloud.

Registration of Two-View Pig Point Clouds
The 4PCS algorithm for coarse registration searches for a rigid transformation based on the minimum distance between two point clouds by constructing and matching a full 4-point basis between the two point clouds. Extracting specific registration regions from two-view pig point clouds as described in Section 2.3.1 can eliminate redundancies in this 4-point basis to some extent, thereby improving the performance of the 4PCS algorithm and reducing the necessary number of iterations of the algorithm.
(a) Select a point a in the region P to be registered. Calculate the maximum variable length m based on the diagonal length of the bounding box and the approximate overlap ratio of the region P to be registered. Then, select a second point b in the region P to be registered based on m, such that a and b satisfy: where e is the intersection of the vector ab and the vector cd. If there are two pairs of such points in Q such that one pair with midpoint e 1 and the other pair with midpoint e 2 are equal within the allowable range of errors, then these two pairs of points can be considered to be corresponding coplanar points of the basis given in P.
Traverse the target point cloud Q to find the set D = {C 1 , C 2 , . . . , C n } of all equal 4-point bases in Q. The largest common pointset (LCP) strategy [39] is used to find the best 4-point matching in the set D of the equal 4-point basis of equivalence, that is, to calculate the rotation and translation matrix of the point cloud, so as to achieve coarse registration of the two-view pig point clouds. Finally, the ICP algorithm is used to accurately register the two-view point clouds to achieve pig point cloud registration, as shown in Figure 4e.

Pig Heart Girth Measurement
The heart girth of a pig is the vertical circumference of the chest as measured with a tape along the posterior border of the scapula [40]. Manual measurement is typically performed using a tape measure wrapped around the pig's chest in the axillary region behind the forelimbs to obtain this circumferential measurement. In a pig point cloud, the heart girth point cloud can be obtained by extracting a suitable heart girth measurement point to use as a starting point to intercept the circumferential perpendicular to the ground from the pig point cloud. In this paper, based on the contour features of the axillary region of the pig, a method of automatically extracting the heart girth measurement point is presented, and a shortest path method is proposed for measuring the distance along the contour of the corresponding heart girth point cloud.

Heart Girth Measurement Point Extraction
After the method introduced in Section 2.3 is applied to register the two-view pig point clouds, the combined registered pig point cloud is further subjected to pose normalization [41]. The centre of gravity of the pig point cloud is taken as the origin O of the coordinate system. The direction pointing vertically upwards from the ground is the positive x-axis direction. The direction along the central axis of the pig's back, pointing towards the head, is the positive direction of the z-axis. The axis oriented along the width direction of the pig's back is the y-axis, and its positive direction is determined by the right-hand rule, as shown in Figure 5a. The registered pig point cloud is projected onto the XOZ surface, and the pig contour is extracted using the method described in Appendix A, as shown in Figure 5b. From the side-view point cloud contour, the concave point behind the forelimb is taken as the heart girth measurement point. shown in Figure 5b. From the side-view point cloud contour, the concave point behind the forelimb is taken as the heart girth measurement point. Pass-through filtering is then applied to obtain the local pig body point cloud C. The minimum point in the x-axis direction of the point cloud C is found to identify the front hoof point TA of the pig. Then, an envelope line l: x = k(z-TA), k ∈ (-∞, 0) is constructed through the front hoof point TA . Initially, the envelope line is oriented horizontally. Each point in the point cloud is traversed to judge the position relationship between that point and the envelope line in order to identify the direction of increase of the K value; then, the envelope line l is rotated to find the critical point TB where l is tangent to the pig contour line, and the corresponding K value is obtained. The local contour C' Pass-through filtering is then applied to obtain the local pig body point cloud C. The minimum point in the x-axis direction of the point cloud C is found to identify the front hoof point T A of the pig. Then, an envelope line l: x = k(z-T A ), k ∈ (−∞, 0) is constructed through the front hoof point T A . Initially, the envelope line is oriented horizontally. Each point in the point cloud is traversed to judge the position relationship between that point and the envelope line in order to identify the direction of increase of the K value; then, the envelope line l is rotated to find the critical point T B where l is tangent to the pig contour line, and the corresponding K value is obtained. The local contour C between the front foot point T A and the critical point T B of the point cloud C in the z coordinate is obtained by means of pass-through filtering. Then, the envelope line l is progressively translated to the right, and the last intersection point between the envelope line l and the local contour line C is identified as the heart girth measurement point B 1 .

Shortest Path Method for Measuring Heart Girth
The heart girth point cloud P B is obtained by taking the heart girth measurement point B 1 as the starting point and intercepting the circumferential perpendicular to the ground from the pose-normalized pig point cloud. Due to the limited perspectives of the sensors used to acquire the depth data, only points from the back and one side of the body of the pig are available; therefore, the obtained heart girth point cloud P B accounts for approximately 3/4 of the complete heart girth region of the pig, as shown in Figure 5c. Although a pig is a nonrigid object, the body of a pig in the individual information collection channel is relatively straight, and a specific part of its body can be approximated as a rigid object. A plane perpendicular to the ground through the z-axis is constructed, which is a plane of symmetry. Then, the method of mirror symmetry [41] is applied to obtain the complete heart girth point cloud P B . As shown in Figure 5d, two points B 2 and B 3 are selected from the point cloud P B that form a triangle with the heart girth measurement point B 1 . Considering that the heart girth region of a pig is an irregular circle, to ensure the formation of a closed contour when calculating the shortest path, we look for two measurement points B 2 and B 3 at a distance of approximately 10 cm from the z-axis on both sides to ensure that there is a certain fault tolerance between these two measurement points. Then, the distances along the curve of the point cloud between pairs of adjacent points B 1 and B 2 , B 2 and B 3 and B 3 and B 1 are calculated, and their sum is taken as the heart girth. When the distance between two points in a point cloud is sufficiently small, the distance along the curve between them can be approximated as the shortest distance between these two points. The classic algorithm for calculating the shortest distance between two points is the Dijkstra algorithm [42]. This algorithm converts the structure of a point cloud into a graph structure in the form of an undirected weighted adjacency table. The vertices adjacent to each vertex are obtained using the K-nearest neighbour search method, and these adjacent vertices are connected to form edges. The edge weights are calculated as the Euclidean distances between each vertex and its adjacent vertices. Taking the calculation of the curve distance between B 1 and B 2 as an example, the specific steps are as follows: (a) Let B 1 be the source point of the graph, let C(B 1 ) = 0 and let C(x i ) = ∞, where C(B 1 ) is the weight from B 1 to itself and C(x i ) is the weight from the current B 1 to other nodes. Define S(x i ) as the set of points that have not yet been visited. (b) Traverse S(x i ) to find the node x 1 with the minimum weight C(x i ) with respect to B 1 . Node x 1 becomes the current node, and x 1 is removed from S(x i ). (c) Compare the current node with each of its adjacent nodes x 2 in S(x i ) as follows: if C(x 1 ) + W(x 1 ,x 2 ) < C(x 2 ), then the path from x 1 to x 2 is B 1 → x 1 → x 2 . Remove x 2 from S(x i ). (d) Repeat steps b and c until the current node is B 2 ; then, C(B 2 ) is the curve distance between B 1 and B 2 .

Comparison of Two-view and Single-view Data Acquisition Result
In order to verify the advantages of the two-view Kinect sensors synchronous data acquisition method described in this paper, a pig was randomly selected to use a top-view Kinect sensor, a side-view Kinect sensor, and two-view Kinect sensors to collect pig point clouds and measure heart girth. Figure 6a-c are heart girth point clouds obtained by a top-view Kinect sensor, a side view Kinect sensor, and two-view Kinect sensors, respectively. As a top-view Kinect sensor can only collect the pig back point cloud, the method proposed in this paper cannot locate the heart girth position and measure heart girth. We used the method in the [43] to measure heart girth based on top-view point cloud, and the fitting heart girth point cloud is shown in Figure 6d. When using proposed measurement method to measure heart girth based on side-view point cloud, the heart girth point cloud obtained by mirror symmetry is shown in Figure 6e. When using two-view Kinect sensors to synchronously collect data for heart girth measurement, the heart girth point cloud obtained by mirror symmetry is shown in Figure 6f. The measurement results of the above 3 heart girth point clouds are shown in Table 1. It can be seen from the table that the absolute error of heart girth measured by a top-view Kinect sensor and a side-view Kinect sensor respectively is large, but measured by two-view Kinect sensors is small. The reason is that it can be seen from Figure 6a,d that heart girth is measured only according to the top-view data. Due to the lack of abdomen, the shape of the fitting heart girth point cloud is greatly different from the actual heart girth. It can be seen from Figure 6b,e that when using only a side-view point cloud for heart girth measurement, the accurate back width cannot be obtained due to the lack of back data, and the measurement error is large. When using two-view Kinect sensors to measure heart girth (as shown in Figure 6c,f), we can obtain heart girth point cloud which accounts for approximately 3/4 of the complete heart girth. Through mirror symmetry, we can get complete heart girth point cloud, and the shape is close to the actual heart girth.
Sensors 2020, 20, x FOR PEER REVIEW 10 of 21 measured by two-view Kinect sensors is small. The reason is that it can be seen from Figure 6a,d that heart girth is measured only according to the top-view data. Due to the lack of abdomen, the shape of the fitting heart girth point cloud is greatly different from the actual heart girth. It can be seen from Figures 6b,e that when using only a side-view point cloud for heart girth measurement, the accurate back width cannot be obtained due to the lack of back data, and the measurement error is large. When using two-view Kinect sensors to measure heart girth (as shown in Figures 6c,f), we can obtain heart girth point cloud which accounts for approximately 3/4 of the complete heart girth. Through mirror symmetry, we can get complete heart girth point cloud, and the shape is close to the actual heart girth.    We used 26 pigs to compare the influence of three data acquisition ways on the measurement accuracy of heart girth. The heart girth point clouds obtained by three acquisition ways were measured, and the measurement results and manual heart girth value are shown in Figure 7. From this figure, we can see that the heart girth measured by using the two-view Kinect sensors synchronous acquisition is closer to the manual heart girth value, with smaller error, while the heart girth measured by using a side-view Kinect sensor and a top-view Kinect sensor has larger error. Therefore, this paper uses two-view Kinect sensors to synchronously collect pig point cloud, which provides data support for the realization of higher precision heart girth measurement.
Sensors 2020, 20, x FOR PEER REVIEW 11 of 21 girth measured by using a side-view Kinect sensor and a top-view Kinect sensor has larger error. Therefore, this paper uses two-view Kinect sensors to synchronously collect pig point cloud, which provides data support for the realization of higher precision heart girth measurement.

Figure 7
Comparison between the measured value obtain by different data acquisition methods and the manual value.

Pig Point Cloud Registration Results
To verify the feasibility and effectiveness of the feature-based improved 4PCS registration method proposed in this paper, the proposed registration method and the traditional point cloud registration method (4PCS registration combined with ICP registration) were both used to register two-view depth images of six pigs with different body positions (standing, walking, looking up, bowing, and arching the back) and of different breeds (five Large White pigs and one Landrace pig).
The registration results obtained using the traditional point cloud registration method are shown in Figure 8, and the registration results obtained using the proposed method are shown in Figure 9. In these figures, the top-view pig point cloud is shown in red, and the side-view pig point cloud is shown in green. From Figure 8, it can be seen that when the traditional point cloud registration method is used to register the two-view pig point clouds, the registration results may be rotated along the back; the registration of the back, ears, tail and other feature-rich parts may fail; and the heads and tails of the two point clouds may even point in opposite directions after registration. By contrast, it can be seen from Figure 9 that the point cloud registration results of the proposed method along the back, ears and tail are good regardless of the pig's posture, and this method is applicable to pigs of different breeds.

Pig Point Cloud Registration Results
To verify the feasibility and effectiveness of the feature-based improved 4PCS registration method proposed in this paper, the proposed registration method and the traditional point cloud registration method (4PCS registration combined with ICP registration) were both used to register two-view depth images of six pigs with different body positions (standing, walking, looking up, bowing, and arching the back) and of different breeds (five Large White pigs and one Landrace pig).
The registration results obtained using the traditional point cloud registration method are shown in Figure 8, and the registration results obtained using the proposed method are shown in Figure 9. In these figures, the top-view pig point cloud is shown in red, and the side-view pig point cloud is shown in green. From Figure 8, it can be seen that when the traditional point cloud registration method is used to register the two-view pig point clouds, the registration results may be rotated along the back; the registration of the back, ears, tail and other feature-rich parts may fail; and the heads and tails of the two point clouds may even point in opposite directions after registration. By contrast, it can be seen from Figure 9 that the point cloud registration results of the proposed method along the back, ears and tail are good regardless of the pig's posture, and this method is applicable to pigs of different breeds. Figure 9. In these figures, the top-view pig point cloud is shown in red, and the side-view pig point cloud is shown in green. From Figure 8, it can be seen that when the traditional point cloud registration method is used to register the two-view pig point clouds, the registration results may be rotated along the back; the registration of the back, ears, tail and other feature-rich parts may fail; and the heads and tails of the two point clouds may even point in opposite directions after registration. By contrast, it can be seen from Figure 9 that the point cloud registration results of the proposed method along the back, ears and tail are good regardless of the pig's posture, and this method is applicable to pigs of different breeds. Ten frames of top-view images and corresponding side-view images of each of the 26 live pigs were selected. After the two-view depth image data of the 26 pigs were preprocessed, the method proposed in this paper and the traditional point cloud registration method were used for registration; in total, 260 live pig point cloud registration results were obtained. To further analyse the accuracy of the proposed registration method and the traditional point cloud registration method, the root mean square error (RMSE) is introduced to quantitatively evaluate the registration error of each of the 260 registration results, as shown in Figure 10. The RMSE was calculated as the average Euclidean distance between corresponding point pairs after registration. The smaller the RMSE value is, the smaller the registration error, and the better the registration effect. Ideally, when the point clouds are fully correctly registered, the average Euclidean distance between corresponding point pairs will be 0. Figure 10 shows that the registration error of the traditional point cloud registration method fluctuates between 26.25 cm and 75.94 cm, while the registration error of the method proposed in this Ten frames of top-view images and corresponding side-view images of each of the 26 live pigs were selected. After the two-view depth image data of the 26 pigs were preprocessed, the method proposed in this paper and the traditional point cloud registration method were used for registration; in total, 260 live pig point cloud registration results were obtained. To further analyse the accuracy of the proposed registration method and the traditional point cloud registration method, the root mean square error (RMSE) is introduced to quantitatively evaluate the registration error of each of the 260 registration results, as shown in Figure 10. The RMSE was calculated as the average Euclidean distance between corresponding point pairs after registration. The smaller the RMSE value is, the smaller the registration error, and the better the registration effect. Ideally, when the point clouds are fully correctly registered, the average Euclidean distance between corresponding point pairs will be 0. Figure 10 shows that the registration error of the traditional point cloud registration method fluctuates between 26.25 cm and 75.94 cm, while the registration error of the method proposed in this paper ranges from 0.10 cm to 2.34 cm. Thus, the registration error of the proposed method is obviously smaller than that of the traditional point cloud registration method, indicating that the registration accuracy of the proposed method is higher. In summary, this paper proposes a feature- Ten frames of top-view images and corresponding side-view images of each of the 26 live pigs were selected. After the two-view depth image data of the 26 pigs were preprocessed, the method proposed in this paper and the traditional point cloud registration method were used for registration; in total, 260 live pig point cloud registration results were obtained. To further analyse the accuracy of the proposed registration method and the traditional point cloud registration method, the root mean square error (RMSE) is introduced to quantitatively evaluate the registration error of each of the 260 registration results, as shown in Figure 10. The RMSE was calculated as the average Euclidean distance between corresponding point pairs after registration. The smaller the RMSE value is, the smaller the registration error, and the better the registration effect. Ideally, when the point clouds are fully correctly registered, the average Euclidean distance between corresponding point pairs will be 0. Figure 10 shows that the registration error of the traditional point cloud registration method fluctuates between 26.25 cm and 75.94 cm, while the registration error of the method proposed in this paper ranges from 0.10 cm to 2.34 cm. Thus, the registration error of the proposed method is obviously smaller than that of the traditional point cloud registration method, indicating that the registration accuracy of the proposed method is higher. In summary, this paper proposes a feature-based improved 4PCS registration method for two-view pig point cloud in which the feature-rich ear and tail regions and the back contour region of the side-view point cloud are extracted to serve as the registration regions, thereby effectively reducing the matching error and improving the registration accuracy.
Sensors 2020, 20, x FOR PEER REVIEW 13 of 21 In order to further verify the influence of the proposed registration method on the subsequent improvement of the heart girth measurement accuracy, a comparative test was conducted on the heart girth measurement accuracy of 26 pig point clouds after registration with the proposed registration method and the traditional point cloud registration method. The results are shown in Figure 11. It should be noted that because of the obvious failure of the traditional point cloud registration method, we remove the failed data before the heart girth measurement. The traditional point cloud registration methods fail to register pig 16, pig 23 and pig 25, so it is impossible to calculate the heart girth and error. The average absolute error of heart girth measurement is 5.15 cm after point cloud registration with traditional point cloud registration method. The average absolute error of heart girth measurement is 1.96 cm after using the proposed feature-based improved 4PCS registration method. Compared with the traditional point cloud registration method, the average absolute error of heart girth measurement is reduced by 3.19 cm. Therefore, the proposed feature-based improved 4PCS registration method provides data support for the subsequent improvement of heart girth measurement accuracy.  In order to further verify the influence of the proposed registration method on the subsequent improvement of the heart girth measurement accuracy, a comparative test was conducted on the heart girth measurement accuracy of 26 pig point clouds after registration with the proposed registration method and the traditional point cloud registration method.
The results are shown in Figure 11. It should be noted that because of the obvious failure of the traditional point cloud registration method, we remove the failed data before the heart girth measurement. The traditional point cloud registration methods fail to register pig 16, pig 23 and pig 25, so it is impossible to calculate the heart girth and error. The average absolute error of heart girth measurement is 5.15 cm after point cloud registration with traditional point cloud registration method. The average absolute error of heart girth measurement is 1.96 cm after using the proposed feature-based improved 4PCS registration method. Compared with the traditional point cloud registration method, the average absolute error of heart girth measurement is reduced by 3.19 cm. Therefore, the proposed feature-based improved 4PCS registration method provides data support for the subsequent improvement of heart girth measurement accuracy.
Sensors 2020, 20, x FOR PEER REVIEW 14 of 21 Figure 11. Absolute errors of pig heart girth measurements after using different registration methods.

Results of Pig Heart Girth Measurement Point Extraction
To verify the validity of the proposed heart girth measurement point extraction method, the LSSA-CAU software was used to interactively select the heart girth measurement points from the pose-normalized pig point clouds. The selected results were compared with the coordinate values extracted using the method proposed in this paper. To reduce the error of interactive point selection using the LSSA-CAU software, each measurement point was selected three times, and the average value was calculated for use in the comparison. The heart girth measurement takes the measurement point as the starting point and intercepts the circumferential perpendicular to the ground from the pose-normalized pig point cloud. Therefore, the z coordinate is the same for all points in the heart girth point cloud, so only the z coordinate needs to be identified to extract the heart girth measurement point. Consequently, when verifying the accuracy of heart girth measurement point extraction, only the error in the z-axis direction between the actual and measured points needs to be calculated.
We selected eight pigs and analysed the three-dimensional circumference values of each pig within 10 cm towards the hip starting from the actual heart girth measurement point; the results are shown in Figure 12. It is found that within 4 cm of the actual heart girth measurement point, the three-dimensional circumference of each pig is fairly constant. Therefore, within this range, the threedimensional circumference value is reasonably close to the actual heart girth value, while beyond 4 cm, the curves of the three-dimensional circumference values of the pigs are relatively steep, meaning that the three-dimensional circumferences in this range are quite different from the actual heart girth value. From the above analysis, it can be seen that if the distance between the actual heart girth measurement point and the extracted point is greater than 4 cm, the error between the heart girth value measured starting from the extracted heart girth measurement point and the actual heart girth value will be large, thus affecting the accuracy of the heart girth measurement. Therefore, in this paper, when the error between the actual heart girth measurement point and the point extracted using the proposed method is less than or equal to 4 cm, the heart girth measurement point is considered to be extracted successfully. Otherwise, the extraction of the heart girth measurement point is considered to have failed.  4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 absolute error [cm] pig ID our method traditional point cloud registration method Figure 11. Absolute errors of pig heart girth measurements after using different registration methods.

Results of Pig Heart Girth Measurement Point Extraction
To verify the validity of the proposed heart girth measurement point extraction method, the LSSA-CAU software was used to interactively select the heart girth measurement points from the pose-normalized pig point clouds. The selected results were compared with the coordinate values extracted using the method proposed in this paper. To reduce the error of interactive point selection using the LSSA-CAU software, each measurement point was selected three times, and the average value was calculated for use in the comparison. The heart girth measurement takes the measurement point as the starting point and intercepts the circumferential perpendicular to the ground from the pose-normalized pig point cloud. Therefore, the z coordinate is the same for all points in the heart girth point cloud, so only the z coordinate needs to be identified to extract the heart girth measurement point. Consequently, when verifying the accuracy of heart girth measurement point extraction, only the error in the z-axis direction between the actual and measured points needs to be calculated.
We selected eight pigs and analysed the three-dimensional circumference values of each pig within 10 cm towards the hip starting from the actual heart girth measurement point; the results are shown in Figure 12. It is found that within 4 cm of the actual heart girth measurement point, the three-dimensional circumference of each pig is fairly constant. Therefore, within this range, the three-dimensional circumference value is reasonably close to the actual heart girth value, while beyond 4 cm, the curves of the three-dimensional circumference values of the pigs are relatively steep, meaning that the three-dimensional circumferences in this range are quite different from the actual heart girth value. From the above analysis, it can be seen that if the distance between the actual heart girth measurement point and the extracted point is greater than 4 cm, the error between the heart girth value measured starting from the extracted heart girth measurement point and the actual heart girth value will be large, thus affecting the accuracy of the heart girth measurement. Therefore, in this paper, when the error between the actual heart girth measurement point and the point extracted using the proposed method is less than or equal to 4 cm, the heart girth measurement point is considered to be extracted successfully. Otherwise, the extraction of the heart girth measurement point is considered to have failed. Extracting the heart girth measurement points of 26 pigs. It is worth noting that each pig has 10 frames, so we need to extract heart girth measurement points from 10 frames, respectively. Then the linear analysis of the actual value and the measurement value of the heart girth measurement point of each pig was carried out. The coefficient of determination R 2 between the actual value and the measured value of each pig's heart girth measurement point was calculated. The coefficient of correlation R 2 of 26 pigs is shown in Figure 13. It can be seen from the figure that the R 2 of pig 2 and pig 21 is smaller. The reason is that there is one frame of heart girth measurement point extraction failure in Pig 2, the absolute error between the actual value and the measured value of heart girth measurement point is 5.27 cm, while there are three frames of heart girth measurement point extraction failure in pig 21, the absolute error is 5.10, 5.34 and 5.20 cm, respectively. The R 2 of the other 24 pigs were all above 0.82. The results showed that proposed method can accurately extract heart girth measurement point. The error of heart girth measurement point extraction method basically meets the demand of heart girth measurement. Extracting the heart girth measurement points of 26 pigs. It is worth noting that each pig has 10 frames, so we need to extract heart girth measurement points from 10 frames, respectively. Then the linear analysis of the actual value and the measurement value of the heart girth measurement point of each pig was carried out. The coefficient of determination R 2 between the actual value and the measured value of each pig's heart girth measurement point was calculated. The coefficient of correlation R 2 of 26 pigs is shown in Figure 13. It can be seen from the figure that the R 2 of pig 2 and pig 21 is smaller. The reason is that there is one frame of heart girth measurement point extraction failure in Pig 2, the absolute error between the actual value and the measured value of heart girth measurement point is 5.27 cm, while there are three frames of heart girth measurement point extraction failure in pig 21, the absolute error is 5.10, 5.34 and 5.20 cm, respectively. The R 2 of the other 24 pigs were all above 0.82. The results showed that proposed method can accurately extract heart girth measurement point. The error of heart girth measurement point extraction method basically meets the demand of heart girth measurement.
To further verify the influence of pig posture on the point extraction results, all 260 pig point clouds registration results were analysed; 166 of the pigs were found to be in a natural standing state, and the remaining 94 pigs were in a walking state. A comparative test was carried out on the results of heart girth measurement point extraction for pigs in the standing state and the walking state, and the extraction success rate and average absolute error were calculated separately. The test results are shown in Table 2. The successful extraction rate for pigs in the standing state is 97.6%, and that for pigs in the walking state is 95.7%. The results indicate that the success rate of heart girth measurement point extraction is slightly lower for pigs in the walking state than for pigs in the standing state. From an analysis of the failure cases, the reason appears to be that when a pig is walking forward with the leg joint of the front leg on the side close to the side-view sensor is bent backwards at a large angle, the proposed point extraction method will fail; however, this is an instantaneous movement state that will rarely be captured by the side-view sensor. The average absolute error of detecting the heart girth measurement points of pigs in both the standing and walking states is less than 4 cm, which is sufficient to meet the needs of heart girth measurement. Therefore, the method proposed in this paper is virtually independent of the pig posture and can be used to accurately extract the heart girth measurement points of pigs. It can provide possibility for the subsequent improvement of heart girth measurement accuracy.
linear analysis of the actual value and the measurement value of the heart girth measurement point of each pig was carried out. The coefficient of determination R 2 between the actual value and the measured value of each pig's heart girth measurement point was calculated. The coefficient of correlation R 2 of 26 pigs is shown in Figure 13. It can be seen from the figure that the R 2 of pig 2 and pig 21 is smaller. The reason is that there is one frame of heart girth measurement point extraction failure in Pig 2, the absolute error between the actual value and the measured value of heart girth measurement point is 5.27 cm, while there are three frames of heart girth measurement point extraction failure in pig 21, the absolute error is 5.10, 5.34 and 5.20 cm, respectively. The R 2 of the other 24 pigs were all above 0.82. The results showed that proposed method can accurately extract heart girth measurement point. The error of heart girth measurement point extraction method basically meets the demand of heart girth measurement.  4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 coefficient of correlation R 2 pig ID Figure 13. The coefficient of correlation R 2 between the actual value and the measured value of each pig's heart girth measurement point R 2 of 26 pigs.

Accuracy of Pig Heart Girth Measurement
To verify the accuracy of the proposed heart girth measurement method, the 26 pigs were measured manually, using the circle fitting method [43], and using the shortest path method proposed in this paper. During the image acquisition period, professional stockmen were also asked to measure the pigs' heart girths manually using a tape measure during feeding. Because manual measurements will be affected by the measurement position, the measurement force and the activity of the pigs, to reduce the error of the manual measurements, the average value of three manual measurements was taken as the actual manual measurement value for each pig, and the measurement accuracy was found to be 1 mm. Then, the proposed method and the circle fitting method were used to measure the heart girth of 10 frames heart girth point cloud for each pig, and respectively obtained 10 sets of measurements of heart girth for each pig. The average value of the 10 sets of measurements was taken as the measured heart girth measurement of this pig. It should be emphasized that if there are a few frames of this pig that fails to extract the heart girth measurement point, it needs to be removed, and then the remaining frames are measured, and the average value is taken as the measured heart girth measurement of this pig. Finally, the absolute and relative errors between the values measured using these two methods and the actual manually measured values were calculated. The absolute errors of the heart girth measurements for the 26 pigs are shown in Figure 14.
From Figure 14 we can see that the absolute errors obtained using the proposed method are all less than 4.19 cm, and the results are stable. In contrast, the absolute errors obtained using the circle fitting method are as large as 8.51 cm, and the measurement results show relatively large fluctuations. The average absolute errors and relative errors of heart girth measurement for the 26 pigs were also calculated. The average absolute error achieved using the proposed method is 1.96 cm, and the average relative error is 2.14%; by contrast, the average absolute error achieved using the circle fitting method is 3.39 cm, and the average relative error is 3.68%. The above data show that the heart girth values measured using the proposed method are more accurate and stable than those measured using the circle fitting method. The proposed method effectively improves the measurement accuracy of pig heart girth.
Sensors 2020, 20, x FOR PEER REVIEW 17 of 21 Figure 14. Absolute errors of pig heart girth measurements obtained using different methods.
From Figure 14 we can see that the absolute errors obtained using the proposed method are all less than 4.19 cm, and the results are stable. In contrast, the absolute errors obtained using the circle fitting method are as large as 8.51 cm, and the measurement results show relatively large fluctuations. The average absolute errors and relative errors of heart girth measurement for the 26 pigs were also calculated. The average absolute error achieved using the proposed method is 1.96 cm, and the average relative error is 2.14%; by contrast, the average absolute error achieved using the circle fitting method is 3.39 cm, and the average relative error is 3.68%. The above data show that the heart girth values measured using the proposed method are more accurate and stable than those measured using the circle fitting method. The proposed method effectively improves the measurement accuracy of pig heart girth.
The actual heart girth values that were measured manually for the 26 pigs and the values obtained using the two automated methods are shown in Figure 15. From Figure 15, it can be seen that the heart girths obtained using the automated methods are sometimes larger and sometimes smaller than those obtained through manual measurement. The reason is that only point cloud data from the back and one side of the pigs were collected in this experiment, while point cloud data from the other side were missing. Since the two sides of a pig are not completely symmetrical, the estimation of the point cloud on the missing side from the existing point cloud data that was performed during the automated measurement procedure could cause the final measured heart girth value to be either larger or smaller than the actual value. The actual heart girth values that were measured manually for the 26 pigs and the values obtained using the two automated methods are shown in Figure 15. From Figure 15, it can be seen that the heart girths obtained using the automated methods are sometimes larger and sometimes smaller than those obtained through manual measurement. The reason is that only point cloud data from the back and one side of the pigs were collected in this experiment, while point cloud data from the other side were missing. Since the two sides of a pig are not completely symmetrical, the estimation of the point cloud on the missing side from the existing point cloud data that was performed during the automated measurement procedure could cause the final measured heart girth value to be either larger or smaller than the actual value.
Sensors 2020, 20, x FOR PEER REVIEW 18 of 21 Figure 15. Pig heart girth measurements obtained using different methods.

Conclusions
In this study, we propose a new non-contact method of measuring pig heart girth using two Kinect sensors. Our method can register the two-view point clouds, extract the measurement point, obtain the complete heart girth point cloud by mirror symmetry, and calculate the heart girth length. This method has been verified by 26

Conclusions
In this study, we propose a new non-contact method of measuring pig heart girth using two Kinect sensors. Our method can register the two-view point clouds, extract the measurement point, obtain the complete heart girth point cloud by mirror symmetry, and calculate the heart girth length. This method has been verified by 26 live pigs in the farm. The feature-based improved 4PCS registration method provides data support for the realization of higher precision heart girth measurement. The results of heart girth measurement point extraction can basically meet the needs of heart girth measurement. The average relative error of heart girth measurement was 2.14%, which effectively improves the measurement accuracy of the pig heart girth and obtains satisfactory results.
However, the accuracy of the measurement points extraction needs to be further improved in our future work. At the same time, the proposed heart girth measurement method is used to verify more pigs, which is expected to be integrated into the software system and applied to commercial farms.