A live pig identity identification tracking method based on machine vision
By combining machine vision and deep learning with pig ear tag color recognition, the problem of accurate detection and individual identification of pig identity IDs has been solved, enabling continuous tracking and identification of pigs, improving identification accuracy, and avoiding the hardware costs and mismatch problems of traditional methods.
Patent Information
- Application Number
- CN202310567796.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-05-18
- Publication Date
- 2026-01-02
- Estimated Expiration
- 2043-05-18
AI Technical Summary
Existing technologies make it difficult to accurately detect pig identification ID codes and identify individual pigs in pig farming, especially for continuous tracking within a designated area. Furthermore, traditional methods require close-range individual identification, which is costly and prone to mismatches.
A machine vision-based pig identification and tracking method is adopted. By initializing the identity ID of each pig, a deep learning object detection network is used for object detection and tracking. The identity ID is calibrated by combining the color recognition of pig ear tags, so as to realize the continuous tracking and identification of pigs.
It achieves accurate and continuous matching of pig identification IDs, improves identification accuracy, does not require additional hardware costs, and has no impact on pig health through non-contact detection. It can also calibrate mismatches during video tracking.
Smart Images

Figure CN116703969B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The application relates to a biological tracking method based on machine vision, in particular to a pig identity tracking method based on machine vision. BACKGROUND
[0002] The current pig breeding industry shows a trend of large-scale and rapid development, and the informatization, automation and intelligent management of the pig breeding process have become the common needs of enterprises. Long-term tracking of the pig's movement, activity, feeding behavior and other behaviors during the growth process is beneficial to the establishment of a personalized pig breeding system and the digital monitoring and early warning of the growth and health of pigs. The rapid development of artificial intelligence technology and the continuous decline in the cost of image acquisition and data processing make it possible for machine vision technology to replace manual inspection and identify pig behavior. In order to solve an important technical problem of pig identity ID code in long-term tracking of the growth process of pigs, only the accurate detection of the identity ID code can match the relevant growth and behavior data, and establish the basic metadata of the growth behavior of individual pigs.
[0003] Traditional pig identity recognition mainly uses ear tags. In the pig breeding industry standard, piglets are born from breeding farms, and physical ear tags are hung on the ears of pigs, and the entire growth process and industry chain traceability of pigs are used as the only identity ID code. Pig ear tags include simple digital coding or two-dimensional code ear tags, and electronic ear tags with built-in radio frequency identification (RFID) tags. Simple ear tags have low cost, but can only be identified and collected manually. Electronic ear tags have slightly higher cost, and RFID readers can be set up in pig farms and circulation links to realize automatic collection of electronic ear tags. The disadvantage is that it can only realize the identity tracking of pigs in the region. If the individual pig identity needs to be identified and collected, it needs to be identified at close range. SUMMARY
[0004] The application aims to provide a pig identity tracking method based on machine vision, which can realize continuous tracking and identity recognition of pigs, and has high tracking and recognition accuracy.
[0005] Technical scheme: the pig identity tracking method based on machine vision comprises the following steps:
[0006] Step 1: initializing the identity ID of the pig, so that each pig in the pig house is configured with an identity ID, and all identity IDs of each pig house form an ID pool, and the identity ID of the pig corresponds to the ear tag;
[0007] Step 2: selecting each video frame image from the pig house monitoring video stream according to a preset frame rate, and performing scaling preprocessing on each video frame image to obtain a pretreated image;
[0008] Step 3, target detection is performed on each piglet in the pre-processed image, so that each piglet detected in the pre-processed image obtains a target detection box, and the movement trajectory of the piglet is obtained through tracking of the target detection box, and each movement trajectory of the piglet corresponds to an identity ID;
[0009] Step 4, an ear identification area is demarcated in the pre-processed image, pig ear identification is performed on the image in each target detection box in the ear identification area, so as to match the identity ID of each piglet in each target detection box according to the correspondence between the pig ear and the identity ID;
[0010] Step 5, the movement trajectory of each piglet obtained in step 3 is calibrated respectively by using each identity ID obtained in step 4, and then step 2 is returned to.
[0011] Further, in step 1, the specific steps for initializing the identity ID of the piglet are:
[0012] Step 1.1, the number of piglets in the pig house is obtained, and a corresponding number of identity IDs are set according to the number of piglets, and each identity ID is different;
[0013] Step 1.2, each identity ID is respectively corresponding to the pig ear tag serial code of each piglet, and the color of the pig ear tag of each piglet in the pig house is different.
[0014] Further, in step 2, the specific steps for obtaining the pre-processed image are:
[0015] Step 2.1, whether the pig house monitoring video stream completely covers the piglet activity area in the pig house is detected, if all piglets in the pig house always remain in the pig house monitoring video stream, it is determined that it is completely covered, and then step 2.3 is entered, otherwise it is determined that it is not completely covered, and then step 2.2 is entered;
[0016] Step 2.2, a prompt information of incomplete monitoring is fed back by using a preset user communication mode, and adjustment confirmation information of the user is waited for, and then step 2.3 is entered after the adjustment confirmation information is obtained;
[0017] Step 2.3, the frame rate of image acquisition preset by the user is obtained, and each video frame image is selected from the pig house monitoring video stream according to the preset frame rate;
[0018] Step 2.4, each video frame image is scaled in length and width at a constant ratio to obtain a pre-processed image meeting the target detection size requirement.
[0019] Further, in step 3, the specific steps for target detection on the piglets in the pre-processed image are:
[0020] Step 3.1, take out a pre-processed image as a to-be-detected image from the cache in chronological order;
[0021] Step 3.2, use a target detection network based on deep learning to detect and identify each pig in the to-be-detected image, and load a corresponding target detection frame on the to-be-detected image after successful identification, so that each pig after identification is located in each target detection frame.
[0022] Further, in step 3, the specific steps of obtaining the moving track of the pig by tracking the target detection frame are as follows:
[0023] Step 3.3, take out a to-be-detected image loaded with a target detection frame from the cache in chronological order, determine whether the to-be-detected image is the first pre-processed image, if it is the first pre-processed image, then directly associate each identity ID in the ID pool with each target detection frame in the to-be-detected image, and then enter step 3.10, if it is not the first pre-processed image, then enter step 3.4;
[0024] Step 3.4, select a to-be-associated target detection frame from the to-be-detected image, and perform data association processing on the to-be-associated target detection frame and the target detection frame in the previous pre-processed image, if the to-be-associated target detection frame and the target detection frame in the previous pre-processed image are associated with each other, then enter step 3.5, if the to-be-associated target detection frame is not associated with any target detection frame in the previous pre-processed image, then enter step 3.7;
[0025] Step 3.5, connect the center points of the two associated target detection frames to form a segmented track, and then connect the segmented track with the historical moving track of the pig in the to-be-associated target detection frame to form the latest moving track;
[0026] Step 3.6, according to the latest moving track of the pig, trace back to obtain the corresponding identity ID, thereby associating the to-be-associated target detection frame with the corresponding identity ID, and then enter step 3.8;
[0027] Step 3.7, associate the to-be-associated target detection frame in the to-be-detected image with the unassociated identity ID in the ID pool, and then enter step 3.8;
[0028] Step 3.8, determine whether all target detection frames in the to-be-detected image have been data-associated, if they have been data-associated, then enter step 3.9, if they have not been data-associated, then return to step 3.3;
[0029] Step 3.9, judge whether each target detection box in the previous pre-processed image achieves mutual correlation, if all achieve mutual correlation, enter step 3.10, otherwise, perform correlation failure processing and then enter step 3.10;
[0030] Step 3.10, judge whether there is a pre-processed image in the cache that needs to be data correlated, if yes, return to step 3.1, if not, wait until there is a pre-processed image in the cache and then return to step 3.1.
[0031] Further, in step 3.3, the specific steps of data correlation processing are as follows:
[0032] Step 3.3.1, align and project the to-be-detected image and the previous pre-processed image onto a projection plane, and calculate the coordinate position of the center point of the target detection box to be correlated in the projection plane as the to-be-correlated position;
[0033] Step 3.3.2, calculate the coordinate position of the center point of each correlated target detection box in the previous pre-processed image in the projection plane as each correlated position, and then calculate the relative distance between the to-be-correlated position and each correlated position, respectively, and sort each relative distance according to the size;
[0034] Step 3.3.3, according to the smallest relative distance, if the smallest relative distance is less than the distance threshold, it is determined that the mutual correlation is achieved, and the target detection box to be correlated and the target detection box corresponding to the smallest relative distance are data correlated, otherwise, it is determined that the mutual correlation is not achieved.
[0035] Further, in step 3.9, when performing correlation failure processing, first, obtain the identity ID of the target detection box in the previous pre-processed image that does not achieve mutual correlation, and then return the obtained identity ID to the ID pool.
[0036] Further, in step 4, the specific steps of pig ear tag color recognition for the image in each target detection box in the pre-processed image are as follows:
[0037] Step 4.1, collect reference images of pig ear tags of each pig in the pig house, and then calculate the HSV maximum threshold and the HSV minimum threshold of the color of each reference image, thereby obtaining the HSV value comparison interval of each pig ear tag;
[0038] Step 4.2, select a target detection box to be recognized from the ear tag recognition area of the pre-processed image, and then intercept the image in the target detection box as a to-be-recognized image, and perform pig ear tag recognition on the to-be-recognized image;
[0039] Step 4.3, determine the corresponding identity ID according to the recognized pig ear tag;
[0040] Step 4.4, judge whether each target detection frame in the ear identification area has been identified, if all have been identified, enter step 5, otherwise return to step 4.2.
[0041] Further, in step 4.2, the specific steps of identifying the pig ear of the to-be-identified image are as follows:
[0042] Step 4.2.1, convert the to-be-identified image from RGB format to HSV format;
[0043] Step 4.2.2, extract the color block contour of the pig ear mark from the to-be-identified image in HSV format, and then judge whether there is only one color block contour in the to-be-identified image, if there is only one color block contour, enter step 4.2.3, if there are multiple color block contours, return to step 2;
[0044] Step 4.2.3, obtain the minimum area of the color block contour, calculate the HSV value of the center point of the circumscribed rectangle, compare the HSV value of the center point with the HSV value comparison interval of each pig ear mark, and find the HSV value comparison interval corresponding to the HSV value of the center point;
[0045] Step 4.2.4, according to the found HSV value comparison interval, query the corresponding pig ear mark.
[0046] Further, in step 5, the specific steps of calibrating each identity ID obtained in step 3 by using each identity ID obtained in step 4 are as follows:
[0047] Step 5.1, select one to-be-calibrated identity ID from the identity IDs obtained in step 4;
[0048] Step 5.2, determine the target detection frame corresponding to the to-be-calibrated identity ID, and then find the corresponding identity ID from the identity IDs obtained in step 3 according to the determined target detection frame, if the to-be-calibrated identity ID is the same as the identity ID found in step 3, no calibration is needed, and directly return to step 2, if the to-be-calibrated identity ID is not the same as the identity ID found in step 3, enter step 5.3;
[0049] Step 5.3, find an identity ID same as the identity ID to be calibrated in each identity ID obtained in step 3, if no same identity ID is found, assign the identity ID to be calibrated to the live pig in the target detection frame corresponding to step 3, so that the identity ID to be calibrated is associated with the moving track of the live pig in the corresponding target detection frame, if a same identity ID is found, obtain the moving track corresponding to the found same identity ID, then obtain the moving track of the live pig in the target detection frame corresponding to the identity ID to be calibrated, and then exchange the two obtained moving tracks;
[0050] Step 5.4, determine whether each identity ID obtained in step 4 is completed verification, if not all are completed verification, return to step 5.1, if all are completed verification, return to step 2.
[0051] Compared with the prior art, the present application has the beneficial effects that: the target detection method is used for target detection of live pigs, and the moving track of the live pigs is tracked, so that the continuous matching of the identity ID is maintained, and no additional hardware cost is needed; the non-contact detection and tracking method of the present application does not affect the health of the live pigs; the color of the pig ear tag is used for identity ID calibration, different colors of pig ear tags are used for each live pig to distinguish different live pigs, and the identity ID of the live pig in the pig house is matched with the pig ear tag, so that the live pig in the specified area can be calibrated through the identification of the pig ear tag; the pig ear tag is used to calibrate the possible mismatching in the video tracking process, and the accuracy of the identity ID tracking is improved. BRIEF DESCRIPTION OF DRAWINGS
[0052] Figure 1 The tracking method flowchart of the present application;
[0053] Figure 2 The target detection network framework diagram based on deep learning of the present application;
[0054] Figure 3 The color block contour diagram of the present application;
[0055] Figure 4 The HSV value comparison interval determination flowchart of the present application;
[0056] Figure 5 The ear tag identification area schematic diagram of the present application;
[0057] Figure 6 The pig ear tag detection flowchart of the present application;
[0058] Figure 7 The verification flowchart of the present application. DETAILED DESCRIPTION
[0059] The technical solutions of the present application will be described in detail below with reference to the drawings, but the protection scope of the present application is not limited to the described embodiments.
[0060] Intelligent pig raising replaces manual observation with machine vision technology to track the movement amount, activity level, feeding behavior, etc. of live pigs in the growth process, which is conducive to establishing a personalized live pig breeding system. The traditional RFID ear tag reader has distance limitations for monitoring live pigs, and the visual multi-target tracking technology is susceptible to the high similarity between pigs and the occlusion between pigs when tracking the identity of live pigs, which can cause ID switching problems between pigs due to errors in the data association stage. In order to achieve the goal of long-term tracking of live pigs, the present application designs a method for correcting the identity of abnormal pigs in a specified area based on color ear tags, which can check and correct the mismatch of identity ID within a certain time even if the identity ID is lost during tracking.
[0061] Embodiment 1
[0062] As shown in Figure 1 The live pig identity tracking method based on machine vision disclosed by the present application includes the following steps:
[0063] Step 1, initializing the identity ID of the live pig, so that each live pig in the pig house is configured with an identity ID, and all identity IDs of each pig house together constitute an ID pool. For example, five identity IDs are set in the ID pool when there are five live pigs in a pig house, and the identity ID of the live pig corresponds to the pig ear tag;
[0064] Step 2, selecting each video frame image from the pig house monitoring video stream according to a preset frame rate, and obtaining a pretreatment image by scaling the pretreatment of each video frame image;
[0065] Step 3, target detection is performed on each live pig in the pretreatment image, so that each live pig detected in the pretreatment image obtains a target detection box, and the movement trajectory of the live pig is obtained by tracking the target detection box, and each movement trajectory of the live pig corresponds to an associated identity ID;
[0066] Step 4, the ear tag recognition area is demarcated in the pretreatment image, and the pig ear tag recognition is performed on the image in each target detection box in the ear tag recognition area, so as to match the identity ID of the live pig in each target detection box according to the corresponding relationship between the pig ear tag and the identity ID;
[0067] Step 5, calibrate the movement trajectory of each live pig obtained in step 3 by using each identity ID obtained in step 4, and return to step 2.
[0068] The live pig is detected by using a target detection method, and the moving track of the live pig is tracked, so that the continuous matching of the identity ID is maintained, and no additional hardware cost is needed; the non-contact detection and tracking method of the application has no influence on the health of the live pig; the color of the pig ear tag is used for identity ID calibration, different colors of pig ear tags are used for each live pig to distinguish different live pigs, and the identity ID of the live pig in the pig house is matched with the pig ear tag, so that the live pig in the specified area can be calibrated through the identification of the pig ear tag; the pig ear tag is used to calibrate the possible mismatch in the video tracking process, and the accuracy of the identity ID tracking is improved.
[0069] Further, in step 1, the specific steps for initializing the identity ID of the live pig are:
[0070] Step 1.1, the number of live pigs in the pig house is obtained, and the corresponding number of identity IDs is set according to the number of live pigs, and each identity ID is different;
[0071] Step 1.2, each identity ID is respectively matched with the pig ear tag serial code of each live pig, and the color of the pig ear tag of each live pig in the pig house is different, for example, five pigs in the pig house are provided with pig ear tags of five colors, blue, green, red, orange and yellow.
[0072] Different colors of pig ear tags can be reliably distinguished during identification, so that the color of the pig ear tag can be quickly determined, and the corresponding identity ID can be further found.
[0073] Further, in step 2, the specific steps for obtaining the preprocessed image are:
[0074] Step 2.1, detect whether the pig house monitoring video stream completely covers the live pig activity area in the pig house, if all live pigs in the pig house always remain in the pig house monitoring video stream, it is determined that it is completely covered, and then step 2.3 is entered, otherwise it is determined that it is not completely covered, and then step 2.2 is entered;
[0075] Step 2.2, use the preset user communication method to feed back the prompt information of incomplete monitoring, and wait for the adjustment confirmation information of the user, and then enter step 2.3 after obtaining the adjustment confirmation information;
[0076] Step 2.3, obtain the frame rate of the image acquisition preset by the user, and select each video frame image from the pig house monitoring video stream according to the preset frame rate;
[0077] Step 2.4, proportionally scale the length and width of each video frame image to obtain a preprocessed image meeting the target detection size requirement.
[0078] Further, the specific steps of step 3 for target detection on live pigs in the pre-processed image are as follows:
[0079] Step 3.1, taking one pre-processed image as a to-be-detected image in time sequence from the cache;
[0080] Step 3.2, using a deep learning-based target detection network to detect and identify each live pig in the to-be-detected image, and loading a corresponding target detection frame on the to-be-detected image after successful identification, so that each identified live pig is located in a target detection frame.
[0081] As shown in Figure 2 , the deep learning-based target detection network adopted for live pig target detection on the to-be-detected image outputs two branches: a target detection (Detections) branch and a Re-ID Embedding branch. The target detection (Detections) branch outputs a target detection frame for each pig; and the Re-ID Embedding branch outputs an identity feature embedding vector of the target.
[0082] Further, in step 3, the specific steps for obtaining the moving track of the live pig by tracking the target detection frame are as follows:
[0083] Step 3.3, taking one to-be-detected image loaded with a target detection frame from the cache in time sequence, determining whether the to-be-detected image is the first pre-processed image, if so, directly associating each identity ID in the ID pool with each target detection frame in the to-be-detected image, and then entering step 3.10, if not, entering step 3.4;
[0084] Step 3.4, selecting one to-be-associated target detection frame from the to-be-detected image, and performing data association processing on the to-be-associated target detection frame and the target detection frame in the previous pre-processed image, if the to-be-associated target detection frame and the target detection frame in the previous pre-processed image are associated with each other, entering step 3.5, if the to-be-associated target detection frame is not associated with any target detection frame in the previous pre-processed image, entering step 3.7;
[0085] Step 3.5, connecting the center points of the two associated target detection frames to form a segmented track, and then connecting the segmented track with the historical moving track of the live pig in the to-be-associated target detection frame to form the latest moving track;
[0086] Step 3.6, obtaining the corresponding identity ID according to the latest moving track of the live pig, thereby associating the to-be-associated target detection frame with the corresponding identity ID, and then entering step 3.8;
[0087] Step 3.7, the target detection frame to be associated in the image to be detected is associated with the identity ID not associated in the ID pool, and then step 3.8 is entered;
[0088] Step 3.8, it is judged whether all the target detection frames in the image to be detected are data association processing completed, if all the data association processing is completed, step 3.9 is entered, if not all the data association processing is completed, step 3.3 is returned;
[0089] Step 3.9, it is judged whether all the target detection frames in the previous preprocessed image are associated with each other, if all the target detection frames are associated with each other, step 3.10 is entered, otherwise, after association failure processing, step 3.10 is entered;
[0090] Step 3.10, it is judged whether there is a preprocessed image in the cache that needs data association, if there is, step 3.1 is returned, if not, step 3.1 is returned after there is a preprocessed image in the cache.
[0091] Further, in step 3.3, the specific steps of data association processing are as follows:
[0092] Step 3.3.1, the image to be detected and the previous preprocessed image are projected onto a projection plane, the coordinate position of the center point of the target detection frame to be associated in the projection plane is calculated as the associated position;
[0093] Step 3.3.2, the coordinate position of the center point of each associated target detection frame in the previous preprocessed image in the projection plane is calculated as each associated position, and the relative distance between the associated position and each associated position is calculated respectively, and each relative distance is sorted according to the size;
[0094] Step 3.3.3, according to the smallest relative distance, if the smallest relative distance is smaller than the distance threshold, it is determined that the target detection frames are associated with each other, and the target detection frame to be associated is data associated with the target detection frame corresponding to the smallest relative distance, otherwise, it is determined that the target detection frames are not associated with each other.
[0095] Further, in step 3.9, when the association failure processing is performed, the identity ID of the target detection frame not associated in the previous preprocessed image is obtained, and then the obtained identity ID is returned to the ID pool. By returning the identity ID not associated to the ID pool, the identity ID can be reactivated when a new target is detected.
[0096] Further, in step 4, the specific steps of pig ear mark color recognition for the image in each target detection frame in the preprocessed image are as follows:
[0097] Step 4.1, the reference image of each piglet's ear tag in the pig house is collected by using the camera, and the HSV maximum threshold and the HSV minimum threshold of the color of each reference image are calculated, so as to obtain the HSV value comparison interval of each ear tag as [HSV minimum threshold, HSV maximum threshold];
[0098] As Figure 3 shown, considering that the pig ear tag target worn in the camera picture is small, in order to more accurately label the HSV value comparison interval of the pig ear tag, the pig ear tag needs to be intercepted and enlarged into a pixel block image, the color of the pig ear tag is determined by the pixel color block in the middle, and the pixel color block close to the edge should not be selected because it contains noise, especially when there are many color types of pig ear tags, clear boundaries are divided when calibrating the HSV value comparison interval, and different colors are distinguished through image filtering algorithm;
[0099] As Figure 4 shown, taking five pigs in the pig house as an example, blue, green, red, orange and yellow pig ear tags of five colors are prepared, the pig house in the real scene is pre-shooted by using the camera, and each pig ear tag image is intercepted from the shot image, which is enlarged into a pixel block image and saved; then the opencv tool is used to read the pixel block image, and the pixel block image is converted from the RGB color model into the HSV color model; the coordinate position (x, y) of the pixel color block is selected in the pixel block image, the h, s, v values of the point are obtained, a group of h, s, v values are obtained by selecting different pixel color blocks for many times; the maximum and minimum values of h, s, v are obtained as the HSV maximum threshold and the HSV minimum threshold as the threshold interval boundary, that is, the HSV value comparison interval is determined, so as to represent the pig ear tag of this color. As Figure 3 shown, the pixel block image corresponds to the blue pig ear tag, and table 1 corresponds Figure 3 to the HSV values of the red frame pixel color block in
[0100] Table 1
[0101] h 1 2 3 4 1 [96 110 234] [96 108 233] 2 [96 127 215] [98 152 244] [98 150 242] [96 133 203] 3 [97 151 220] [98 178 245] [98 170 253] [96 140 243] 4 [97 169 223] [98 194 246] [97 187 254] [96 160 249] 5 [97 158 215] [98 179 246] [97 178 249] [96 157 231] 6 [96 125 212] [98 150 238] [97 147 244] [95 118 242]
[0102] Table 2
[0103] Live Pig ID 1 2 3 4 5 Pig Ear Tag Color Blue Green Red Orange Yellow hsv_min (95,108,203) (51,101,234) (0,165,130) (15,184,235) (25,77,253) hsv_max (98,194,254) (65,133,255) (179,234,223) (17,215,255) (30,116,255)
[0104] Step 4.2, selecting a target detection frame to be identified from the ear mark identification area of the pre-processed image, and then intercepting the image in the target detection frame as a to-be-identified image, and performing pig ear mark identification on the to-be-identified image;
[0105] Step 4.3, determining the corresponding identity ID according to the identified pig ear mark;
[0106] Step 4.4, judging whether each target detection frame in the ear mark identification area has been subjected to pig ear mark identification, if all have been subjected to pig ear mark identification, then entering step 5, otherwise returning to step 4.2.
[0107] As shown in Figure 6 Further, the specific steps of performing pig ear mark identification on the to-be-identified image in step 4.2 are as follows:
[0108] Step 4.2.1, converting the to-be-identified image from RGB format to HSV format;
[0109] Step 4.2.2, using the inRange function of opencv to filter out all pixel points in the to-be-identified image in HSV format within the HSV value comparison interval of various pig ear marks to obtain a mask, setting a 3x3 kernel convolution kernel, extracting a series of color blocks from the mask through the getStructuringElement image erosion operation of opencv, filtering out the noise in the color block contour, finding the color block contour by using the findContours function of opencv, and then judging whether there is only one color block contour in the to-be-identified image, if there is only one color block contour, then entering step 4.2.3, if there are multiple color block contours, then returning to step 2;
[0110] Step 4.2.3, obtaining the minimum area of the color block contour, calculating the HSV value of the center point of the circumscribed rectangle, matching the HSV value of the center point with the HSV value comparison interval of each pig ear mark, finding the HSV value comparison interval corresponding to the HSV value of the center point by querying table 2, and further determining the color of the pig ear mark to obtain the identity ID of the live pig;
[0111] Step 4.2.4, querying the corresponding pig ear mark according to the found HSV value comparison interval.
[0112] As shown in Figure 5As shown, in determining the ear identification area, assuming that the resolution of the preprocessed image is HxW, the middle area of the preprocessed image, i.e. the area directly below the camera [1 / 5*H:4 / 5*H, 1 / 4*W:3 / 4*W] is selected as the ear identification area, so that the pig ear marks in the entire preprocessed image do not need to be calibrated, effectively improving the calibration efficiency of the moving track and saving computing resources.
[0113] As shown, further, in step 5, the specific steps of calibrating each identity ID obtained in step 3 by using each identity ID obtained in step 4 are as follows: Figure 7
[0114] Step 5.1, selecting one identity ID to be calibrated from each identity ID obtained in step 4;
[0115] Step 5.2, determining the target detection frame corresponding to the identity ID to be calibrated, and then searching for the corresponding identity ID from each identity ID obtained in step 3 according to the determined target detection frame, if the identity ID to be calibrated is the same as the identity ID searched in step 3, no calibration is needed, and step 2 is directly returned, if the identity ID to be calibrated is not the same as the identity ID searched in step 3, step 5.3 is entered;
[0116] Step 5.3, searching for an identity ID same as the identity ID to be calibrated from each identity ID obtained in step 3, if no same identity ID is found, the identity ID to be calibrated is assigned to the live pig in the corresponding target detection frame in step 3, so that the identity ID to be calibrated is associated with the moving track of the live pig in the corresponding target detection frame, if a same identity ID is found, the moving track corresponding to the found same identity ID is obtained, the moving track of the live pig in the target detection frame corresponding to the identity ID to be calibrated is obtained, and the two obtained moving tracks are interchanged;
[0117] Step 5.4, judging whether each identity ID obtained in step 4 is completed, if not all are completed, step 5.1 is returned, if all are completed, step 2 is returned.
[0118] As described above, although the present application has been indicated and expressed with reference to specific preferred embodiments, it should not be interpreted as a limitation of the present application itself. Various changes can be made to the form and details thereof without departing from the spirit and scope of the present application defined in the appended claims.
Claims
1. A machine vision-based live pig identity tagging and tracking method, characterized in that, The method comprises the following steps: Step 1, initializing the identity ID of the live pig, so that each live pig in the pig house is configured with an identity ID, all the identity IDs of each pig house collectively constitute an ID pool, and the identity ID of the live pig corresponds to the pig ear tag; Step 2, selecting each video frame image from the pig house monitoring video stream according to a preset frame rate, and obtaining a pretreatment image by scaling the pretreatment of each video frame image; Step 3, target detection is performed on each live pig in the pretreatment image, so that each live pig detected in the pretreatment image obtains a target detection box, and the movement trajectory of the live pig is obtained by tracking the target detection box, and the movement trajectory of each live pig is associated with an identity ID; Step 4, delimiting an ear recognition area in the pretreatment image, performing pig ear recognition on the image in each target detection box in the ear recognition area, and matching the identity ID of the live pig in each target detection box according to the correspondence between the pig ear and the identity ID; Step 5, using each identity ID obtained in step 4 to calibrate the movement trajectory of each live pig obtained in step 3, and returning to step 2; In step 1, the specific steps of initializing the identity ID of the live pig are as follows: Step 1.1, obtaining the number of live pigs in the pig house, and setting a corresponding number of identity IDs according to the number of live pigs, and each identity ID is different; Step 1.2, each identity ID is corresponded to the pig ear tag serial code of each live pig, and the color of the pig ear tag of each live pig in the pig house is different; In step 5, the specific steps of calibrating each identity ID obtained in step 3 using each identity ID obtained in step 4 are as follows: Step 5.1, selecting one identity ID to be calibrated from the identity IDs obtained in step 4; Step 5.2, determining the target detection box corresponding to the identity ID to be calibrated, and finding the corresponding identity ID from the identity IDs obtained in step 3 according to the determined target detection box, if the identity ID to be calibrated is the same as the identity ID found in step 3, no calibration is needed, and step 2 is directly returned, if the identity ID to be calibrated is different from the identity ID found in step 3, step 5.3 is entered; Step 5.3, finding an identity ID that is the same as the identity ID to be calibrated in the identity IDs obtained in step 3, if no same identity ID is found, the identity ID to be calibrated is assigned to the live pig in the corresponding target detection box in step 3, so that the identity ID to be calibrated is associated with the movement trajectory of the live pig in the corresponding target detection box, if a same identity ID is found, the movement trajectory corresponding to the found same identity ID is obtained, the movement trajectory of the live pig in the target detection box corresponding to the identity ID to be calibrated is obtained, and the two obtained movement trajectories are interchanged; Step 5.4, judging whether all the identity IDs obtained in step 4 are verified, if not all are verified, returning to step 5.1, if all are verified, returning to step 2.
2. The machine vision-based pig identity tracking method according to claim 1, wherein, In step 2, the specific steps of obtaining the pretreatment image are as follows: Step 2.1, detecting whether the pig house monitoring video stream completely covers the piglet activity area in the pig house, if all piglets in the pig house are always kept in the pig house monitoring video stream, it is determined that it is completely covered, and then step 2.3 is entered, otherwise it is determined that it is not completely covered, and then step 2.2 is entered; Step 2.2, using the preset user communication mode to feed back the prompt information of incomplete monitoring, and waiting for the adjustment confirmation information of the user, and then entering step 2.3 after obtaining the adjustment confirmation information; Step 2.3, obtaining the frame rate of image acquisition preset by the user, and selecting each video frame image from the pig house monitoring video stream according to the preset frame rate; Step 2.4, scaling the length and width of each video frame image by the same ratio to obtain a preprocessed image meeting the target detection size requirement.
3. The machine vision-based pig identity tracking method according to claim 1, wherein, In step 3, the specific steps of target detection of piglets in the preprocessed image are as follows: Step 3.1, taking a preprocessed image from the cache in chronological order as a to-be-detected image; Step 3.2, using a target detection network based on deep learning to detect and identify each piglet in the to-be-detected image, and loading a corresponding target detection frame on the to-be-detected image after successful identification, so that each identified piglet is located in each target detection frame.
4. The machine vision-based pig identity tracking method according to claim 3, wherein, In step 3, the specific steps of obtaining the moving track of the piglet by tracking the target detection frame are as follows: Step 3.3, taking a to-be-detected image loaded with a target detection frame from the cache in chronological order, judging whether the to-be-detected image is the first preprocessed image, if it is the first preprocessed image, directly associating each identity ID in the ID pool with each target detection frame in the to-be-detected image, and then entering step 3.10, if it is not the first preprocessed image, entering step 3.4; Step 3.4, selecting a to-be-associated target detection frame from the to-be-detected image, and performing data association processing on the to-be-associated target detection frame and the target detection frame in the previous preprocessed image, if the to-be-associated target detection frame and the target detection frame in the previous preprocessed image are associated with each other, entering step 3.5, if the to-be-associated target detection frame is not associated with any target detection frame in the previous preprocessed image, entering step 3.7; Step 3.5, connecting the center points of the two mutually associated target detection frames to form a segmented track, and then connecting the segmented track with the historical moving track of the piglet in the to-be-associated target detection frame to form the latest moving track; Step 3.6, obtaining the corresponding identity ID according to the latest moving track of the piglet, thereby associating the to-be-associated target detection frame with the corresponding identity ID, and then entering step 3.8; Step 3.7, associating the to-be-associated target detection frame in the to-be-detected image with the unassociated identity ID in the ID pool, and then entering step 3.8; Step 3.8, judging whether all target detection frames in the to-be-detected image are data association processed, if all target detection frames are data association processed, entering step 3.9, if not all target detection frames are data association processed, returning to step 3.3; Step 3.9, judge whether each target detection box in the previous pre-processed image achieves mutual correlation, if all achieve mutual correlation, enter step 3.10, otherwise, perform correlation failure processing and then enter step 3.10; Step 3.10, judge whether there is still a pre-processed image in the cache to be correlated, if yes, return to step 3.1, if no, wait until there is a pre-processed image in the cache and then return to step 3.
1.
5. The machine vision-based pig identity tracking method according to claim 4, wherein, In step 3.3, the specific steps of data correlation processing are as follows: Step 3.3.1, align and project the to-be-detected image and the previous pre-processed image onto a projection plane, and calculate the coordinate position of the center point of the to-be-correlated target detection box in the projection plane as the to-be-correlated position; Step 3.3.2, calculate the coordinate position of the center point of each correlated target detection box in the previous pre-processed image in the projection plane as each correlated position, and then calculate the relative distance between the to-be-correlated position and each correlated position respectively, and sort each relative distance according to size; Step 3.3.3, make correlation judgment according to the smallest relative distance, if the smallest relative distance is less than the distance threshold, it is judged as mutual correlation, and the to-be-correlated target detection box is correlated with the target detection box corresponding to the smallest relative distance, otherwise, it is judged as non-mutual correlation.
6. The machine vision-based pig identity tracking method according to claim 4, wherein, In step 3.9, when performing correlation failure processing, first obtain the identity ID of the target detection box in the previous pre-processed image that does not achieve mutual correlation, and then return the obtained identity ID to the ID pool.
7. The machine vision-based pig identity tracking method according to claim 1, wherein, In step 4, the specific steps of pig ear tag color recognition for the image in each target detection box in the pre-processed image are as follows: Step 4.1, collect reference images of pig ear tags of each pig in the pig house, and then calculate the HSV maximum threshold and HSV minimum threshold of the color of each reference image, thereby obtaining the HSV value comparison interval of each pig ear tag; Step 4.2, select a to-be-recognized target detection box from the ear tag recognition area of the pre-processed image, and then intercept the image in the target detection box as a to-be-recognized image, and perform pig ear tag recognition on the to-be-recognized image; Step 4.3, determine the corresponding identity ID according to the recognized pig ear tag; Step 4.4, judge whether each target detection box in the ear tag recognition area has been subjected to pig ear tag recognition, if all have been subjected to pig ear tag recognition, enter step 5, otherwise, return to step 4.
2.
8. The machine vision-based pig identity tracking method according to claim 7, wherein, In step 4.2, the specific steps of pig ear tag recognition for the to-be-recognized image are as follows: Step 4.2.1, convert the to-be-recognized image from RGB format to HSV format; Step 4.2.2, extract the color block contour of the pig ear tag from the to-be-recognized image in HSV format, and then judge whether there is only one color block contour in the to-be-recognized image, if there is only one color block contour, enter step 4.2.3, if there are multiple color block contours, return to step 2; Step 4.2.3, obtain the minimum area of the color block contour, calculate the HSV value of the circumscribed rectangle center point, match the HSV value of the center point with the HSV value comparison interval of each pig ear mark, find the HSV value comparison interval corresponding to the HSV value of the center point; Step 4.2.4, query the corresponding pig ear mark according to the found HSV value comparison interval.
Citation Information
Patent Citations
Pig monitoring method, device and system based on pig ear tags in different shapes
CN112135102A
Cow ear tag identification system
CN115171156A