An Approach of Pig Weight Estimation Using Binocular Stereo System Based On LabVIEW
An Approach of Pig Weight Estimation Using Binocular Stereo System Based On LabVIEW
Original papers
a r t i c l e i n f o a b s t r a c t
Article history: The change of the daily weight of the pig is significant to the pig’s health and process of real production.
Received 16 April 2016 This study combined the binocular stereo vision system with the LabVIEW development platform to ana-
Received in revised form 10 August 2016 lyze and estimate body size and live body weight using 10 landrace aged from 14 to 25 weeks old at the
Accepted 16 August 2016
end under indoor farm condition. The experimental facility was composed of data collection system,
Available online 22 September 2016
image acquisition system, and image analysis system. Data collection system including binocular camera
and specially designed limitation fence was used to ensure the pig’s ID recognition and image acquisition
Keywords:
were implemented automatically. The images were acquired, saved, and processed by the other two
Pig weight
Body size
systems to analysis the relationship between body weight and body size. Images acquired by binocular
Estimation cameras were segmented by the depth threshold. The system verified that the body length (BL) and with-
LabVIEW ers height (WH) were estimated with the R2 ranged from 0.91 to 0.98. The back area and the body weight
Binocular camera data obtained by a ground scale were fitted into linear model. According to the result of regression by
least square method, the parameters of the function were calculated. Results revealed that live body
weight was closely related to the sum of pixel values (SPV) which was calculated from the reconstructed
image. Coefficient of determination R2 value was as high as 0.9931. It meant this procedure performed
well in predicting live weight. The whole automatic systems have the potential to be applied in the real
farm environment.
Ó 2016 Published by Elsevier B.V.
http://dx.doi.org/10.1016/j.compag.2016.08.012
0168-1699/Ó 2016 Published by Elsevier B.V.
38 C. Shi et al. / Computers and Electronics in Agriculture 129 (2016) 37–43
Body measurements suggested for estimating live body weight were Y1 and Y2 (Y1 and Y2 were the year of 2014 and 2015, respec-
(Slippers et al., 2000; Topal and Macit, 2004) are simple and easily tively). At the beginning of experiment, the pigs’ ages were
measured. Heinrichs et al. (1992) built the relationship between between 14 and 15 weeks old and the weight ranged from 30 to
hip widths, body length, withers height, and heart girth and body 40 kg, until which reached about 25 weeks old and the weight ran-
weight to do the estimation. Enevoldsen and Kristensen (1997) ged from 90 to 110 kg at the end. The pig’s body length and withers
evaluated live cow weight by body size measurements. Girth height were manually measured by a tape during the feeding
measurement was one of the main indirect ways and also applied period every morning for comparing with the computed values
in pigs weighing (Pope and Moore, 2002). However, high labor by image processing. The total samples of manually measured BL
intensity and inevitable contact were always needed during the (Body Length) and WH (Withers Height) were 1460.
processes of measurement.
The non-contact measurement method can effectively 3. Experimental method
reduce the stress behavior of animals. Therefore, the automatic
weighing systems such as radio frequency identification system The whole experimental period was nearly 80 consecutive days
(Schwartzkopf-Genswein et al., 2002), fuzzy-logic dynamic for 12 h a day (07:00–19:00) in each group. There was a ground scale
weighing system (Cveticanin and Wendl, 2004) and strain gauge with pressure sensors under the farm floor of the drinking area to
balance devices (Pastell et al., 2006), are another estimating ways measure body weight of pig when it came to drink. The data of the
and have been developed and used in cattle to analysis the side body weight, ear-tag number and the image would be recorded
view of the cow that passing through the certain route (Tasdemir and saved in the database in real time, as shown in Fig. 1. The pur-
et al., 2011; Viazzi et al., 2014). pose of pig weight data collection was for the comparison between
At present, the development of computer and digital imaging real value and estimated value which was determined by body area.
system provides an indirect way to estimate live animal weight The body weight data volume estimated by image analysis was the
from its body feature by image analysis technique. Image analysis same as those measured by weighing method. It was 730.
method has been successfully used to estimate body weight. White The experimental facility was composed of data collection sys-
et al. (2004) used visual image analysis system for monitoring size tem, image acquisition system, and image analysis system. The
and shape of pigs to determine live body weight as an efficient data collection system collected and uploaded the pig’s ID and
way. It is an accurate means for reflecting pig live weight by track- the actual weight to the database. The image acquisition system
ing pig changes with time that are sufficiently short for commercial acquired and saved image data for evaluating the pig’s body
use. Mollah et al. (2010) performed experiments to estimate body weight. The image analysis system processed image to generate
weight of broiler. They captured images and analyzed them by ras- the segmented body contour and the reconstructed pig image.
ter image analysis software (IDRISI 32) to calculate the body sur- In order to explore the relationship between the pigs’ body
face area from surface-area pixels with a predicted equation. The weight and size, the regression analysis between measured weight
estimated results were closed to manually measured body weight. and the SPV of the daily reconstructed image on 10 pigs was done.
According to Schaefer and Tong (2000), infrared thermal images of The measured body weight and SPV was fitted into linear model
animals were applied for predicting the body composition. Kashiha and regressed with the following equation:
et al. (2014) used shape recognition techniques and ellipse fitting
W ¼ AS þ B ð1Þ
algorithm to get the weight of each individual pig. Kongsro
(2014) put the three-dimensional data into estimating the pig body The weight estimation parameters were obtained by the Eq. (5).
weight of different breeds based on Kinect system of Microsoft. W and S in the function was the measured weight and the SPV. To
These methods are all the pioneer work used for estimating the estimate body weight with an efficient model, least square method
body weight with non-contact involved. However, image analysis was used to calculate the parameters A and B. The minimum
method to monitor the pig weight needs the high quality image deviation is realized by:
and the perfect posture of the animal body. The high quality image
X
n
means that the acquired image should avoid the factors against Min ½W i ðA þ BSi Þ2 ð2Þ
segmentation such as illumination changes, shadows and back- i¼1
ground noises as much as possible. The perfect posture represents
The partial derivative of Eq. (2) is expressed as:
that the pig body not only keeps straight without bend and the
8
head is as high as back without up or down, but also the pig has > X
n
>
> @
½W i ðB þ ASi Þ2 ¼ 0
to keep standing without lying or sitting on their hind legs. Besides, >
< @A
i¼1
all of those requirements are the necessary conditions to attain the ð3Þ
>
> X
n
full automatic pig weight monitoring to the manager in real farm >
> @
½W i ðB þ ASi Þ2 ¼ 0
: @B
environments. All these issues are urgent and needed to solve i¼1
timely and effectively.
Eq. (3) is sorted and showed as Eq. (3),
The objective of this paper was to study: (1) method of automatic
8 n
monitoring system including ID recognition, image acquisition, > X
>
> ½W i ðB þ ASi ÞSi ¼ 0
image analysis, and data uploading based on internet of things tech- >
<
i¼1
nology; (2) the error of binocular stereo vision system for calculating ð4Þ
>
> X
n
the three-dimensional data of pig body size; (3) the relationship >
> ½W i ðB þ ASi Þ ¼ 0
:
between live body weight and back area in the process of growth, i¼1
and the validity of this method to estimate pig weight.
Eq. (4) can be solved and the expression of the best A and B with the
known conditions are derived as follow:
2. Materials and methods
8 Pn Pn Pn
>
> A ¼
W
i¼1 i
S N
i¼1 i
2
W
i¼1 i
2.1. Animals >
< P n P n
N S2i Si
Pn i¼1Pn 2 P i¼1
Pn ð5Þ
>
> Wi Si
n
Wi S
In this study, a total of the 10 fattening barrows of landrace in >
:B ¼ i¼1
Pn i¼1
Pi¼1 n
2
i¼1 i
N S2 S
HUI KANG pig farm in China were divided into 2 groups which i¼1 i i¼1 i
C. Shi et al. / Computers and Electronics in Agriculture 129 (2016) 37–43 39
Fig. 1. Experimental facility. (a) Lighting lamp; (b) digital camera; (c) RFID reader; (d) RFID signal; (e) pressure sensor; (f) ground scale; (g) drinker; (h) limitation fence and (i)
pig.
3.1. Data collection system The field of view of the drinking area determined the height of
the dual camera. The camera was mounted 2.2 m above the farm
The pig body image was taken by the binocular stereo vision floor by the Eq. (6).
acquisition system which was composed of two ‘‘Basler acA-
1300-30gc” digital cameras with 1294 ⁄ 964 pixel resolution. A OS
BL ¼ WD OD ð6Þ
‘‘Raybaca RBC-A04” RFID reader, which was 134.2 kHz operating FL
frequency and long distance ISO 11784/11785 ear-tag reader, In the above equation, OS is the optical size (4.8 mm ⁄ 3.6 mm).
identified the pig and triggered the camera which captured image BL is the maximum body length. OD is the optical center distance
in drinking area. This area was equipped with specially designed of the dual cameras (115 mm). WD is the working distance which
limitation fence for entrance of only one pig, as shown in Fig. 2. is the subtraction of the height of the body and the dual camera. FL
The NI (National Instruments) EVS-1463 (Embedded Vision is the focus length (5 mm).
System) connected the camera, ground scale, and RFID reader with
gigabit interface, analog acquisition module and RS 485 serial
3.2. Image acquisition
interface (the core of the internet of things system). Therefore,
the image, pig’s weight and ID were synchronously acquired and
The images were acquired by the image acquisition system
uploaded to database automatically through the designed software
using LabVIEW (Laboratory virtual instrumentation engineering
system based on EVS when pig was drinking.
workbench, 2015) with the VDM (vision development module).
The images, which acquired by this system, were saved in the spec-
ified location and sorted by date automatically to build database
for body weight estimation.
reconstructed pig image removed the head, ears and tails for the 5. Discussion
reason that the accuracy of the estimated weight would be greatly
improved by removing those body parts (Wang et al., 2008) as The estimation of WH observed the lower error than the esti-
shown in Fig. 3(c). mated BL. It had gradually become apparent that the estimated
BL was higher than the measured values due to the variation of
height was neglected during the image processing. The closer the
4. Results distance between object and lens, the larger the object in image.
The high R2 and low RUME showed in Table 1 seem to indicate that
The measured BL and WH were regressed with estimated val- the new method was capable of measuring WH and BL. The high
ues. The results of R2 and the root mean square error (RMSE) of correlation ship between body weight and SPV gave a new enlight-
the estimated BL and WH from a total of 1460 samples of the 10 enment to explore the more accurate method. The validity of this
pigs in 80 days are shown in Table 1. RMSE ranged from 1.73 to method to estimate pig weight had been verified. In addition, Eq.
2.05 cm of BL and 0.71 to 0.92 cm of WH indicated that the esti- (7) can be used to estimate body weight if the value of SPV was
mated results were very close to the true value. The accuracy of acquired. Under this circumstance, the method had the capability
estimation of this method exceeded 90% based on binocular stereo to replace the traditional contact and weighing method as a stan-
vision system which provided the basis for subsequence research. dard method for estimating body size and pig weight timely and
Through the linear regression analysis by Eq. (1), the relation- effectively.
ship between the pig weight acquired by ground scale and SPV of The quality of image plays an important role in estimation
the pig contour is shown in Fig. 4. results and it is difficult to get a good quality image of the perfect
The fitting parameters A and B of the linear regression are listed posture pig at a time (Wongsriworaphon et al., 2015; Kongsro,
in Table 2, and all the coefficients of determination (R2) are very 2014). Therefore, the new methods have been proposed to
high, nearly closed to 0.99, suggest that the pig body weight is decrease the number of low quality image.
strongly related to the pig body size. Each pig’s value of parameter The height of the trough and drinker were the same to avoid the
A or B is also closed, which indicates that there is a good represen- phenomenon of pig head down while manually measured the BL
tation in the respects of body weight estimation. during the eating process. Thus, the error between measured and
The parameter estimation of A and B, which is deduced by Eq. the estimated value would be decreased. The body of pig kept
(5), is 0.568 and 15.612, respectively. Eq. (1) is substituted the standing and rarely moved when it was eating or drinking, so the
estimated value of A and B, then a linear model for calculating cameras mounted on the drinking area were the best option.
the estimated weight is acquired. Which is: Meanwhile, the photoelectric sensors and pneumatic door devices
were used to transform the drinking area into a one-way street
W ¼ 0:568S 15:612 ð7Þ that only one pig can enter, and the limitation fence to make sure
The estimated body weight is calculated by Eq. (7). The result of the pig cannot turn round. The pneumatic door closed automati-
the comparison of the body weight between measured and esti- cally as soon as the signals of pig entrance into the drinking area
mated value is shown in Fig. 5 with the R2 of 0.9931 and the stan- were found by the photoelectric sensor, and if other sensors recog-
dard error of 1.988 kg. With this estimated method, the body nized the pig left the drinking area, the closed door would open. So
weight can be calculated from SPV precisely. the better quality images can be obtained.
Fig. 3. Automatic process of the reconstructed image. (a) Depth image; (b) pig contour and (c) reconstructed pig image.
Table 1
The results of estimated value on 5 pigs.
ID Sample volume BL WH
2
R RMSE, cm R2 RMSE, cm
Y1 Y2 Y1 Y2 Y1 Y2 Y1 Y2 Y1 Y2
1 70 78 0.92 0.93 1.97 2.01 0.98 0.99 0.87 0.73
2 72 73 0.93 0.93 1.73 1.89 0.98 0.98 0.80 0.90
3 73 75 0.91 0.92 2.03 1.86 0.98 0.98 0.92 0.88
4 68 69 0.92 0.94 1.91 2.05 0.99 0.97 0.74 0.89
5 75 77 0.93 0.91 1.78 1.75 0.99 0.99 0.71 0.74
BL = Body Length; WH = Withers Height. Y1 and Y2 is the year of 2014 and 2015, respectively.
C. Shi et al. / Computers and Electronics in Agriculture 129 (2016) 37–43 41
100 100
Pig 1 in Y1 Pig 2 in Y1
60 60
40 40
20 20
50 100 150 200 50 100 150 200
SPV SPV
100 100
Pig 3 in Y1
Measured body weight (kg)
Pig 4 in Y1
60 60
40 40
20 20
50 100 150 200 50 100 150 200
SPV SPV
100 100
Pig 5 in Y1 Pig 1 in Y2
Measured body weight (kg)
80 80
60 60
40 40
20 20
50 100 150 200 50 100 150 200
SPV
100 100
Measured body weitht (kg)
Pig 2 in Y2 Pig 3 in Y2
Measured body weight (kg)
80 80
60 60
40 40
20 20
50 100 150 200 50 100 150 200
SPV SPV
100 100
Measured body weight (kg)
Pig 4 in Y2 Pig 5 in Y2
Measured body weight (kg)
80 80
60 60
40 40
20 20
50 100 150 200 50 100 150 200
SPV SPV
Table 2
The result of fitting parameters of pig 1, 2, 3, 4 and 5 in Y1 and Y2.
ID A B R2
Y1 Y2 Y1 Y2 Y1 Y2
1 0.5729 0.5655 15.08 15.29 0.9959 0.9902
2 0.5732 0.5741 15.46 15.40 0.9967 0.9982
3 0.5745 0.5747 15.90 15.02 0.9985 0.9920
4 0.5680 0.5747 17.24 15.88 0.9874 0.9905
5 0.5708 0.5673 16.01 15.40 0.9925 0.9976
100 The accuracy of the calibration was 0.72% of the maximum relative
errors and 0.1% of the minimum relative errors. The calibration
often failed many times due to the excessive acquisition of grid
Estimated body weight (kg)
80 images and the change of grid angle irregularly, and the matching
of images taken by left and right camera was a really difficult
process (Wu et al., 2004). Therefore, more new products and tech-
nologies should be applied such as the Kinect and other three-
60
dimensional cameras to avoid the complicated calibration.
40 6. Conclusion
Khamjan, S., Piewthongngam, K., Pathumnakul, S., 2013. Pig procurement Slippers, S.C., Letty, B.A., de Villiers, J.F., 2000. Prediction of the body weight of
planconsidering pig growth and size distribution. Comput. Ind. Eng. 64 (4), Nguni goats. South African J. Anim. Sci. 30, 127–128.
886–894. Stajnko, D., Brus, M., Hočevar, M., 2008. Estimation of bull live weight through
Kongsro, J., 2014. Estimation of pig weight using a Microsoft Kinect prototype thermographically measured body dimensions. Comput. Electr. Agric. 61 (2),
imaging system. Comput. Electr. Agric. 109, 32–35. 233–240.
Li, Z., Du, X.D., Mao, T.T., Teng, G.H., 2016. A pig dimension detection system based Tasdemir, Sakir, Urkmez, Abdullah, Inal, Seref, 2011. Determination of body
on depth image. Trans. Chinese Soc. Agric. Mach. <http://www.cnki.net/kcms/ measurements on the Holstein cows using digital image analysis and
detail/11.1964.S.20151218.1148.004.html>. estimation of live weight with regression analysis. Comput. Electr. Agric. 76
Menesatti, P., Costa, C., Antinucci, F., Steri, R., Pallottino, F., 2014. A low-cost (2), 189–197.
stereovision system to estimate size and weight of live sheep. Comput. Electron. Topal, M., Macit, M., 2004. Prediction of body weight from body measurements in
Agric. 103, 33–38. Morkaraman sheep. J. Appl. Anim. Res. 25, 97–100.
Mollah, M.B.R., Hasan, M.A., Salam, M.A., Ali, M.A., 2010. Digital image analysis to Viazzi, S., Bahr, C., Van Hertem, T., et al., 2014. Comparison of a three-dimensional
estimate the live weight of broiler. Comp. Electron. Agric. 72 (1), 48–52. and two-dimensional camera system for automated measurement of back
Oliveira, J., Yus, E., Guitián, F.J., 2009. Effects of management, environmental and posture in dairy cows. Comput. Electr. Agric. 100 (1), 139–147.
temporal factors on mortality and feed consumption in integrated swine Wang, Y., Yang, W., Walker, L.T., Rababah, T.M., 2008. Enhancing the accuracy of
fattening farms. Livest. Sci. 123, 221–229. area extraction in machine vision-based pig weighing through edge detection.
Pastell, M., Takko, H., Gröhn, H., Hautala, M., Poikalainen, V., Praks, J., Veermäe, I., Int. J. Agric. Biol. Eng. 1 (1), 37–42.
Kujala, M., Ahokas, J., 2006. Assessing cows’ welfare: weighing the cow in a White, R.P., Schofield, C.P., Green, D.M., Parsons, D.J., Whittemore, C.T., 2004. The
milking robot. Biosyst. Eng. 93 (1), 81–87. effectiveness of a visual image analysis (VIA) system for monitoring the
Pathumnakul, S., Piewthongngam, K., Apichottanakul, A., 2009. A neural network performance of growing/finishing pigs. Anim. Sci. 78, 409–418.
approach to the selection of feed mix in the feed industry. Comput. Electr. Agric. Wongsriworaphon, A., Arnonkijpanich, B., Pathumnakul, S., 2015. An approach
68 (1), 18–24. based on digital image analysis to estimate the live weights of pigs in farm
Pope, G., Moore, M., 2002. Estimating Sow Live Weights Without Scales. From the environments. Comput. Electr. Agric. 115, 26–33.
Web Site of the Department of Primary Industries, Queensland, Australia. Wu, J., Tillett, R., McFarlane, N., et al., 2004. Extracting the three-dimensional shape
Schaefer, A.L., Tong, A.K.W., 2000. Process for Determining a Tissue Composition of live pigs using stereo photogrammetry. Comput. Electr. Agric. 44 (3), 203–
Characteristic of an Animal. U.S. Patent No. 6,123,451. 26 Sep. 222.
Schwartzkopf-Genswein, K.S., Atwood, S., McAllister, T.A., 2002. Relationships Yeo, M.L., Smith, P., 1977. A note on relationships between girth measurements and
between bunk attendance, intake and performance of steers and heifers on sow live weight gain. Exp. Husbandry 33, 81–84.
varying feeding regimes. Appl. Anim. Behav. Sci. 76 (3), 179–188.