Target detection and image enhancement method based on attention mechanism
Through the target detection model and local image enhancement method based on the attention mechanism, the problem of target detection and recognition under extreme lighting conditions is solved, fast and stable text frame detection and recognition is achieved, and real-time requirements are met.
Patent Information
- Application Number
- CN202410864369.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-06-30
- Publication Date
- 2024-10-01
AI Technical Summary
Under extreme lighting conditions, the pixel dynamic range of the image is unreasonable, causing the target text to be lost or the background to change, making it difficult to detect and identify text frames. Existing image enhancement algorithms are slow in processing and cannot meet real-time requirements.
Using a target detection model based on the attention mechanism, the target position is determined through the text box detection model, and local image enhancement is performed based on the light intensity. The SimAM attention mechanism is used to improve the YOLOv7 network structure, and the FPN+PAN structure is combined for multi-scale fusion to optimize the neural network. Linear separability between elements enables fast target detection and local image enhancement.
It achieves rapid detection and stable recognition of target text frames, reduces the impact of lighting conditions on text recognition, meets real-time requirements, and improves the efficiency of image processing.
Smart Images

Figure CN118736587A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to computer vision technology, and in particular to a target detection and image enhancement method based on an attention mechanism. Background Art
[0002] Under extreme lighting conditions such as weak light, strong light and backlight, the pixel dynamic range of the image directly obtained by the photoelectric sensor is unreasonable, which often causes the loss of key details of the image, and may cause the target text to be lost or the target text background to change, which may make subsequent text box detection and recognition difficult to achieve. The introduction of image enhancement algorithm is to solve the problem of unsatisfactory imaging results caused by complex recognition scenes.
[0003] At present, image enhancement has been widely used in medical diagnosis, military reconnaissance, fingerprint recognition and other fields. At the same time, image enhancement can also be used as a preprocessing algorithm for image processing algorithms such as target recognition, target tracking, feature point matching, image fusion, and super-resolution reconstruction.
[0004] Traditional image enhancement has been studied for a long time, and the existing methods can be roughly divided into three categories: spatial domain methods directly process pixel values, such as histogram equalization and gamma transform; frequency domain methods operate in a certain transform domain, such as wavelet transform; hybrid domain methods are some methods that combine spatial domain and frequency domain.
[0005] Compared with traditional methods, deep learning solutions have obvious advantages in improving image quality. Whether it is clarity or contrast, satisfactory results can be obtained. However, the processing speed is relatively slow. The processing of an image with poor imaging may take hundreds of milliseconds or several seconds, which cannot meet real-time requirements. Summary of the invention
[0006] The technical problem to be solved by the present invention is to provide a target detection and image enhancement method based on an attention mechanism in view of the defects in the prior art.
[0007] The technical solution adopted by the present invention to solve the technical problem is: a target detection and image enhancement method based on an attention mechanism, comprising the following steps:
[0008] Step 1: Create a text box detection dataset and annotate the text box position of each image in the dataset according to the text box annotation rules. The dataset includes samples with different lighting intensities, different shooting angles, and different text forms.
[0009] Step 2: Establish a text box detection model based on the attention mechanism, and perform target detection through the text box detection model to obtain the position of the text box;
[0010] Step 3: After the position of the text box is detected, the text box is locally enhanced using a corresponding image enhancement algorithm according to the light intensity for subsequent text recognition.
[0011] According to the above scheme, in step 2), the network structure includes an input module, a backbone extraction module, a detection module and a prediction module; and an attention mechanism module is added to the backbone extraction module and the detection module;
[0012] in,
[0013] The input module scales the input image to the network input size and performs normalization.
[0014] The backbone extraction module includes multiple Bconv convolutional layers, E-ELAN convolutional layers and MPConv convolutional layers; among them, the BConv convolutional layer consists of a convolutional layer, a batch normalization (BN) layer and a LeakyReLU activation function, which is used to extract image features of different scales;
[0015] The detection module uses the FPN+PAN structure to perform multi-scale fusion of target features.
[0016] According to the above scheme, in step 2), in the backbone extraction module, the attention mechanism module is added between the E-ELAN convolution layer and the MPConv convolution layer.
[0017] According to the above scheme, in step 2),
[0018] The energy function of the attention mechanism is used to define the linear separability between neuron t and all other neurons in the same channel. The energy function of each neuron is defined as follows:
[0019]
[0020] Among them, t and x i are the target neuron and other neurons in the channel, ω t and b t are the weights and biases of the linear transformation of t, i is the index in the spatial dimension, λ is a hyperparameter, and M=HW is the number of all neurons on a single channel;
[0021] The transformation weights and biases are expressed as follows:
[0022]
[0023] where μ t and is the mean and variance of all neurons except t, calculated as follows:
[0024]
[0025] By calculating ω t 、b t As well as the analytical solution of the mean and variance of all neurons in the channel, the minimum energy formula can be obtained as:
[0026]
[0027] in, and are the mean and variance respectively, and the expressions are:
[0028]
[0029] It can be seen from the above formula that the smaller the energy function value, the greater the linear separability between neuron t and other neurons.
[0030] According to the above scheme, the step 3) uses a corresponding image enhancement algorithm to locally enhance the text box according to the light intensity, as follows:
[0031] First, the original BGR image in the detection area is converted into an HSV image, and divided into three cases: brighter, darker, and darkest according to the brightness value of the brightness map V. The key brightness V value range here is [V min ,V max ], when the brightness V of the original image satisfies V<V min When the image is dark, the brightness, color, contrast and sharpness of the image are introduced to enhance the image, and V satisfies V>V max When only color enhancement is performed, V satisfies V min ≤V≤V max Brightness and color enhancement operations are performed separately.
[0032] The beneficial effects produced by the present invention are:
[0033] 1. The present invention realizes fast and stable detection of target text boxes by establishing a target detection model based on the attention mechanism, and also greatly reduces the influence of factors such as complex imaging conditions in natural scenes on subsequent text recognition through local image enhancement.
[0034] 2. First lock the target area and then perform local image enhancement. This can meet the real-time requirements in image processing and provide favorable conditions for subsequent recognition. BRIEF DESCRIPTION OF THE DRAWINGS
[0035] The present invention will be further described below with reference to the accompanying drawings and embodiments, in which:
[0036] Figure 1 is a method flow chart of an embodiment of the present invention;
[0037] Figure 2It is a structural diagram of a text box detection model according to an embodiment of the present invention. DETAILED DESCRIPTION
[0038] In order to make the purpose, technical solution and advantages of the present invention more clearly understood, the present invention is further described in detail below in conjunction with the embodiments. It should be understood that the specific embodiments described herein are only used to explain the present invention and are not used to limit the present invention.
[0039] like Figure 1 As shown, a target detection and image enhancement method based on an attention mechanism includes the following steps:
[0040] Step 1: Create a text box detection dataset and annotate the text box position of each image in the dataset according to the text box annotation rules. The dataset includes samples with different lighting intensities, different shooting angles, and different text forms.
[0041] Step 2: Establish a text box detection model based on the attention mechanism, and use the text box detection model to perform target detection on the read optoelectronic video to obtain the position of the text box;
[0042] In this embodiment, the SimAM attention mechanism is used to improve the YOLOv7 network structure, and the network structure with the SimAM attention mechanism is added to perform target detection on the read optoelectronic video to obtain the position of the text box.
[0043] The network structure includes an input module, a backbone extraction module, a detection module and a prediction module; and an attention mechanism module is added to the backbone extraction module and the detection module; in the backbone extraction module, the attention mechanism module is added between the E-ELAN convolution layer and the MPConv convolution layer.
[0044] in,
[0045] The input module scales the input image to the network input size and performs normalization.
[0046] The backbone extraction module (backbone) includes multiple Bconv convolutional layers, E-ELAN convolutional layers and MPConv convolutional layers; among them, the BConv convolutional layer consists of a convolutional layer, a batch normalization (BN) layer and a LeakyReLU activation function, which is used to extract image features of different scales;
[0047] The detection module (neck) uses the FPN+PAN structure to perform multi-scale fusion of target features.
[0048] The prediction module (perdiction) has different numbers of branches at the output for different detection algorithms, and usually includes a classification branch and a regression branch.
[0049] The attention mechanism finds important neurons by measuring the linear separability between neurons and assigns higher priority to these neurons. By comparing various attention mechanisms, we embed SimAM into the YOLOv7 model to improve the performance of target detection. The structural principle diagram of the model is shown in the figure. Figure 2 shown.
[0050] The energy function is used to define the linear separability between neuron t and all other neurons in the same channel. The energy function of each neuron is defined as follows:
[0051]
[0052] Among them, t and x i are the target neuron and other neurons in the channel, ω t and b t are the weights and biases of the linear transformation of t, i is the exponent in the spatial dimension, λ is a hyperparameter, and M=HW is the number of all neurons on a single channel.
[0053] The transformation weights and biases are expressed as follows:
[0054]
[0055] where μ t and is the mean and variance of all neurons except t, calculated as follows:
[0056]
[0057] By calculating ω t 、b t As well as the analytical solution of the mean and variance of all neurons in the channel, the minimum energy formula can be obtained as:
[0058]
[0059] in, and are the mean and variance respectively, and the expressions are:
[0060]
[0061] As can be seen from the above formula, the smaller the energy function value, the greater the linear separability between neuron t and other neurons. The entire attention module is implemented under the guidance of this energy function, avoiding excessive heuristics and adjustments. By operating on individual neurons and integrating this linear separability into an end-to-end framework, the neural network is improved.
[0062] The algorithm selects IOU value and GLOU value as the criteria for judging target detection, and uses the average precision (AP) as the evaluation indicator of the model.
[0063] Specifically, IoU is the result of dividing the overlapping part of two regions by the region set. The IoU calculation result is compared with the set threshold (generally set to 0.5), and its expression is:
[0064]
[0065] The higher the IoU value, the more accurate the bounding box is. Since IoU is a ratio concept, it is not sensitive to the size of the target object.
[0066] The regression loss optimization of BBox in the detection task is not completely equivalent to IoU optimization, and is also sensitive to the size of the object, which will lead to the inability of IoU to directly optimize these inequivalent parts, that is, IoU itself has limitations. In order to improve the limitations caused by using only IoU, the GIoU indicator is introduced, and its expression is:
[0067]
[0068] That is, first calculate the minimum enclosed area of the two boxes, calculate IoU, then calculate the proportion of the area that does not belong to the two boxes in the enclosed area, and finally subtract this proportion from IoU to get GIoU. Unlike IoU, which only focuses on overlapping areas, GIoU not only focuses on overlapping areas, but also other non-overlapping areas, which can better reflect the overlap between the two.
[0069] Step 3: After the position of the text box is detected, the text box is locally enhanced using a corresponding image enhancement algorithm according to the light intensity for subsequent text recognition.
[0070] First, the original BGR image in the detection area is converted into an HSV image, and divided into three cases: brighter, darker, and darkest according to the brightness value of the brightness map V. The key brightness V value range here is [V min ,V max ], when the brightness V of the original image satisfies V<V min When the image is dark, the brightness, color, contrast and sharpness of the image are introduced to enhance the image, and V satisfies V>V max When only color enhancement is performed, V satisfies V min ≤V≤V max Brightness and color enhancement operations are performed separately.
[0071] It should be understood that those skilled in the art can make improvements or changes based on the above description, and all these improvements and changes should fall within the scope of protection of the appended claims of the present invention.
Claims
1. A target detection and image enhancement method based on attention mechanism, characterized in that: The following steps are involved: Step 1: Create a text box detection dataset and annotate the text box position of each image in the dataset according to the text box annotation rules. The dataset includes samples with different lighting intensities, different shooting angles, and different text forms. Step 2: Establish a text box detection model based on the attention mechanism, and perform target detection through the text box detection model to obtain the position of the text box; Step 3: After the position of the text box is detected, the text box is locally enhanced using a corresponding image enhancement algorithm according to the light intensity for subsequent text recognition.
2. The object detection and image enhancement method based on the attention mechanism according to claim 1, characterized in that: In the step 2), the network structure includes an input module, a backbone extraction module, a detection module and a prediction module; and an attention mechanism module is added to the backbone extraction module and the detection module; in, The input module scales the input image to the network input size and performs normalization. The backbone extraction module includes multiple Bconv convolutional layers, E-ELAN convolutional layers and MPConv convolutional layers; among them, the BConv convolutional layer consists of a convolutional layer, a batch normalization layer and a LeakyReLU activation function, which is used to extract image features of different scales; The detection module uses the FPN+PAN structure to perform multi-scale fusion of target features.
3. The object detection and image enhancement method based on the attention mechanism according to claim 1, characterized in that: In the step 2), in the backbone extraction module, the attention mechanism module is added between the E-ELAN convolution layer and the MPConv convolution layer.
4. The object detection and image enhancement method based on the attention mechanism according to claim 1, characterized in that: In step 2), the energy function of the attention mechanism is used to define the linear separability between neuron t and all other neurons in the same channel. The energy function of each neuron is defined as follows: Among them, t and x i are the target neuron and other neurons in the channel, ω t and b t are the weights and biases of the linear transformation of t, i is the index in the spatial dimension, λ is a hyperparameter, and M=HW is the number of all neurons on a single channel; The transformation weights and biases are expressed as follows: where μ t and is the mean and variance of all neurons except t, calculated as follows: By calculating ω t , b t As well as the analytical solution of the mean and variance of all neurons in the channel, the minimum energy formula can be obtained as: in, and are the mean and variance respectively, and the expressions are: It can be seen from the above formula that the smaller the energy function value, the greater the linear separability between neuron t and other neurons.
5. The object detection and image enhancement method based on the attention mechanism according to claim 1, characterized in that: The step 3) uses a corresponding image enhancement algorithm to locally enhance the text box according to the light intensity, as follows: First, the original BGR image in the detection area is converted into an HSV image, and divided into three cases: brighter, darker, and darkest according to the brightness value of the brightness map V. The key brightness V value range here is [V min ,V max ], when the brightness V of the original image satisfies V<V min When the image is dark, the brightness, color, contrast and sharpness of the image are introduced to enhance the image, and V satisfies V>V max When only color enhancement is performed, V satisfies V min ≤V≤V max Brightness and color enhancement operations are performed separately.
6. An electronic device, characterized in that: include: one or more processors; as well as a storage device for storing one or more programs, When the one or more programs are executed by the one or more processors, the one or more processors are caused to execute the method according to any one of claims 1 to 5.
7. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the method according to any one of claims 1 to 5 is implemented.
