An automatic recognition method and system for cow mastitis based on infrared thermal imaging and deep learning
Patent Information
- Application Number
- CN202610860232.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-06-15
- Publication Date
- 2026-08-21
AI Technical Summary
[0003]然而,现有基于红外热成像的奶牛乳房炎检测方案,通常仅采用单一温度阈值对眼乳温差进行判断,未能综合利用乳区温度标准差、乳区最大温度差及乳区与眼部温度差值等多维温度特征,且未考虑环境温度变化对判别结果的影响,导致在不同季节条件下判别结果稳定性差,难以满足规模化牧场对乳房炎早期精准识别的实际需求
[0015] This invention automatically binds the individual identity information of dairy cows to the thermal imaging acquisition process, making the temperature data of each cow traceable to a specific individual. This provides a reliable data management foundation for subsequent health status analysis and effectively avoids the information confusion caused by manual recording. Regarding image quality assurance, adaptive enhancement processing using quantile clipping and linear stretching for the brightness channel ensures that the infrared thermal imaging images maintain stable and consistent image quality under different acquisition times, ambient lighting, and temperature conditions, significantly reducing the risk of subsequent target recognition failure due to fluctuations in acquisition conditions. An oriented bounding box target detection model is introduced to automatically locate the cow's eyes and each udder region. Compared to the traditional axis-aligned rectangle detection method, this model better matches the actual posture of the target area at an upward viewing angle, effectively reducing positioning deviations caused by posture deflection and thus ensuring the accuracy of the temperature extraction area. Pixel-level temperature extraction of the target area based on a polygonal mask avoids interference from background temperature pixels on the statistical results, making the calculation results of feature parameters such as the maximum, minimum, average, and standard deviation of the four highest temperature values corresponding to the four udder regions of the cow more accurate and reliable. At the level of mastitis discrimination, eye temperature is used as a reference for environmental thermal state. The corresponding discrimination rule set is adaptively selected, and multi-dimensional features such as the standard deviation, range, and the difference between the maximum value of the four highest temperature values and the eye surface temperature are combined for joint discrimination. This enables the system to output stable classification results under different seasonal conditions such as high temperature in summer and low temperature in winter. It achieves fine differentiation between healthy state, subclinical mastitis and different levels of clinical mastitis, and significantly improves the reliability and practicality of early automatic identification of mastitis in large-scale ranches.
Smart Images

Figure CN122604323A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of artificial intelligence technology, and in particular to an automatic identification method and system for bovine mastitis based on infrared thermal imaging and deep learning. Background Technology
[0002] Mastitis in dairy cows is a common and highly contagious disease in dairy farming, leading to decreased milk production and reduced milk quality. In severe cases, it can result in the culling of cows, causing significant economic losses to large-scale farms. Current methods for detecting mastitis mainly fall into two categories: manual detection and milk physicochemical analysis. Manual detection relies on farmers observing the appearance of the udder and feeling its temperature. Milk physicochemical analysis involves methods such as somatic cell count, milk conductivity, and bacterial culture. With the development of artificial intelligence technology, deep learning-based target detection methods are gradually being applied in the livestock industry. Infrared thermal imaging technology, due to its non-contact and real-time temperature measurement advantages, has also been introduced into dairy cow health monitoring scenarios, providing a new technological path for the automated detection of mastitis.
[0003] However, existing infrared thermal imaging-based mastitis detection schemes for dairy cows typically only use a single temperature threshold to judge the temperature difference between the eye and the milk, failing to comprehensively utilize multi-dimensional temperature characteristics such as the standard deviation of milk temperature, the maximum temperature difference in the milk area, and the temperature difference between the milk area and the eye. Furthermore, they do not consider the impact of environmental temperature changes on the discrimination results, resulting in poor stability of the discrimination results under different seasonal conditions, making it difficult to meet the actual needs of large-scale farms for early and accurate identification of mastitis. Summary of the Invention
[0004] This invention provides an automatic identification method and system for bovine mastitis based on infrared thermal imaging and deep learning, in order to overcome the shortcomings of existing technologies.
[0005] This invention provides an automatic identification method for bovine mastitis based on infrared thermal imaging and deep learning, comprising: S1. Trigger the infrared thermal imager to collect thermal images of one side of the cow and obtain a thermal image dataset. S2. Perform brightness adaptive enhancement on the multiple frames of pseudo-color images generated from the corresponding thermal imaging video data in the thermal imaging dataset to obtain an enhanced thermal imaging image sequence. S3. Based on the enhanced thermal imaging image sequence, the target region is located using the directional bounding box target detection model, and the temperature features of the target region are extracted to obtain a temperature feature set; S4. Based on the temperature feature set, select the corresponding multivariate threshold combination strategy to classify and distinguish the health status of dairy cow udders under different environments, and obtain the mastitis discrimination result.
[0006] According to the present invention, an automatic identification method for bovine mastitis based on infrared thermal imaging and deep learning is provided, wherein step S1 further includes: S11. When a cow enters the collection area, the individual identification device reads the identification information carried by the cow, parses it to obtain the cow number, and obtains the cow information file. S12. Using the cow number as a trigger condition, start the infrared thermal imager to continuously collect data on one side of the cow, simultaneously covering the cow's eye area and multiple udder areas within the single-sided field of view, and obtain thermal imaging video data. S13. The thermal imaging video data, the temperature data corresponding to the thermal imaging video data, and the cow information file are associated and stored to obtain a thermal imaging dataset with identity tags.
[0007] According to the present invention, an automatic identification method for bovine mastitis based on infrared thermal imaging and deep learning is provided, wherein step S2 further includes: S21. Convert the multi-frame pseudo-color image generated from the corresponding thermal imaging video data in the thermal imaging dataset from the RGB color space to the HSV color space, and separate the hue channel, saturation channel and initial brightness channel. S22. Statistically analyze the pixel value distribution of the initial brightness channel, calculate the low quantile threshold and high quantile threshold of the pixel value distribution respectively, and obtain the effective brightness distribution range; S23. Truncate the pixel values in the initial brightness channel that are lower than the low quantile threshold to the low quantile threshold, and truncate the pixel values in the initial brightness channel that are higher than the high quantile threshold to the high quantile threshold, to obtain the cropped brightness channel. S24. Linearly map the pixel values of the cropped brightness channel to a preset brightness range to obtain an enhanced brightness channel; S25. Merge the enhanced brightness channel with the hue channel and the saturation channel, and convert them back to the RGB color space to obtain multi-frame enhanced thermal imaging images; S26. Output the enhanced thermal imaging images of all frames of pseudo-color images to obtain the enhanced thermal imaging image sequence.
[0008] According to the present invention, an automatic identification method for mastitis in dairy cows based on infrared thermal imaging and deep learning is provided. In step S22, when the high quantile threshold is detected to be less than or equal to the low quantile threshold, the low quantile threshold and the high quantile threshold are replaced by the global minimum and global maximum values of the initial brightness channel.
[0009] According to the present invention, an automatic identification method for bovine mastitis based on infrared thermal imaging and deep learning is provided, wherein step S3 further includes: S31. Input the enhanced thermal imaging image sequence into the directional bounding box target detection model to detect and locate the cow's eye area and multiple milk areas, and obtain the coordinates of the vertices of the rotating detection box of multiple target areas. S32. Based on the vertex coordinates of the rotating detection frame, construct a polygonal mask on the temperature matrix data corresponding to the enhanced thermal imaging image sequence, extract temperature feature quantities of multiple target areas, and obtain a temperature feature set.
[0010] According to the present invention, an automatic identification method for bovine mastitis based on infrared thermal imaging and deep learning is provided, wherein step S32 further includes: S321. Analyze the rotated bounding box to obtain the coordinates of the corner points of the target region boundary, forming a set of polygon coordinates; S322. Based on the set of polygon coordinates, perform boundary constraint processing on the vertex coordinates of the rotation detection box, crop coordinates that exceed the image size range to the image boundary, construct a polygon region based on the cropped vertex coordinates, calculate the area of the polygon region, remove target regions with an area smaller than a preset minimum area threshold, retain valid target regions, and generate a target region coordinate file based on the valid target regions. S323. Read the temperature matrix data corresponding to the current image frame, construct a polygonal mask on the temperature matrix data region by region according to the target region coordinate file, and extract pixel-level temperature data of multiple target regions within the mask range. S324. Based on pixel-level temperature data, calculate the eye temperature value of the cow, the temperature values of the four udder regions of the cow, and the feature parameters based on the eye temperature value and the temperature values of the four udder regions to obtain a temperature feature set.
[0011] Specifically, the temperature feature set in step S324 includes: Eye temperature in the cow's eye area; The four highest temperature values corresponding to the four udders of a dairy cow; The maximum and minimum values among the four highest temperature values, and the average, standard deviation, and range of the four highest temperature values; The first temperature difference data is the difference between the maximum and minimum values among the four highest temperature values; The second temperature difference data is the difference between the maximum value among the four highest temperature values and the eye temperature value; The third temperature difference data is the difference between the average of the four highest temperature values and the eye temperature value.
[0012] In step S4, when the eye temperature value in the temperature feature set is less than or equal to the first preset temperature, the first mastitis discrimination rule set is selected; when the eye temperature value in the temperature feature set is greater than the first preset temperature, the second mastitis discrimination rule set is selected.
[0013] Specifically, the first set of rules for identifying mastitis includes: When the standard deviation of the breast area temperature is less than or equal to the first preset threshold, and the first temperature difference data is less than the second preset threshold, it is judged to be in a healthy state. When the standard deviation of breast temperature is greater than the first preset threshold and less than the third preset threshold, and the first temperature difference data is greater than or equal to the second preset threshold and less than the fourth preset threshold, it is determined to be subclinical mastitis. When the first temperature difference data is greater than the fourth preset threshold, and the standard deviation of the breast temperature is greater than the third preset threshold and less than the fifth preset threshold, and the second temperature difference data is greater than or equal to the fourth preset threshold, it is determined to be a first-degree clinical mastitis. When the standard deviation of breast temperature is greater than or equal to the fifth preset threshold, and the second temperature difference data is greater than or equal to the sixth preset threshold, it is judged as grade II clinical mastitis; The second set of rules for identifying mastitis is as follows: When the standard deviation of the breast area temperature is less than or equal to the first preset threshold, and the first temperature difference data is less than or equal to the seventh preset threshold, and the absolute value of the third temperature difference data is less than or equal to the eighth preset threshold, and the second temperature difference data is less than or equal to the second preset threshold, it is determined to be in a healthy state. When the first temperature difference data is greater than the seventh preset threshold and less than the fourth preset threshold, and the standard deviation of the breast area temperature is greater than the first preset threshold and less than or equal to the third preset threshold, and the second temperature difference data is greater than the second preset threshold, it is determined to be subclinical mastitis. When the first temperature difference data is greater than or equal to the fourth preset threshold, and the standard deviation of the breast area temperature is greater than the third preset threshold and less than or equal to the eighth preset threshold, and either the first sub-condition or the second sub-condition is met, it is determined to be a first-degree clinical mastitis. When either the third or fourth condition is met, it is determined to be grade II clinical mastitis; The first condition is that the second temperature difference data is greater than or equal to the fourth preset threshold. The second condition is that the third temperature difference data is greater than or equal to the second preset threshold. The third condition is that the first temperature difference data is greater than or equal to the ninth preset threshold and the standard deviation of the breast area temperature is greater than the eighth preset threshold. The fourth condition is that the eye temperature is greater than or equal to the second preset temperature, and the maximum value of multiple breast area temperatures is greater than or equal to the third preset temperature, and the minimum value of multiple breast area temperatures is greater than or equal to the second preset temperature.
[0014] This invention also provides an automatic identification system for bovine mastitis based on infrared thermal imaging and deep learning, used to execute an automatic identification method for bovine mastitis based on infrared thermal imaging and deep learning as described in any of the above claims, comprising: Acquisition module: Used to receive thermal imaging data of one side of the cow from the infrared thermal imager and obtain thermal imaging dataset; Enhancement module: used to perform brightness adaptive enhancement on multiple frames of pseudo-color images generated from corresponding thermal imaging video data in the thermal imaging dataset to obtain an enhanced thermal imaging image sequence; Extraction module: used to locate the target region based on the enhanced thermal imaging image sequence using a directional bounding box target detection model, and extract the temperature features of the target region to obtain a temperature feature set; The discrimination module is used to select the corresponding multivariate threshold combination strategy based on the temperature feature set, classify and discriminate the health status of dairy cow udders under different environments, and obtain the mastitis discrimination result.
[0015] This invention automatically binds the individual identity information of dairy cows to the thermal imaging acquisition process, making the temperature data of each cow traceable to a specific individual. This provides a reliable data management foundation for subsequent health status analysis and effectively avoids the information confusion caused by manual recording. Regarding image quality assurance, adaptive enhancement processing using quantile clipping and linear stretching for the brightness channel ensures that the infrared thermal imaging images maintain stable and consistent image quality under different acquisition times, ambient lighting, and temperature conditions, significantly reducing the risk of subsequent target recognition failure due to fluctuations in acquisition conditions. An oriented bounding box target detection model is introduced to automatically locate the cow's eyes and each udder region. Compared to the traditional axis-aligned rectangle detection method, this model better matches the actual posture of the target area at an upward viewing angle, effectively reducing positioning deviations caused by posture deflection and thus ensuring the accuracy of the temperature extraction area. Pixel-level temperature extraction of the target area based on a polygonal mask avoids interference from background temperature pixels on the statistical results, making the calculation results of feature parameters such as the maximum, minimum, average, and standard deviation of the four highest temperature values corresponding to the four udder regions of the cow more accurate and reliable. At the level of mastitis discrimination, eye temperature is used as a reference for environmental thermal state. The corresponding discrimination rule set is adaptively selected, and multi-dimensional features such as the standard deviation, range, and the difference between the maximum value of the four highest temperature values and the eye surface temperature are combined for joint discrimination. This enables the system to output stable classification results under different seasonal conditions such as high temperature in summer and low temperature in winter. It achieves fine differentiation between healthy state, subclinical mastitis and different levels of clinical mastitis, and significantly improves the reliability and practicality of early automatic identification of mastitis in large-scale ranches. Attached Figure Description
[0016] To more clearly illustrate the technical solutions in this invention or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are some embodiments of this invention. For those skilled in the art, other drawings can be obtained from these drawings without creative effort.
[0017] Figure 1 A schematic diagram of the process for an automatic identification method of bovine mastitis based on infrared thermal imaging and deep learning provided by the present invention; Figure 2 The present invention provides an automatic identification system structure for bovine mastitis based on infrared thermal imaging and deep learning. Detailed Implementation
[0018] To make the objectives, technical solutions, and advantages of this invention clearer, the technical solutions of this invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some, not all, embodiments of this invention, and should not be construed as limiting the invention. All other embodiments obtained by those skilled in the art based on the embodiments of this invention without creative effort are within the scope of protection of this invention. In the description of this invention, it should be understood that the terminology used is for descriptive purposes only and should not be construed as indicating or implying relative importance.
[0019] The embodiments of the present invention are described below with reference to the figures.
[0020] like Figure 1 As shown, this invention provides an automatic identification method for bovine mastitis based on infrared thermal imaging and deep learning, comprising: S1. Trigger the infrared thermal imager to collect thermal images of one side of the cow and obtain a thermal image dataset.
[0021] Step S1 further includes: S11. When a cow enters the collection area, the individual identification device reads the identification information carried by the cow, parses it to obtain the cow number, and obtains the cow information file.
[0022] When a cow enters the walking path in front of the milking machine and approaches the collection area of the infrared thermal imager, the radio frequency identification (RFID) device deployed on the side of the path automatically reads the electronic tag carried on the cow's ear tag or neck collar, then parses the unique cow number code corresponding to the cow, and uses the cow number code as an index to pre-create a cow information file corresponding to the cow in the local storage unit. The obtained file serves as the storage carrier for all subsequent temperature data.
[0023] S12. Using the cow number as a trigger condition, start the infrared thermal imager to continuously collect data on one side of the cow, simultaneously covering the cow's eye area and multiple udder areas within the single-sided field of view, and obtain thermal imaging video data.
[0024] In step S12, the invention uses successful cow number resolution as a trigger condition to activate the infrared thermal imager via the data acquisition control unit, continuously acquiring thermal images of the cow from one side at an upward angle. The infrared thermal imager utilizes the natural height difference between the milking aisle and the milking work area to create an upward imaging angle, ensuring that the single-sided field of view simultaneously covers the eye area and all four udder areas during the cow's natural walking process. After acquisition, the infrared thermal imager simultaneously outputs two types of data: first, thermal imaging video data presented in pseudo-color image format, where different temperature values are mapped to different colors and stored in BGR color format; second, pixel-level temperature matrix data corresponding frame-by-frame to the thermal imaging video, where each pixel in each frame corresponds to a specific temperature value in degrees Celsius, forming a two-dimensional numerical matrix of the same size as the image.
[0025] S13. The thermal imaging video data, the temperature data corresponding to the thermal imaging video data, and the cow information file are associated and stored to obtain a thermal imaging dataset with identity tags.
[0026] Furthermore, after the acquisition is completed, the present invention performs frame parsing on the acquired thermal imaging video data, extracts the corresponding pseudo-color image sequence, and simultaneously acquires the temperature matrix data that corresponds one-to-one with each frame of the pseudo-color image; then, the pseudo-color image sequence, temperature matrix data and acquisition time information are organized according to the cow number and uniformly associated with the corresponding cow information file for storage, thereby constructing a thermal imaging dataset with cow identity tags.
[0027] S2. Perform brightness adaptive enhancement on the multiple frames of pseudo-color images generated from the corresponding thermal imaging video data in the thermal imaging dataset to obtain an enhanced thermal imaging image sequence.
[0028] Step S2 further includes: S21. Convert the multi-frame pseudo-color images generated from the corresponding thermal imaging video data in the thermal imaging dataset from the RGB color space to the HSV color space, and separate the hue channel, saturation channel and initial brightness channel.
[0029] In step S21, the present invention reads pseudo-color images frame by frame from the thermal imaging dataset and performs the following data processing flow sequentially on each frame. Specifically, the current frame pseudo-color image is first converted from the BGR color space to the HSV color space. The HSV color space consists of three components: hue channel H, saturation channel S, and luminance channel V. The luminance channel V independently represents the brightness of each pixel in the image and is directly related to the visual representation of temperature intensity in infrared thermal imaging. After completing the color space conversion, the present invention separates the image into three independent single-channel data: hue channel H, saturation channel S, and initial luminance channel V. The hue channel H and saturation channel S remain unchanged in subsequent processing, while only the luminance channel V is enhanced.
[0030] S22. Statistically analyze the pixel value distribution of the initial brightness channel, calculate the low quantile threshold and high quantile threshold of the pixel value distribution respectively, and obtain the effective brightness distribution range.
[0031] In step S22, when the high quantile threshold is detected to be less than or equal to the low quantile threshold, the low quantile threshold and the high quantile threshold are replaced by the global minimum and global maximum values of the initial luminance channel.
[0032] In step S22, the present invention performs statistical analysis on all pixel values within the luminance channel V, calculating the pixel values corresponding to the preset low quantile and high quantile respectively. These two values together constitute the effective distribution range of luminance, used to eliminate the influence of extremely low and extremely high values on image contrast. When it is detected that the pixel value corresponding to the high quantile is less than or equal to the pixel value corresponding to the low quantile, it indicates that the luminance distribution of the current frame is too concentrated. In this case, the global minimum and global maximum values of the luminance channel are used to replace the corresponding quantile values to ensure the effectiveness of subsequent enhancement processing.
[0033] S23. Pixel values in the initial brightness channel that are lower than the low quantile threshold are truncated to the low quantile threshold, and pixel values in the initial brightness channel that are higher than the high quantile threshold are truncated to the high quantile threshold, to obtain a cropped brightness channel.
[0034] In step S23, after determining the effective brightness distribution range, the present invention performs quantile clipping processing on the initial brightness channel V. Specifically, the present invention forcibly assigns all pixel values in the initial brightness channel below the low quantile threshold to the low quantile threshold, forcibly assigns all pixel values above the high quantile threshold to the high quantile threshold, and leaves the remaining pixel values unchanged, thus obtaining the clipped brightness channel. In step S23, the present invention aims to compress extreme pixel values in the brightness channel caused by environmental noise or abnormal hotspots to the boundary of the effective range, making the brightness data distribution more concentrated and easier to process.
[0035] S24. Linearly map the pixel values of the cropped brightness channel to a preset brightness range to obtain an enhanced brightness channel.
[0036] In step S24, the present invention performs linear stretching enhancement processing on the cropped brightness channel, linearly mapping the actual pixel values of the cropped brightness channel to a preset target brightness range (i.e., the standard grayscale range of 0 to 255), so that the brightness values originally concentrated in a local area are uniformly expanded to the complete dynamic range, thus obtaining an enhanced brightness channel. Specifically, during linear mapping, the present invention scales each pixel value in the cropped brightness channel proportionally to the corresponding value within the target range according to its relative position within the effective range, ultimately obtaining the enhanced brightness channel.
[0037] S25. Merge the enhanced brightness channel with the hue channel and the saturation channel, and convert them back to the RGB color space to obtain multiple frames of enhanced thermal imaging images; S26. Output the enhanced thermal imaging images of all frames of pseudo-color images to obtain an enhanced thermal imaging image sequence.
[0038] In step S25, after calculating the enhanced luminance channel, the present invention re-merges the enhanced luminance channel with the hue channel H and saturation channel S, which retain their original values, to obtain an enhanced HSV format image. This image is then converted back from the HSV color space to the BGR color space to obtain the enhanced thermal imaging image of the current frame. After sequentially performing the above processing steps on all frames in the thermal imaging video data, the present invention outputs the enhanced thermal imaging images of all frames in chronological order to obtain an enhanced thermal imaging image sequence.
[0039] S3. Based on the enhanced thermal imaging image sequence, the target region is located using the directional bounding box target detection model, and the temperature features of the target region are extracted to obtain a temperature feature set.
[0040] Step S3 further includes: S31. Input the enhanced thermal imaging image sequence into the directional bounding box target detection model to detect and locate the cow's eye area and multiple udder areas, and obtain the vertex coordinates of the rotating detection boxes for multiple target areas.
[0041] In step S31, the present invention first reads the enhanced thermal imaging image frame by frame from the enhanced thermal imaging image sequence and inputs it into a pre-trained directional bounding box target detection model, which is a target detection model that can output the bounding box of the target area at any rotation angle. Unlike the traditional axis-aligned detection model that can only output horizontal rectangular boxes, this model can perform inference based on the actual tilt posture of the cow's eyes and udder area in the image when viewed from below. The model locates the eye area and the four udder areas in the cow's infrared thermal imaging image, outputs the rotation bounding box coordinates corresponding to each target area, and represents them by four vertex coordinates. The vertex coordinates are uniformly arranged in a preset order (top left, top right, bottom right, bottom left) to form a closed polygon area for subsequent temperature extraction.
[0042] S32. Based on the vertex coordinates of the rotating detection frame, construct a polygonal mask on the temperature matrix data corresponding to the enhanced thermal imaging image sequence, extract temperature feature quantities of multiple target areas, and obtain a temperature feature set.
[0043] Step S32 further includes: S321. Parse the rotated bounding box to obtain the corner coordinates of the target region boundary, forming a polygon coordinate set; S322. Crop the coordinates in the polygon coordinate set that exceed the effective size range of the image to the image boundary, and calculate the area of the region enclosed by multiple polygons; remove the detection results whose area is lower than the preset minimum area threshold, and generate the target region coordinate file from the filtered effective polygon coordinate set.
[0044] In steps S321 to S322, the present invention first parses the rotation detection box, converting each detection bounding box into a polygon composed of four vertex pixel coordinates. The vertex coordinates are arranged in order to form a polygon coordinate set. Subsequently, for the polygon coordinate set, the present invention first crops the coordinate values that exceed the effective pixel size range of the image to the image boundary. Then, it calculates the area of the region enclosed by each polygon, and removes the detection results with an area lower than a preset minimum area threshold from the polygon coordinate set. The remaining effective polygon coordinate set is used to generate a target region coordinate file, recording the effective vertex coordinates of each target region.
[0045] S323. Read the temperature matrix data corresponding to the current image frame, construct a polygonal mask on the temperature matrix data region by region according to the target region coordinate file, and extract pixel-level temperature data of multiple target regions within the mask range.
[0046] After generating the target region coordinate file, this invention reads the temperature matrix data corresponding one-to-one with the current frame enhanced thermal imaging image. The temperature matrix data is a two-dimensional numerical matrix with the same size as the image, where each element corresponds to the measured Celsius temperature value of a pixel at the same location in the image. Specifically, based on the vertex coordinates of each valid polygon in the target region coordinate file, this invention constructs a polygonal mask region by region on the temperature matrix. In the polygonal mask, positions inside the polygonal region are marked as valid, and positions outside the polygonal region are marked as invalid, thereby accurately separating the temperature data belonging to the target region from the background temperature data in the temperature matrix. Based on the effective range of the mask, this invention can extract the temperature data of all valid pixels within each target region from the temperature matrix.
[0047] S324. Based on pixel-level temperature data, calculate the eye temperature value of the cow, the temperature values of the four udder regions of the cow, and the feature parameters based on the eye temperature value and the temperature values of the four udder regions to obtain a temperature feature set.
[0048] Specifically, the temperature feature set in step S324 includes: the eye temperature value of the cow's eye area; four highest temperature values corresponding to the four udders of the cow; the maximum and minimum values of the four highest temperature values; the average, standard deviation, and range of the four highest temperature values; a first temperature difference data, which is the difference between the maximum and minimum values of the four highest temperature values; a second temperature difference data, which is the difference between the maximum value of the four highest temperature values and the eye temperature value; and a third temperature difference data, which is the difference between the average of the four highest temperature values and the eye temperature value.
[0049] In step S324, after obtaining the highest temperature values and ocular surface temperature of the four mammary regions, the present invention further performs an overall statistical analysis on the highest temperature values of the four mammary regions to construct the basic temperature characteristic quantity of the mammary region level: the highest temperature value of the four highest temperature values is taken as the maximum temperature value of the mammary region (max_udder), the lowest temperature value of the four highest temperature values is taken as the minimum temperature value of the mammary region (min_udder), the arithmetic mean of the four highest temperature values is taken as the average temperature value of the mammary region (mean_udder), and the standard deviation of the four highest temperature values is taken as the standard deviation of the mammary region temperature (udder_sd) (the standard deviation is used to characterize the degree of dispersion of temperature distribution between different mammary regions; the larger the value, the more significant the temperature difference between the mammary regions).
[0050] Based on the structured temperature feature data, this invention further calculates three derived temperature feature parameters. Among them, the temperature range of the milk fold reflects the degree of temperature difference between different milk folds; the difference between the maximum temperature of the milk fold and the eye surface temperature reflects the deviation of the local high-temperature area from the body's baseline temperature; and the difference between the average temperature of the milk fold and the eye surface temperature characterizes the changing trend of the overall temperature level of the milk fold relative to the body's baseline temperature. These basic and derived temperature feature quantities together constitute a temperature feature set for a single dairy cow, and serve as input variables for subsequent mastitis diagnosis. They are uniformly written into the corresponding dairy cow's information file, realizing the storage and output of structured temperature feature data.
[0051] S4. Based on the temperature feature set, select the corresponding multivariate threshold combination strategy to classify and distinguish the health status of dairy cow udders under different environments, and obtain the mastitis discrimination result.
[0052] In step S4, when the eye temperature in the temperature feature set is less than or equal to the first preset temperature, the first mastitis discrimination rule set is selected; when the eye temperature in the temperature feature set is greater than the first preset temperature, the second mastitis discrimination rule set is selected.
[0053] Specifically, the first set of rules for identifying mastitis includes: When the standard deviation of the breast area temperature is less than or equal to the first preset threshold, and the first temperature difference data is less than the second preset threshold, it is judged to be in a healthy state. When the standard deviation of breast temperature is greater than the first preset threshold and less than the third preset threshold, and the first temperature difference data is greater than or equal to the second preset threshold and less than the fourth preset threshold, it is determined to be subclinical mastitis. When the first temperature difference data is greater than the fourth preset threshold, and the standard deviation of the breast temperature is greater than the third preset threshold and less than the fifth preset threshold, and the second temperature difference data is greater than or equal to the fourth preset threshold, it is determined to be a first-degree clinical mastitis. When the standard deviation of breast temperature is greater than or equal to the fifth preset threshold, and the second temperature difference data is greater than or equal to the sixth preset threshold, it is judged as grade II clinical mastitis; The second set of rules for identifying mastitis is as follows: When the standard deviation of the breast area temperature is less than or equal to the first preset threshold, and the first temperature difference data is less than or equal to the seventh preset threshold, and the absolute value of the third temperature difference data is less than or equal to the eighth preset threshold, and the second temperature difference data is less than or equal to the second preset threshold, it is determined to be in a healthy state. When the first temperature difference data is greater than the seventh preset threshold and less than the fourth preset threshold, and the standard deviation of the breast area temperature is greater than the first preset threshold and less than or equal to the third preset threshold, and the second temperature difference data is greater than the second preset threshold, it is determined to be subclinical mastitis. When the first temperature difference data is greater than or equal to the fourth preset threshold, and the standard deviation of the breast area temperature is greater than the third preset threshold and less than or equal to the eighth preset threshold, and either the first sub-condition or the second sub-condition is met, it is determined to be a first-degree clinical mastitis. When either the third or fourth condition is met, it is determined to be grade II clinical mastitis; The first condition is that the second temperature difference data is greater than or equal to the fourth preset threshold. The second condition is that the third temperature difference data is greater than or equal to the second preset threshold. The third condition is that the first temperature difference data is greater than or equal to the ninth preset threshold and the standard deviation of the breast area temperature is greater than the eighth preset threshold. The fourth condition is that the eye temperature is greater than or equal to the second preset temperature, and the maximum value of multiple breast area temperatures is greater than or equal to the third preset temperature, and the minimum value of multiple breast area temperatures is greater than or equal to the second preset temperature.
[0054] The first condition is that the second temperature difference data is greater than or equal to the fifth preset threshold; the second condition is that the third temperature difference data is greater than or equal to the second preset threshold; the third condition is that the first temperature difference data is greater than or equal to the tenth preset threshold and the standard deviation of the breast area temperature is greater than the ninth preset threshold; the fourth condition is that the eye temperature is greater than or equal to the second preset temperature, and the maximum temperature value of multiple breast areas is greater than or equal to the fourth preset temperature, and the minimum temperature value of multiple breast areas is greater than or equal to the second preset temperature.
[0055] In step S4, the present invention reads structured temperature feature data from the cow information file, first extracting the eye temperature value and comparing it with a first preset temperature (33°C). Eye temperature serves as a reference benchmark in infrared thermal imaging, reflecting the current thermal state of the individual cow and the ambient temperature level. When the ambient temperature is low, the cow's eye temperature typically does not exceed 33°C; when the ambient temperature is high, the eye temperature increases accordingly. When the eye temperature is less than or equal to 33°C, the present invention selects the first mastitis discrimination rule set for subsequent discrimination; when the eye temperature is greater than 33°C, the second mastitis discrimination rule set is selected for subsequent discrimination.
[0056] In the above-mentioned determination conditions, the first preset threshold is 0.30, the second preset threshold is 0.80, the third preset threshold is 0.45, the fourth preset threshold is 1.20, the fifth preset threshold is 0.50, the sixth preset threshold is 1.40, the seventh preset threshold is 0.70, the eighth preset threshold is 0.60, the ninth preset threshold is 1.50, the first preset temperature is 33 ℃, the second preset temperature is 37.5℃, and the third preset temperature is 38℃.
[0057] Expressed using expressions, the specific first mastitis discrimination rule set is as follows: Based on the standard deviation of udder temperature udder_sd and the maximum temperature difference in the udder (i.e., the first temperature difference data) udiff as the discrimination basis, when udder_sd ≤ 0.30 and udiff < 0.80, it is determined to be in a healthy state; When 0.30 < udder_sd < 0.45 and 0.80 ≤ udiff < 1.20, it is determined to be subclinical mastitis; Based on udiff, udder_sd, and the temperature difference between the maximum temperature in the udder and the eye temperature (i.e., the second temperature difference data) eye_udiff as the combined discrimination basis, when udiff > 1.20 and 0.45 < udder_sd < 0.50 and eye_udiff ≥ 1.20, it is determined to be grade 1 clinical mastitis; When udder_sd ≥ 0.50 and eye_udiff ≥ 1.40, it is determined to be grade 2 clinical mastitis.
[0058] The specific second mastitis discrimination rule set is as follows: When udder_sd ≤ 0.30 and udiff ≤ 0.70 and the absolute value of the temperature difference between the average udder temperature and the eye temperature |mean_udder eye ≤ 0.60| and eye_udiff ≤ 0.80, it is determined to be in a healthy state; When 0.70 < udiff < 1.20 and 0.30 < udder_sd ≤ 0.45 and eye_udiff > 0.80, it is determined to be subclinical mastitis; When udiff ≥ 1.20 and 0.45 < udder_sd ≤ 0.60, and when at least one of the following conditions is met: eye_udiff ≥ 1.20 or mean_udder eye ≥ 0.80, it is determined to be grade 1 clinical mastitis; When one of the following conditions is met, it is determined to be grade 2 clinical mastitis: First, udiff ≥ 1.50 and udder_sd > 0.60; Second, eye ≥ 37.5 and the maximum temperature in each udder max_udder ≥ 38.0 and the minimum temperature in each udder min_udder ≥ 37.5.
[0059] After the discrimination is completed, the present invention writes the discrimination level result, the cow number, the temperature characteristic parameters, and the detection time into the cow information file together, completing the mastitis discrimination process for the current cow.
[0060] As Figure 2 shown, the present invention also provides an automatic cow mastitis recognition system based on infrared thermal imaging and deep learning, including: Acquisition module 100: Used to receive thermal imaging data of one side of a dairy cow from an infrared thermal imager and obtain a thermal imaging dataset; Enhancement module 200: used to perform brightness adaptive enhancement on multiple frames of pseudo-color images generated from corresponding thermal imaging video data in the thermal imaging dataset to obtain an enhanced thermal imaging image sequence; Extraction module 300: Based on the enhanced thermal imaging image sequence, it locates the target region through a directional bounding box target detection model, and extracts the temperature features of the target region to obtain a temperature feature set; The discrimination module 400 is used to select a corresponding multivariate threshold combination strategy based on the temperature feature set to classify and discriminate the health status of the cow's udder under different environments, thereby obtaining a mastitis discrimination result. The device embodiments described above are merely illustrative. The units described as separate components may or may not be physically separated. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the modules can be selected to achieve the purpose of this embodiment according to actual needs. Those skilled in the art can understand and implement this without any creative effort.
[0061] Through the above description of the embodiments, those skilled in the art can clearly understand that each embodiment can be implemented by means of software plus necessary general-purpose hardware platforms, and of course, it can also be implemented by hardware. Based on this understanding, the above technical solutions, in essence or the part that contributes to the prior art, can be embodied in the form of a software product. This computer software product can be stored in a computer-readable storage medium, such as ROM / RAM, magnetic disk, optical disk, etc., including several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute the automatic identification method for bovine mastitis based on infrared thermal imaging and deep learning described in the various embodiments or some parts of the embodiments.
[0062] To address the common problems in existing dairy cow mastitis detection technologies, such as reliance on human experience, inaccurate target area localization, and poor discrimination stability under varying environmental temperatures, this invention constructs a complete automatic processing and intelligent discrimination technology solution for infrared thermal imaging. This invention improves image consistency under different acquisition conditions by performing adaptive enhancement processing based on the brightness channel of the infrared thermal imaging image; it achieves high-precision automatic localization of the cow's eyes and various udder regions by introducing a directional bounding box target detection model; and it extracts pixel-level temperature of the target area based on a polygonal mask, effectively avoiding interference from the temperature of non-target areas on the measurement results, thus providing a reliable foundation for accurate acquisition of temperature features.
[0063] Based on obtaining high-quality temperature characteristic data, this invention introduces a multi-index mastitis discrimination and grading rule system with ocular temperature as a branch condition. The discrimination rules are adaptively selected according to different thermal environments and individual thermal states. By comprehensively considering the differences in breast temperature, the degree of temperature dispersion, and the relationship between breast temperature and ocular temperature, the invention achieves refined discrimination of healthy state, subclinical mastitis, and different grades of clinical mastitis.
[0064] This invention not only improves the automation and accuracy of mastitis detection, but also enhances the system's adaptability and stability in complex farming environments, better meeting the practical needs of early disease detection and precise management in large-scale dairy farming. Furthermore, it can be used in conjunction with existing parallel milking machines, eliminating the need for additional channels or milk sample testing. It offers advantages such as real-time operation, non-contact processing, and no stress on dairy cows, effectively reducing farm expenses and milking labor costs.
[0065] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, and not to limit them; although the present invention has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features; and these modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of the present invention.
Claims
1. An automatic identification method for bovine mastitis based on infrared thermal imaging and deep learning, characterized in that, include: S1. Trigger the infrared thermal imager to collect thermal images of one side of the cow and obtain a thermal image dataset. S2. Perform brightness adaptive enhancement on the multiple frames of pseudo-color images generated from the corresponding thermal imaging video data in the thermal imaging dataset to obtain an enhanced thermal imaging image sequence. S3. Based on the enhanced thermal imaging image sequence, the target region is located using the directional bounding box target detection model, and the temperature features of the target region are extracted to obtain a temperature feature set; S4. Based on the temperature feature set, select the corresponding multivariate threshold combination strategy to classify and distinguish the health status of dairy cow udders under different environments, and obtain the mastitis discrimination result.
2. The automatic identification method for bovine mastitis based on infrared thermal imaging and deep learning according to claim 1, characterized in that, Step S1 further includes: S11. When a cow enters the collection area, the individual identification device reads the identification information carried by the cow, parses it to obtain the cow number, and obtains the cow information file. S12. Using the cow number as a trigger condition, start the infrared thermal imager to continuously collect data on one side of the cow, simultaneously covering the cow's eye area and multiple udder areas within the single-sided field of view, and obtain thermal imaging video data. S13. The thermal imaging video data, the temperature data corresponding to the thermal imaging video data, and the cow information file are associated and stored to obtain a thermal imaging dataset with identity tags.
3. The automatic identification method for bovine mastitis based on infrared thermal imaging and deep learning according to claim 1, characterized in that, Step S2 further includes: S21. Convert the multi-frame pseudo-color image generated from the corresponding thermal imaging video data in the thermal imaging dataset from the RGB color space to the HSV color space, and separate the hue channel, saturation channel and initial brightness channel. S22. Statistically analyze the pixel value distribution of the initial brightness channel, calculate the low quantile threshold and high quantile threshold of the pixel value distribution respectively, and obtain the effective brightness distribution range; S23. Truncate the pixel values in the initial brightness channel that are lower than the low quantile threshold to the low quantile threshold, and truncate the pixel values in the initial brightness channel that are higher than the high quantile threshold to the high quantile threshold, to obtain the cropped brightness channel. S24. Linearly map the pixel values of the cropped brightness channel to a preset brightness range to obtain an enhanced brightness channel; S25. Merge the enhanced brightness channel with the hue channel and the saturation channel, and convert them back to the RGB color space to obtain multi-frame enhanced thermal imaging images; S26. Output the enhanced thermal imaging images of all pseudo-color images to obtain the enhanced thermal imaging image sequence.
4. The automatic identification method for bovine mastitis based on infrared thermal imaging and deep learning according to claim 1, characterized in that, In step S22, when the high quantile threshold is detected to be less than or equal to the low quantile threshold, the low quantile threshold and the high quantile threshold are replaced by the global minimum and global maximum values of the initial luminance channel.
5. The automatic identification method for bovine mastitis based on infrared thermal imaging and deep learning according to claim 1, characterized in that, Step S3 further includes: S31. Input the enhanced thermal imaging image sequence into the directional bounding box target detection model to detect and locate the cow's eye area and multiple milk areas, and obtain the coordinates of the vertices of the rotating detection box of multiple target areas. S32. Based on the vertex coordinates of the rotating detection frame, construct a polygonal mask on the temperature matrix data corresponding to the enhanced thermal imaging image sequence, extract temperature feature quantities of multiple target areas, and obtain a temperature feature set.
6. The automatic identification method for bovine mastitis based on infrared thermal imaging and deep learning according to claim 1, characterized in that, Step S32 further includes: S321. Analyze the rotated bounding box to obtain the coordinates of the corner points of the target region boundary, forming a set of polygon coordinates; S322. Based on the set of polygon coordinates, perform boundary constraint processing on the vertex coordinates of the rotation detection box, crop coordinates that exceed the image size range to the image boundary, construct a polygon region based on the cropped vertex coordinates, calculate the area of the polygon region, remove target regions with an area smaller than a preset minimum area threshold, retain valid target regions, and generate a target region coordinate file based on the valid target regions. S323. Read the temperature matrix data corresponding to the current image frame, construct a polygonal mask on the temperature matrix data region by region according to the target region coordinate file, and extract pixel-level temperature data of multiple target regions within the mask range. S324. Based on pixel-level temperature data, calculate the eye temperature value of the cow, the temperature values of the four udder regions of the cow, and the feature parameters based on the eye temperature value and the temperature values of the four udder regions to obtain a temperature feature set.
7. The automatic identification method for bovine mastitis based on infrared thermal imaging and deep learning according to claim 6, characterized in that, The temperature feature set mentioned in step S324 specifically includes: Eye temperature in the cow's eye area; The four highest temperature values corresponding to the four udders of a dairy cow; The maximum and minimum values among the four highest temperature values, and the average, standard deviation, and range of the four highest temperature values; The first temperature difference data is the difference between the maximum and minimum values among the four highest temperature values; The second temperature difference data is the difference between the maximum value among the four highest temperature values and the eye temperature value; The third temperature difference data is the difference between the average of the four highest temperature values and the eye temperature value.
8. The automatic identification method for bovine mastitis based on infrared thermal imaging and deep learning according to claim 7, characterized in that, In step S4, when the eye temperature value in the temperature feature set is less than or equal to the first preset temperature, the first mastitis discrimination rule set is selected; when the eye temperature value in the temperature feature set is greater than the first preset temperature, the second mastitis discrimination rule set is selected.
9. The automatic identification method for bovine mastitis based on infrared thermal imaging and deep learning according to claim 8, characterized in that, The first set of rules for mastitis diagnosis is as follows: When the standard deviation of the breast area temperature is less than or equal to the first preset threshold, and the first temperature difference data is less than the second preset threshold, it is judged to be in a healthy state. When the standard deviation of breast temperature is greater than the first preset threshold and less than the third preset threshold, and the first temperature difference data is greater than or equal to the second preset threshold and less than the fourth preset threshold, it is determined to be subclinical mastitis. When the first temperature difference data is greater than the fourth preset threshold, and the standard deviation of the breast temperature is greater than the third preset threshold and less than the fifth preset threshold, and the second temperature difference data is greater than or equal to the fourth preset threshold, it is determined to be a first-degree clinical mastitis. When the standard deviation of breast temperature is greater than or equal to the fifth preset threshold, and the second temperature difference data is greater than or equal to the sixth preset threshold, it is judged as grade II clinical mastitis; The second set of rules for identifying mastitis is as follows: When the standard deviation of the breast area temperature is less than or equal to the first preset threshold, and the first temperature difference data is less than or equal to the seventh preset threshold, and the absolute value of the third temperature difference data is less than or equal to the eighth preset threshold, and the second temperature difference data is less than or equal to the second preset threshold, it is determined to be in a healthy state. When the first temperature difference data is greater than the seventh preset threshold and less than the fourth preset threshold, and the standard deviation of the breast area temperature is greater than the first preset threshold and less than or equal to the third preset threshold, and the second temperature difference data is greater than the second preset threshold, it is determined to be subclinical mastitis. When the first temperature difference data is greater than or equal to the fourth preset threshold, and the standard deviation of the breast area temperature is greater than the third preset threshold and less than or equal to the eighth preset threshold, and either the first sub-condition or the second sub-condition is met, it is determined to be a first-degree clinical mastitis. When either the third or fourth condition is met, it is determined to be grade II clinical mastitis; The first condition is that the second temperature difference data is greater than or equal to the fourth preset threshold. The second condition is that the third temperature difference data is greater than or equal to the second preset threshold. The third condition is that the first temperature difference data is greater than or equal to the ninth preset threshold and the standard deviation of the breast area temperature is greater than the eighth preset threshold. The fourth condition is that the eye temperature is greater than or equal to the second preset temperature, and the maximum value of multiple breast area temperatures is greater than or equal to the third preset temperature, and the minimum value of multiple breast area temperatures is greater than or equal to the second preset temperature.
10. An automatic identification system for bovine mastitis based on infrared thermal imaging and deep learning, used to execute the automatic identification method for bovine mastitis based on infrared thermal imaging and deep learning as described in any one of claims 1 to 9, characterized in that, include: Acquisition module: Used to receive thermal imaging data of one side of the cow from the infrared thermal imager and obtain thermal imaging dataset; Enhancement module: used to perform brightness adaptive enhancement on multiple frames of pseudo-color images generated from corresponding thermal imaging video data in the thermal imaging dataset to obtain an enhanced thermal imaging image sequence; Extraction module: used to locate the target region based on the enhanced thermal imaging image sequence using a directional bounding box target detection model, and extract the temperature features of the target region to obtain a temperature feature set; The discrimination module is used to select the corresponding multivariate threshold combination strategy based on the temperature feature set, classify and discriminate the health status of dairy cow udders under different environments, and obtain the mastitis discrimination result.