ABSTRACT
The increase in the number of free-range breeders in Canela-Preta strengthens the Brazilian poultry industry, mainly in terms of biosafety, health and quality of the animals. Therefore, it is necessary to identify these chickens using modern and non-invasive techniques, thus, this study aimed to develop a computer vision algorithm based on artificial intelligence to identify Canela-Preta chickens using images. An accuracy rate of 86.54% and similarity of 99.58% were obtained using YOLO (you only look once) for detection and template matching for identification. It was concluded that the individual identification of free-range Canela-Preta chickens using the proposed methodology was accurate.
Keywords:
artificial intelligence; Canela-Preta chicken; Convolutional neural network; template matching; YOLO
RESUMO
O aumento do número de criadores de galinhas caipiras em Canela-Preta fortalece a avicultura brasileira, principalmente em termos de biossegurança, saúde e qualidade dos animais. Assim, este estudo teve como objetivo desenvolver um algoritmo de visão computacional baseado em inteligência artificial para identificar frangos da raça Canela-Preta por meio de imagens. Foram obtidas uma taxa de precisão de 86,54% e uma similaridade de 99,58% usando YOLO (you only look once) para detecção e correspondência de modelos para identificação. Concluiu-se que a identificação individual de galinhas Canela-Preta criadas ao ar livre usando a metodologia proposta foi precisa.
Palavras-chave:
inteligência artificial; frango Canela-Preta; rede neural convolucional; correspondência de modelos; YOLO
INTRODUCTION
In the 1930s, poultry farming showed considerable progress in Brazil, so that the native breeds were endangered. However, in 1980, the demand for native breed products increased due to the valuation of natural products and the rusticity of native birds, which are suitable to be raised in extensive systems (Carvalho et al., 2016). Among the so-called native breeds that emerged in Brazil, we can mention the Canela-Preta chickens, which are mostly present in the northeast region. Despite traditionally being raised by smallholders in Piauí with low or no technological investment, Canela-Preta chickens became an object of institutional interest only in 2008 (Carvalho et al., 2020).
The increase in the number of Canela-Preta free-range chicken breeders strengthens poultry farming in Brazil, especially in terms of biosecurity, health, and quality of the animals. Therefore, it is necessary to identify those chickens using modern and non-invasive techniques, such as Artificial Intelligence and Pattern Recognition based on convolutional neural networks (CNN) for image processing. CNN are particularly effective in extracting the appropriate features from a set of training images without the need for manual extraction (McCool et al., 2017; Rahnemoonfar and Sheppard, 2017).
The number of published reviewed articles demonstrates the interest and rapid development of learning algorithms as the main image analysis framework in computer vision systems for livestock species of economic interest, especially cattle and swine (Oliveira et al., 2021). Despite the high accuracy reported in the literature, the correct individual identification of animals based only on RGB (red, green, blue) images can be challenging. The amount of information loaded in a single image usually exceeds the primary interest of the developer when creating computer vision systems. The amount of information in the image can allow for future development as new ideas are created and more sophisticated data analysis tools become available.
Several studies have reported the identification of animals from different species. For example, Hansen et al. (2018) used various techniques for pig face recognition. In that study, the authors applied algorithms such as Fisherfaces, a pre-trained facial CNN, and their own convolutional neural network, which achieved the highest accuracy in pig identification. Similarly, Salama et al. (2019) conducted facial identification of sheep using their own CNN with data augmentation. Shen et al. (2020) proposed a method for identifying cows using side-view images. In this case, the YOLO (You Only Look Once) network, two convolutional neural networks, and data augmentation techniques were used to classify each individual.
Deep learning algorithms for computer vision systems, such as Mask R-CNN, Faster R-CNN, YOLO, DeepLab, and U-Net, among others, have been used to detect and identify individuals and/or objects through images (Oliveira et al., 2021). Nevertheless, in the identification of free-range poultry, this approach is still incipient. Thus, the objective of the current study was to develop and evaluate computer vision algorithms for the individual identification of Canela-Preta chickens using CNN, YOLO, and template matching.
MATERIALS AND METHODS
The experimental procedures carried out in this study were approved by the Committee on Ethics in the Use of Animals (CEUA) of the Federal University of Piauí (UFPI), Brazil (protocol number 692/2021).
For this experiment, we collected images of 167 healthy free-roaming Canela- Preta hens raised on the Débora Carvalho Farm, located in the rural settlement Resistência Camponesa, in the municipality of Demerval Lobão, PI, Brazil. The experimental birds were distributed into two groups of individuals with predominant ages of 6 and 15 months and average weight of 1,591kg. The birds were dewormed and vaccinated against Newcastle and Gumboro diseases, infectious bronchitis, fowl pox, and avian infectious coryza. Each vaccine was administered according to the protocol used on the farm. Each hen was restrained for 10 seconds to capture the images in three different planes (Fig. 1). For this, a Canon digital camera, model T5i, 18-55 mm lens was used.
A total of 501 images with the dimensions (height and width) 1280×1920 113 pixels were collected. Subsequently, unusable images of 11 individuals were discarded, that is, 33 pictures were deleted due to their low quality (Fig. 2). Therefore, the image database used for the analyses contained 468 images of 156 chickens.
Two methods were used for the identification of Canela-Preta chickens. In the first method, a convolutional neural network was used to identify each hen in the database (Fig. 3).
In the second method, the YOLO network was used for chicken detection and then the image bounding box was extracted. Finally, each hen was identified using template matching (Hashemi et al., 2016), as shown in Fig. 4.
For identification via CNN, 468 images of the right side, frontal and left side planes of 156 chickens were used. The database used for identification of Canela-Preta chickens using CNN was distributed at 64% for training, 16% for validation, and 20% for testing.
The same label was assigned for each image of a certain chicken in order to allow the network to identify that the images belonged to the same individual. Therefore, random numbers ranging from 1 to 156 were randomly generated for each individual.
The labels were represented by integer numbers and were categorized, that is, transformed into the data format, labeling each image to insert them into the network. Details of the CNN architecture used are shown in Table 1.
The network was composed of five convolutional layers with 3×3 and 2×2 kernels with rectified linear unit (ReLU) activations, five max pooling layers with 2×2 kernels and two fully connected layers with ReLU and softmax activations.
The input images were resized to 416×416 and the CNN was trained using the Adam optimizer with a learning rate of 0.001, using eight batches and 100 epochs. The categorical cross-entropy loss function was used in the last classification layer. Hyperparameter tuning was performed by varying the number of epochs, input image dimensions, and batch size.
Only the 156 images of the frontal plane were used for identification using template matching. The following steps were performed to apply template matching: i) extraction of the bounding box region of the chicken detected using YOLO; ii) recognition of the individual extracted using template matching based on normalized correlation coefficient.
YOLO version 3 Redmon et al. (2016) was used for chicken detection. It is important to mention that YOLO v3 is an algorithm with high performance and speed of detection of small objects.
The YOLO v3 pre-trained weights were initially stored on COCO dataset (Lin et al., 2014) for chicken detection. Since the pre-trained model performs the detection of chickens, it was not necessary to train the YOLO network. After detection, the images were cropped and sent as templates for the next identification step using template matching.
The extraction was performed to crop the region of interest from the image, starting from the detected bounding box. This process was performed to crop the neck and head regions of the chickens delimited in the images (Fig. 5), and served as input for chicken identification.
(a) Image of Canela-Preta chicken detected and its bounding box; (b) 435 Image of Canela-Preta chicken cropped from (a) delimited by the bounding box.
Of the 156 images of the frontal plane of chickens, 21 images were not detected by the YOLO network. Thus, for identification via template matching, we used 135 frontal images obtained after the detection performed to train the algorithm. Images of the detected chickens (templates) were used to identify each hen in the database (search).
The algorithm was used to find in the database the image that corresponds to the template image of the chicken. For this, the algorithm used normalized cross- correlation to measure the degree of similarity between images in the database.
The algorithm performed a database scan comparing each template image looking at each pixel in the search image and storing the computed result metric. Subsequently, this metric was normalized to detect the most correlated points in the image.
The minMaxLoc function was used to find the minimum and maximum values, which indicate the best matches, thus drawing a bounding box in the image where the points are at a larger scale. After a chicken image (template) was evaluated using template matching, the resulting image corresponding to that chicken template was compared to all the images in the database. The image of a hen identified via template matching using normalized cross- correlation is shown in Fig. 6.
This metric was used to evaluate chickens correctly classified using the convolutional neural network. In this case, accuracy can be defined as the ratio between the number of chickens correctly classified and the total number of predictions made. We calculated accuracy using the equation below.
in which: TC is the true classification of chicken; TN represents the true classification of non-chicken; FC is the false classification of chicken; FN is the false classification of non-chicken.
The mean absolute deviation (MAD) is the average of the absolute differences between the predicted and actual values of the chickens. In this case, all individual differences are given equal weight, and the direction of the error is not considered.
in which: N is the number of chickens; yi is the real value of each hen; ŷi is the predicted value of each hen.
This metric was used to evaluate the similarity between the templates of each hen and all search images in the database. The normalized cross correlation was calculated using the equation below.
in which: R(x,y) is the resulting matrix; T(x,y) represents the position of pixels in the template; I(x,y) is the position of pixels in the search image.
For the development of algorithms, we used a virtual cloud environment that provides graphics processing unit and 16GB of RAM. The chicken detection was performed using CNN and YOLO neural network, whereas the template matching was used for chicken identification. The Python programming language and the following Python libraries were used: TensorFlow (Goldsborough, 2016); Keras (Gulli and Pal, 2017); OpenCV (Culjak et al., 2012).
RESULTS
A database containing 468 images of chickens in three different planes was used to apply CNN. The number of images for training, validation, and testing are shown in Table 2.
The CNN model accuracy was 40% in the validation dataset (Figure 7). During the training, the accuracy values increased in each step. Meanwhile, the validation accuracy value remained constant from epoch 30 onwards.
It was observed that the network was overfitted, probably due to the number of images used in network training, since CNN have several parameters to be trained and, therefore, several images are required for training. It is also important to mention that when the training accuracy value is high, but the validation accuracy is low, the network is probably only memorizing training data that are not relevant for a more inclusive image classification.
In this step, we analyzed the number of chickens detected or not by YOLO in the images that showed the frontal plane of the chickens (Table 3). The YOLO network showed accuracy of 86.54%.
The identification of Canela-Preta chickens using template matching was efficient with average similarity of 99.58%, mean error of 0.42%, and accuracy of 86.54% (Table 4).
The accuracy and MAD were also used for analyzing the algorithm performance, as shown in Table 4. The accuracy was used to evaluate the number of images of chickens correctly identified using template matching. Meanwhile, the MAD metric was used to evaluate the average similarity in the identification of the Canela-Preta chickens in study. The values obtained were sufficient for identification of the chickens in the images.
DISCUSSION
The identification via CNN used all the search images available; however, no satisfactory result was obtained in the classification of individuals. These results showed low accuracy, probably due to the low number of images obtained for training.
In a study to identify dairy cows through lateral view images using their own database, Shen et al. (2020) used information of 105 different individuals and the data augmentation approach, which generated a total of 82,633 images. In the aforementioned study the authors used the YOLO network to detect cows in the images and an AlexNet convolutional neural network for image classification.
Second Hansen et al. (2018) proposed different methods for the facial identification of pigs using their own database and data augmentation techniques, which allowed them to obtain 1,553 images of 10 individuals. In this case, the convolutional neural network was the most efficient method, with accuracy of 96.7%.
In a study for facial identification of sheep, Salama et al. (2019) used images of 52 animals. For each sheep, 1,000 images were generated after data augmentation, resulting in a total of 52,000 images. In the aforementioned study, a convolutional neural network was created for the sheep classification, which generated a model that achieved 98.0% accuracy.
The main differences between the approaches applied in the studies mentioned above (Table 5) and the method used in the current study were the data augmentation techniques and animal species. In the present study, template matching reached 99.58% of similarity and overcame the convolutional neural network in the identification of Canela-Preta chickens. This result was observed especially due to the lower complexity in image processing performed using template matching.
It is important to mention that template matching compared two images (template and search) to indicate a certain correspondence between them. On the other hand, the convolutional neural network needs a sufficient number of images along with other parameters for classification of chickens. It is also noteworthy that the data augmentation technique was not used in this study for two reasons. Firstly, because the deformation of image structures could be significantly affected by pre-processing, leading to the loss of relevant information and compromising the learning of the convolutional neural network.
The second reason is that the large number of images to be trained would increase the computational cost, thus leading to costly training and probably more hardware and software requirements. The method proposed here reached accuracy of 86.54% in the identification of Canela-Preta chickens. No studies related to chicken identification using images were found in the literature. Therefore, we compared our findings to those reported in other animal species.
Differently of our work, in which we used only original images, the studies reported in other species used image data augmentation techniques to expand the size of the datasets. Therefore, we believe that accuracy tends to increase when data augmentation is used.
CONCLUSIONS
It was possible to identify Canela-Preta chickens using the proposed algorithm. This will expand the understanding of bird identification from images, thus contributing to the development of computational tools based on artificial intelligence.
ACKNOWLEDGEMENTS
This study was partially funded by the Coordenação de Aperfeiçoamento de Pessoal de Nível Superior (CAPES).
REFERENCES
- CARVALHO, D.A.; BONAFÉ, C.M.; RODRIGUEZ-RODRIGUEZ, M.D.P. et al. Caracterização genética e estrutura populacional de galinhas crioulas Canela-Preta. Pesqui. Agropecu. Bras., v.51,p.1899-1906, 2016.
- CARVALHO, D.A.; MARTÍNEZ, A.M.; CAROLINO, I. et al. Diversity and genetic relationship of free-range chickens from the northeast region of Brazil. Animals, v.10, p.1857, 2020.
- CULJAK, I.; ABRAM, D.; PRIBANIC, T.; DZAPO, H.; CIFREK, M. A brief introduction to OpenCV. In: INTERNATIONAL CONVENTION MIPRO, 35., 2012, Opatija. Proceedings… Opatija, Croatia: IEEE, 2012. p.1725-1730.
-
GOLDSBOROUGH, P. A tour of TensorFlow. arXiv preprint arXiv.1610.01178. 2016. Available in: https://arxiv.org/pdf/ 1610.01178.pdf Accessed in: 25, jun, 2025.
» https://arxiv.org/pdf/ 1610.01178.pdf - GULLI, A.; PAL, S. Deep learning with Keras. [s.l.]: Packt Publishing Ltd, 2017.
- HANSEN, M.F.; SMITH, M.L.; SMITH, L.N. et al. Towards on-farm pig face recognition using convolutional neural networks. Comput Ind., v.98, p.145-152, 2018.
- HASHEMI, N.S.; AGHDAM, R.B.; GHIASI, A.S.B.; FATEMI, P. Template matching advances and applications in image analysis. arXiv preprint arXiv:1610.07231. Am. Sci. Res. J. Eng. TechnolSci., v.26, p.91-108, 2016.
- LIN, T.Y.; MAIRE, M.; BELONGIE, S. et al. Microsoft COCO: common objects in context. Eur. Conf. Comp. Vision, v.8693, p.740-755, 2014.
- McCOOL, C.; PEREZ, T.; UPCROFT, B. Mixtures of lightweight deep convolutional neural networks: applied to agricultural robotics. IEEE Robot. Autom Lett., v.2, p.1344-1351, 2017.
- OLIVEIRA, D.A.B.; PEREIRA, L.G.R.; BRESOLIN, T. et al. A review of deep learning algorithms for computer vision systems.. Livest. Sci., v.253, p.104-700, 2021.
- RAHNEMOONFAR, M.; SHEPPARD, C. Deep count: fruit counting based on deep simulated learning. Sensors, v.17, p.905, 2017.
-
REDMON, J.; DIVVALA, S.; GIRSHICK, R.; FARHADI, A. You only look once: unified, real-time object detection. In: CONFERENCE ON COMPUTER VISION AND PATTERN RECOGNITION, 2016. Proceedings… [s.l.]: IEEE / CVPR, 2016. p.779-788. Available in: http://pjreddie.com/yolo/. Accessed in: 25, jun, 2025.
» http://pjreddie.com/yolo - SALAMA, A.; HASSANIEN, A.E.; FAHMY, A. Sheep identification using a hybrid deep learning and Bayesian optimization approach. IEEE, v.7, p.31681-31687, 2019.
- SHEN, W.; HU, H.; DAI, B. et al. Individual identification of dairy cows based on convolutional neural networks. Multimed Tools Appl., v.79, p.14711-14724, 2020.














