A method for identifying illegal dog walking without a leash based on deep learning Yolov8
By developing a deep learning Yolov8-based method for identifying illegal dog walking without a leash, and combining image equalization and multi-scale detection models, the efficiency and accuracy issues in dog walking behavior monitoring are resolved, achieving efficient and accurate dog walking behavior recognition.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- NANJING UNIV OF SCI & TECH
- Filing Date
- 2024-04-28
- Publication Date
- 2026-05-26
AI Technical Summary
In existing technologies, methods for monitoring dog walking behavior rely on manual review, which is inefficient and inaccurate. Deep learning-based algorithms for detecting illegal dog walking perform poorly in terms of processing speed and accuracy, and also have errors in judging logical relationships.
A method for identifying illegal dog walking without a leash based on deep learning Yolov8 is adopted. Image data is enhanced by image equalization algorithm, and dog, leash and human detection models are combined to judge the state of dog, leash and human respectively. The model is optimized by multi-scale framework and improved loss function to identify dog walking behavior.
It improves the accuracy and efficiency of dog walking behavior detection, reduces false detections and missed detections, adapts to diverse leash structures and complex scenarios, can better assess dog walking status, and reduces the workload of manual review.
Smart Images

Figure CN118762316B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of computer vision technology, and in particular to a method for identifying illegal dog walking without a leash based on deep learning Yolov8. Background Technology
[0002] Dog owners usually take their dogs for walks in public places regularly, but if they do not use a leash or do not properly leash their dogs, it is difficult for dog walkers to effectively control their dogs, which poses a serious threat to the personal safety of others in the community and to the community's public property.
[0003] As regulations continue to improve, relevant agencies have begun to implement stricter supervision and control over dog walking that violates regulations. According to the latest regulations, dogs must wear tags and be leashed when walked. Currently, the detection of legal dog walking in public places mainly relies on manual visual inspection; however, manual inspection is prone to omissions and inefficiency, and often fails to immediately identify the responsible parties. This means that current methods for monitoring violations of dog walking regulations lack sufficient effectiveness and feasibility. Similarly, some invention patents use deep learning-based algorithms to detect illegal dog walking; however, these algorithms are limited by the constraints of deep learning models, resulting in poor processing speed and accuracy. Furthermore, their judgment of the logical relationship between the person, dog, and leash differs from the real-world environment, leading to a high false detection rate in some scenarios when assessing whether dog owners are leashing their dogs. Summary of the Invention
[0004] To overcome the shortcomings of existing technologies, the purpose of this invention is to provide a method for identifying illegal dog walking without a leash based on deep learning Yolov8, which solves the problems of low efficiency in current manual supervision of dog walking violations and low accuracy in existing deep learning-based models for detecting illegal dog walking.
[0005] To achieve the above objectives, the present invention provides the following solution:
[0006] A method for identifying illegal dog walking without a leash based on deep learning Yolov8 includes the following steps:
[0007] The image data to be detected is acquired, and the color of the image data is enhanced using an image equalization algorithm to obtain the image to be detected;
[0008] The image to be detected is input into the dog detection model to detect dogs, and a dog detection box is obtained.
[0009] The dog detection model is used to determine the dog status of the dog detection box to obtain the result of whether a dog exists in the dog detection box;
[0010] Based on whether there is a dog status result in the dog detection box, the rope interest region result appearing near the dog is calculated with the dog detection box as the center, and the rope interest region result is input into the rope detection model for rope detection to obtain the rope-dog detection box.
[0011] The rope-dog detection box is input into the rope detection model for judgment to obtain the result of whether the rope is in the correct dog-tethering state;
[0012] Based on whether the leash is in the correct dog-tethering state, the human interest region appearing in the leash-dog detection box is calculated with the leash-dog detection box as the center, and the human interest region result is input into the human detection model for human detection to obtain the human-leash-dog detection box.
[0013] The human-leash-dog detection box is input into the human detection model for judgment to obtain the result of whether the human is in a correct dog-leaning state or the result of the predicted correct dog-leaning state, so as to identify whether there is illegal dog-walking behavior in the image to be detected.
[0014] Preferably, the step of acquiring the image data to be detected and enhancing the color of the image data using an image equalization algorithm to obtain the image to be detected includes:
[0015] The original image data to be processed is acquired, and the color and spatial domain of the original image data are adjusted to complete the color and tone correction of the original image data, thereby obtaining the image to be detected after spatial domain reconstruction.
[0016] The color and spatial domain of the original image data are adjusted to complete the color and tone correction of the original image data, resulting in the spatially reconstructed image to be detected. The specific calculation formula is as follows:
[0017]
[0018] In the formula, S α (·) represents the slope function; R(m) represents the spatial reconstructed image; Ω represents the set of all pixels in the original image; I(m) represents the pixel value of point m in the original image; I(n) represents the pixel value of point n in the original image; I(m)-I(n) represents the pixel difference between points m and n; ∥mn∥ represents the distance metric.
[0019] The corrected spatial reconstruction image is dynamically expanded and normalized to the range [0,1] to obtain the image to be detected:
[0020]
[0021] In the formula, G(m) represents the image to be detected; maxR represents the maximum value of R(m); and minR represents the minimum value of R(m).
[0022] Preferably, the dog detection model, leash detection model, and human detection model all employ a deep learning Yolov8 detection model. The dog detection model, leash detection model, and human detection model are trained using the deep learning Yolov8 detection model, and optimized using a loss function.
[0023] L loss =λ1L conf +λ2L cla +λ3L loc ;
[0024] In the formula, L conf L represents the confidence loss of the target. cla For class loss, L loc For the localization loss, λ1, λ2, and λ3 are the corresponding balance coefficients; L loss This represents the total loss.
[0025] Preferably, the step of determining the dog's status by using a dog detection model to determine whether a dog exists in the dog detection box includes:
[0026] The dog detection and judgment module in the dog detection model judges the dog detection box. If there is a dog in the dog detection box, the dog detection box is input to the rope detection stage; otherwise, the image to be detected is judged to be in a state without dogs.
[0027] Preferably, the step of calculating the rope interest region near the dog based on whether there is a dog state result in the dog detection box, with the dog detection box as the center, and inputting the rope interest region result into the rope detection model for rope detection to obtain the rope-dog detection box includes:
[0028] Centered on the dog detection box, and based on the aspect ratio of the image to be detected and the dog detection box, the region of interest of the rope appearing near the dog is calculated; the scale is changed, the region of interest of the rope appearing near the dog is recalculated, and the rope-dog detection box at different scales is obtained through the rope detection model.
[0029] Based on the aspect ratio of the image to be detected and the dog detection bounding box, the width and height of the region of interest are calculated as follows:
[0030]
[0031]
[0032] In the formula, Winterest and H interest W represents the width and height of the region of interest, respectively; dog and H dog W represents the width and height of the dog detection frame, respectively; image and H image represents the width and height of the complete image, respectively; β represents the scale factor, which dynamically adjusts the extent of the region of interest to adapt to diverse rope structures; and These represent the aspect ratios of the image and the detection box, respectively, to reasonably calculate the size of the region of interest;
[0033] Based on the width and height of the region of interest, calculate the region of interest near the dog as follows:
[0034]
[0035] In the formula, I R The coordinates of the top-left and bottom-right corners of the region of interest; and To prevent the top-left corner coordinates from exceeding the image boundary; and To prevent the bottom right corner coordinates from exceeding the image boundary.
[0036] Preferably, obtaining rope-dog detection frames at different scales using the rope detection model includes:
[0037] If a rope is present in the rope-detection frame, proceed to the rope-dog relationship determination stage;
[0038] If multiple ropes exist in the rope detection frame, the maximum intersection mode is used, and the rope with the highest overlap with the dog is selected as the target rope to be judged.
[0039]
[0040] In the formula, I rope The target rope to be judged; argmax(t) is the index corresponding to the maximum value; t is the value of I. rope_i ∩I dog ;I rope_i For any rope currently detected; I dog The current detection frame for dogs that need to be processed;
[0041] If no rope is present, the output image will show a violation involving a dog without a leash.
[0042] Preferably, the rope-dog detection frame is input into the rope detection model for judgment to obtain a result on whether the rope is in a correct tethering state, including:
[0043] The rope detection and judgment module in the rope detection model calculates the intersection area of the rope and dog detection boxes. The calculation formula is as follows:
[0044] A rope_dog =area(I rope ∩I dog );
[0045] In the formula, the area() function calculates the area of a square region based on the coordinates of its top-left and bottom-right corners; A rope_dog The area of the intersection between the target dog and the target rope detection frame;
[0046] If A rope_dog If the dog-leash relationship threshold is greater than the set threshold, the dog is legally leashed; otherwise, the dog and leash are in an illegal relationship.
[0047] Preferably, based on whether the leash is in a correctly leashed state, the human region of interest (ROI) within the leash-dog detection box is calculated, centered on the leash-dog detection box. This ROI result is then input into a human detection model for human detection, resulting in a human-leash-dog detection box, including:
[0048] If a human body is present or absent in the human body-rope-dog detection frame, the process proceeds directly to the human body-rope-dog relationship determination stage.
[0049] If multiple human bodies exist within the human-rope-dog detection frame, the maximum intersection mode is used, selecting the human body with the highest overlap with the rope as the target human body to be identified.
[0050]
[0051] In the formula, I people The target human body to be judged; argmax(t) is the index corresponding to the maximum value; t is the value of I. people_i ∩I rope ;I people_i For any rope or human body currently detected; I rope This is the rope-dog detection frame that needs to be processed currently.
[0052] Preferably, the human-leash-dog detection box is input into the human detection model for judgment to obtain a result of whether the human is in a correct dog-leaning state or an estimated result of a correct dog-leaning state, so as to identify whether there is illegal dog-walking behavior in the image to be detected, including:
[0053] The human detection and judgment module in the human detection model judges the human-rope-dog detection box. If a human body is present in the human-rope-dog detection box, the intersection area of the human body and the rope-dog detection box is calculated.
[0054] A people_rope_dog =area(I people ∩I rope ∩I dog );
[0055] In the formula, the area() function calculates the area of the square region based on the coordinates of the top left and bottom right corners of the human-rope-dog detection box; A people_rope_dog The area of intersection between the target human body, the target dog, and the target rope detection frame;
[0056] If A people_rope_dog If the relationship between the human, the dog, and the leash exceeds the set threshold, the dog is considered to be legally leashed and the human is legally holding the other half of the leash; otherwise, the human is considered to be illegally walking the dog.
[0057] Preferably, the estimated result of the correct human-leaf-dog state includes: if there is no human body in the human-leash-dog detection frame, then calculate whether the target leash reasonably extends to the boundary of the image to be detected. If reasonable, then determine that the target dog-target leash is legally leashed by a human body that is not visible outside the image to be detected. The judgment condition is:
[0058]
[0059]
[0060]
[0061]
[0062] In the formula, x threshold and y threshold This represents the minimum threshold between the target rope and the boundary of the image to be detected. and Indicates the coordinates of the top left corner of the target rope; and This indicates the coordinates of the lower right corner of the target leash. If all four conditions are met, it is determined that the target dog and its leash are legally tethered by a human body not visible outside the image. Otherwise, the image to be detected indicates that the dog is being walked illegally.
[0063] According to specific embodiments provided by the present invention, the present invention discloses the following technical effects:
[0064] (1) Based on the deep learning YOLOv8 detection framework, this invention designs a dog, rope and human detection model, which can ensure that the model has a better recognition effect on dogs, rope and human, greatly avoids false detection and false negative detection, and thus ensures the credibility of the detection results; compared with the traditional manual review method, it greatly improves the review speed and ensures the practical feasibility; compared with the existing deep detection frameworks (YoLOv7, YOLOv5, etc.), YOLOv8 adopts a brand-new backbone, based on anchor-free, and designs a brand-new loss function, which further ensures the processing speed and accuracy of the detection effect and has a stronger ability to be deployed in the field.
[0065] (2) Based on the diverse rope structures and rope-like obstacles in the real environment, this invention designs a rope interest region detection method under a multi-scale framework. It can search for the existence of ropes near dogs from multiple scales. On the one hand, it can adapt to dog leashes of different lengths, and on the other hand, it can reduce the misjudgment of rope detection by rope-like interference objects such as wall cracks, ground cracks and tree branches.
[0066] (3) Based on the reality dimension, this invention takes into account the relationship between the human body, the dog and the leash, and proposes a dog walking state of "predicting that someone is walking the dog". Compared with the existing dog walking detection methods, this state can better evaluate the scene of a pedestrian walking a dog in some images with only half of the body (and below) captured, and avoid the dog being wrongly judged as illegally walking the dog due to the lack of pedestrian detection, thereby increasing the ineffective visits of management personnel. Attached Figure Description
[0067] To more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the drawings used in the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0068] Figure 1 This is a flowchart illustrating a method for identifying illegal dog walking without a leash based on deep learning Yolov8 according to the present invention.
[0069] Figure 2 This is an overall flowchart of the present invention, which is a method for identifying illegal dog walking without a leash based on deep learning Yolov8.
[0070] Figure 3 A flowchart provided for the dog detection and judgment module of the present invention;
[0071] Figure 4 A flowchart provided for the rope detection and judgment module of this invention;
[0072] Figure 5 This is a flowchart provided for the human body detection and judgment module of the present invention. Detailed Implementation
[0073] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0074] To make the above-mentioned objects, features and advantages of the present invention more apparent and understandable, the present invention will be further described in detail below with reference to the accompanying drawings and specific embodiments.
[0075] Example 1
[0076] like Figure 1 and Figure 2 As shown, this invention provides a method for identifying illegal dog walking without a leash based on deep learning Yolov8, including the following steps:
[0077] Step 100: Acquire the image data to be detected, and enhance the color of the image data using an image equalization algorithm to obtain the image to be detected;
[0078] Step 200: Input the image to be detected into the dog detection model to detect dogs and obtain the dog detection box;
[0079] Step 300: Use the dog detection model to determine the dog status of the dog detection box to obtain the result of whether a dog exists in the dog detection box;
[0080] Step 400: Based on whether there is a dog in the dog detection box, calculate the rope interest region near the dog with the dog detection box as the center, and input the rope interest region result into the rope detection model to detect the rope, and obtain the rope-dog detection box.
[0081] Step 500: Input the rope-dog detection box into the rope detection model for judgment to obtain the result of whether the rope is in the correct dog-tethering state;
[0082] Step 600: Based on whether the leash is in the correct dog-tethering state, take the leash-dog detection box as the center, calculate the human interest region result in the leash-dog detection box, and input the human interest region result into the human detection model for human detection to obtain the human-leash-dog detection box.
[0083] Step 700: Input the human-leash-dog detection box into the human detection model for judgment, and obtain the result of whether the human is in a correct dog-leaning state or the result of the predicted correct dog-leaning state, so as to identify whether there is illegal dog-walking behavior in the image to be detected.
[0084] Specifically, in step 100, acquiring the image data to be detected and enhancing the color of the image data using an image equalization algorithm to obtain the image to be detected includes:
[0085] The original image data to be processed is acquired, and the color and spatial domain of the original image data are adjusted to complete the color and tone correction of the original image data, thereby obtaining the image to be detected after spatial domain reconstruction.
[0086] In this embodiment, image data captured in a real environment may be affected by environmental factors such as lighting and obstructions, resulting in abnormal phenomena such as excessively dark or overexposed image data. Therefore, this embodiment uses an image equalization algorithm to enhance the original image data to avoid excessively dark or overexposed images in the image to be detected, thus preventing the actual detection effect from deteriorating.
[0087] Therefore, the color and spatial domain of the original image data are adjusted to complete the color and tone correction of the original image data, resulting in the spatially reconstructed image to be detected. The specific calculation formula is as follows:
[0088]
[0089] In the formula, S α (·) represents the slope function; R(m) represents the spatial reconstructed image; Ω represents the set of all pixels in the original image; I(m) represents the pixel value of point m in the original image; I(n) represents the pixel value of point n in the original image; I(m)-I(n) represents the pixel difference between points m and n; ∥mn∥ represents the distance metric.
[0090] The corrected spatial reconstruction image is then dynamically expanded and normalized to the range [0,1] to obtain the image to be detected.
[0091]
[0092] In the formula, G(m) represents the image to be detected; maxR represents the maximum value of R(m); and minR represents the minimum value of R(m).
[0093] In addition, in step 200, the dog detection model, rope detection model, and human detection model all apply the deep learning YOLOv8 detection model, which inherits and optimizes the design concept of its predecessor, YOLOv5, and mainly consists of a backbone network, a Neck layer, and a prediction layer. Regarding the backbone network, YOLOv8 adopts a more advanced structural design, integrating the SwinTransformer and ConvNext structures to achieve a balanced optimization of depth and width, further improving the model's understanding of complex scenes and feature extraction capabilities, while ensuring the model's lightweight and efficient performance. In the Neck layer, YOLOv8 introduces a more complex feature fusion strategy, employing Bi-FPN (Bidirectional Feature Pyramid Network) and SPP (Spatial Pyramid Pooling) structures to enhance the model's ability to fuse features at different scales, thereby improving the detection accuracy of small targets and the localization ability of large targets. In the prediction layer, YOLOv8 utilizes an improved anchor-free mechanism combined with an adaptive label allocation strategy, effectively improving the model's prediction accuracy for target object category and coordinate information. Overall, the YOLOv8 model achieves dual optimization of accuracy and real-time performance in object detection tasks through structural and algorithmic innovations, making it suitable for more complex and diverse application scenarios.
[0094] The deep learning Yolov8 detection model was used to train the dog detection model, rope detection model, and human detection model respectively, and then optimized using a loss function.
[0095] L loss =λ1L conf +λ2L cla +λ3L loc ;
[0096] In the formula, L conf L represents the confidence loss of the target. cla For class loss, L loc For the localization loss, λ1, λ2, and λ3 are the corresponding balance coefficients; L loss This represents the total loss.
[0097] More specifically, the process begins by using web scraping code to collect open-source dog leash datasets online. Then, labeling software is used to manually label the dogs, people, and leashes in these datasets; for example, dogs are labeled "dog," people are labeled "people," and leashes are labeled "rope." Finally, these labeled datasets are input into the initially completed network model for training and optimization using a loss function. During the model inference phase, after the image data is input into the model, the model outputs the bounding box parameters for the target. These parameters typically default to four values, representing the two-dimensional coordinates of the top-left and bottom-right corners of the rectangular bounding box.
[0098] Specifically, in step 300, the step of using a dog detection model to determine the dog's state within the dog detection box and obtaining a result indicating whether a dog exists within the detection box includes:
[0099] The dog detection and judgment module in the dog detection model judges the dog detection box. If there is a dog in the dog detection box, the dog detection box is input to the rope detection stage; otherwise, the image to be detected is judged to be in a state without dogs.
[0100] Specifically, in step 400, based on the presence or absence of a dog in the dog detection box, the region of interest (ROI) of the rope near the dog is calculated, centered on the dog detection box. This ROI result is then input into the rope detection model for rope detection, resulting in a rope-dog detection box. This includes:
[0101] Reference Figure 3 Centered on the dog detection box, and based on the aspect ratio of the image to be detected and the dog detection box, the rope interest region appearing near the dog is calculated; the scale is changed, the rope interest region appearing near the dog is recalculated, and the rope-dog detection box at different scales is obtained through the rope detection model.
[0102] Based on the aspect ratio of the image to be detected and the dog detection bounding box, the width and height of the region of interest are calculated as follows:
[0103]
[0104]
[0105] In the formula, W interest and H interest W represents the width and height of the region of interest, respectively; dog and H dog W represents the width and height of the dog detection frame, respectively; image and H image represents the width and height of the complete image, respectively; β represents the scale factor, which dynamically adjusts the extent of the region of interest to adapt to diverse rope structures; and These represent the aspect ratios of the image and the detection box, respectively, to reasonably calculate the size of the region of interest;
[0106] Based on the width and height of the region of interest, calculate the region of interest near the dog as follows:
[0107]
[0108] In the formula, I R The coordinates of the top-left and bottom-right corners of the region of interest; and To prevent the top-left corner coordinates from exceeding the image boundary; and To prevent the bottom right corner coordinates from exceeding the image boundary.
[0109] Furthermore, in this embodiment, the most common rope interest regions near the dog are within 4, 6, 8, and 10 times the size of the dog detection box. Due to the size of the dog and the pixel size of the camera, the size of the dog in the original dataset varies considerably from the image size, making it difficult to use a uniform model to learn about small ropes in frequently changing scenes. Therefore, this invention, based on the dog detection box, first uses the ratio of the dog detection box to the image size as a benchmark, considering their relative positions to alleviate these issues. Secondly, it utilizes multi-scale detection; the 4, 6, 8, and 10 times sizes mentioned above represent different scales for detecting regions of interest. In this way, small and diverse objects like ropes can be detected effectively.
[0110] Reference Figure 4 The method of obtaining rope-dog detection boxes at different scales through the rope detection model includes:
[0111] If a rope is present in the rope-detection frame, proceed to the rope-dog relationship determination stage;
[0112] If multiple ropes exist in the rope detection frame, the maximum intersection mode is used, and the rope with the highest overlap with the dog is selected as the target rope to be judged.
[0113]
[0114] In the formula, I rope The target rope to be judged; argmax(t) is the index corresponding to the maximum value; t is the value of I. rope_i ∩I dog ;I rope_i For any rope currently detected; I dog The current detection frame for dogs that need to be processed;
[0115] If no rope is present, the output image will show a violation involving a dog without a leash.
[0116] Specifically, in step 500, the leash-dog detection box is input into the leash detection model for judgment to obtain the result of whether the leash is in a correct dog-tethering state, including:
[0117] The rope detection and judgment module in the rope detection model calculates the intersection area of the rope and dog detection boxes. The calculation formula is as follows:
[0118] A rope_dog =area(I rope ∩I dog );
[0119] In the formula, the area() function calculates the area of a square region based on the coordinates of its top-left and bottom-right corners; A rope_dog The area of the intersection between the target dog and the target rope detection frame;
[0120] If A rope_dog If the dog-leash relationship threshold is greater than the set threshold, the dog is legally leashed; otherwise, the dog and leash are in an illegal relationship.
[0121] In the above process, the mere intersection of the leash and the dog is insufficient to determine if the dog is leashed. This is because other dog walkers' leashes might overlap, leading to misjudgment, and the leash might simply be hanging on the dog without actually tethering it. Therefore, specific thresholds need to be set based on the actual application scenario and required considerations.
[0122] Reference Figure 5 In step 600, based on whether the leash is in a correctly leashed state, the human region of interest (ROI) within the leash-dog detection box is calculated, centered on the leash-dog detection box. This ROI result is then input into the human detection model for human detection, resulting in the human-leash-dog detection box, which includes:
[0123] If a human body is present or absent in the human body-rope-dog detection frame, the process proceeds directly to the human body-rope-dog relationship determination stage.
[0124] If multiple human bodies exist within the human-rope-dog detection frame, the maximum intersection mode is used, selecting the human body with the highest overlap with the rope as the target human body to be identified.
[0125]
[0126] In the formula, I people The target human body to be judged; argmax(t) is the index corresponding to the maximum value; t is the value of I. people_i ∩I rope ;I people_i For any rope or human body currently detected; I rope This is the rope-dog detection frame that needs to be processed currently.
[0127] Furthermore, in this embodiment, a single frame may contain a scene with multiple people walking multiple dogs. Due to the limitations of the camera, the captured photos may inevitably overlap these people with their respective dog leashes. If the algorithm simply randomly matches a pedestrian to a target dog leash, then subsequent dog leashes may not be matched with suitable pedestrians. Therefore, to minimize this phenomenon, the theoretically best approach is to find a strategy that can correctly assign the correct leash to each dog leash. Thus, in this embodiment, the maximum intersection strategy is adopted. Generally speaking, a dog leash belonging to a certain pedestrian must be held by that pedestrian, so the corresponding intersection must also be the largest.
[0128] Specifically, the human-leash-dog detection box is input into the human detection model for judgment to obtain a result of whether the human is in a correct dog-leaning state or an estimated result of a correct dog-leaning state, in order to identify whether there is illegal dog-walking behavior in the image to be detected, including:
[0129] The human detection and judgment module in the human detection model judges the human-rope-dog detection box. If a human body is present in the human-rope-dog detection box, the intersection area of the human body and the rope-dog detection box is calculated.
[0130] A people_rope_dog =area(I people ∩I rope ∩I dog );
[0131] In the formula, the area() function calculates the area of the square region based on the coordinates of the top left and bottom right corners of the human-rope-dog detection box; A people_rope_dog The area of intersection between the target human body, the target dog, and the target rope detection frame;
[0132] If A people_rope_dog If the relationship between the human, the dog, and the leash exceeds the set threshold, the dog is considered to be legally leashed and the human is legally holding the other half of the leash; otherwise, the human is considered to be illegally walking the dog.
[0133] Furthermore, in this embodiment, the mere presence of intersection between the pedestrian and the leash is insufficient to determine if the pedestrian is holding the leash. This is because other dog walkers' leashes might overlap, leading to misjudgment, and the leash may simply be hanging on the pedestrian without the pedestrian legally holding it. Based on the current considerations, specific thresholds need to be set in conjunction with real-world application scenarios.
[0134] In step 700, the estimated result of the correct human-leaning dog state includes: if there is no human body in the human-leash-dog detection frame, then calculate whether the target leash reasonably extends to the boundary of the image to be detected. If reasonable, then determine that the target dog-target leash is legally leashed by a human body that is not visible outside the image to be detected. The judgment condition is:
[0135]
[0136]
[0137]
[0138]
[0139] In the formula, x threshold and y threshold This represents the minimum threshold between the target rope and the boundary of the image to be detected. and Indicates the coordinates of the top left corner of the target rope; and This indicates the coordinates of the lower right corner of the target leash. If all four conditions are met, it is determined that the target dog and its leash are legally tethered by a human body not visible outside the image. Otherwise, the image to be detected indicates that the dog is being walked illegally.
[0140] In this context, the dog leash extends from the dog's body and beyond the image boundary. This typically means that the image only captures the portion of the person walking the dog, with the crucial pedestrian not fully included, as evidenced by the absence of detected human figures. Current detection algorithms ignore this, uniformly treating it as illegal dog walking. However, this increases the workload for management personnel. Therefore, this embodiment employs the leash extension discrimination formula described above to more accurately determine the true relationship between the pedestrian and the dog, reducing false positives.
[0141] The various embodiments in this specification are described in a progressive manner, with each embodiment focusing on its differences from other embodiments. Similar or identical parts between embodiments can be referred to interchangeably. For the systems disclosed in the embodiments, since they correspond to the methods disclosed in the embodiments, the descriptions are relatively simple; relevant parts can be referred to the method section.
[0142] This document uses specific examples to illustrate the principles and implementation methods of the present invention. The descriptions of the above embodiments are only for the purpose of helping to understand the method and core ideas of the present invention. Furthermore, those skilled in the art will recognize that, based on the ideas of the present invention, there will be changes in the specific implementation methods and application scope. Therefore, the content of this specification should not be construed as a limitation of the present invention.
Claims
1. A method for identifying illegal dog walking without a leash based on deep learning Yolov8, characterized in that, Includes the following steps: The image data to be detected is acquired, and the color of the image data is enhanced using an image equalization algorithm to obtain the image to be detected; The image to be detected is input into the dog detection model to detect dogs, and a dog detection box is obtained. The dog detection model is used to determine the dog status of the dog detection box to obtain the result of whether a dog exists in the dog detection box; Based on the presence or absence of a dog in the dog detection frame, the region of interest (ROI) of the rope near the dog is calculated, centered on the dog detection frame. This ROI result is then input into the rope detection model for rope detection, resulting in a rope-dog detection frame; including: Centered on the dog detection box, and based on the aspect ratio of the image to be detected and the dog detection box, the region of interest of the rope appearing near the dog is calculated; the scale is changed, the region of interest of the rope appearing near the dog is recalculated, and the rope-dog detection box at different scales is obtained through the rope detection model. Based on the aspect ratio of the image to be detected and the dog detection bounding box, the width and height of the region of interest are calculated as follows: ; ; In the formula, and These represent the width and height of the region of interest, respectively. and These represent the width and height of the dog detection frame, respectively; and These represent the width and height of the complete image, respectively. It represents the scale factor, which dynamically adjusts the range of the region of interest to adapt to diverse rope structures; and These represent the aspect ratios of the image and the detection box, respectively, to reasonably calculate the size of the region of interest; Based on the width and height of the region of interest, calculate the region of interest near the dog as follows: ; In the formula, The coordinates of the top-left and bottom-right corners of the region of interest; and To prevent the top-left corner coordinates from exceeding the image boundary; and To prevent the bottom right corner coordinates from exceeding the image boundary; The rope-dog detection boxes at different scales were obtained using the rope detection model, including: If a rope is present in the rope-detection frame, proceed to the rope-dog relationship determination stage; If multiple ropes exist in the rope detection frame, the maximum intersection mode is used, and the rope with the highest overlap with the dog is selected as the target rope to be judged. ; In the formula, The target rope to be identified; To select the index corresponding to the maximum value; t is For any rope body currently detected; The current detection frame for dogs that need to be processed; If no leash is present, the output image will show a dog without a leash, indicating a violation. The rope-dog detection box is input into the rope detection model for judgment to obtain the result of whether the rope is in a correct tethered state; including: The rope detection and judgment module in the rope detection model calculates the intersection area of the rope and dog detection boxes. The calculation formula is as follows: ; In the formula, The function calculates the area of a square region based on the coordinates of its top-left and bottom-right corners. The area of the intersection between the target dog and the target rope detection frame; like If the dog-leash relationship threshold is greater than the set threshold, the dog is legally leashed; otherwise, the dog and leash are in an illegal relationship. Based on whether the leash is in a correctly leashed state, the human region of interest (ROI) within the leash-dog detection box is calculated, centered on the leash-dog detection box. This ROI result is then input into the human detection model for human detection, resulting in the human-leash-dog detection box; including: If a human body is present or absent in the human body-rope-dog detection frame, the process proceeds directly to the human body-rope-dog relationship determination stage. If multiple human bodies exist within the human-rope-dog detection frame, the maximum intersection mode is used, selecting the human body with the highest overlap with the rope as the target human body to be identified. ; In the formula, The target human body to be identified; To select the index corresponding to the maximum value; t is The detection frame is for any rope or human body currently detected; The rope-dog detection frame that needs to be processed now; The human-leash-dog detection box is input into the human detection model for judgment to obtain a result of whether the human is in a correct leash state or a predicted result of a correct leash state, so as to identify whether there is illegal dog walking behavior in the image to be detected; including: The human detection and judgment module in the human detection model judges the human-rope-dog detection box. If a human body is present in the human-rope-dog detection box, the intersection area of the human body and the rope-dog detection box is calculated. ; In the formula, The function calculates the area of the square region based on the coordinates of the top left and bottom right corners of the human-rope-dog detection box; The area of intersection between the target human body, the target dog, and the target rope detection frame; like If the relationship between the human, the dog, and the leash exceeds the set threshold, the dog is considered to be legally leashed and the human is legally holding the other half of the leash; otherwise, the human is considered to be illegally walking the dog. The predicted result of the correct human-leaf-dog leash state includes: if there is no human in the human-leash-dog detection frame, then calculate whether the target leash reasonably extends to the boundary of the image to be detected. If reasonable, then determine that the target dog-target leash is legally leashed by a human not visible outside the image to be detected. The judgment condition is: ; ; ; ; In the formula, and This represents the minimum threshold between the target rope and the boundary of the image to be detected. and Indicates the coordinates of the top left corner of the target rope; and This indicates the coordinates of the lower right corner of the target leash. If all four conditions are met, it is determined that the target dog and its leash are legally tethered by a human body not visible outside the image. Otherwise, the image to be detected indicates that the dog is being walked illegally.
2. The method for identifying illegal dog walking without a leash based on deep learning Yolov8 according to claim 1, characterized in that, The process of acquiring the image data to be detected and enhancing the color of the image data using an image equalization algorithm to obtain the image to be detected includes: The original image data to be processed is acquired, and the color and spatial domain of the original image data are adjusted to complete the color and tone correction of the original image data, thereby obtaining the image to be detected after spatial domain reconstruction. The color and spatial domain of the original image data are adjusted to complete the color and tone correction of the original image data, resulting in the spatially reconstructed image to be detected. The specific calculation formula is as follows: ; In the formula, Represented as a slope function; Represented as a spatially reconstructed image; Represented as the set of all pixels in the original image; Represented in the original image m The pixel value of the point; Represented in the original image n The pixel value of the point; Represented as m , n The pixel difference between the two points; Represented as a distance metric; The corrected spatial reconstruction image is dynamically expanded and normalized to the range [0,1] to obtain the image to be detected: ; In the formula, Represented as the image to be detected; Represented as The maximum value; Represented as The minimum value.
3. The method for identifying illegal dog walking without a leash based on deep learning Yolov8 as described in claim 1, characterized in that, The dog detection model, leash detection model, and human detection model all utilize a deep learning Yolov8 detection model. These models are trained using the Yolov8 deep learning model and then optimized using a loss function. ; In the formula, The confidence loss represents the target. For category loss, To pinpoint the loss, , and These are all corresponding balance coefficients; This represents the total loss.
4. The method for identifying illegal dog walking without a leash based on deep learning Yolov8 according to claim 1, characterized in that, The step of determining the dog's status by using a dog detection model to obtain a result indicating whether a dog exists in the dog detection box includes: The dog detection and judgment module in the dog detection model judges the dog detection box. If there is a dog in the dog detection box, the dog detection box is input to the rope detection stage; otherwise, the image to be detected is judged to be in a state without dogs.