A deep learning-based yak face detection and recognition method
By employing a multi-strategy heterogeneous detection method, combining YOLO, HSV color space, and Canny edge detection, the problem of detection accuracy and adaptability of a single deep learning model in complex environments during yak farming at high altitudes was solved. This resulted in high-precision yak face recognition with a low false detection rate, adapting to complex pastoral environments and reducing the need for labeled data.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- XICHANG COLLEGE
- Filing Date
- 2026-02-12
- Publication Date
- 2026-06-05
- Estimated Expiration
- Not applicable · inactive patent
AI Technical Summary
In yak farming at high altitudes, existing technologies struggle to simultaneously guarantee high accuracy, rapid detection, and adaptability in complex pastoral environments using a single deep learning model, and obtaining high-quality labeled data is also difficult.
A multi-strategy heterogeneous detection method is adopted, which combines YOLO, HSV color space and Canny edge detection, and executes multiple detection algorithms in parallel. Feature extraction and classification are performed through cross-union ratio fusion and an improved ResNet network to output structured data.
It significantly improves detection accuracy and recall, reduces false positive rate, enhances system environmental adaptability and computational efficiency, reduces dependence on labeled data, and supports subsequent analysis and system optimization.
Smart Images

Figure CN122157304A_ABST
Abstract
Description
Technical Field
[0001] This invention belongs to the field of image recognition and relates to a method for detecting and recognizing yak faces based on deep learning. Background Technology
[0002] In modern livestock farming, especially yak breeding and management in high-altitude areas, accurate identification of individual yaks is a crucial prerequisite for health monitoring, feeding management, pedigree tracking, and disease prevention and control. Cattle face recognition, as a non-contact, stress-free biometric identification method, has become a key research direction in this field. With the development of deep learning technology, object detection algorithms such as YOLO and Faster R-CNN have been attempted to be applied to cattle face detection tasks.
[0003] However, applying existing technologies directly to real-world, complex pastoral environments still faces significant challenges. First, the robustness of single deep learning models is insufficient: pastoral environments exhibit drastic lighting changes (e.g., strong light, shadows, dusk), cluttered backgrounds (e.g., grasslands, fences, mountains), and the varied postures of yaks easily cause occlusion. A single model struggles to maintain high accuracy in all scenarios, easily resulting in missed detections (especially of small distant targets) or false detections (identifying objects with similar textures and colors as yak faces). Second, balancing performance is difficult: simplified models aimed at increasing detection speed often sacrifice accuracy; while complex models prioritizing high accuracy are difficult to run in real-time on edge computing devices (e.g., portable inspection terminals, fixed cameras in pastures). Furthermore, acquiring high-quality labeled data is costly: training a high-generalization deep learning recognition model requires a large amount of accurately labeled yak face data, but collecting and labeling such data in real-world production environments is time-consuming and labor-intensive, becoming a bottleneck for technology implementation.
[0004] Therefore, existing single-technology approaches are difficult to achieve a good balance between accuracy, speed, and environmental adaptability. There is an urgent need for a yak face detection and recognition solution that can integrate multiple types of information, adapt to complex scenarios, and has relatively low dependence on labeled data. Summary of the Invention
[0005] To address the problems existing in the background technology, this invention proposes a deep learning-based method for yak face detection and recognition.
[0006] To achieve the above objectives, the technical solution adopted by the present invention is as follows:
[0007] A deep learning-based method for yak face detection and recognition includes:
[0008] S1. Perform multi-scale preprocessing on the original cow face image to be processed to generate feature maps of different resolutions, and enhance and denoise the image.
[0009] S2. Based on the preprocessed image, execute at least three heterogeneous detection algorithms in parallel to generate candidate cow face regions and their confidence scores, respectively.
[0010] S3. Perform cross-intersection over union (CUI) fusion and deduplication on all candidate detection results generated in step S2 to obtain a preliminary set of cow face detection boxes;
[0011] S4. For each detection box region obtained in step S3, use an improved convolutional neural network to perform feature extraction and classification to obtain the cow face identification result and classification confidence.
[0012] S5. For each detection box, merge its detection confidence and classification confidence to calculate the overall confidence score, and filter the results according to a preset threshold.
[0013] S6. Output the final recognition results, which include visual annotations and structured data.
[0014] Furthermore, the multi-scale preprocessing in step S1 includes: generating a three-layer feature map containing the original image, 1 / 2 scale, and 1 / 4 scale using an image pyramid algorithm; and using adaptive histogram equalization for contrast enhancement and bilateral filtering for noise suppression.
[0015] Furthermore, the three heterogeneity detection algorithms in step S2 include:
[0016] YOLO-based deep learning detection uses a pre-trained YOLO model and sets the detection confidence threshold to a value lower than the normal value to improve recall.
[0017] Traditional visual detection based on HSV color space converts the image to HSV space, defines the color range of the cow face, and extracts candidate regions through morphological operations and contour analysis.
[0018] Edge detection based on the Canny operator is performed on grayscale images, and contour finding and shape features are combined for auxiliary verification.
[0019] Further, the fusion and deduplication in step S3 specifically involves: sorting all candidate detection boxes by confidence level, calculating the intersection-union ratio (IUU) between the current detection box and the confirmed detection boxes in turn, and retaining the detection box with higher confidence level if the IUU is higher than a preset threshold.
[0020] Otherwise, add it as a new detection result to the final set.
[0021] Furthermore, the improved convolutional neural network used in step S4 is based on the ResNet architecture and introduces the following improvements: adding Dropout layers with different ratios before the fully connected layers and after the intermediate layers to prevent overfitting; expanding the final feature dimension of the network; and using weights pre-trained on a large image dataset for transfer learning.
[0022] Furthermore, the improved convolutional neural network includes an adaptive average pooling layer after convolutional feature extraction, which is used to receive input regions of different sizes and output feature vectors of fixed dimensions.
[0023] Furthermore, the overall credibility score in step S5 is obtained by multiplying the detection confidence score by the classification confidence score, and the identification results with an overall credibility score lower than the dynamic threshold are filtered out.
[0024] Furthermore, the structured output data in step S6 includes at least: timestamp, image path, number of detections, bounding box coordinates of each detection result, detection confidence, classification confidence, overall confidence, source of detection method, and variety statistics.
[0025] Compared with the prior art, the present invention has the following beneficial effects:
[0026] Significant improvements in detection accuracy and recall, and a substantial reduction in false positive rate: By employing a multi-strategy heterogeneous detection parallel fusion mechanism, this approach integrates the global perception capabilities of YOLO-based deep learning, the unique color features of cow faces based on the HSV color space, and edge shape verification based on the Canny operator. These three complementary strengths effectively address the challenges of detecting complex backgrounds, varying lighting conditions, and small targets. Experiments show that this fusion strategy improves detection accuracy from approximately 85% of a single model to over 96%, while simultaneously reducing the false positive rate from 15% to below 4%, achieving a qualitative leap.
[0027] Achieving a good balance between accuracy and efficiency: This invention is not a simple stacking algorithm, but rather uses an intelligent fusion and deduplication algorithm based on intersection-union ratio (IU) to efficiently integrate the results of parallel detection, avoiding redundant computation. Compared to serializing multiple complex models, this method significantly improves accuracy while keeping computational overhead manageable, making it easier to achieve a balance between accuracy and speed in practical deployments.
[0028] Environmental adaptability and system robustness are significantly enhanced: the multi-source information fusion mechanism makes the system independent of a single feature. When one detection method fails due to specific environmental conditions (such as extreme lighting affecting color or motion blur affecting edges), other methods can still provide valid candidates, and the overall system performance remains stable. This design greatly enhances the algorithm's adaptability and robustness in the variable outdoor pasture environment.
[0029] It reduces the absolute dependence on large-scale, high-quality labeled data: Although the deep learning part still requires labeled data, the introduction of traditional visual methods (color, edge) reduces the over-reliance on purely data-driven models. The system can use prior visual features for effective initial screening and verification, enabling the construction of a relatively reliable basic detection framework even with limited labeled data, thus lowering the threshold and cost of technical implementation.
[0030] The method provides rich output information, supporting subsequent analysis and system optimization: it not only outputs detection and identification results but also provides an overall credibility score and the source of the detection method for each result. This structured output facilitates result tracing, confidence analysis, and performance evaluation of algorithm modules, providing valuable data support for continuous iterative optimization of the system. It also facilitates integration into larger-scale livestock management information systems. Attached Figure Description
[0031] Figure 1 This is a flowchart of the method of the present invention. Detailed Implementation
[0032] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0033] Example:
[0034] A method for yak face detection and recognition based on multi-strategy fusion
[0035] This embodiment aims to perform real-time video frame analysis on free-range yak herds under outdoor natural lighting conditions to achieve high-precision yak face detection and individual identification.
[0036] S1. Perform multi-scale preprocessing on the original cow face image to be processed to generate feature maps of different resolutions, and enhance and denoise the image.
[0037] The camera on the mobile inspection vehicle captured an image of several yaks (raw resolution set to 1920x1080). Upon receiving the RGB image, the system immediately initiated the preprocessing pipeline:
[0038] 1. Construct an image pyramid using the Gaussian pyramid algorithm to generate three multi-scale feature maps: Layer 0 (original image 1920x1080), Layer 1 (1 / 2 scale, 960x540), and Layer 2 (1 / 4 scale, 480x270). This aims to simultaneously detect large nearby targets and small distant targets.
[0039] 2. Image enhancement and denoising: Limit contrast adaptive histogram equalization (CLAHE) is applied to each image layer to compensate for uneven lighting (such as cows under the shade of trees). Subsequently, bilateral filtering (d=9, sigmaColor=75, sigmaSpace=75) is used to smooth the image texture while preserving the clear edges of the cow's face.
[0040] 3. Data Augmentation (Training Phase): During the model training phase, additional random brightness adjustments (coefficients randomly selected between 0.8 and 1.2) and random contrast adjustments (coefficients randomly selected between 0.8 and 1.2) are applied to the input image to improve the model's robustness to changes in lighting conditions throughout the day.
[0041] S2. Based on the preprocessed image, execute at least three heterogeneous detection algorithms in parallel to generate candidate cow face regions and their confidence scores.
[0042] The preprocessed three-layer image is simultaneously fed into three heterogeneous detection modules:
[0043] Module A: YOLOv8-based deep learning detection, loading a YOLOv8n model pre-trained on the COCO dataset and fine-tuned for animal categories (ID 15-23).
[0044] The detection confidence threshold was reduced from the usual 0.5 to 0.1 to improve recall for blurred, small, or partially occluded cow faces.
[0045] Inference is performed on each of the three pyramid images. For example, a "cow" target with a confidence of 0.15 is detected on Layer 2 (480x270), with its bounding box [x=120, y=80, w=60, h=50]. The coordinates of this bounding box are mapped back to the original image scale to obtain candidate bounding box A1.
[0046] Module B: Traditional visual inspection based on the HSV color space, converting the original image to the HSV color space.
[0047] Define typical color ranges for a yak's face (example):
[0048] Dark brown / black: H∈[0,180],S∈[50,255],V∈[0,100]
[0049] White / light-colored area: V>150
[0050] Morphological closing operations (5x5 cores) are applied to fill the small gaps between hairs, and then opening operations (3x3 cores) are applied to remove isolated noise points.
[0051] Find the outline and filter out candidate regions by setting an area threshold (e.g., greater than 500 pixels) and an aspect ratio threshold (e.g., between 0.8 and 1.5, approximately square or rectangular). For example, filter out an outline whose bounding rectangle is candidate box B1.
[0052] Module C: Edge detection assistance based on the Canny operator, converts the original image to grayscale, and smooths it with Gaussian filtering (5x5 kernel).
[0053] Use Canny edge detection (low threshold = 50, high threshold = 150) to obtain significant edges.
[0054] Find closed contours and calculate their area and convex hull. Based on the prior knowledge that a cow's face is roughly rectangular, select regions with moderate area and approximately rectangular contours as auxiliary candidate boxes, such as candidate box C1.
[0055] S3. Perform cross-intersection over union (CUI) fusion and deduplication on all candidate detection results generated in step S2 to obtain a preliminary set of cow face detection boxes.
[0056] All candidate bounding boxes (e.g., A1, B1, C1, etc.) and their confidence scores (provided by the deep learning module, and assigned a default value of 0.5 by the traditional module) from the three modules are compiled into a list. After sorting by confidence score in descending order, non-maximum suppression fusion based on intersection-union ratio is performed:
[0057] 1. Select the box with the highest confidence level (such as A1) as the baseline.
[0058] 2. Traverse subsequent bounding boxes and calculate their Intersection over Union (IoU) with the baseline bounding box. If IoU > threshold (set to 0.3), they are considered to be detecting the same cow, the box with higher confidence is retained, and the coordinates are merged (e.g., by taking a weighted average); if IoU ≤ 0.3, it is considered a new target.
[0059] 3. Repeat this process until all boxes have been traversed. Finally, assuming that the IoU calculation of the three candidate boxes A1, B1, and C1 shows that they are highly overlapping, a final detection box FinalBox1, which is the optimal one representing the yak's face, is generated after fusion, and its overall detection confidence is updated to det_conf=0.85.
[0060] S4. For each detection box region obtained in step S3, use an improved convolutional neural network to perform feature extraction and classification to obtain the cow face identification result and classification confidence.
[0061] 1. Region Cropping and Standardization: Based on the coordinates of FinalBox1, crop the corresponding cow face region from the original image. Scale this region image to a fixed size (e.g., 224x224) and perform normalization.
[0062] 2. Improved forward propagation in ResNet18 networks:
[0063] The network uses ResNet18, which is pre-trained on ImageNet, as its backbone.
[0064] Double Dropout. After the output of the last convolutional block, it first passes through a random deactivation layer with a Dropout rate of 0.3, and then enters an adaptive average pooling layer. The pooled 512-dimensional feature vector passes through another random deactivation layer with a Dropout rate of 0.5 before being input to the fully connected layer, effectively preventing overfitting.
[0065] Expanding feature dimensions. The fully connected layer is designed with a 512->256->N structure (N is the number of known yak individuals in the farm, for example, 100 heads), which enhances the feature representation capability.
[0066] The cropped cow face region is input into the network, which outputs a 100-dimensional probability vector. The category corresponding to the highest probability value is the identified individual ID, such as "Yak_015", with a classification confidence of cls_conf=0.92.
[0067] S5. For each detection box, merge its detection confidence and classification confidence to calculate the overall confidence score, and filter the results according to a preset threshold.
[0068] Calculate the overall reliability of the test results:
[0069] overall_confidence=det_conf*cls_conf=0.85*0.92≈0.78;
[0070] The dynamic filtering threshold was set to 0.3. Since 0.78 > 0.3, the result was retained. Simultaneously, the system recorded that this result originated from "YOLO + Color + Edge Blending Detection".
[0071] S6. Output the final recognition results, which include visual annotations and structured data.
[0072] 1. Visualize the image: Generate a labeled result image. FinalBox1 is drawn with a solid green line (representing the final result). For easier debugging, the results of the initial three detectors (YOLO-Green, Color-Red, Edge-Blue) can be indicated with small boxes of different colors in a corner of the image or in a saved file. The label "Yak_015|Confidence: 0.78|Source: Fusion" is displayed above FinalBox1.
[0073] 2. Structured data (JSON format):
[0074] json
[0075] {
[0076] "timestamp": "2023-10-27T14:30:05Z",
[0077] "image_path": " / data / capture / Image of Ranch A_20231027_143005.jpg",
[0078] "detection_count": 1,
[0079] "results":
[0080] {
[0081] "bbox": [450, 320, 150, 180],
[0082] "detection_confidence": 0.85,
[0083] "classification_id": "Yak_015",
[0084] "classification_confidence": 0.92,
[0085] "overall_confidence": 0.78,
[0086] "method_source": ["YOLOv8", "HSV_Color", "Canny_Edge"]
[0087] }
[0088] ,
[0089] "breed_statistics": {"Recognition Successful": 1},
[0090] "confidence_distribution": {"High (>0.7)": 1}
[0091] }。
[0092] In the complex outdoor scenario described in this embodiment, the system successfully detected and identified a yak through multi-strategy fusion. Experimental data shows that compared to using YOLOv8 alone (which may result in missed detections due to the similarity between yak hair color and withered grass color) or using color segmentation alone (which may result in false detections due to changes in lighting), this fusion method maintains a stable overall recognition accuracy of over 96%, a false detection rate of less than 4%, and the processing time per image meets the real-time requirements of mobile devices, effectively supporting intelligent pasture management.
[0093] Although the present invention has been described in detail with reference to the foregoing embodiments, those skilled in the art can still modify the technical solutions described in the foregoing embodiments or make equivalent substitutions for some of the technical features. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of the present invention should be included within the protection scope of the present invention.
Claims
1. A deep learning-based method for yak face detection and recognition, characterized in that, include: S1. Perform multi-scale preprocessing on the original cow face image to be processed to generate feature maps of different resolutions, and enhance and denoise the image. S2. Based on the preprocessed image, execute at least three heterogeneous detection algorithms in parallel to generate candidate cow face regions and their confidence scores, respectively. S3. Perform cross-intersection over union (CUI) fusion and deduplication on all candidate detection results generated in step S2 to obtain a preliminary set of cow face detection boxes; S4. For each detection box region obtained in step S3, use an improved convolutional neural network to perform feature extraction and classification to obtain the cow face identification result and classification confidence. S5. For each detection box, merge its detection confidence and classification confidence to calculate the overall confidence score, and filter the results according to a preset threshold. S6. Output the final recognition results, which include visual annotations and structured data.
2. The method according to claim 1, characterized in that, The multi-scale preprocessing in step S1 includes: generating a three-layer feature map containing the original image, 1 / 2 scale, and 1 / 4 scale using the image pyramid algorithm; Adaptive histogram equalization is used to enhance contrast, and bilateral filtering is used to suppress noise.
3. The method according to claim 1, characterized in that, The three heterogeneity detection algorithms in step S2 include: YOLO-based deep learning detection uses a pre-trained YOLO model and sets the detection confidence threshold to a value lower than the normal value to improve recall. Traditional visual detection based on HSV color space converts the image to HSV space, defines the color range of the cow face, and extracts candidate regions through morphological operations and contour analysis. Edge detection based on the Canny operator is performed on grayscale images, and contour finding and shape features are combined for auxiliary verification.
4. The method according to claim 1 or 3, characterized in that, The fusion and deduplication in step S3 are as follows: sort all candidate detection boxes according to their confidence level, calculate the intersection-union ratio of the current detection box and the confirmed detection boxes in turn, and if it is higher than the preset threshold, retain the detection box with higher confidence level. Otherwise, add it as a new detection result to the final set.
5. The method according to claim 1, characterized in that, The improved convolutional neural network used in step S4 is based on the ResNet architecture and introduces the following improvements: adding Dropout layers with different ratios before the fully connected layers and after the intermediate layers to prevent overfitting; expanding the final feature dimension of the network; and using weights pre-trained on a large image dataset for transfer learning.
6. The method according to claim 5, characterized in that, The improved convolutional neural network includes an adaptive average pooling layer after convolutional feature extraction, which is used to receive input regions of different sizes and output feature vectors of fixed dimensions.
7. The method according to claim 1, characterized in that, The overall credibility score in step S5 is obtained by multiplying the detection confidence score by the classification confidence score, and the identification results with an overall credibility score lower than the dynamic threshold are filtered out.
8. The method according to claim 1, characterized in that, The structured output data in step S6 includes at least: timestamp, image path, number of detections, bounding box coordinates of each detection result, detection confidence, classification confidence, overall confidence, source of detection method, and variety statistics.