Target detection model training, target detection method, device, equipment and medium
By cropping and copying the target area in the image, the target detection model is trained. Combined with face detection and smoking behavior analysis, the problem of recognizing small target objects in surveillance scenarios is solved, and the detection accuracy and generalization ability of the model are improved.
Patent Information
- Application Number
- CN202211143256.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-09-20
- Publication Date
- 2026-01-06
- Estimated Expiration
- 2042-09-20
AI Technical Summary
In surveillance scenarios, existing target detection technologies struggle to effectively identify small objects such as cigarettes or smoking behavior, suffer from high false detection rates, require large amounts of data, and have limited adoption of infrared cameras. Furthermore, human posture analysis faces challenges in locating key human points in complex scenarios.
By cropping the image region containing the target object, copying and pasting it, the proportion of the target object in the image is increased. The target detection model is trained using feature information, and combined with face detection and smoking behavior analysis, it is determined whether smoking behavior exists.
It improves the detection accuracy of small target objects, reduces the false detection rate, enhances the generalization ability of the model, and can accurately identify objects, their locations, and behaviors in the images to be detected.
Smart Images

Figure CN115457474B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of target detection technology, and in particular to a target detection model training, target detection method, apparatus, equipment and medium. Background Technology
[0002] In the field of surveillance, cameras are currently the most widely used non-human monitoring tool. Surveillance cameras typically monitor a large area, while the object to be detected (such as cigarettes or smoking behavior) occupies a very small portion of the frame, constituting a small target object. In such scenarios, detecting and identifying the object faces the challenge of having few distinguishing features, leading to the presence of many similar items and resulting in false alarms. Furthermore, the low resolution of images acquired from surveillance cameras also affects recognition accuracy.
[0003] Current target detection technologies mainly include the following: (1) Image classification technology based on deep learning: This technology performs image classification on images after extracting frames of camera monitoring streaming media data, and directly determines whether there is an object to be detected (such as cigarettes or smoking behavior). Alternatively, it performs video classification on videos after time-series segmentation of camera monitoring streaming media data, and directly determines whether there is an object to be detected (such as cigarettes or smoking behavior). However, directly performing image classification and video classification requires a large amount of data to enable the model to have good generalization ability, which is very demanding for the needs of monitoring different scenarios. At the same time, it is easy to identify other items, actions, etc. as objects to be detected, such as identifying actions like wiping one's mouth as smoking, which is particularly easy to misdetect. (2) Target detection technology based on deep learning: Directly perform target detection on images after extracting frames of camera monitoring streaming media data. If an object to be detected is detected, it is determined that there is an object to be detected. Alternatively, perform region detection on images after extracting frames of camera monitoring streaming media data, and then perform image classification on the detected regions to determine whether there is an object to be detected. However, the objects to be detected are small target objects, which account for a very low proportion in the entire monitoring screen, making it extremely difficult to perform target detection directly. At the same time, a large area of the screen will also contain a large number of similar objects, greatly increasing the false detection rate. (3) When the object to be detected is cigarettes or smoking behavior, target detection can also be performed based on infrared technology: the image after the infrared camera is collected is segmented into high-temperature areas by threshold segmentation method, and then further matched with the feature of the cigarette burning boundary. Given that most monitoring scenarios are not equipped with infrared cameras, this type of method is not conducive to large-scale promotion. (4) When the object to be detected is cigarettes or smoking behavior, target detection can also be performed based on human posture analysis technology: after extracting frames from the camera monitoring streaming media data, pedestrian detection is performed first, and then human posture analysis is performed on the human body area to obtain the key point positions of each part of the human body. The relative distance between the hand and mouth is obtained based on the key point information. When the distance is less than the threshold, the hand and mouth area images are cropped, and the smoking identification is performed using the image classification model. In complex pedestrian scenes, especially in the case of occlusion between pedestrians, it is difficult to accurately locate the key points of the human body. Summary of the Invention
[0004] To solve the above-mentioned technical problems, or at least partially solve the above-mentioned technical problems, embodiments of the present invention provide a target detection model training method, a target detection method, an apparatus, an electronic device, and a computer-readable medium.
[0005] In a first aspect, embodiments of the present invention provide a method for training an object detection model, comprising: acquiring an image set, the image set including a plurality of first sample images, wherein the first sample images are images including a detection object; determining a detection region in the first sample image including the detection object, cropping an image within the detection region to obtain a second sample image; copying the detection object in the second sample image, and pasting the copied detection object into the second sample image according to preset constraints; determining the target location information of the detection object in the second sample image; and training the object detection model based on the second sample image and the target location information of the detection object in the second sample image.
[0006] Optionally, before copying the detected object in the second sample image, the method further includes performing data augmentation processing on the second sample image.
[0007] Optionally, the step of copying the detection object in the second sample image and pasting the copied detection object into the second sample image according to preset constraints includes: copying and randomly transforming the detection object in the second sample image, and pasting the copied detection object into the second sample image according to preset constraints.
[0008] Optionally, the preset constraints include: the pasting position of the copied detection object does not overlap with the original position of the detection object in the second sample image; and / or, the distance between the pasting position and the boundary of the second sample image is greater than or equal to a preset threshold.
[0009] Optionally, when the object to be detected is a cigarette, determining the detection region in the first sample image that includes the object to be detected includes: annotating the face region in the first sample image to determine the face region in the first sample image; expanding the face region in the first sample image according to a preset expansion strategy, and using the expanded face region as the detection region of the first sample image.
[0010] Optionally, the image set further includes multiple third sample images, wherein the third sample images are images that do not include the detection object; the method further includes: obtaining first location information of the face region in the first sample image; annotating the face region in the third sample image to determine the face region in the third sample image, and obtaining second location information of the face region in the third sample image; and training a face detection model based on the first sample image, the first location information, the third sample image, and the second location information.
[0011] Secondly, embodiments of the present invention provide a target detection method, comprising: acquiring an image to be detected; determining a region to be detected in the image to be detected; cropping an image within the region to be detected in the image to be detected to obtain an image to be identified; and determining whether the image to be identified includes a detection object based on a pre-built target detection model.
[0012] Optionally, when the object to be detected is a cigarette, determining the region to be detected in the image to be detected includes: determining the face region in the image to be detected based on a pre-built face detection model; expanding the face region in the image to be detected according to a preset expansion strategy, and using the expanded face region as the region to be detected in the image to be detected.
[0013] Optionally, if it is determined that the image to be identified includes the detection object, the method further includes: obtaining third location information of the detection object in the image to be identified; performing facial key point detection on the face region in the image to be identified, determining fourth location information of the mouth in the face region, and obtaining the fourth location information of the mouth; and determining whether smoking behavior exists based on the third location information and the fourth location information.
[0014] Optionally, determining whether smoking behavior exists based on the third location information and the fourth location information includes: determining the distance between the detection object and the mouth and the angle between the line connecting the detection object and the mouth and a preset reference line based on the third location information and the fourth location information; and determining whether smoking behavior exists based on the distance and the angle.
[0015] Optionally, the distance between the detection object and the mouth is determined according to the following formula (1):
[0016]
[0017] Among them, l ij g represents the distance between the mouth of the i-th face region in the image to be detected and the j-th detected object. i This represents the mouth in the i-th face region of the image to be detected, (x gi y gi ) represents the fourth position information of the mouth in the i-th face region of the image to be detected, s ij This represents the j-th detected object in the i-th face region of the image to be detected, (x sij y sij ) represents the third location information of the j-th detected object in the i-th face region of the image to be detected, (w sij h sij) represents the width and height of the detection box corresponding to the j-th detection object in the i-th face region in the to-be-detected image;
[0018] The included angle between the connection line of the detection object and the mouth and the preset reference line is determined according to the following formula (2):
[0019]
[0020] where, θ ij represents the included angle between the connection line of the mouth and the j-th detection object in the i-th face region in the to-be-detected image and the preset reference line.
[0021] Optionally, determining whether there is a smoking behavior according to the distance and the included angle includes: when l ij < b, and y gi -(y sij -h sij ) / 2 > 0, it is determined that there is a smoking behavior; or, when l ij < b, y gi -(y sij -h sij ) / 2 < 0, and θ ij < c, it is determined that there is a smoking behavior; or, when l ij < b, y gi -(y sij -h sij ) / 2 < 0, and θ ij > π - c, it is determined that there is a smoking behavior; where, b represents a distance threshold, and c represents an angle threshold.
[0022] Optionally, the distance threshold is determined according to the width of the detection box corresponding to the detection object in the to-be-detected image.
[0023] Optionally, determining the to-be-detected region in the to-be-detected image includes: segmenting the to-be-detected image according to a preset closed box to divide the to-be-detected image into a no-smoking area image and a non-no-smoking area image; determining the to-be-detected region in the no-smoking area image.
[0024] Thirdly, embodiments of the present invention provide a target detection model training apparatus, comprising: a first acquisition module, configured to acquire an image set, the image set including multiple first sample images, wherein the first sample images are images including a detection object; a range reduction module, configured to determine a detection region including the detection object in the first sample image, crop the image within the detection region, and obtain a second sample image; a copying module, configured to copy the detection object in the second sample image, and paste the copied detection object into the second sample image according to preset constraints; a position determination module, configured to determine the target position information of the detection object in the second sample image; and a first training module, configured to train the target detection model based on the second sample image and the target position information of the detection object in the second sample image.
[0025] Optionally, the device further includes an enhancement module for performing data enhancement processing on the second sample image.
[0026] Optionally, the copying module is further configured to: copy and randomly transform the detection object in the second sample image, and paste the copied detection object into the second sample image according to preset constraints.
[0027] Optionally, the preset constraints include: the pasting position of the copied detection object does not overlap with the original position of the detection object in the second sample image; and / or, the distance between the pasting position and the boundary of the second sample image is greater than or equal to a preset threshold.
[0028] Optionally, the range reduction module is further configured to: annotate the face region in the first sample image to determine the face region in the first sample image; expand the face region in the first sample image according to a preset expansion strategy, and use the expanded face region as the detection region of the first sample image.
[0029] Optionally, the image set further includes multiple third sample images, wherein the third sample images are images that do not include the detection object; the device further includes a second training module, configured to: obtain first location information of the face region in the first sample image; annotate the face region in the third sample image to determine the face region in the third sample image, and obtain second location information of the face region in the third sample image; and train a face detection model based on the first sample image, the first location information, the third sample image, and the second location information.
[0030] Fourthly, embodiments of the present invention provide a target detection device, comprising: a second acquisition module for acquiring an image to be detected; a region determination module for determining a region to be detected in the image to be detected, and cropping an image within the region to be detected in the image to be detected to obtain an image to be identified; and a detection module for determining whether the image to be identified includes a detection object based on a pre-built target detection model.
[0031] Optionally, when the object to be detected is a cigarette, the region determination module is further configured to: determine the face region in the image to be detected based on a pre-built face detection model; expand the face region in the image to be detected according to a preset expansion strategy, and use the expanded face region as the region to be detected in the image to be detected.
[0032] Optionally, the device further includes a behavior detection module, configured to: acquire third location information of the detected object in the image to be identified; perform facial key point detection on the face region in the image to be identified, determine fourth location information of the mouth in the face region, and acquire the fourth location information of the mouth; and determine whether smoking behavior exists based on the third location information and the fourth location information.
[0033] Optionally, the behavior detection module is further configured to: determine the distance between the detection object and the mouth and the angle between the line connecting the detection object and the mouth and a preset reference line based on the third position information and the fourth position information; and determine whether smoking behavior exists based on the distance and the angle.
[0034] Optionally, the behavior detection module is further configured to determine the distance between the detection object and the mouth according to the following formula (1):
[0035]
[0036] Among them, l ij g represents the distance between the mouth of the i-th face region in the image to be detected and the j-th detected object. i This represents the mouth in the i-th face region of the image to be detected, (x gi y gi ) represents the fourth position information of the mouth in the i-th face region of the image to be detected, s ij This represents the j-th detected object in the i-th face region of the image to be detected, (x sij y sij ) represents the third location information of the j-th detected object in the i-th face region of the image to be detected, (w sij h sijrepresents the width and height of the detection box corresponding to the j-th detection object in the i-th face region of the to-be-detected image;
[0037] The behavior detection module is further configured to determine the included angle between the connection line of the detection object and the mouth and a preset reference line according to the following formula (2):
[0038]
[0039] where, θ ij represents the included angle between the connection line of the mouth and the j-th detection object in the i-th face region of the to-be-detected image and the preset reference line.
[0040] Optionally, the behavior detection module is further configured to: when l ij < b, and y gi -(y sij -h sij ) / 2 > 0, determine that there is a smoking behavior; or, when l ij < b, y gi -(y sij -h sij ) / 2 < 0, and θ ij < c, determine that there is a smoking behavior; or when l ij < b, y gi -(y sij -h sij ) / 2 < 0, and θ ij > π - c, determine that there is a smoking behavior; where, b represents a distance threshold, and c represents an angle threshold.
[0041] Optionally, the behavior detection module is further configured to determine the distance threshold according to the width of the detection box corresponding to the detection object in the to-be-detected image.
[0042] Optionally, the device further includes an image segmentation module, configured to: segment the to-be-detected image according to a preset closed box, so as to segment the to-be-detected image into a no-smoking area image and a non-no-smoking area image; determine the to-be-detected area in the no-smoking area image.
[0043] In a fifth aspect, an embodiment of the present invention provides an electronic device, including: one or more processors; a storage device, configured to store one or more programs, and when the one or more programs are executed by the one or more processors, enable the one or more processors to implement the target detection model training method or the target detection method of the embodiments of the present invention.
[0044] In a sixth aspect, embodiments of the present invention provide a computer-readable medium having a computer program stored thereon, wherein the program, when executed by a processor, implements the target detection model training method or the target detection method of the embodiments of the present invention.
[0045] One embodiment of the above invention has the following advantages or beneficial effects:
[0046] This invention provides a second sample image by cropping an image from the detection region of the target object in a first sample image. This increases the proportion of the target object in the image. Using this second sample image to train the target detection model reduces the impact of noise data on training and improves the model's accuracy. Furthermore, the target object in the second sample image is copied and pasted into the second sample image, thereby increasing the number of target objects, expanding their proportion in the image, and improving the model's detection performance. The target location information of the target objects in the second and second sample images is used as training data to train the target detection model. This target detection model can accurately detect whether the image to be detected contains a target object, and if the image to be detected contains a target object, it can identify the location of the target object.
[0047] The further effects of the aforementioned unconventional alternative methods will be explained below in conjunction with specific implementation methods. Attached Figure Description
[0048] The accompanying drawings are provided to better understand the invention and are not intended to unduly limit the scope of the invention. Wherein:
[0049] Figure 1 A flowchart illustrating the target detection model training method according to an embodiment of the present invention is shown;
[0050] Figure 2 A flowchart illustrating a target detection model training method according to another embodiment of the present invention is shown;
[0051] Figure 3 A flowchart of the face detection training process in a target detection model training method according to another embodiment of the present invention is shown;
[0052] Figure 4 A flowchart illustrating the target detection method according to an embodiment of the present invention is shown;
[0053] Figure 5 A flowchart illustrating another embodiment of the target detection method of the present invention is shown;
[0054] Figure 6 A flowchart illustrating a target detection model training method according to another embodiment of the present invention is shown;
[0055] Figure 7 A flowchart illustrating another embodiment of the target detection method of the present invention is shown;
[0056] Figure 8 A schematic diagram of the target detection model training device according to an embodiment of the present invention is shown;
[0057] Figure 9 A schematic diagram of the target detection device according to an embodiment of the present invention is shown;
[0058] Figure 10 A schematic diagram of the structure of an electronic device according to an embodiment of the present invention is shown. Detailed Implementation
[0059] The following description, in conjunction with the accompanying drawings, illustrates exemplary embodiments of the present invention, including various details to aid understanding. These details should be considered merely exemplary. Therefore, those skilled in the art will recognize that various changes and modifications can be made to the embodiments described herein without departing from the scope and spirit of the invention. Similarly, for clarity and brevity, descriptions of well-known functions and structures are omitted in the following description.
[0060] Figure 1 A flowchart illustrating the target detection model training method according to an embodiment of the present invention is shown, as follows: Figure 1 As shown, the method includes:
[0061] Step S101: Obtain an image set, which includes multiple first sample images. Each first sample image contains a detected object. The detected object can be an object that occupies a very small portion of the entire frame of a first sample image. For example, the image set could be a surveillance video of a pedestrian smoking captured by a security camera, the first sample images could be each frame of the video showing the pedestrian smoking, and the detected object could be the cigarette in the surveillance video.
[0062] Step S102: Determine the detection region containing the detection object in the first sample image, and crop the image within the detection region to obtain the second sample image.
[0063] Since the detected object occupies a very small portion of the entire first sample image, directly using the original image or a scaled-down version as training data is unlikely to yield good results when the image set data is limited. Therefore, in this embodiment, to increase the proportion of the detected object and improve detection accuracy, the image containing the detected object can be cropped out and used for model training. The size of the cropped image can be flexibly set according to the application scenario requirements, and this invention does not impose any limitations on it. During the model training phase, the detection region containing the detected object in the first sample image can be manually labeled, thereby cropping the image within that detection region. As an example, when the detection target is a cigarette, the detection region can be the face region in the first sample image, which can be labeled using the LabelImg tool to obtain the detection region.
[0064] Step S103: Copy the detected object in the second sample image, and paste the copied detected object into the second sample image according to the preset constraints.
[0065] In step S102, to increase the proportion of detected objects and improve the accuracy of the model, an image containing the detection region of the detected object in the first sample image is extracted as the second sample image. To further increase the proportion of detected objects and expand the feature proportion of the detected objects, this embodiment can increase the number of detected objects in the second sample image. Therefore, the detected objects in the second sample image can be copied and pasted into the second sample image.
[0066] When pasting copied detection objects, certain constraints can be followed to ensure that the pasted detection object does not affect the original detection objects in the second sample image. For example, constraints could include that the pasted position of the copied detection object does not overlap with the position of the original detection object in the second sample image, or that the distance between the pasted position of the copied detection object and the boundary of the second sample image is greater than or equal to a preset threshold. As an example, the distance between the pasted position of the copied detection object and the boundary of the second sample image is greater than or equal to 5 pixels; that is, the pasted position of the copied detection object is at least 5 pixels away from the boundary of the second sample image.
[0067] In an optional embodiment, when copying the detected object in the second sample image, the copied detected object can be randomly transformed, and then pasted into the second sample image according to preset constraints. The random transformation of the copied detected object can include, but is not limited to, flipping, rotating, scaling proportionally, or resizing the detected object. In this embodiment, randomly transforming the copied detected object can increase the diversity of the detected objects, enhance their feature representation, thereby increasing the diversity of the training data, improving the model's generalization ability, and ultimately enhancing the model's performance.
[0068] Step S104: Determine the target location information of the detected object in the second sample image.
[0069] In this step, detection boxes can be used to label the objects to be detected in the second sample image. The position information of the detection boxes is the target position information of the detected objects. As an example, the target position information of the detected objects can be denoted as s. ij =[x ij ,y ij ,w ij ,h ij ]. Among them, s ij This represents the target location information of the j-th detected object in the i-th second sample image, (x ij ,y ij (w) represents the coordinates of a preset corner point of the detection box corresponding to the j-th detection object in the i-th second sample image, for example, the coordinates of the top left corner point of the detection box. ij ,h ij ) represents the width and height of the detection box corresponding to the j-th detection object in the i-th second sample image.
[0070] Step S105: Train the target detection model based on the target location information of the detected object in the second sample image and the second sample image.
[0071] As an example, object detection models can employ YOLOv5, Retina-Net, SSD, or PP-YOLOE models that incorporate FPN (Feature Pyramid Networks). The model is trained using the target location information of the second sample image and the second sample image. The trained object detection model can then identify the location information of the target object in the image to be detected.
[0072] This invention provides a second sample image by cropping an image from the detection region of the target object in a first sample image. This increases the proportion of the target object in the image. Using this second sample image to train the target detection model reduces the impact of noise data on training and improves the model's accuracy. Furthermore, the target object in the second sample image is copied and pasted into the second sample image, thereby increasing the number of target objects, expanding their proportion in the image, and improving the model's detection performance. The target location information of the target objects in the second and second sample images is used as training data to train the target detection model. This target detection model can accurately detect whether the image to be detected contains a target object, and if the image to be detected contains a target object, it can identify the location of the target object.
[0073] In an optional embodiment, in step S101, the first sample image in the image set can be processed by image preprocessing steps such as rotation, flipping, scaling, size change, and random deletion, thereby increasing the number of first sample images in the image set and increasing the diversity of samples in the image set.
[0074] In an optional embodiment, the second sample image can be data augmented before copying the detected object. Data augmentation refers to adding information or transforming data to the original image through certain means, selectively highlighting features of interest or suppressing (masking) unwanted features to match the image's visual response characteristics. This embodiment, by performing data augmentation on the second sample image, can improve the feature resolution and enrich the feature details of the detected object, obtaining rich, high-resolution feature representations. As an example, data augmentation of the second sample image can be performed using a GAN (Generative Adversarial Network).
[0075] Figure 2 A flowchart illustrating a target detection model training method according to another embodiment of the present invention is shown. In this embodiment, cigarettes are used as an example for illustration. Figure 2 As shown, the method includes:
[0076] Step S201: Obtain an image set, which includes multiple first sample images, each of which contains a detection object. The image set may be a surveillance video of a pedestrian smoking captured by a surveillance camera, the first sample images may be each frame of the pedestrian smoking in the surveillance video, and the detection object may be a cigarette in the surveillance footage.
[0077] Step S202: Label the face regions in the first sample image to determine the face regions in the first sample image.
[0078] In this step, for example, the LabelImg tool can be used to annotate the face region to obtain the face location information (i.e., the first location information) for each first sample image. As an example, the face location information can be denoted as o. i =[x′ ij ,y′ ij ,w′ ij ,h′ ij ], where o i This represents the face location information of the j-th face region in the i-th first sample image of the image set, (x′) ij ,y′ ij (w′) represents the coordinates of a preset corner point of the face detection box corresponding to the j-th face region in the i-th first sample image of the image set, for example, the coordinates of the top left corner point of the face detection box. ij ,h′ ij ) represents the width and height of the face detection box corresponding to the j-th face region in the i-th first sample image of the image set.
[0079] Step S203: According to the preset expansion strategy, the face region in the first sample image is expanded, and the expanded face region is used as the detection region of the first sample image. The image within the detection region is cropped to obtain the second sample image.
[0080] In real-world smoking scenarios, cigarettes may extend beyond the face area. To detect cigarettes beyond the face area, and considering that cigarettes are most effective when they appear near the mouth to reduce false detections caused by handheld cigarettes, background images containing cigarettes, and complex hand environments, the cigarette detection area is limited to the vicinity of the face. Therefore, this embodiment expands the face area according to a preset expansion strategy, using the expanded area as the detection area. As an example, the expanded area, i.e., the detection area k, can be obtained by expanding the side length of the face detection box by a coefficient α. ij =[x′ ij ,y′ ij ,a·w′ ij ,a·h′ ij The coefficient α can be a positive number greater than 1, such as 2.
[0081] Step S204: Copy and randomly transform the detection object in the second sample image, and paste the copied detection object into the second sample image according to preset constraints.
[0082] Step S205: Determine the target location information of the detected object in the second sample image.
[0083] Step S206: Train the target detection model based on the second sample image and the target location information of the detected object in the second sample image.
[0084] Steps S204-S206 can be referred to Figure 1 The embodiments shown are not intended to limit the scope of this embodiment.
[0085] The target detection model training method of this invention takes into account that cigarettes can only effectively reduce false detections caused by situations such as cigarettes being held near the mouth, cigarette images in the background, and complex hand environments. Therefore, the cigarette target detection area is limited to the vicinity of the face. At the same time, for the model, cropping images near the face as training data increases the proportion of cigarette features, reduces the model's receptive field, and further reduces the false detection rate and false negative rate of cigarette detection.
[0086] In an optional embodiment, the method can further train a face detection model to determine face regions in the first sample image. Wherein, such as Figure 3 As shown, the process of training a face detection model may include:
[0087] Step S301: Obtain an image set, which includes multiple first sample images and multiple third sample images. The first sample images are images that include the detection object, and the third sample images are images that do not include the detection object. For example, the first sample images are images of smokers captured by a surveillance camera, and the third sample images are images of non-smokers captured by the surveillance camera.
[0088] Step S302: Mark the face regions in the first sample image, determine the face regions in the first sample image, and obtain the first position information of the face regions in the first sample image;
[0089] Step S303: Annotate the face regions in the third sample image, determine the face regions in the third sample image, and obtain the second location information of the face regions in the third sample image;
[0090] Step S304: Based on the first sample image, the first location information, the third sample image, and the second location information, a face detection model is trained.
[0091] This embodiment uses images of smokers and non-smokers as training data to train a face detection model, which enables the face detection model to accurately detect face regions in both smoking and non-smoking situations, thus improving the accuracy of the face detection model.
[0092] Figure 4 A flowchart of a target detection method according to an embodiment of the present invention is shown, as follows: Figure 4 As shown, the method includes:
[0093] Step S401: Obtain the image to be detected.
[0094] Step S402: Determine the region to be detected in the image to be detected, and crop the image within the region to be detected to obtain the image to be identified.
[0095] In optional embodiments, the region to be detected in the image can be determined according to preset rules or strategies. For example, the upper or lower half of the image can be used as the region to be detected, or the central region can be used. In other optional embodiments, the region to be detected can be determined based on a pre-built model, or a combination of a pre-built model and preset rules. For example, when detecting cigarettes, a pre-built face detection model can be used to determine the face region in the image to be detected. Then, according to a preset expansion strategy (which is a preset rule), the face region in the image to be detected can be expanded, and the expanded face region can be used as the region to be detected in the image.
[0096] Step S403: Based on the pre-built target detection model, determine whether the image to be identified contains a detection object.
[0097] In this step, we can utilize Figures 1-2 The target detection model trained in the illustrated embodiment detects objects in the image to be identified to determine whether the image contains a target object. When it is determined that the image contains a target object, the target detection model can output the location information of the target object, which can be represented by the coordinates of the corner points of the detection box, as well as its width and height.
[0098] The target detection method of this invention can increase the proportion of the detected object in the image and increase the feature proportion of the detected object by cropping the image within the region to be detected in the image to be detected, thereby improving the detection accuracy.
[0099] In an optional embodiment, after obtaining the image to be identified, the method can further perform data augmentation on the image to improve its feature resolution and enrich its feature details. Then, the data-augmented image is input into a target detection model to determine whether the image contains a target object. As an example, a GAN (Generative Adversarial Network) can be used to perform data augmentation on the image to be identified.
[0100] Figure 5 A flowchart of another embodiment of the target detection method of the present invention is shown. In this embodiment, the detection object is a cigarette. When it is determined that the image to be detected includes the detection object, i.e., a cigarette, it can be further determined whether smoking is occurring. The specific implementation process of this embodiment is as follows: Figure 5 As shown, it includes:
[0101] Step S501: Acquire the image to be detected;
[0102] Step S502: Based on the pre-built face detection model, determine the face region in the image to be detected;
[0103] Step S503: According to the preset expansion strategy, the face region in the image to be detected is expanded, and the expanded face region is used as the region to be detected in the image to be detected. The image within the region to be detected in the image to be detected is cropped to obtain the image to be recognized.
[0104] Step S504: Based on the pre-built target detection model, determine whether the image to be identified contains a detection object.
[0105] Step S505: If it is determined that the image to be identified includes a detection object, obtain the third position information of the detection object in the image to be identified; wherein, the third position information is the coordinates based on the coordinate system of the image to be identified.
[0106] Step S506: Perform facial landmark detection on the face region in the image to be detected to determine the fourth position information of the mouth in the face region. Specifically, in step S502, after detecting the face region in the image to be detected, the image within that face region can be cropped to obtain a face image. The fourth position information is the coordinate system of the face image.
[0107] Step S507: Determine whether smoking behavior exists based on the third position information of the detection object and the fourth position information of the mouth.
[0108] Among them, steps S501-S505 and Figure 4 The embodiments shown are the same, and the present invention will not be described again here.
[0109] For step S506, a facial landmark detection model can be used to detect facial landmarks in the face region of the image to be detected, determine the coordinate information of the facial landmarks, and then extract the fourth position information of the mouth from the coordinate information of the facial landmarks. As an example, the facial landmark model is a model trained by a coordinate regression scheme, and the backbone network is Mobile-Net-0.5.
[0110] For step S507, since the coordinate systems of the third and fourth position information are different, in order to facilitate the calculation of the third and fourth position information, this embodiment can map the third and fourth position information onto the original image to be detected to obtain new third and fourth position information. Then, based on the new third and fourth position information, it is determined whether smoking behavior exists.
[0111] In an optional embodiment, the process of determining whether smoking behavior exists based on the new third location information and the new fourth location information includes:
[0112] Based on the third and fourth position information, determine the distance between the detection object and the mouth, as well as the angle between the line connecting the detection object and the mouth and the preset reference line; based on the distance between the detection object and the mouth, as well as the angle between the line connecting the detection object and the mouth and the preset reference line, determine whether smoking behavior exists.
[0113] In this embodiment, the third and fourth positional information refer to the new third and fourth positional information mapped onto the original image to be detected. Based on this new third and fourth positional information, the distance between the detected object and the mouth, as well as the angle between the line connecting the detected object and the mouth and a preset reference line, are calculated. If the distance and angle meet preset conditions, smoking behavior is determined to exist.
[0114] The distance between the object being tested and the mouth is determined according to the following formula (1):
[0115]
[0116] Among them, l ij g represents the distance between the mouth of the i-th face region in the image to be detected and the j-th detected object. i Let x represent the mouth in the i-th face region of the image to be detected. gi y gi ) represents the fourth position information of the mouth in the i-th face region of the image to be detected, s ij This represents the j-th detected object in the i-th face region of the image to be detected, (x sij y sij) represents the third position information of the j-th detection object in the i-th face region of the image to be detected, (w sij , h sij ) represents the width and height of the detection box corresponding to the j-th detection object in the i-th face region of the image to be detected. As can be seen from the above formula, (x sij + w sij ) / 2, y sij - h sij ) / 2) are the coordinates of the center position of the detection box, and l ij refers to the distance between the mouth and the center position of the detection box.
[0117] The angle between the connection line of the detection object and the mouth and the preset reference line is determined according to the following formula (2):
[0118]
[0119] where, θ ij represents the angle between the connection line of the mouth and the j-th detection object in the i-th face region of the image to be detected and the preset reference line.
[0120] After determining the distance between the detection object and the mouth and the angle between the connection line of the detection object and the mouth and the preset reference line, determine whether there is a smoking behavior according to the following strategy:
[0121] When l ij < b, and y gi - (y sij - h sij ) / 2 > 0, it is determined that there is a smoking behavior;
[0122] When l ij < b, y gi - (y sij - h sij ) / 2 < 0, and θ ij < c, it is determined that there is a smoking behavior;
[0123] When l ij < b, y gi - (y sij - h sij ) / 2 < 0, and θ ij > π - c, it is determined that there is a smoking behavior;
[0124] where, b represents the distance threshold, and c represents the angle threshold.
[0125] In an optional embodiment, the distance threshold b and the angle threshold c can be preset to fixed values. In other optional embodiments, the angle threshold c can be preset to a fixed value, and the distance threshold b can be determined based on the width of the detection box corresponding to the detected object. That is, for the j-th detected object in the i-th face region of the image to be detected, the distance threshold b is... ij Based on the width w of the detection box corresponding to the j-th detection object in the i-th face region of the image to be detected. sij OK. As an example, b ij =3×w sij .
[0126] This invention addresses a real-world business scenario where a camera's monitoring range typically includes both permitted and prohibited smoking areas. Directly analyzing camera data for smoking detection would fail to differentiate between prohibited and non-smoking areas, leading to numerous false alarms. Therefore, this invention utilizes pre-defined bounding boxes to segment the image to be detected, dividing it into non-smoking and non-smoking area images. Then, target detection is performed on the non-smoking area image. This involves first identifying the target region within the non-smoking area image, extracting an image within that region as the target image, and using a target detection model to identify the target image to determine if a target object is present. The bounding boxes can be flexibly configured according to the business scenario. This embodiment divides the image to be detected into non-smoking and non-smoking areas, enriching the application scenarios and improving detection accuracy.
[0127] The following description uses cigarettes as an example to illustrate the training method of the object detection model and the object detection method itself. Figure 6 As shown, the training methods for the object detection model include:
[0128] Step S601: Obtain sample images containing ordinary pedestrians and smokers from the surveillance camera scene. To enhance the generalization ability of the training model, perform random transformation operations on the images to obtain the dataset X1 = {x i ,i∈N1}, Where x i ∈R r×r×3 It is a three-stage tensor.
[0129] Step S602: Label the face locations in dataset X1 to obtain the face locations of each image x in dataset X1. i Face location related information L1={O i ,i∈N1},O i ={o ij ,j∈M i},o i =[x ij ,yij ,w ij ,h ij ], {x ij ,y ij ,w ij ,h ij}∈R. The dataset X1 and the face location annotation information L1 are used as training data for face detection.
[0130] Step S603: Use dataset X1 and face location annotation information L1 to train a face detection model.
[0131] Step S604: Filter the dataset X2 = {x} from dataset X1 to find datasets containing smoking behavior. i ,i∈N2}, The corresponding X2 labeled face location information is L2={O i ,i∈N2},O i ={o ij ,j∈M i},o ij =[x ij ,y ij ,w ij ,h ij ],in {x ij ,y ij ,w ij ,h ij}∈R.
[0132] Step S605: Considering that cigarettes are small targets, while the monitoring range of a typical camera frame-by-frame image is very large, cigarettes account for a very small proportion of the entire image. With limited data, directly inputting the original image (including the original image after scaling) as training data for the cigarette detection model is unlikely to yield good results. Therefore, to increase the proportion of cigarette target features and reduce the impact of noisy data on training, and considering actual smoking scenarios, images near faces are selected as cigarette detection and training data. Each labeled bounding box h in L2 is expanded by coefficient a. i The side length yields new regional location information L3={O i ,i∈N2},O i ={o ij ,j∈M i}, o ij =[x ij ,y ij ,a·w ij ,a·h ij ], {x ij ,y ij ,w ij ,hij}∈R. Extract the image from region L3 of dataset X2 as the cigarette detection dataset Y1={y i ,i∈T1}, y i ∈R r×r×3 It is a three-stage tensor.
[0133] Step S606: Extract each image y from dataset Y1 i The image is input into a GAN network for image enhancement, acquiring high-resolution features and rich feature details. Simultaneously, the cigarette target is copied and randomly transformed, then pasted onto the original image. i The dataset Y2 is obtained from this. When pasting, ensure that the newly pasted cigarette does not overlap with existing cigarettes and is at least 5 pixels away from the image boundary.
[0134] Step S607: Mark the target location of the cigarette to obtain the cigarette location information M1 = {S i ,i∈T1},S i ={s ij ,j∈K i},s ij =[x ij ,y ij ,w ij ,h ij ],in {x ij ,y ij ,w ij ,h ij}∈R. The dataset Y2 and the face location annotation information I1 are used as training data for cigarette detection.
[0135] Step S608: Input the cigarette detection training data Y2 and I1 into the object detection network (YOLOv5, Retina-Net, SSD, pp-yoloe) combined with FPN for training to obtain the trained object detection model.
[0136] The training method of the target detection model in this embodiment of the invention uses images cropped near the face as training data instead of directly using the entire surveillance image for training. This expands the feature proportion of cigarettes in the image, reduces the influence of noise on the model, reduces the receptive field of the algorithm model, increases the feature effect of the algorithm model on small target objects, and improves the algorithm performance. The labeled cigarettes are expanded by copying, flipping, scaling, and pasting to increase the number of target detection training data. This addresses the issue of limited feature representation for small target detection and weak model generalization ability. Expanding the training data improves the performance of the algorithm model. When training on images near the face, image enhancement processing is performed to obtain high-resolution features and rich feature details, upgrading the representation of the cigarette target to a super-resolution representation. This solves the problem of limited discriminative features for small targets, effectively reduces the false negative rate of cigarette detection, and improves the model algorithm performance.
[0137] like Figure 7 As shown, target detection methods include:
[0138] Step S701: Obtain the image t1∈R to be used for smoking recognition. r×r×3 For a third-order tensor, using the closed frame A = [[x] a1 ,y a1 ],[x a2 ,y a2 ],[x a3 ,y a3 ],[x a4 ,y a4 Extract the image t2∈R within the no-smoking area A. r×r×3 Image of a no-smoking area.
[0139] Step S702: Input the no-smoking area image t2 into the trained face detection model to obtain the face image region O1 = {o1, o2, ..., o n},o i =[x i ,y i ,w i ,h i ].
[0140] Step S703: If O1 is an empty set, it means no face was detected, and the behavior is judged as no smoking. If it is not empty, expand each border h in O1 by coefficient a. i The side lengths yield new regional location information O2={o1,o2,...,o n},o i =[x i ,y i ,a·w i ,a·h iThe image within region O2 of t2 is cropped to obtain the set of cigarette detection images to be identified, Z = {z1, z2, ..., z...}. n},z i ∈R r×r×3 Each image in the set Z of cigarette detection images to be identified undergoes image enhancement processing.
[0141] Step S704: Input the enhanced image of the cigarette to be detected into the trained target detection model to obtain the cigarette detection result H1={S1,S2...,S...} n},S i ={s1,s2,...,s m},s ij =[x sij ,y sij ,w sij ,h sij The coordinates in the cigarette detection result H1 are mapped onto the t2 image to obtain H2.
[0142] Step S705: Extract face images from set O1 in t2, and input each face image sequentially into the face landmark detection model to obtain the face landmark location information P = {p1, p2, ..., p n},p i =[ρ1,ρ2,...,ρ 106 The center position of the mouth is obtained from the key points, and the coordinate information of the center position of the mouth is obtained as G1={g1,g2,...,g n},g i =[x gi ,y gi The coordinates of the mouth are mapped from the face image to the t2 image to obtain the position information G2 of the mouth in the t2 image.
[0143] Step S706: Based on H2 and G2, calculate the distance between each cigarette and its corresponding mouthpiece, as well as the angle between the line connecting the two and the preset reference line.
[0144] Step S707: Considering actual smoking scenarios, when a smoker smokes, the cigarette is always positioned close to the mouth and rarely appears on the top of the head. Therefore, a threshold b is set for the distance between the cigarette and the mouth, and a threshold c is set for the angle between the straight line connecting the cigarette and the mouth and the horizontal axis. Each face o in the face region O1... i This corresponds to the g in the mouth position G. i S in cigarette detection results H1 from the surrounding area i Calculate S. i The position of each cigarette detection box in the middle s ij and its corresponding mouth position g i distance lij and the included angle θ between its connecting line and the horizontal axis ij . In this embodiment, its calculation formula is defined as
[0145]
[0146]
[0147] At l ij <b ij , and when y gi -(y sij -h sij ) / 2 > 0, it is determined that there is a smoking behavior;
[0148] At l ij <b ij , y gi -(y sij -h sij ) / 2 < 0, and when θ ij <c, it is determined that there is a smoking behavior;
[0149] At l ij <b ij , y gi -(y sij -h sij ) / 2 < 0, and when θ ij > π - c, it is determined that there is a smoking behavior.
[0150] Among them, b ij represents the distance threshold, b ij = 3×w sij , and c represents the angle threshold.
[0151] The object detection method of the embodiment of the present invention divides the image to be detected into a no-smoking area and a non-no-smoking area, making the application scenario more abundant, and improving the detection accuracy. After detecting the cigarette target, restrictions are made according to the distance between the cigarette target and the key point of the human face (mouth) and the included angle between the connecting line of the two and the preset reference line to determine whether there is a smoking behavior, effectively reducing the detection rate of other suspected cigarette objects and effectively reducing the false detection rate.
[0152] Figure 8 shows the structural schematic diagram of the object detection model training device of the embodiment of the present invention, as Figure 8 shown, this device includes:
[0153] The first acquisition module 801 is used to acquire an image set, and the image set includes multiple first sample images, and the first sample image is an image including a detection object;
[0154] The range reduction module 802 is used to determine the detection region containing the detection object in the first sample image, and to crop the image within the detection region to obtain the second sample image;
[0155] The copying module 803 is used to copy the detected object in the second sample image and paste the copied detected object into the second sample image according to preset constraints.
[0156] The location determination module 804 is used to determine the target location information of the detected object in the second sample image;
[0157] The first training module 805 is used to train an object detection model based on the target location information of the detected object in the second sample image and the second sample image.
[0158] Optionally, the device further includes an enhancement module for performing data enhancement processing on the second sample image.
[0159] Optionally, the copying module is further configured to: copy and randomly transform the detection object in the second sample image, and paste the copied detection object into the second sample image according to preset constraints.
[0160] Optionally, the preset constraints include: the pasting position of the copied detection object does not overlap with the original position of the detection object in the second sample image; and / or, the distance between the pasting position and the boundary of the second sample image is greater than or equal to a preset threshold.
[0161] Optionally, the range reduction module is further configured to: annotate the face region in the first sample image to determine the face region in the first sample image; expand the face region in the first sample image according to a preset expansion strategy, and use the expanded face region as the detection region of the first sample image.
[0162] Optionally, the image set further includes multiple third sample images, wherein the third sample images are images that do not include the detection object; the device further includes a second training module, configured to: obtain first location information of the face region in the first sample image; annotate the face region in the third sample image to determine the face region in the third sample image, and obtain second location information of the face region in the third sample image; and train a face detection model based on the first sample image, the first location information, the third sample image, and the second location information.
[0163] Figure 9 A schematic diagram of the target detection device 900 according to an embodiment of the present invention is shown, as follows: Figure 9As shown, the target detection device 900 includes:
[0164] The second acquisition module 901 is used to acquire the image to be detected;
[0165] The region determination module 902 is used to determine the region to be detected in the image to be detected, and to extract the image within the region to be detected to obtain the image to be recognized.
[0166] The detection module 903 is used to determine whether the image to be identified contains a detection object based on a pre-built target detection model.
[0167] Optionally, when the object to be detected is a cigarette, the region determination module is further configured to: determine the face region in the image to be detected based on a pre-built face detection model; expand the face region in the image to be detected according to a preset expansion strategy, and use the expanded face region as the region to be detected in the image to be detected.
[0168] Optionally, the device further includes a behavior detection module, configured to: acquire third location information of the detected object in the image to be identified; perform facial key point detection on the face region in the image to be identified, determine fourth location information of the mouth in the face region, and acquire the fourth location information of the mouth; and determine whether smoking behavior exists based on the third location information and the fourth location information.
[0169] Optionally, the behavior detection module is further configured to: determine the distance between the detection object and the mouth and the angle between the line connecting the detection object and the mouth and a preset reference line based on the third position information and the fourth position information; and determine whether smoking behavior exists based on the distance and the angle.
[0170] Optionally, the behavior detection module is further configured to determine the distance between the detection object and the mouth according to the following formula (1):
[0171]
[0172] Among them, l ij g represents the distance between the mouth of the i-th face region in the image to be detected and the j-th detected object. i This represents the mouth in the i-th face region of the image to be detected, (x gi y gi ) represents the fourth position information of the mouth in the i-th face region of the image to be detected, s ij This represents the j-th detected object in the i-th face region of the image to be detected, (x sij y sij) represents the third position information of the j-th detection object in the i-th face region of the to-be-detected image, (w sij , h sij ) represents the width and height of the detection frame corresponding to the j-th detection object in the i-th face region of the to-be-detected image;
[0173] The behavior detection module is further configured to determine the included angle between the connection line between the detection object and the mouth and a preset reference line according to the following formula (2):
[0174]
[0175] where, θ ij represents the included angle between the connection line between the mouth in the i-th face region of the to-be-detected image and the j-th detection object and the preset reference line.
[0176] Optionally, the behavior detection module is further configured to: when l ij < b, and y gi -(y sij -h sij ) / 2 > 0, determine that there is a smoking behavior; or, when l ij < b, y gi -(y sij -h sij ) / 2 < 0, and θ ij < c, determine that there is a smoking behavior; or, when l ij < b, y gi -(y sij -h sij ) / 2 < 0, and θ ij > π - c, determine that there is a smoking behavior; where, b represents a distance threshold, and c represents an angle threshold.
[0177] Optionally, the behavior detection module is further configured to determine the distance threshold according to the width of the detection frame corresponding to the detection object in the to-be-detected image.
[0178] Optionally, the device further includes an image segmentation module, configured to: segment the to-be-detected image according to a preset closed frame, so as to segment the to-be-detected image into a no-smoking area image and a non-no-smoking area image; determine the to-be-detected area in the no-smoking area image.
[0179] The above device can execute the method provided by the embodiments of the present invention, and has corresponding functional modules and beneficial effects for executing the method. Technical details not described in detail in this embodiment can be referred to the method provided by the embodiments of the present invention.
[0180] Embodiments of the present invention also provide an electronic device, such as Figure 10As shown, it includes a processor 1001, a communication interface 1002, a memory 1003, and a communication bus 1004, wherein the processor 1001, the communication interface 1002, and the memory 1003 communicate with each other through the communication bus 1004.
[0181] Memory 1003 is used to store computer programs;
[0182] The processor 1001 is used to execute the program stored in the memory 1003 to implement the target detection model training method of any embodiment of the present invention or the target detection method of any embodiment of the present invention.
[0183] The communication bus 1004 mentioned above can be a Peripheral Component Interconnect (PCI) bus or an Extended Industry Standard Architecture (EISA) bus, etc. This communication bus 1004 can be divided into an address bus, a data bus, a control bus, etc. For ease of illustration, it is represented by only one thick line in the figure, but this does not indicate that there is only one bus or one type of bus.
[0184] The communication interface 1002 is used for communication between the aforementioned terminal and other devices.
[0185] The memory 1003 may include random access memory (RAM) or non-volatile memory, such as at least one disk storage device. Optionally, the memory may also be at least one storage device located remotely from the aforementioned processor 1001.
[0186] The processor 1001 mentioned above can be a general-purpose processor, including a central processing unit (CPU), a network processor (NP), etc.; it can also be a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a field-programmable gate array (FPGA), or other programmable logic devices, discrete gate or transistor logic devices, or discrete hardware components.
[0187] In another embodiment of the present invention, a computer-readable medium is also provided, which stores instructions that, when executed on a computer, cause the computer to perform the target detection model training method of any embodiment of the present invention or the target detection method of any embodiment of the present invention.
[0188] In another embodiment of the present invention, a computer program product containing instructions is also provided, which, when run on a computer, causes the computer to execute the target detection model training method of any embodiment of the present invention or the target detection method of any embodiment of the present invention.
[0189] In the above embodiments, implementation can be achieved, in whole or in part, through software, hardware, firmware, or any combination thereof. When implemented in software, it can be implemented, in whole or in part, as a computer program product. A computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, all or part of the flow or function according to the embodiments of the present invention is generated. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions can be stored in a computer-readable storage medium or transmitted from one computer-readable storage medium to another. For example, computer instructions can be transmitted from one website, computer, server, or data center to another website, computer, server, or data center via wired (e.g., coaxial cable, fiber optic, digital subscriber line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.) means. The computer-readable storage medium can be any available medium that a computer can access or a data storage device such as a server or data center that integrates one or more available media. The available medium can be a magnetic medium (e.g., floppy disk, hard disk, magnetic tape), an optical medium (e.g., DVD), or a semiconductor medium (e.g., a solid-state disk (SSD)).
[0190] It should be noted that, in this document, relational terms such as "first" and "second" are used merely to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Furthermore, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitations, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes the element.
[0191] The various embodiments in this specification are described in a related manner. Similar or identical parts between embodiments can be referred to mutually. Each embodiment focuses on describing the differences from other embodiments. In particular, the system embodiments are basically similar to the method embodiments, so the description is relatively simple; relevant parts can be referred to the descriptions of the method embodiments.
[0192] The above are merely preferred embodiments of the present invention and are not intended to limit the scope of protection of the present invention. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of the present invention are included within the scope of protection of the present invention.
Claims
1. A method for training an object detection model, characterized in that, The method comprises the following steps: obtaining an image set comprising a plurality of first sample images, the first sample images being images comprising a detection object; determining a detection region comprising the detection object in the first sample image, and cutting out the image in the detection region to obtain a second sample image; copying the detection object in the second sample image and pasting the copied detection object in the second sample image according to a preset constraint condition; determining target position information of the detection object in the second sample image; training the target detection model according to the second sample image and the target position information of the detection object in the second sample image; the target detection model is used to determine whether the detection object is included in a to-be-recognized image; in a case where it is determined that the detection object is included in the to-be-recognized image, obtaining third position information of the detection object in the to-be-recognized image; performing face key point detection on a face region in the to-be-detected image to determine fourth position information of a mouth part in the face region, and obtaining the fourth position information of the mouth part; determining a distance between the detection object and the mouth part and an included angle between a connection line between the detection object and the mouth part and a preset reference line according to the third position information and the fourth position information; determining whether there is a smoking behavior according to the distance and the included angle; the distance between the detection object and the mouth part is determined according to the following formula (1): (1) wherein, denotes a distance between the mouth in the i-th face region in the image to be detected and the j-th detection object, denotes the mouth in the i-th face region in the image to be detected, denotes fourth position information of the mouth in the i-th face region in the image to be detected, denotes the j-th detection object in the i-th face region in the image to be detected, denotes third position information of the j-th detection object in the i-th face region in the image to be detected, , denotes a width and a height of a detection frame corresponding to the j-th detection object in the i-th face region in the image to be detected; the included angle between the connection line between the detection object and the mouth part and the preset reference line is determined according to the following formula (2): (2) wherein, represents an included angle between a connecting line of the mouth in the i-th face region in the image to be detected and the j-th detection object and a preset reference line.
2. The method of claim 1, wherein, before copying the detection object in the second sample image, the method further comprises performing data enhancement processing on the second sample image.
3. The method of claim 1, wherein, the copying of the detection object in the second sample image and the pasting of the copied detection object in the second sample image according to the preset constraint condition comprises: copying and randomly transforming the detection object in the second sample image, and pasting the copied detection object in the second sample image according to the preset constraint condition.
4. The method of claim 1, wherein, the preset constraint condition comprises: the pasting position of the copied detection object does not overlap with the position of the original detection object in the second sample image; and / or the distance between the pasting position and the boundary of the second sample image is greater than or equal to a preset threshold. in a case where the detection object is a cigarette, the determination of the detection region comprising the detection object in the first sample image comprises:
5. The method according to any one of claims 1 to 4, characterized in that, annotating a face region in the first sample image to determine the face region in the first sample image; extending the face region in the first sample image according to a preset extension strategy, and taking the extended face region as the detection region of the first sample image. the image set further comprises a plurality of third sample images, the third sample images being images not comprising the detection object; the method further comprises:
6. The method of claim 5, wherein, obtaining first position information of a face region in the first sample image; annotating a face region in the third sample image, determining the face region in the third sample image, and obtaining second position information of the face region in the third sample image; training a face detection model based on the first sample image, the first position information, the third sample image, and the second position information.
7. A target detection method characterized by, Comprise: obtaining a to-be-detected image; the to-be-detected image includes a face region; determining a to-be-detected region in the to-be-detected image, and obtaining a to-be-recognized image by intercepting an image in the to-be-detected region in the to-be-detected image; determining whether the to-be-recognized image includes a detection object based on a pre-constructed target detection model; in a case where it is determined that the to-be-recognized image includes the detection object, obtaining third position information of the detection object in the to-be-recognized image; performing face key point detection on the face region in the to-be-detected image, determining fourth position information of a mouth in the face region, and obtaining the fourth position information of the mouth; determining a distance between the detection object and the mouth and an included angle between a connection line of the detection object and the mouth and a preset reference line according to the third position information and the fourth position information; determining whether there is a smoking behavior according to the distance and the included angle; the distance between the detection object and the mouth is determined according to the following formula (1): (1) wherein, denotes a distance between the mouth in the i-th face region in the image to be detected and the j-th detection object, denotes the mouth in the i-th face region in the image to be detected, denotes fourth position information of the mouth in the i-th face region in the image to be detected, denotes the j-th detection object in the i-th face region in the image to be detected, denotes third position information of the j-th detection object in the i-th face region in the image to be detected, , denotes a width and a height of a detection frame corresponding to the j-th detection object in the i-th face region in the image to be detected; the included angle between the connection line of the detection object and the mouth and the preset reference line is determined according to the following formula (2): (2) wherein, represents an included angle between a connecting line of the mouth in the i-th face region in the image to be detected and the j-th detection object and a preset reference line.
8. The method of claim 7, wherein, in a case where the detection object is a cigarette, the determining of the to-be-detected region in the to-be-detected image comprises: determining a face region in the to-be-detected image based on a pre-constructed face detection model; extending the face region in the to-be-detected image according to a preset extension strategy, and taking the extended face region as the to-be-detected region in the to-be-detected image.
9. The method of claim 7, wherein, the determining of whether there is a smoking behavior according to the distance and the included angle comprises: In the case that the value of the parameter is greater than 0.5, it is determined that there is smoking behavior; or , and , it is determined that there is smoking behavior; or In the , ,and In cases where smoking behavior is confirmed; or In the case that the value of the parameter is greater than the value of the parameter , , and smoking behavior is determined to exist. wherein denotes a distance threshold, c denotes an angle threshold.
10. The method of claim 9, wherein, the distance threshold is determined according to a width of a detection frame corresponding to a detection object in the to-be-detected image.
11. The method according to any one of claims 8-10, characterized in that, the determining of the to-be-detected region in the to-be-detected image comprises: segmenting the to-be-detected image according to a preset closed frame to segment the to-be-detected image into a no-smoking area image and a non-no-smoking area image; determining a to-be-detected region in the no-smoking area image.
12. An object detection model training apparatus, comprising: Comprise: a first obtaining module configured to obtain an image set, the image set comprising a plurality of first sample images, the first sample images being images comprising a detection object; a range narrowing module configured to determine a detection region in the first sample image comprising the detection object, and obtain a second sample image by intercepting an image in the detection region; a copying module configured to copy the detection object in the second sample image, and paste the copied detection object in the second sample image according to a preset constraint condition; a position determining module configured to determine target position information of the detection object in the second sample image; a first training module configured to train the target detection model according to the second sample image and the target position information of the detection object in the second sample image; The target detection model is used to determine whether the detection object is included in the to-be-recognized image; In a case where it is determined that the detection object is included in the to-be-recognized image, third position information of the detection object in the to-be-recognized image is acquired; Face key point detection is performed on a face region in the to-be-detected image, fourth position information of a mouth in the face region is determined, and the fourth position information of the mouth is acquired; According to the third position information and the fourth position information, a distance between the detection object and the mouth and an included angle between a connection line of the detection object and the mouth and a preset reference line are determined; According to the distance and the included angle, it is determined whether there is a smoking behavior; The distance between the detection object and the mouth is determined according to the following formula (1): (1) wherein, denotes a distance between the mouth in the i-th face region in the image to be detected and the j-th detection object, denotes the mouth in the i-th face region in the image to be detected, denotes fourth position information of the mouth in the i-th face region in the image to be detected, denotes the j-th detection object in the i-th face region in the image to be detected, denotes third position information of the j-th detection object in the i-th face region in the image to be detected, , denotes a width and a height of the detection frame corresponding to the j-th detection object in the i-th face region in the image to be detected; The included angle between the connection line of the detection object and the mouth and the preset reference line is determined according to the following formula (2): (2) wherein, represents an included angle between a connecting line of the mouth in the i-th face region in the image to be detected and the j-th detection object and a preset reference line.
13. A target detection apparatus characterized by comprising: Comprising: A second acquisition module is configured to acquire a to-be-detected image, wherein the to-be-detected image includes a face region; A region determination module is configured to determine a to-be-detected region in the to-be-detected image, and acquire a to-be-recognized image by intercepting an image in the to-be-detected region in the to-be-detected image; A detection module is configured to determine, based on a pre-constructed target detection model, whether a detection object is included in the to-be-recognized image; A behavior detection module is configured to acquire third position information of the detection object in the to-be-recognized image; Face key point detection is performed on a face region in the to-be-detected image, fourth position information of a mouth in the face region is determined, and the fourth position information of the mouth is acquired; According to the third position information and the fourth position information, a distance between the detection object and the mouth and an included angle between a connection line of the detection object and the mouth and a preset reference line are determined; The distance between the detection object and the mouth is determined according to the following formula (1): (1) wherein, denotes a distance between the mouth in the i-th face region in the image to be detected and the j-th detection object, denotes the mouth in the i-th face region in the image to be detected, denotes fourth position information of the mouth in the i-th face region in the image to be detected, denotes the j-th detection object in the i-th face region in the image to be detected, denotes third position information of the j-th detection object in the i-th face region in the image to be detected, , denotes a width and a height of a detection frame corresponding to the j-th detection object in the i-th face region in the image to be detected; The included angle between the connection line of the detection object and the mouth and the preset reference line is determined according to the following formula (2): (2) wherein, represents an included angle between a connecting line of the mouth in the i-th face region in the image to be detected and the j-th detection object and a preset reference line.
14. An electronic device, comprising: Comprising: One or more processors; A storage device configured to store one or more programs, When the one or more programs are executed by the one or more processors, the one or more processors implement the method in any one of claims 1-11.
15. A computer readable medium having stored thereon a computer program, characterized in that, The program is executed by the processor to implement the method in any one of claims 1-11. The program is executed by the processor to implement the method in any one of claims 1-11.
Citation Information
Patent Citations
Smoking behavior detection method, electronic equipment and readable storage medium
CN113505707A