A stray dog detection method

By generating sub-images through static and dynamic segmentation of the detected images and using the YOLOv4 algorithm model for recognition, combined with perspective distortion and distance judgment, the detection accuracy problem caused by high-resolution image compression in the YOLOv4 algorithm model is solved, achieving higher accuracy in stray dog ​​detection.

CN114092872BActive Publication Date: 2026-02-06钱昱成
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202111269870.5
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-10-29
Publication Date
2026-02-06
Estimated Expiration
2041-10-29

Smart Images

  • Figure CN114092872B_ABST
    Figure CN114092872B_ABST
Patent Text Reader

Abstract

The application discloses a stray dog detection method, which comprises the following steps: constructing a two-dimensional coordinate system in a detection picture, performing static cutting and dynamic cutting on the detection picture to obtain three static cutting sub-pictures or three static cutting sub-pictures and a plurality of dynamic cutting sub-pictures, adopting a YOLOv4 algorithm model to recognize the obtained sub-pictures, mapping a rectangular frame corresponding to the coordinates to a corresponding position in the detection picture after obtaining the rectangular frame of the category of person or dog, performing deformation on the transmission sub-picture and the target frame after constructing the transmission sub-picture, and judging whether the dog is a stray dog according to whether there is a person within a set distance of the deformed target frame of each category of dog; the method has the advantages that cutting is adopted instead of compression, the accuracy is not lost due to excessive compression, the accuracy of recognizing dogs and persons is improved, and through the judgment of the distance between the dog and the person, the dog can be more accurately judged to be a stray dog or a pet dog, false positives are reduced, and the detection accuracy is high.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present application relates to a detection technology, in particular to a stray dog detection method. BACKGROUND

[0002] With the rapid development of China's economy, people's living standards continue to improve, and more and more people choose to raise pet dogs to meet their spiritual comfort. But at the same time, due to the immaturity of the dog culture, the thin responsibility consciousness of the dog raiser, and the imperfect abandoned dog tracking system, it has affected the social public safety. The traditional stray dog management method is mainly through special personnel on the road without interruption patrol, and the stray dog is captured after being found. But this method is time-consuming and labor-intensive, and needs to use a large amount of human resources, and the cost is very high. Using the existing security camera in the city to detect whether there is a dog and a person around the dog, and then judging whether the dog is a stray dog, not only can save a lot of manpower and material resources, but also the maintenance of the equipment is very easy, and has good application value, and has been widely used at present.

[0003] The existing method for detecting stray dogs by using the video stream transmitted by the security camera mainly uses the YOLOv4 algorithm model to identify the targets of people and dogs in the picture, and determines the distance between the identified dog and the person, so as to judge whether there is a stray dog. However, the YOLOv4 algorithm model requires the resolution of the input picture to be 416x416, and for pictures with a resolution higher than 416x416, the recognition effect of the YOLOv4 algorithm model will be poor. The resolution of the security camera is generally 1920x1080, and if the picture of the security camera is directly input into the YOLOv4 algorithm model, the picture with a resolution of 1920x1080 will be compressed to a picture with a resolution of 416x416 before being recognized. When a high-resolution picture is compressed to a low-resolution picture, the size of the object in the picture will also be lost due to excessive compression, so that the recognition effect of the YOLOv4 algorithm model on the target will be poor, and the stray dog detection accuracy will not be high enough. SUMMARY

[0004] The technical problem to be solved by the present application is to provide a stray dog detection method with high detection accuracy.

[0005] The technical solution adopted by the present application to solve the above technical problem is: a stray dog detection method, comprising the following steps:

[0006] Step (1), creating a counter and setting the initial value of the counter to 0;

[0007] Step (2), reading the video stream of the security camera, taking the current frame as the detection picture, and if it is the first time to read the security camera, taking the current frame as the reference frame at the same time;

[0008] Step (3), the current value of the counter is taken modulo 25, if the modulo result is 0, the reference frame is updated to the current frame, and the value of the counter is reset to 0, if the modulo result is not 0, the reference frame remains unchanged, and the value of the counter is increased by 1;

[0009] Step (4), the detection picture is statically cut, specifically: taking the upper left corner of the detection picture as the origin, the straight line direction from the upper left corner to the upper right corner as the positive half axis direction of the x axis, and the straight line direction from the upper left corner to the lower left corner as the positive half axis direction of the y axis, a two-dimensional coordinate system is constructed, the length of the detection picture on the x axis is taken as the width w of the detection picture, and the length of the detection picture on the y axis is taken as the height h of the detection picture, in the detection picture, taking the coordinates (0, 0) as the upper left corner, the coordinates (w / 2, h / 2) as the lower right corner, a rectangular region surrounded by the upper left corner and the lower right corner as the first static cutting sub-picture, taking the coordinates (0, h / 2) as the upper left corner, the coordinates (w / 2, h / 2) as the lower right corner, a rectangular region surrounded by the upper left corner and the lower right corner as the second static cutting sub-picture, taking the coordinates (w / 2, 0) as the upper left corner, the coordinates (w / 2, h / 2) as the lower right corner, a rectangular region surrounded by the upper left corner and the lower right corner as the third static cutting sub-picture, thereby obtaining three static cutting sub-pictures, namely three sub-pictures;

[0010] Step (5), the current frame and the reference frame are converted from RGB images into grayscale images respectively;

[0011] Step (6), the grayscale image of the current frame and the grayscale image of the reference frame are respectively subjected to Gaussian blur change, to obtain a current frame Gaussian blur image and a reference frame Gaussian blur image;

[0012] Step (7), a difference image is designed, specifically: taking the upper half of the current frame Gaussian blur image and the upper half of the reference frame Gaussian blur image, the absolute value of the difference between the pixel values of the pixel points at the same position in each image as the pixel value of the pixel point at the same position in the difference image, to obtain the difference image, wherein the upper half refers to the part above the middle line of the rectangular picture along the left-right direction;

[0013] Step (8), each pixel point of the difference image obtained in step (7) is traversed, if the pixel value of a certain pixel point is greater than 40, the pixel value of the pixel point is set to 255, that is, a white pixel point, otherwise it is set to 0, that is, a black pixel point, at this time a first binary difference image is obtained;

[0014] Step (9), a two-dimensional matrix of size 5x5 as shown in formula (1) is constructed, and the two-dimensional matrix is taken as an erosion convolution kernel:

[0015]

[0016] ​Step (10), constructing a two-dimensional matrix of size 45x45 as shown in formula (2), taking this two-dimensional matrix as the dilated convolution kernel:

[0017]

[0018] Step (11), performing convolution operation on the first binary difference image using the eroded convolution kernel and performing convolution operation using the dilated convolution kernel, to obtain a second binary difference image;

[0019] Step (12), judging whether there is an independent white pixel point or a white pixel point connected region in the second binary difference image, wherein a white pixel point is called an independent white pixel point if it is not adjacent to any other white pixel point, and a white pixel point connected region is formed by at least two white pixel points being adjacent, taking the independent white pixel point and the white pixel point connected region as the target region respectively, counting the number of target regions existing in the second binary difference image, if the number is greater than or equal to 1, then each target region is processed according to the following method: when the area of the smallest area rectangle that can contain all the white pixel points of the target region is greater than 1800 pixels, judging whether the 416x416 rectangular picture centered at the rectangle in the second binary difference image exceeds the second binary difference image area, if it does not exceed, recording the coordinates of the 416x416 rectangular picture centered at the rectangle in the second binary difference image, if it exceeds, translating the rectangle to the 416x416 rectangular picture centered at it in the second binary difference image which does not exceed the second binary difference image area, recording the coordinates of the 416x416 rectangular picture obtained at this time, after processing all target regions, entering step (13), when the area of the smallest area rectangle that can contain all the white pixel points of the target region is less than or equal to 1800 pixels, no other processing is performed, and directly jumping to step (14), if the number is equal to 0, no other processing is performed, and directly jumping to step (14);

[0020] Step (13), cutting out a rectangular picture at the same position in the detection picture according to the coordinates recorded in step (12), the rectangular picture is the dynamic cut sub-image, at this time, a total of three static cut sub-images and at least one dynamic cut sub-image are obtained, a total of at least four sub-images;

[0021] Step (14), input all the sub-pictures obtained at this time into the YOLOv4 algorithm model in turn, and the YOLOv4 algorithm model performs forward propagation on each sub-picture in turn to detect whether there is a person or a dog in each sub-picture. When the YOLOv4 algorithm model detects a person or a dog in a sub-picture, the YOLOv4 algorithm model outputs, and at this time, the output is all the rectangular frame coordinates detected from the sub-picture and the categories of these rectangular frames, which are person or dog. The height (length on the y-axis) and width (length on the x-axis) of these rectangular frames are recorded. When the YOLOv4 algorithm model does not detect a person or a dog in a sub-picture, the YOLOv4 algorithm model does not output;

[0022] Step (15), after the YOLOv4 algorithm model completes detection on all sub-pictures, it is determined whether the YOLOv4 algorithm model outputs. If no output is performed, the current round of detection is completed, and step (2) is returned to perform the next round of detection. If output is performed, and all the categories of the output are not dog, the current round of detection is completed, and step (2) is returned to perform the next round of detection. If output is performed, and at least one of all the categories of the output is dog, all the rectangular frame coordinates of the output are mapped back to the detection picture. Specifically, since the coordinates of each sub-picture in the detection picture are clear, the left upper corner coordinates of a sub-picture in the detection picture are added to the left upper corner coordinates of a rectangular frame in the sub-picture to obtain the left upper corner coordinates of the rectangular frame in the detection picture. The horizontal coordinate value of the left upper corner coordinates of the sub-picture is added to the width of the rectangular frame in the sub-picture, and the vertical coordinate value is unchanged to determine the right upper corner coordinates of the rectangular frame in the detection picture. The vertical coordinate value of the left upper corner coordinates of the sub-picture is added to the height of the rectangular frame in the sub-picture, and the horizontal coordinate value is unchanged to determine the left lower corner coordinates of the rectangular frame in the detection picture. The horizontal coordinate value of the left upper corner coordinates of the sub-picture is added to the width of the rectangular frame in the sub-picture, and the vertical coordinate value is added to the height of the rectangular frame in the sub-picture to determine the right lower corner coordinates of the rectangular frame in the detection picture. According to the obtained coordinates, the rectangular frame is drawn in the detection picture to realize the mapping of the rectangular frame in the detection picture. After the mapping of all the output rectangular frames is completed, a detection picture with a rectangular frame is obtained.

[0023] Step (16), non maximum suppression (NMS) is performed on the detection picture with the rectangular frame. Finally, there is only one rectangular frame on each detected category, which is the target frame. A detection picture with the target frame is obtained, and the length of each target frame on the x-axis is recorded.

[0024] Step (17), in the detection picture with the target frame, the coordinates As the upper left corner, the coordinate (w, 0) as the upper right corner, the coordinate (0, h) as the lower left corner, and the coordinate As the parallelogram region surrounded by the lower right corner, a perspective subgraph is formed;

[0025] Step (18), the detection picture with the target frame is shifted to the left as a whole except for the last row of pixel points, until the perspective subgraph changes from a parallelogram to a rectangle, and at the same time, the target frame in the detection picture with the target frame becomes a parallelogram due to the pixel shift, and a deformed detection picture with the target frame is obtained after the shift is completed.

[0026] Step (19), for each parallelogram frame belonging to the category of "dog" in the deformed detection picture with the target frame, the following processing is performed: taking the midpoint of the lowermost edge of the parallelogram frame as the center and twice the length of the lowermost edge of the parallelogram frame as the diameter to draw a circle, at this time, if the circle region overlaps with any one parallelogram frame belonging to the category of "person", it is considered that the dog does not belong to the stray dog, and if there is no overlap with any one parallelogram frame belonging to the category of "person", it is considered that the dog belongs to the stray dog.

[0027] Step (20), after the completion of this round of detection, return to step (2) to start the next round of detection.

[0028] Compared with the prior art, the advantages of the present application are that after constructing a two-dimensional coordinate system in the detection picture, the detection picture is cut statically and dynamically to obtain three static cutting subgraphs or three static cutting subgraphs and a plurality of dynamic cutting subgraphs, then the YOLOv4 algorithm model is used to recognize the obtained subgraphs, after obtaining the rectangular frame belonging to the category of person or dog, the rectangular frame is mapped to the corresponding position in the detection picture according to the corresponding coordinates, the transmission subgraph is constructed, and the transmission subgraph and the target frame are deformed, and according to whether there is a person within a certain distance of each deformed target frame belonging to the category of "dog", it is judged whether it is a stray dog, the present application uses cutting instead of direct compression, which does not lose accuracy due to excessive compression, improves the accuracy of recognizing dogs and people, and through the judgment of the distance between dogs and people, the stray dog or pet dog can be more accurately judged, the false positives are reduced, and the detection accuracy is high. BRIEF DESCRIPTION OF DRAWINGS

[0029] Figure 1 The detection picture of the stray dog detection method of the present application;

[0030] Figure 2 The difference graph of the stray dog detection method of the present application;

[0031] Figure 3 The first binary difference graph of the stray dog detection method of the present application;

[0032] Figure 4 This is the second binary difference image of the stray dog ​​detection method of the present invention;

[0033] Figure 5 This is a detection image with a target bounding box for the stray dog ​​detection method of the present invention. Detailed Implementation

[0034] The present invention will be further described in detail below with reference to the accompanying drawings and embodiments.

[0035] Example: A method for detecting stray dogs, comprising the following steps:

[0036] Step (1): Create a counter and set the initial value of the counter to 0;

[0037] Step (2): Read the video stream from the security camera and take the current frame as the detection image, such as... Figure 1 As shown, if this is the first time the security camera is accessed, the current frame will be used as the reference frame.

[0038] Step (3): Calculate the current value of the counter modulo 25. If the modulo result is 0, update the reference frame to the current frame and reset the value of the counter to 0. If the modulo result is not 0, keep the reference frame unchanged and increment the value of the counter by 1.

[0039] Step (4): Staticly segment the detection image, specifically: Using the top left corner of the detection image as the origin, the straight line from the top left corner to the top right corner is the positive x-axis, and the straight line from the top left corner to the bottom left corner is the positive y-axis, construct a two-dimensional coordinate system. The length of the detection image on the x-axis is taken as the width w, and the length of the detection image on the y-axis is taken as the height h. Segment the detection image, with coordinates (0,0) as the top left corner, and... The rectangular area enclosed in the lower right corner is used as the first static segmented sub-image, with coordinates... The rectangular area enclosed by the top-left corner and the bottom-right corner (w, h) serves as the second static sub-image. As the top left corner, coordinates The rectangular area enclosed by the lower right corner is used as the third static cut sub-image, thus obtaining three static cut sub-images, i.e., three sub-images;

[0040] Step (5): Convert the current frame and the reference frame from RGB images to grayscale images respectively;

[0041] Step (6): Perform Gaussian blur transformation on the grayscale image of the current frame and the grayscale image of the reference frame respectively to obtain the Gaussian blur image of the current frame and the Gaussian blur image of the reference frame.

[0042] Step (7), a difference image is designed, specifically: taking the picture of the upper half region in the current frame Gaussian blur image and the picture of the upper half region in the reference frame Gaussian blur image, the absolute value of the pixel difference of each same position pixel point is taken as the pixel value of the same position pixel point in the difference image, and the difference image is obtained, as shown in Figure 2 , wherein the upper half region refers to the part above the middle line of the rectangular picture in the left and right directions of the rectangular picture;

[0043] Step (8), each pixel point of the difference image obtained in step (7) is traversed, if the pixel value of a certain pixel point is greater than 40, the pixel value of the pixel point is set to 255, that is, a white pixel point, otherwise it is set to 0, that is, a black pixel point, at this time the first binary difference image is obtained, as shown in Figure 3 ;

[0044] Step (9), a two-dimensional matrix with a size of 5x5 as shown in formula (1) is constructed, and the two-dimensional matrix is taken as the erosion convolution kernel:

[0045]

[0046] Step (10), a two-dimensional matrix with a size of 45x45 as shown in formula (2) is constructed, and the two-dimensional matrix is taken as the expansion convolution kernel:

[0047]

[0048] Step (11), the first binary difference image is sequentially subjected to convolution operation with the erosion convolution kernel and convolution operation with the expansion convolution kernel, and the second binary difference image is obtained, as shown in Figure 4 ;

[0049] Step (12), determine whether there is an independent white pixel point or a white pixel point connected region in the second binary difference image, wherein a white pixel point is called an independent white pixel point if it is not adjacent to any other white pixel point, and a white pixel point connected region is formed by at least two white pixel points adjacent to each other, count the number of target regions in the second binary difference image, if the number is greater than or equal to 1, then each target region is processed according to the following method: when the area of the smallest area rectangle that can contain all the white pixel points of the target region is greater than 1800 pixels, determine whether the 416x416 rectangular picture centered at the rectangle in the second binary difference image exceeds the second binary difference image area, if it does not exceed, record the coordinates of the 416x416 rectangular picture centered at the rectangle in the second binary difference image, if it exceeds, translate the rectangle to the 416x416 rectangular picture centered at it in the second binary difference image, which does not exceed the second binary difference image area, record the coordinates of the 416x416 rectangular picture obtained at this time, after processing all target regions, go to step (13), when the area of the smallest area rectangle that can contain all the white pixel points of the target region is less than or equal to 1800 pixels, no other processing is performed, and directly jump to step (14), if the number is equal to 0, no other processing is performed, and directly jump to step (14);

[0050] Step (13), cut out a rectangular picture at the same position in the detection picture according to the coordinates recorded in step (12), the rectangular picture is the dynamic cutting subgraph, at this time, a total of three static cutting subgraphs and at least one dynamic cutting subgraph are obtained, a total of at least four subgraphs are obtained;

[0051] Step (14), input all the subgraphs obtained at this time into the YOLOv4 algorithm model in turn, and the YOLOv4 algorithm model performs forward propagation on each subgraph in turn to detect whether there is a person or a dog in each subgraph, when the YOLOv4 algorithm model detects a person or a dog in a subgraph, the YOLOv4 algorithm model outputs, at this time, the output is all the rectangular frame coordinates detected from the subgraph and the categories of these rectangular frames, the categories of these rectangular frames are person or dog, record the height (length on the y-axis) and width (length on the x-axis) of these rectangular frames, when the YOLOv4 algorithm model does not detect a person or a dog in a subgraph, the YOLOv4 algorithm model does not output;

[0052] Step (15), after the YOLOv4 algorithm model completes detection on all subgraphs, it is determined whether the YOLOv4 algorithm model has performed output. If no output is performed, the current round of detection is completed, and step (2) is returned to perform the next round of detection. If output is performed, and all the output belongs to the category of dogs, the current round of detection is completed, and step (2) is returned to perform the next round of detection. If output is performed, and at least one of all the output belongs to the category of dogs, the coordinates of all the rectangular frames output by it are mapped back to the detection picture. Specifically, since the coordinates of each subgraph in the detection picture are clear, the upper left corner coordinates of a certain subgraph in the detection picture are added to the upper left corner coordinates of the rectangular frame in the subgraph to obtain the upper left corner coordinates of the rectangular frame in the detection picture. The value of the horizontal coordinate of the upper left corner coordinates of the subgraph is added to the width of the rectangular frame in the subgraph, and the value of the vertical coordinate is unchanged to determine the upper right corner coordinates of the rectangular frame in the detection picture. The value of the vertical coordinate of the upper left corner coordinates of the subgraph is added to the height of the rectangular frame in the subgraph, and the value of the horizontal coordinate is unchanged to determine the left lower corner coordinates of the rectangular frame in the detection picture. The value of the horizontal coordinate of the upper left corner coordinates of the subgraph is added to the width of the rectangular frame in the subgraph, and the value of the vertical coordinate is added to the height of the rectangular frame in the subgraph to determine the right lower corner coordinates of the rectangular frame in the detection picture. According to the obtained coordinates, the rectangular frame is drawn in the detection picture to realize the mapping of the rectangular frame in the detection picture. When all the output rectangular frames are mapped, a detection picture with rectangular frames is obtained.

[0053] Step (16), non maximum suppression (NMS) is performed on the detection picture with rectangular frames. Finally, there is only one rectangular frame on each detected category, which is the target frame. A detection picture with target frames is obtained, and the length of each target frame on the x-axis is recorded.

[0054] Step (17), in the detection picture with target frames, the coordinates as the upper left corner, the coordinates (w, 0) as the upper right corner, the coordinates (0, h) as the left lower corner, and the coordinates as the right lower corner form a parallelogram region as a perspective subgraph.

[0055] Step (18), the other row pixel points in the detection picture with target frames except the last row pixel point are shifted to the left as a whole until the perspective subgraph changes from a parallelogram to a rectangle. At the same time, the target frame in the detection picture with target frames becomes a parallelogram because of the pixel shift. A deformed detection picture with target frames is obtained after the shift is completed, as shown in Figure 5 .

[0056] Step (19), for each parallelogram frame belonging to the category of "dog" in the deformed detection picture with target frame, the following processing is performed respectively: taking the midpoint of the lowermost edge of the parallelogram frame as the center and twice the length of the lowermost edge of the parallelogram frame as the diameter to draw a circle, at this time if the drawn circle region overlaps with any parallelogram frame belonging to the category of "person", it is considered that the dog does not belong to the stray dog, at this time if the drawn circle region does not overlap with any parallelogram frame belonging to the category of "person", it is considered that the dog belongs to the stray dog.

[0057] Step (20), after the completion of this round of detection, return to step (2) to start the next round of detection.

Claims

1. A stray dog detection method characterized by The method comprises the following steps: Step (1), creating a counter and setting the initial value of the counter to 0; Step (2), reading the video stream of the security camera, taking the current frame as the detection picture, and if it is the first time to read the security camera, taking the current frame as the reference frame at the same time; Step (3), taking the current value of the counter modulo 25, if the modulo result is 0, updating the reference frame to the current frame and resetting the value of the counter to 0, if the modulo result is not 0, the reference frame remains unchanged and the value of the counter is increased by 1; Step (4): Staticly segment the detection image, specifically: Using the top left corner of the detection image as the origin, the straight line from the top left corner to the top right corner is the positive x-axis, and the straight line from the top left corner to the bottom left corner is the positive y-axis, construct a two-dimensional coordinate system. The length of the detection image on the x-axis is taken as the width w, and the length of the detection image on the y-axis is taken as the height h. Segment the detection image, with coordinates (0,0) as the top left corner, and... The rectangular area enclosed in the lower right corner is used as the first static segmented sub-image, with coordinates... The rectangular area enclosed by the top-left corner and the bottom-right corner (w, h) serves as the second static sub-image. As the top left corner, coordinates The rectangular area enclosed by the lower right corner is used as the third static cut sub-image, thus obtaining three static cut sub-images, i.e., three sub-images; Step (5), converting the current frame and the reference frame from RGB image to grayscale image respectively; Step (6), respectively performing Gaussian blur change on the grayscale image of the current frame and the grayscale image of the reference frame to obtain the current frame Gaussian blur image and the reference frame Gaussian blur image; Step (7), designing a difference image, specifically: taking the picture in the upper half of the current frame Gaussian blur image and the picture in the upper half of the reference frame Gaussian blur image, the absolute value of the difference between the pixel values of the same position pixels in each as the pixel value of the same position pixel in the difference image, to obtain the difference image, wherein the upper half region refers to the part above the middle line of the rectangular picture along the left and right directions of the rectangular picture; Step (8), traversing each pixel point of the difference image obtained in step (7), if the pixel value of a certain pixel point is greater than 40, the pixel value of the pixel point is set to 255, that is, a white pixel point, otherwise it is set to 0, that is, a black pixel point, at this time a first binary difference image is obtained; Step (9), constructing a two-dimensional matrix of size 5x5 as shown in formula (1), taking this two-dimensional matrix as the erosion convolution kernel: Step (10), constructing a two-dimensional matrix of size 45x45 as shown in formula (2), taking this two-dimensional matrix as the expansion convolution kernel: Step (11), the first binary difference image is sequentially subjected to convolution operation with the erosion convolution kernel and convolution operation with the expansion convolution kernel to obtain a second binary difference image; Step (12), determine whether there is an independent white pixel point or a white pixel point connected region in the second binary difference image, wherein a white pixel point is called an independent white pixel point if it is not adjacent to any other white pixel point, and a white pixel point connected region is formed by at least two white pixel points adjacent to each other, count the number of target regions in the second binary difference image, if the number is greater than or equal to 1, then process each target region according to the following method: when the area of the smallest area rectangle that can contain all the white pixel points of the target region is greater than 1800 pixels, determine whether the 416x416 rectangular picture centered at the rectangle in the second binary difference image exceeds the second binary difference image area, if it does not exceed, record the coordinates of the 416x416 rectangular picture centered at the rectangle in the second binary difference image, if it exceeds, translate the rectangle to the 416x416 rectangular picture centered at it in the second binary difference image, which just does not exceed the second binary difference image area, record the coordinates of the 416x416 rectangular picture obtained at this time, after all target regions are processed, go to step (13), when the area of the smallest area rectangle that can contain all the white pixel points of the target region is less than or equal to 1800 pixels, no other processing is performed, and directly jump to step (14), if the number is equal to 0, no other processing is performed, and directly jump to step (14); Step (13), cut out a rectangular picture at the same position in the detection picture according to the coordinates recorded in step (12), the rectangular picture is the dynamic cutting subgraph, at this time, a total of three static cutting subgraphs and at least one dynamic cutting subgraph are obtained, a total of at least four subgraphs are obtained; Step (14), input all the subgraphs obtained at this time into the YOLOv4 algorithm model in turn, the YOLOv4 algorithm model performs forward propagation on each subgraph in turn to detect whether there is a person or a dog in each subgraph, when the YOLOv4 algorithm model detects a person or a dog in a subgraph, the YOLOv4 algorithm model outputs, at this time, the output is all the rectangular box coordinates detected from the subgraph and the categories of these rectangular boxes, the categories of these rectangular boxes are person or dog, record the height (length on the y-axis) and width (length on the x-axis) of these rectangular boxes, when the YOLOv4 algorithm model does not detect a person or a dog in a subgraph, the YOLOv4 algorithm model does not output; Step (15), after the YOLOv4 algorithm model completes detection on all subgraphs, it is determined whether the YOLOv4 algorithm model has performed output. If no output is performed, the current round of detection is completed, and step (2) is returned to perform the next round of detection. If output is performed, and all the output belongs to the category of dogs, the current round of detection is completed, and step (2) is returned to perform the next round of detection. If output is performed, and at least one of all the output belongs to the category of dogs, the coordinates of all the output rectangular frames are mapped back to the detection picture. Specifically, since the coordinates of each subgraph in the detection picture are clear, the upper left corner coordinates of a certain subgraph in the detection picture are added to the upper left corner coordinates of the rectangular frame in the subgraph to obtain the upper left corner coordinates of the rectangular frame in the detection picture. The value of the horizontal coordinate of the upper left corner coordinates of the subgraph is added to the width of the rectangular frame in the subgraph, and the value of the vertical coordinate is unchanged to determine the upper right corner coordinates of the rectangular frame in the detection picture. The value of the vertical coordinate of the upper left corner coordinates of the subgraph is added to the height of the rectangular frame in the subgraph, and the value of the horizontal coordinate is unchanged to determine the lower left corner coordinates of the rectangular frame in the detection picture. The value of the horizontal coordinate of the upper left corner coordinates of the subgraph is added to the width of the rectangular frame in the subgraph, and the value of the vertical coordinate is added to the height of the rectangular frame in the subgraph to determine the right lower corner coordinates of the rectangular frame in the detection picture. According to the obtained coordinates, the rectangular frame is drawn in the detection picture to realize the mapping of the rectangular frame in the detection picture. When the mapping of all the output rectangular frames is completed, a detection picture with rectangular frames is obtained. Step (16), non maximum suppression (NMS) is performed on the detection picture with rectangular frames, and finally only one rectangular frame is obtained on each detected category, which is the target frame. A detection picture with target frames is obtained, and the length of each target frame on the x-axis is recorded. Step (17), coordinates of the target frame in the detection picture as the upper left corner, coordinates (0, h) as the upper right corner, coordinates as the lower right corner, the parallelogram region surrounded by the four corners as the perspective sub-picture; Step (18), the left of the other rows of pixel points in the detection picture with target frames is shifted as a whole except for the last row of pixel points until the perspective subgraph changes from a parallelogram to a rectangle. At the same time, the target frame in the detection picture with target frames becomes a parallelogram due to pixel translation, and a deformed detection picture with target frames is obtained after the translation is completed. Step (19), each parallelogram frame with the category of "dog" in the deformed detection picture with target frames is processed as follows: taking the midpoint of the lowermost side of the parallelogram frame as the center and twice the length of the lowermost side of the parallelogram frame as the diameter to draw a circle. At this time, if the drawn circle region overlaps with any parallelogram frame with the category of "person", it is considered that the dog does not belong to a stray dog. If there is no overlap between the drawn circle region and any parallelogram frame with the category of "person", it is considered that the dog belongs to a stray dog. Step (20), the current round of detection is completed, and step (2) is returned to start the next round of detection.

Citation Information

Patent Citations

  • Railway foreign matter invasion detection method based on railway monitoring

    CN111160125A

  • Image recognition method, image recognition device, computer readable medium and computer readable system

    CN111291222A