Pig Weight Estimation According to RGB Image Analysis 51 Pig Weight Estimation According to RGB Image Analysis Andras KÁRPINSZKY*, Gergely DOBSINSZKI EN-CO Software cPlc., Schweidel street 5, H-1118 Budapest, Hungary Agricultura Scientia 20: No 1: 51-60(2023) https://doi.org/10.18690/agricsci.20.1.6 *Correspondence to: E-mail: karpinszky.andras@encosoft.hu ABSTRACT In pig farming, knowing the exact weight of each animal is critical for the owner. Such information can help determine the amount and type of feed that needs to be fed to a specific fattening pig. Weighing pigs has always been problematic, because it is highly time consuming, and herding the pigs on the scale is extremely cumbersome. Moreover, it causes stress to the animals. The aim of our study was to build an RGB-based system that could estimate the daily weight of pigs and individual animal weight. The study was set up in a 100-day rotation in a commercial pig farm where we monitored 32 pigs. We developed a system to identify the features of the pigs, more particularly the head, shoulder, belly, and rump part. Three different models were tested, and their main differences were linked to image processing and training data. Using these models, we received higher than 97% accuracy between the predicted and the manually recorded weight of the animals. This system allows owners to manage and monitor their pigs using our web interface, allowing them to make crucial decisions during the farming process. Key words: image processing, pig size, decision support system, precision livestock farming INTRODUCTION The world is in protein scarcity and such shortage will rise due to the developing countries’ growing needs for proteins. Pork is one of the most important protein sources among the various plant and animal-based protein sources. In the last sixty years the production of pigs steadily grown along with growing yields due to the constant development of genetics and technology (feeding management, environment management). Nowadays, in traditional pork consuming countries there are more than 800 million heads at a time, about half of them in China, and a notable amount in EU countries and the USA. The pork industry entails intensive in-house farming, where the animals are kept away from the outdoors, securing the herd by keeping them away from pathogens as much as possible. This means that farmers try to keep human contacts with the animals as low as possible, but at the same time, they need information about the daily weight gain of the fattening group to manage feeding and to be able to plan the time when the animals will reach the ideal weight for processing. Farmers can gather this information with physical scales, but the method is labor intensive, time consuming and causes stress to the animals. As a result of these problems, most of the farmers only weighs few pigs at the end of the fattening process, to get some information. The lack of information leads to mistakes in planning and management, causing profit loss to the farmers. Precision farming (PF) solutions have become increas- ingly popular worldwide, in all sectors of agriculture, such as arable plant production, horticulture and livestock farming (Stafford, 2000; Zude-Sasse et al., 2016). Main purposes of PF in all sectors include decreasing environmental impact and cost of production, while increasing quality and yields. According to Andonovic et al. (2018), given the increase of the farm size in livestock farming, owners have less time to perform traditional practices. Therefore, they rely more on technological solutions, e.g., animal activity detection and fertility, moreover feed intake monitoring. Aquilani et al. (2022) complement that the main purposes with e.g., animal identification, body weight measurement, automat- ic drafting systems, temperature and humidity data record, animal location detection and prevention of livestock theft. The authors highlighted that both single and multiple tools, information technologies, communication systems have high importance, particularly given the decrease of the price of the small size electronic devices. Pig Weight Estimation According to RGB Image Analysis 52 Remote sensing methods are usually grouped as active and passive devices according to the structure of the device. Among the active devices, LiDAR, RaDAR are the most widespread, while within the passive devices RGB, thermal, near infrared, multispectral and hyperspectral cameras are involved in PF. RGB image analysis is one of the most wide- spread methods to monitor livestock. Recently, Mollah et al. (2010) showed that predicted weight based on the broiler body surface area and real weight have high and significant correlation. Later, Szabo and Alexy (2022) reported valuable results about the image analysis-based weigh estimation of ducks. Pig weight estimation based on image analysis has been also in the focus of precision farming research. In the past years, several reports were published where different image capturing and data analysis were introduced. For example, Kongsro (2014) applied Kinect camera and found high accuracy between the predicted and measured weight. Later, Pezzuolo et al. (2018) used SfM (Structure from Motion) technique which generates 3D reconstruction from 2D images. To estimate the body size and weight, Zhang et al. (2021) applied depth camera and multiple output regression convolutional neural network (CNN). There are methods to calculate weight from the physical build of a swine, but these parameters are not measurable with a camera and this approach is not fully accurate, either. For this reason, we aimed to find appropriate methodology for the image capture, tracking, segmentation, and models for average daily weight and individual pig weight estimation. MATERIALS AND METHODS Experimental farm The experiment was conducted on a pig barn in a commercial indoor system. The study was set up on a private farm in Németkér (Tolna county, Trans-Danubia, Hungary). We followed a complete pig fattening cycle (approximately for 100 days) and run our experiment from August 2020 to November 2020. It was important to have weight information for all training data so that it could be used as a label. To match the data from the image analysis with weight information, we needed manual weight measurements of the individual animals. Such exercise was performed at the farm using scales (DEMANDY, Hungária Mérleg Holding Ltd.). The official accuracy of the scale is 0.5 kg. The pigs were identified by marking each animal with unique paint markers. Initially, there were 32 pigs involved in the experiment, but two animals needed to be removed from the investigations due to illness. One week before the end of the experiment, 10 pigs were sold (on 10 November 2020) as they reached the required weight. In summary, starting from 25 August 2020, there were 32 pigs. After 7 days, two pigs were eliminated. As such, between 1 September and 9 November 2020, all together 30 animals were monitored. As from 10 November 2020, further animals were removed: only 20 animals were left in the pen. The camera setup can be seen on Figure 1. Figure 1: Camera installation on the experimental farm Image capturing During the experiment, four different Dahua cameras were set up and tested (Dahua IPC-HFW1230S-S4, IPC-HFW1230S- 0280B-S5, IPC-HFW1230S-0280B-S4 and IPC-HFW1235S- W-0280B-S2). These cameras have different fields of view, CMOS sensor sizes and focal lengths, so we had to consider all these parameters to be able to transform the images as they had been taken by the same camera. The market of PoE security cameras is ever-changing and, as such, a solution was developed to transform the image from one camera’s perspective to another. To capture images, we placed cameras over the target pig pens at a fixed height. Since cameras distort images, we needed to individually calibrate them after installation. The parameters calculated during calibration were used in the pipeline to undistort our data. For more accurate weight prediction, 10 pictures were taken every 1 minute with a one-second difference. Thus, we managed to get multiple pictures from the same animal. For animal tracking, the Kalman filter was used, first described by Swerling (1958), Kalman (1960) and Kalman and Bucy (1961). Every camera was hooked up to a Raspberry Pi 4 model which was re- sponsible for creating the images. The Raspberry Pi 4 Model B 4Gb (https://www.raspberrypi.com/products/raspber- ry-pi-4-model-b/) usually controlled 4 cameras, 40 image are taken every minute, 10 from each camera: first camera – 1-10 seconds; second camera – 16-25 seconds; third camera – 31-40 seconds; fourth camera – 46-55 seconds. The images were stored temporarily on the edge device which uploaded them to a cloud-based server for further calculations and perma- nent storage. There are feeders in the middle of the pen and on the wall, where it is accessible from two pens. For these reasons, two camera setting were applied (Figure 2). Pig Weight Estimation According to RGB Image Analysis 53 Weight estimation Accurately measuring swine weight by relying on cutting-edge technology involves a number of steps – we believe the most critical ones are segmentation, Pretty Contour Picker (PCP), feature extraction, tracking and aggregation. Below we shortly address each of them. Segmentation The server first segmented the images using a neural network architecture, Mask R-CNN (He et al., 2017). The model identified three classes: (i) standing animal – 5062 contours, (ii) lying animal – 4758 contours, (iii) to be discarded – 38500 contours (for maximum precision, only contours on which pigs are standing and clearly visible were used in future calculation). 80% of the dataset were used as training data, while the remaining 20% (divided into 10%-10%) of the images were used for testing and validation, respectively. The model was trained using our custom dataset, for which data had been captured with a test camera. The pictures were annotated with outlines, then classi- fied into the previously mentioned groups, and finally, they were filtered to only contain valid and clean training data. We wrote a special program for annotating images and val- idating these annotations, which sped up the process sig- nificantly. A custom class was written for data preparation and loading. To train the neural network, we used weights pretrained on the COCO dataset (Lin et al., 2014). The pre- trained weight data allowed our model to converge faster. We used augmentation (rotation) to increase the size of the standing and lying contours dataset for higher accuracy. To avoid overfitting, we used the “early stopping” technique. The augmentation parameters were: • hsv hue modification probability: 0.015 • hsv value modification probability: 0.4 • rotation: 90 degrees • translate: 0.1 • scale: 0.5 • flip upside-down probability: 0.5 • flip left to right probability: 0.5 • mosaic probability (create collage from images): 0.5 • copy paste probability (cut animals out and put them on other images): 0.5 Training for a large quantity of images over multiple epochs may take days so we only modified hyperparameters conservatively, exploring only the most common changes. Model weights were exported in „saved model” format for usage with TensorFlow Serving. As such, we created a docker image using our custom weight data based on the GPU image of TensorFlow serving. The Segmentator container connect- ed with a single (or more, depending on the settings) docker- ized Mask R-CNN model which inferenced images that had been previously created by a Raspberry Pi endpoint. After in- ference, processed images were saved in a separate database. During optimization, the precision of the detected contours was evaluated using F1 score by comparing the result area to that of the annotated contours. Transformation To avoid and solve camera lens distortion, each camera was calibrated, and images were transformed prior to weight calculations. This was crucial because, as noted above, all Figure 2: Proposed camera setup according to the position of the feeder: (a) feeder is in the middle of the pen and (b) feeder is between two pens where 1: cameras, 2: area seen by the camera Pig Weight Estimation According to RGB Image Analysis 54 cameras had varying distortion. To make our final calculations consistent and “camera-agnostic” across different pig pens and piggeries, we needed the images and contours to be distortion- free and identical in scale. Each camera needed to be calibrated after installation. The values calculated during calibration could be added to the pipeline – as a result, the images ended up being un- distorted in the transformation phase. We used a plain A4 sheet placed exactly under the camera to calculate the dis- tortion of the lens (Figure 3). For calibration we had to put a A4 paper exactly under the camera. From there, we could calculate the required calibration of the image. Tracking Detecting and predicting single contours and treating them separately did not prove to be the most accurate approach. A pig may stay in the same position, or it can walk around the cameras’ field of view and may appear in multiple images taken every second. To factor this situation into our calculations, we created a tracking solution: if the same pig is detected across multiple images, its final weight is calculated using these detections. The tracking helped us estimate the weight of the pig with higher accuracy. Our tracking algorithm consisted of four steps. 1. A segmentation service that detected contours on “neigh- bouring” images. 2. For every pair of contours between “neighbouring” images, the IOU was calculated (intersection over union = it is a double value between 0 and 1). After calculating the IOU, the “maximum pairing” algorithm connects the contours with highest pairing (https://en.wikipedia.org/ wiki/Jaccard_index). 3. A bipartite graph was created. Then, an assignment was created with the help of the “Hungarian method”, max- imizing the overall IOU sum (https://en.wikipedia.org/ wiki/Hungarian_algorithm). 4. The result of the “Hungarian algorithm” linked the contours with the tracking list. On figure 4, there are images of the same animal, where different colors visualize the previous and next contours (red and green contours). On the picture, the topmost value is the predicted weight, the values below represent the values of different features. PCP The Pretty Contour Picker’s (PCP) is a service to filter out contours which are not to be used for weight estimation, through flagging all of them. Contours are considered faulty if features can only be calculated on them in a way different from usual, the precise method is described in the “Featurizer” part. This can happen if a pig is situated on the edge of an image, or it is in an unusual position. PCP is based on a Multi- Layer Perceptron (MLP) architecture and allows operators to determine the position and shape of a pig contour. The following parameters were determined using MLP and some algorithmic evaluation: Figure 3: Calibration of a camera by means of A4 paper We chose a specific camera which would serve as the standard image. The scaling for this camera was [1,1] (we cal- culated both x and y scaling factors). For all other cameras we calculated the scaling factor to get the same pixel length for the same object, no matter the camera type. For this purpose, we computed how many mm we had in one pixel (standard A4 paper has 210×297 mm size, its area is 62370 mm2). Next, we measured the pixel size of the A4 on the photo under the camera. The CMOS sensor size was a critical piece of informa- tion, as this parameter determined the field of view of the camera. With larger field of view (and same resolution) the same A4 paper hasless pixels, so the whole scaling should be decreased by the difference in cmos sensor. As such, the whole difference between lenses could be formalized as: • diff_lens= scaling + diff_cmos • scaling = diff_lens – diff_cmos The diff_cmos is the difference between cmos sensor size to the second power. To calculate the scale factor of length, we should take root of the scaling. Here is an example for two cameras. Camera1 has 1/2.8” CMOS sensor, the A4 paper sizes are [159,222], the camera2 has 1/2.7” CMOS sensor, the A4 paper sizes are [110,158]. The scaling factor would be: • scaling = (159×222)/(110×158) – ((2.82 − 2.72)/2.82)=1.96 The linear scaling factor would be: • linear_scaling = √scaling = √1.96 = 1.4 Pig Weight Estimation According to RGB Image Analysis 55 • is_in_middle – the fisheye distortion of the camera on the edges of the picture is too strong to be able to estimate the animal’s weight precisely • is_lied_down – is the animal standing or lying • has_leg – is a leg visible under the spine For weight estimation we use only contours where • is_in_middle = True • is_lied_down = False • has_leg = False As mentioned previously, during segmentation, the Mask R-CNN model had been already trained to classify the contours based on their shape and color. In most cases, it was capable to separate unreliable data from useful ones. When it failed, the PCP served as our “backup” to make sure that the contour is useable. Featurizer The Featurizer algorithmically fits features on the detected contours. To successfully accomplish this, it first matches a „Pig Model” to each contour. The model consists of a head, a shoulder, a belly and a rump part. The model’s parts consist of six primitive shapes: (i) circle (tail, hip); (ii) oval (back, stomach); (iii) circle (shoulder) and (iv) rectangle with two triangles (neck, head), the size of which may differ for higher precision fitting. Once the model was fitted to the contour, features are easily calculated based on the pigs’ assumed orienta- tion and the positions of the model’s parts. The following features were extracted: hip width, waist width, stomach width, „heart” width (the width of the animal’s back below shoulder), shoulder width, total length (from neck to hip), contour area (only in Model V3), and contour perimeter (only in Model V3). There is an image of an animal on Figure 5 with estimated weight, calculated feature lengths. Figure 4: Different contours of the same animal with different feature values and different estimated weight Figure 5: Visualisation of different features Weight Estimator The weight estimator, similarly, to the PCP, is based on MLP architecture. The architecture’s size and its parameters have been finetuned. The training data was calculated on previously segmented images, which were used for training the Mask R-CNN network, while the input data were the features that had been calculated previously in the pipeline by the Featurizer. The data was scaled to a specified minimum and maximum range and was augmented by creating extra inputs in a way so that it contains equally sized weight groups. Features were checked for importance; irrelevant features have been excluded from the training process for example: width of neck, max contour length. We chose the most appropriate input vector by adding attributes to the training process one by one until the results were improved. Given the relatively small size of the dataset with only a few features, we used Early Stopping to avoid over- fitting. We used Tensorboard to monitor the training process and chose the best performing model. Multiple models with differing layer sizes, types, activation functions were tested. Precision was evaluated by calculating the percentage-based deviation between the predicted and actual values. For this purpose, a “validation” dataset was used. On Figure 6, the actual data is compared with our predictions with respect to the validation dataset. Outliers can be ignored which further improves precision-focused efforts. Pig Weight Estimation According to RGB Image Analysis 56 • average daily weight of the pigs, and • individual weight estimation. Knowing the average weight of all pigs in the pen is critical. However, this information is not enough to decide when and how many pigs should be sent to the slaughter- house – we had to calculate the standard deviation of the weight estimations and learnt the exact number of animals in the pen. The average weight was calculated as average of the aforementioned pig weight estimations. We defined a derived parameter, average accuracy, which we calculated using equation: 1− ABS d a ( ) (1) where ’d’ was the difference of our calculated average weights from the measured average weights and ’a’ was our calculated average weight. RESULTS In this experiment RGB based image analysis was established to estimate the pig weight according to the contour of the animals. A 100-day long rotation was monitored following the weight change of the animals. Average weight estimation During the investigated period, the lowest accuracy of the system was 95.72% (Model V1 on 8 September 2020 at 54.77 kg weight), while the highest accuracy was achieved with 99.91% (Model V3 on 30 September 2020 at 80.5 kg). Overall accuracy of the models was 98.54%, 98.63% and 97.94% for the three model V3, V2, and V1 respectively. Table 1 indicates that although version 3 (V3) had the highest number of precise days, it could not be regarded as reliable due to inconsistencies on certain days (2020.08.25., 2020.10.16.). Version 1 (V1) was mostly accurate; however, it predicts poorly on larger weights (end of rotation). Version 2 (V2) was preferred due to its overall consistency and highest average accuracy. The actual weight of each animal was measured manually by means of analog weight (Demandy AM02-da-22). Individual weight estimation Knowing the actual weight of all pigs in the pen allowed us to calculate how well the models estimated the weight of these pigs individually. In Table 2, the three different versions of pipelines are shown, where first row represent the manually measured weight of each pig for the given day, Figure 6: Weight estimator validation Weight Aggregator With the use of tracking, it became possible to predict the weight of a single pig multiple times by assigning identification for each animal. This technique allowed us to analyze the predictions, the minimum and maximum value of a series of predictions on the same animal and its deviation. Our main goal was to estimate the daily average weight and standard deviation of all pigs in a pen. The daily weight estimation consisted of five steps: (i) Get all weight data from all cameras for the specific pen for the specific day, (ii) Get all image metadata for these weights, (iii) Get all tracking data for all images from point 2, (iv) for weights associated to the same tracking get the average of this weights, and (v) Get the average weight and standard deviation for this dataset. Applied models We evaluated three different models as follows. • Model V1 used the basic versions of the services. • Model V2: the weight estimator has been trained on a training set, which contained more examples of large weights. • Model V3: this method used an alternative version of feature extractor, which extracted not only the length and width of the pig in different points but also the area and perimeter of the contour. The microservice architecture approach allowed us to compare different approaches with little effort, as only 1-2 services should be modified for creating a new model version while all other services stayed intact. On Figure 7, the micro- services and the data flow between them is visualized. All three models were compared from the two perspec- tives below: Pig Weight Estimation According to RGB Image Analysis 57 while underneath the tracked, grouped, and averaged weight figures of each pig is indicated. The % row contains the weight deviation of the calculated weights from the measured one. Highest accuracy was achieved in the case of Model V2 as it provided 99.9% correct weight prediction at 73 kg of the pig in the end of the rotation. The lowest accuracy was recorded in the case of Model V3 at 47.5 kg pig weight as the value was 93.4%. According to the patterns of differences, the system is less accurate when the pigs have lower weight. Similarly, to the daily average calculation, we also eval- uated the aggregated results, over every day of the rotation. The results can be seen in Table 3. Each row represents a day when pigs were measured on a scale. The “Mean” column contains the average precision values of the given pipeline on the given day of the rotation. The “Min” column shows the least accurate precision figures on the given day and “Max Diff” numbers indicate the corresponding deviation. Similar- ly, to average weight computation, the Model V1 is particu- larly accurate regarding small weight figures, while Model V3 did not deliver reliable results. The Model V2 performs best at the average weight over 110 kg, as it was expected. DISCUSSION Given the increasing farm sizes in livestock production, there is a growing need for automatization in feeding, and evaluation of the pig weight has been of rising importance (Milligan et al., 2001; 2002; Szabó and Bilkei, 2002; Wongsriworaphon et al., 2015; Shi et al., 2016) yet it is highly time consuming and stressful for the animals. Several studies showed that no-contact weight estimation could be a solution to address animal stress. For this reason, several image analysis systems Figure 7: RGB pig weight estimation pipeline Table 1: Example of daily average calculation Date of measurement Real pig weight (kg) Model V3 Model V2 Model V1 2020.08.25. 40.27 96.43% 98.04% 99.45% 2020.09.01. 46.0 97.59% 98.33% 98.51% 2020.09.08. 54.77 98.24% 97.12% 95.72% 2020.09.15. 60.6 98.97% 99.59% 98.98% 2020.09.22. 68.46 98.76% 97.11% 96.48% 2020.09.30. 80.5 99.91% 98.06% 97.82% 2020.10.06. 85.68 99.65% 99.47% 99.45% 2020.10.16. 99.6 96.96% 98.95% 99.17% 2020.10.20. 104.3 97.68% 99.50% 99.83% 2020.10.27. 113.6 99.82% 99.61% 97.85% 2020.11.03. 122.6 99.84% 98.91% 96.19% 2020.11.11. 119.20 98.64% 98.89% 95.83% Overall mean 98.54% 98.63% 97.94% Pig Weight Estimation According to RGB Image Analysis 58 Table 2: Example of individual weights calculation for day 2020.09.15. Real pig weight (kg) 44.5 47.5 51.5 54.5 58.5 60.0 61.5 64.0 65.0 65.5 65.5 73.0 Model V1 prediction (kg) 44.3 50.11 52.51 54.96 57.54 60.21 61.61 63.39 64.04 65.18 66.62 74.04 Difference (kg) 0.20 −2.61 −1.01 −0.46 0.96 −0.21 −0.11 0.61 0.96 0.32 −1.12 −1.04 Accuracy (%) 99.5 94.5 98.0 99.1 98.3 99.6 99.8 99.0 98.5 99.5 98.2 98.6 Model V2 prediction (kg) 42.58 48.59 52.44 54.76 58.36 60.24 61.21 62.6 63.65 64.45 65.69 72.97 Difference (kg) 1.92 −1.09 −0.94 −0.26 0.14 −0.24 0.29 1.40 1.35 1.05 −0.19 0.03 Accuracy (%) 95.6 97.7 98.1 99.5 99.8 99.6 99.5 97.8 97.9 98.4 99.7 99.9 Model V3 prediction (kg) 44.17 50.63 52.86 55.33 57.32 59.02 59.88 61.63 62.49 63.54 64.71 72.39 Difference (kg) 0.33 −3.13 −1.36 −0.83 1.18 0.98 1.62 2.37 2.51 1.96 0.79 0.61 Accuracy (%) 99.3 93.4 97.4 98.5 97.9 98.4 97.4 96.3 96.1 97.0 98.79 99.2 Table 3: Example of Individual weights averaged over the whole rotation Date Real pig weight (kg) Model V3 Model V2 Model V1 Mean (kg) Min (kg) Max diff. (kg) Mean (kg) Min (kg) Max diff. (kg) Mean (kg) Min (kg) Max diff. (kg) 2020.08.25. 40.27 0.96 0.92 3.2 0.97 0.93 2.24 0.97 0.93 2.1 2020.09.01. 46.0 0.97 0.93 3.24 0.98 0.95 2.56 0.98 0.95 2.09 2020.09.08. 54.77 0.98 0.95 2.47 0.96 0.92 4.08 0.96 0.91 4.62 2020.09.15. 60.6 0.98 0.94 2.61 0.98 0.96 2.25 0.97 0.93 3.13 2020.09.22. 68.46 0.96 0.94 4.25 0.96 0.91 4.82 0.96 0.93 4.5 2020.09.30. 80.5 0.98 0.95 3.7 0.97 0.95 3.83 0.97 0.95 4.25 2020.10.06. 85.68 0.98 0.91 5.93 0.98 0.90 6.91 0.98 0.93 5.05 2020.10.16. 99.6 0.96 0.91 9.67 0.97 0.93 5.59 0.98 0.96 4.01 2020.10.20. 104.3 0.98 0.94 6.64 0.97 0.93 5.72 0.98 0.95 4.49 2020.10.27. 113.6 0.98 0.93 9.16 0.98 0.96 5.57 0.97 0.94 6.45 2020.11.03. 122.6 0.98 0.97 3.79 0.98 0.96 5.42 0.96 0.93 8.25 2020.11.11. 119.20 0.98 0.94 6.61 0.99 0.95 5.54 0.96 0.93 8.01 were developed (Li et al., 2014). Accuracy of these systems are high with help of advanced technology and data evaluation. He et al. (2021) applied 3D image (depth images) based system that could eliminate the influence of the envi- ronment and achieved 95.1% average accuracy on the test dataset, where the accuracy ranged from 89.5% to 100%. Zhang et al. (2021) investigated the body length, shoulder width, shoulder height, hip width, and hip height using a multiple output regression convolutional neural network and found that coefficient of determination between the estimated and measured data ranged between 0.9879–0.9973. In this study, we tested different models according to most important information we could give for end users: average weight of the pen and individual weight estimation in the pen. We have created a robust, scalable model which could automatically predict the weight of pigs with on average >97% accuracy. Changes and improvements could be easily made to the system thanks to the microservice architecture. The RGB image-based system is affordable to install and easy to use which makes it highly valuable to any farmer. It offers a fast and stress-free method of measuring pig weights which can be useful in determin- ing food amount and type used or when a pig is ready to be slaughtered. Using of a specific contour classifier (PCP) helps us discard all contours which we cannot reliably use for feature extraction: pigs lying on their side, and “chunks” of animals which are visible under other pigs. Our experi- ence shows that there are seemingly valid contours that the PCP does not discard. But they are also damaged – they contain only part of the pig, because shadows are casted on the animal, or one animal covers the other. The outliers are managed with the help of tracking through which we filtered these figures. The Model V1 performed well, though it was clear that as the average weight of the pigs grew the overall accuracy of the weight estimator decreased. We annotated a few larger pigs and retrained our model. As a result, this Model V2 was performed way better with respect to the larger pigs and was overall better in our opinion. The Model V3 did not fulfill our expectation as to more data on the animal improves the accuracy of the weight estima- tor neural network. Though there was a high correlation between contour area, parameter and weight of the pig, the Pig Weight Estimation According to RGB Image Analysis 59 area and the perimeter have excessive deviation to help us to estimate the pig weight more accurately. There are still a lot of possibilities to improve the accuracy of the models. More training data can be collected to train a new model or more images can be acquired from the camera to get more weight data. The main bottleneck of the model is the server, which has limited resources. One may look for more efficient neural network architectures which requires less calculations therefore it is possible to collect more data from a camera per day to improve the overall accuracy. CONCLUSION Precision livestock farming technologies play and important role in the pig production. To reduce the stress during the weight estimation and fasten the process, several methods were introduced in the past years. In this experiment an RGB image-based weight estimation technique was developed and tested with different camera types, and data evaluation methods. Our findings showed great potential of remote sensing-based methodology to accurately predict the weight of pigs. We consider that the technology would provide valuable information for the farmers. The system needs to be tested on other pig fattening facilities with different camera setups, feeders and lightening conditions. Acknowledgements This work and the ‘PigBrother’ project were supported by the European Agricultural Fund for Rural Development. Project number: 1862424254. We thank Péter Bodor-Pesti for the helpful contribution with his useful comments on the earlier draft. REFERENCES 1. Andonovic, I., Michie, C., Cousin, P., Janati, A., Pham, C., & Diop, M. (2018). Precision livestock farming technologies. In 2018 Global internet of things summit (GIoTS) 1-6. 2. Aquilani, C., Confessore, A., Bozzi, R., Sirtori, F., & Pugliese, C. (2022). Precision livestock farming technologies in pas- ture-based livestock systems. Animal, 16(1), 100429. 3. He, H., Qiao, Y., Li, X., Chen, C., & Zhang, X. (2021). Automatic weight measurement of pigs based on 3D images and regression network. Computers and Electronics in Agriculture, 187, 106299. 4. He, K., Gkioxari, G., Dollár, P., & Girshick, R. (2017). Mask R-CNN. 2017 IEEE International Conference on Computer Vision (ICCV). Venice, Italy. 2980-2988. 5. Kalman, R. (1960). A New approach to linear filtering and prediction problems. ASME Journal of Basic Engineering, 82, 35-45. http://dx.doi.org/10.1115/1.3662552 6. Kalman, R. E., & Bucy, R. S. (1961). New results in linear filtering and prediction theory. Journal of Basic Engineering, 83, 95-108. 7. Kongsro, J. (2014). Estimation of pig weight using a Microsoft Kinect prototype imaging system. Computers and Electronics in Agriculture, 109, 32-35. 8. Li, Z., Luo, C., Teng, G., & Liu, T. (2014). Estimation of pig weight by machine vision: A review. In D. Li, Y. Chen (eds), Computer and computing technologies in agriculture VII. CCTA 2013. IFIP Advances in Information and Communica- tion Technology, vol 420. Springer, Berlin, Heidelberg. https:// doi.org/10.1007/978-3-642-54341-8_5 9. Lin, T., Maire, M., Belongie, S. J., Bourdev, L. D., Girshick, R. B., Hays, J., Perona, P., Ramanan, D., Dollár, P., & Zitnick, C. L. (2014). Microsoft COCO: common objects in context. CoRR abs/1405.0312 10. Milligan, B. B., Fraser, D., & Kramer, D. L. (2001). Birth weight variation in the domestic pig: effects on offspring survival, weight gain and suckling behaviour. Applied Animal Behaviour Science, 73(3), 179-191. 11. Milligan, B. B., Fraser, D., & Kramer, D. L. (2002). Within-litter birth weight variation in the domestic pig and its relation to pre-weaning survival, weight gain, and variation in weaning weights. Livestock Production Science, 76, 181-191. 12. Mollah, M. B. R., Hasan, M. A., Salam, M. A., & Ali, M. A. (2010). Digital image analysis to estimate the live weight of broiler. Computers and Electronics in Agriculture, 72(1), 48-52. 13. Pezzuolo, A., Milani, V., Zhu, D., Guo, H., Guercini, S., & Marinello, F. (2018). On-barn pig weight estimation based on body meas- urements by structure-from-motion (SfM). Sensors, 18(11), 3603. 14. Shi, C., Teng, G., & Li, Z. (2016). An approach of pig weight estimation using binocular stereo system based on LabVIEW. Computers and Electronics in Agriculture, 129, 37-43. 15. Stafford, J. V. (2000). Implementing precision agriculture in the 21st century. Journal of Agricultural Engineering Research, 76(3), 267-275. 16. Swerling, P. (1958). Note on the minimum variance of unbiased estimates of Doppler shift, Tech. report, The RAND Corporation. 1700 Main st. Santa Monica, California, USA. pp. 6. 17. Szabó, P., & Bilkei, G. (2002). Iron deficiency in outdoor pig production. Journal of Veterinary Medicine Series A, 49(7), 390-391. 18. Szabo, S., & Alexy, M. (2022). Practical aspects of weight measurement using image processing methods in waterfowl production. Agriculture, 12(11), 1869. 19. Wongsriworaphon, A., Arnonkijpanich, B., & Pathumnakul, S. (2015). An approach based on digital image analysis to estimate the live weights of pigs in farm environments. Computers and Electronics in Agriculture, 115, 26-33. 20. Zhang, J., Zhuang, Y., Ji, H., & Teng, G. (2021). Pig weight and body size estimation using a multiple output regression con- volutional neural network: A fast and fully automatic method. Sensors, 21(9), 3218. 21. Zude-Sasse, M., Fountas, S., Gemtos, T. A., & Abu-Khalaf, N. (2016). Applications of precision agriculture in horticultural crops. European Journal of Horticultural Science, 81(2), 78-90 Pig Weight Estimation According to RGB Image Analysis 60 Ocena teže prašičev z analizo slike RGB IZVLEČEK V prašičereji je poznavanje dejanske telesne mase posamezne živali ključnega pomena za rejca. Tovrstne informacije lahko pomagajo določiti ustrezno količino in vrsto krme za določenega prašiča pitanca. Tehtanje prašičev je bilo že od nekdaj problematično, saj je zamudno, priganjanje prašičev na tehtnico pa je tudi izjemno naporno. Poleg tega je postopek tehtanja za živali stresen. Cilj te raziskave je bil vzpostaviti RGB sistem, s katerim bi lahko ocenili dnevno telesno maso vseh prašičev in telesno maso posamezne živali. Raziskava je bila zastavljena v 100-dnevni rotaciji na komercialni prašičji farmi, kjer smo spremljali 32 prašičev. Razvili smo sistem za prepoznavanje značilnosti prašičev in sicer na predelu glave, pleč, trebuha in zadnjega dela telesa. Preizkušeni so bili trije različni modeli, pri čemer so bile glavne razlike med njimi povezane z obdelavo slike in kalibracijskimi podatki. S pomočjo modelov smo dobili več kot 97% ujemanje med telesno maso, napovedano z RGB modelom in ročno zabeleženo maso živali. V raziskavi razviti sistem rejcu omogoča, da upravlja in spremlja svoje prašiče z uporabo spletnega vmesnika, na osnovi česar lahko sprejema ključne odločitve v procesu reje. Ključne besede: obdelava slik, velikost prašiča, sistem za podporo pri odločanju, precizna živinoreja