Training method of image definition detection model and focusing method of camera equipment

Through the training and application of the image clarity detection model, the problem of difficulty in finding the best position and motor return during the focus process of the camera equipment is solved, and a more accurate and stable focus process is achieved.

CN119048428APending Publication Date: 2024-11-29SHENZHEN BAICHUAN SECURITY TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411001476.7
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-07-24
Publication Date
2024-11-29

AI Technical Summary

Technical Problem

It is difficult for existing camera equipment to find the best focus position during the focusing process, and the motor is prone to empty back, resulting in damage to the motor that controls the camera lens, and the contrast focusing method cannot reach the clearest position on the picture.

Method used

Using the training method of image definition detection model, by obtaining real and synthesizing image data sets, generating grayscale maps and out-of-focus grayscale maps, calculating loss functions, extracting feature maps, and training image definition detection models, which are used to detect camera lenses The captured image clarity and focus adjustments are made according to the detection results to avoid the influence of moving objects at high speed and strong light sources.

Benefits of technology

It improves the accuracy and speed of the camera equipment's focus, reduces the occurrence of motor air return, reduces the risk of motor damage, and achieves stable focus in complex scenarios.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119048428A_ABST
    Figure CN119048428A_ABST
Patent Text Reader

Abstract

The invention relates to the technical field of video monitoring, and discloses a training method of an image definition detection model, a focusing method of camera equipment, training equipment, the camera equipment and a computer readable storage medium, and the method comprises the steps: obtaining a first data set and a second data set, respectively detecting the definition of each pixel point on the real image and the synthetic image to generate a corresponding grey-scale map, determining a first loss function according to the first sharpness analysis result and the second sharpness analysis, determining a second loss function according to the gray value of the out-of-focus grey-scale map and the gray value of the grey-scale map corresponding to the synthetic image, and generating a second loss function according to the second loss function. And determining a third loss function according to the first feature map and the second feature map, and training the image definition detection model according to the first loss function, the second loss function and the third loss function. Through the above mode, the accuracy of the image definition detection model is improved, and the camera device can directly judge whether focusing is completed according to the definition detection result.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The embodiments of the present application relate to the field of video surveillance technology, and specifically to a training method for an image clarity detection model, a focusing method for a camera device, a training device, a camera device, and a computer-readable storage medium. Background Art

[0002] Existing focusing methods include phase focusing and contrast focusing. Phase focusing, also known as phase difference focusing, determines whether focusing is completed by detecting whether the light projected from different edges of the same subject on the camera lens overlaps on the phase focusing sensor. This results in special requirements for camera lenses and sensors, and the cost is relatively high. Therefore, surveillance cameras basically do not use this focusing method to achieve automatic focusing, but use contrast focusing instead.

[0003] The inventor of the present application found in his research that when using contrast focus to achieve automatic focus, theoretically, it can only focus to the suboptimal point, but cannot focus to the clearest position of the picture, and when the scene is single, there is a fast-moving target, or the image texture collected by the camera is not rich, it is easy to fail to focus or the focusing time is too long. In addition, during the focusing process, the motor often returns, resulting in the camera lens being unable to return to the clear position found before due to the motor return problem after finding the best position of the lens, and it is also easy to cause damage to the motor that controls the camera lens. Summary of the invention

[0004] In view of the above problems, the embodiments of the present application provide a training method for an image clarity detection model, a focusing method for a camera device, a training device, a camera device, and a computer-readable storage medium, aiming to solve the technical problems in the prior art that it is difficult to find the optimal focus position and motor backlash is prone to occur during the focusing process of the camera device.

[0005] According to one aspect of an embodiment of the present application, a training method for an image clarity detection model is provided, the method comprising: acquiring a first data set and a second data set, wherein the first data set comprises at least one real image and the second data set comprises at least one synthetic image; detecting the clarity of each pixel on the real image, and generating a grayscale image corresponding to the real image according to the clarity of each pixel on the real image; detecting the clarity of each pixel on the synthetic image, and generating a grayscale image corresponding to the synthetic image according to the clarity of each pixel on the synthetic image; performing sharpness analysis on the grayscale values ​​of each pixel on the grayscale image corresponding to the real image, and obtaining a first sharpness analysis result; performing sharpness analysis on each pixel on the real image according to an indication of a real out-of-focus area of ​​the real image, and obtaining a second sharpness analysis result; and A first loss function is determined by a sharpness analysis result and a second sharpness analysis result; a synthetic image is analyzed according to a synthetic out-of-focus area indication of the synthetic image to generate a defocus grayscale map corresponding to the synthetic image, wherein the synthetic out-of-focus area indication is generated according to the real out-of-focus area indication; the difference between the grayscale value of each pixel on the defocus grayscale map corresponding to the synthetic image and the grayscale value of each pixel on the grayscale map corresponding to the synthetic image is calculated to determine a second loss function; image features of the defocus grayscale map corresponding to the synthetic image are extracted to obtain a first feature map; image features of the grayscale map corresponding to the synthetic image are extracted to obtain a second feature map; a third loss function is determined according to the first feature map and the second feature map; an image clarity detection model is trained according to the first loss function, the second loss function and the third loss function.

[0006] According to another aspect of an embodiment of the present application, a focusing method for a camera device is provided, the method comprising: acquiring an image at a current moment captured by a camera lens; detecting the clarity of each pixel on the image at the current moment by means of an image clarity detection model, and generating a grayscale image corresponding to the image at the current moment according to the clarity of each pixel on the image at the current moment; analyzing the grayscale values ​​of the grayscale image corresponding to the image at the current moment, and determining a clarity detection result corresponding to the image at the current moment; and adjusting the focus of the camera lens according to the clarity detection result; wherein the image clarity detection model is an image clarity detection model obtained after training by the above-mentioned image clarity detection model training method.

[0007] According to another aspect of an embodiment of the present application, a training device is provided, including a memory, a processor, and a computer program stored in the memory, and the processor executes the computer program to implement the training method of the above-mentioned image clarity detection model.

[0008] According to another aspect of an embodiment of the present application, a camera device is provided, which includes a camera lens, a memory and a processor; the camera lens is used to capture images; the memory is used to store computer programs; the processor executes the computer program to implement the focusing method of the above-mentioned camera device.

[0009] According to another aspect of an embodiment of the present application, a computer-readable storage medium is provided, and when the computer program is executed by a processor, the training method of the above-mentioned image clarity detection model is implemented, or when the computer program is executed by a processor, the focusing method of the above-mentioned camera device is implemented.

[0010] In an embodiment of the present application, in view of the difference between the real out-of-focus area indication and the synthetic out-of-focus area indication, the image clarity detection model is trained by obtaining loss functions using different verification methods for the grayscale image corresponding to the real image and the grayscale image corresponding to the synthetic image. Specifically, for real images that have only two labels of "clear" and "blurred", after performing sharpness analysis on the real image and its corresponding grayscale image, the first loss function is determined according to the sharpness analysis result. For synthetic images marked with grayscale values, the second loss function and the third loss function are determined by calculating the difference in grayscale values ​​of corresponding pixels on the synthetic image and its corresponding grayscale image and the distance between the two images in the feature space. This verification method effectively improves the accuracy of the trained image clarity detection model, so that the camera device can directly determine whether the camera device is in focus based on the clarity of the image captured by the camera lens according to the image clarity detection model, without having to complete the focus of the camera device by comparing the clarity of the images captured by the camera lens corresponding to different lens positions. It effectively avoids the influence of factors such as high-speed moving objects or strong light sources on the focus adjustment of the camera device, reduces the situation of rotating the motor, and reduces the occurrence of motor backlash.

[0011] The above description is only an overview of the technical solution of the embodiment of the present application. In order to more clearly understand the technical means of the embodiment of the present application, it can be implemented in accordance with the contents of the specification. In order to make the above and other purposes, features and advantages of the embodiment of the present application more obvious and easy to understand, the specific implementation methods of the present application are listed below. BRIEF DESCRIPTION OF THE DRAWINGS

[0012] The accompanying drawings are only used to illustrate the embodiments and are not to be considered as limiting the present application. In addition, the same reference symbols are used to represent the same components throughout the accompanying drawings. In the accompanying drawings:

[0013] Figure 1 A diagram showing an application scenario of the focusing method of a camera device provided in an embodiment of the present application;

[0014] Figure 2A schematic diagram of the structure of a camera device provided in an embodiment of the present application is shown;

[0015] Figure 3 A schematic diagram of the structure of a training device provided in an embodiment of the present application is shown;

[0016] Figure 4 A flow chart of a method for training an image clarity detection model provided in an embodiment of the present application is shown;

[0017] Figure 5 A flowchart of a focusing method for an imaging device provided by a first embodiment of the present application is shown;

[0018] Figure 6 A comparison diagram of a grayscale image generated by an image clarity detection model provided in an embodiment of the present application and an original image is shown;

[0019] Figure 7 The image captured by the camera lens at the current moment in the focusing method of the camera device provided by the embodiment of the present application is shown;

[0020] Figure 8 A flow chart showing a focusing method for an imaging device provided by a second embodiment of the present application is shown;

[0021] Fig. 9 A schematic diagram showing the position state of a lens during focus adjustment of a camera device provided by an embodiment of the present application is shown;

[0022] Fig.10 A flow chart of a focusing method for an imaging device provided in a third embodiment of the present application is shown. DETAILED DESCRIPTION

[0023] The exemplary embodiments of the present application will be described in more detail below with reference to the accompanying drawings. Although the exemplary embodiments of the present application are shown in the drawings, it should be understood that the present application can be implemented in various forms and should not be limited by the embodiments set forth herein.

[0024] See also Figure 1 As shown, Figure 1The following is a schematic diagram of an application scenario of the focusing method of the camera device provided in the embodiment of the present application. The focusing method of the camera device in the embodiment of the present application is applied to the camera device 1. The camera device 1 can be a camera, an IP camera or other video surveillance equipment for security monitoring. The camera device 1 can establish a communication connection with the electronic device 2 through the network 3. The electronic device 2 can be a touch-screen mobile phone, a smart phone, a tablet computer, a portable electronic device or other terminal electronic device with a display screen. The network 3 includes but is not limited to one or more of a local area network (LAN), a metropolitan area network (MAN), a wide area network (WAN), a 4G / 5G network, WIFI, Bluetooth (Bluetooth) and a point-to-point (P2P) communication network.

[0025] In the embodiment of the present application, the camera device 1 and the electronic device 2 may include one or more processors, which may be a central processing unit CPU, or an application specific integrated circuit (ASIC), or one or more integrated circuits configured to implement the present embodiment, which is not limited here. The one or more processors included in the electronic device may be processors of the same type, such as one or more CPUs; or they may be processors of different types, such as one or more CPUs and one or more ASICs, which is not limited here.

[0026] In an embodiment of the present application, the camera device 1 is installed in an area that needs to be monitored (such as a home, office, shopping mall, etc.), so that the camera device 1 can continuously capture surveillance videos in the monitored area and send the captured videos to the terminal electronic device 2 through the network 3 for users to browse.

[0027] See also Figure 2 As shown, Figure 2 FIG. 1 shows a schematic diagram of the structure of the camera device provided in an embodiment of the present application. Figure 2 As shown, the camera device 1 may include a camera lens 11, a memory 12 and a processor 13. The camera lens 11 is used to capture images, the memory 12 is used to store a computer program 14, and the processor 13 executes the computer program 14 to implement a focusing method of the camera device.

[0028] Among them, the camera lens 11 is used to shoot and record the shooting area of ​​the camera device 1. A lens group is arranged inside the camera lens 11, and the lens group can focus the light in the scene onto the image sensor 15 of the camera device 1, and then form an image on the display screen of the camera device 1 or the electronic device 2. During the focusing process of the camera device 1, adjusting the camera lens 11 is actually adjusting the position of the lens group inside the camera lens 11 to adjust the distance between the lens group and the image sensor 15 (i.e., the focal length). The lens group includes but is not limited to one or more of a convex lens, a concave lens, a zoom lens, and an infrared lens.

[0029] The processor 13 is used to execute the computer program 14, and specifically can execute the relevant steps in the embodiment of the focusing method of the camera device provided in the present application. Specifically, the computer program 14 can include computer executable instructions.

[0030] The processor 13 may be a CPU, or an ASIC, or one or more integrated circuits configured to implement the embodiments of the present application. The one or more processors included in the camera device 1 may be processors of the same type, such as one or more CPUs; or may be processors of different types, such as one or more CPUs and one or more ASICs.

[0031] The memory 12 is used to store a computer program 14. The memory 12 may include a high-speed RAM memory, and may also include a non-volatile memory, such as at least one disk memory.

[0032] In the embodiment of the present application, the camera device 1 further includes a focus motor 16. The processor 13 detects the image captured by the camera lens 11 by executing the steps in the embodiment of the focusing method of the camera device described below. When it is detected that the image captured by the camera lens 11 is blurred, the processor 13 controls the focus motor 16 to drive the camera lens 11 to move according to the generated focus instruction, and performs real-time detection on the image captured by the camera lens 11 during the movement of the camera lens 11 until it is detected that the image captured by the camera lens 11 is clear, and the focusing of the camera device 1 is completed. The focus motor 16 may include a zoom motor and a focus motor, wherein the zoom motor is used to adjust the focal length, and the focus motor is used to adjust the focal position.

[0033] In the focusing method of the camera device and the camera device 1 proposed in the present application, the clarity of the image captured by the camera lens 11 is detected by a pre-trained image clarity detection model, so that the camera device 1 can directly determine whether the focus is completed according to the clarity of the image, thereby realizing the rapid focusing of the camera device 1. Before performing the focusing operation of the camera device, it is necessary to first train the image clarity detection model. In the embodiment of the present application, in order to improve the accuracy of the prediction of the clarity of the image captured by the camera lens 11, the present application also proposes a training method for the image clarity detection model. Before introducing the embodiment of the focusing method of the camera device, the training method and training device of the image clarity detection model used in the focusing method of the camera device are first introduced.

[0034] See also Figure 3 As shown, Figure 3 The schematic diagram of the structure of the training device provided by the embodiment of the present application is shown. During the focusing process of the camera device, the clarity of the image captured by the camera lens 11 needs to be detected by the image clarity detection model, so as to determine whether the camera lens 11 needs to be focused according to the detection result of the image clarity detection model. The image clarity detection model can be pre-trained by the training device, such as Figure 3 As shown, the training device 4 can be a local offline electronic device, such as a computer device. In this embodiment, the training device 4 includes, but is not limited to: a processor 41 and a memory 42.

[0035] The memory 42 is used to store a computer program 43. The memory 42 may include a high-speed RAM memory, or may also include a non-volatile memory, such as at least one disk memory. The computer program 43 may include computer executable instructions.

[0036] The processor 41 is used to execute the computer program 43, and specifically can execute the specific steps of the training method of the image clarity detection model provided in this application.

[0037] The processor 41 may be a central processing unit (CPU), or an application-specific integrated circuit (ASIC), or one or more integrated circuits configured to implement the embodiments of the present application. The one or more processors included in the training device 4 may be processors of the same type, such as one or more CPUs; or may be processors of different types, such as one or more CPUs and one or more ASICs.

[0038] According to another aspect of the embodiment of the present application, a training method for an image definition detection model is provided, such as Figure 4 As shown, Figure 4A flowchart of a method for training an image definition detection model provided in an embodiment of the present application is shown. The method can be executed by a training device 4. The method includes the following steps:

[0039] Step S100: Acquire a first data set and a second data set, wherein the first data set includes at least one real image, the real image includes a real out-of-focus area indication, and the second data set includes at least one synthetic image, the synthetic image includes a synthetic out-of-focus area indication, and the synthetic image is an image generated based on the real image.

[0040] Among them, a synthetic image is a new image generated manually or programmatically based on an existing real image, for example, different parts of two images are merged to generate a new image (for example, the background in one image and the foreground in another image are synthesized into a new image), or parts of a real image are blurred to obtain a new image (for example, moving people and distant objects in a real image are blurred to obtain a new synthetic image), etc.

[0041] The out-of-focus area indication is used to characterize whether the corresponding area on the image is out of focus. The real out-of-focus area indication is the out-of-focus area indication marked on the real image, which is usually manually marked, and mainly includes two indications of "clear" and "blurred", that is, the clear area on the real image is marked with "clear" and the blurred area is marked with "blurred". Of course, in order to facilitate the computer to identify the real out-of-focus area indication, "0" and "1" can also be used to represent "clear" and "blurred", for example, the pixel points corresponding to the clear area on the real image are marked as "0" and the pixel points corresponding to the blurred area are marked as "1".

[0042] The synthetic out-of-focus area indication is an out-of-focus area indication marked on the synthetic image, which is usually automatically generated by a program. When generating a synthetic image, the real out-of-focus area indication on the real image can be directly marked on the corresponding part of the synthetic image as a synthetic out-of-focus area indication, or the clear area and the blurred area on the synthetic image can be determined according to the real out-of-focus area indication, and then different grayscale values ​​can be generated for pixels at different positions according to the positional relationship between the clear area and the blurred area as a synthetic out-of-focus area indication; when blurring the real image, different grayscale values ​​can be generated according to the real out-of-focus area indication of each area on the image and the degree of blurring as a synthetic out-of-focus area indication for each pixel, and so on.

[0043] It should be pointed out that the clarity of each pixel on the image captured by the camera is related to the focus and focal length of the camera. The closer the area is to the focal point, the higher the clarity of the image. The closer the distance to the focal length of the camera lens on the camera is, the higher the clarity of the image. Therefore, although the human eye only has two types of clear areas and blurred areas when judging an image, the clarity from the clear area to the blurred area gradually decreases. Therefore, using grayscale values ​​to represent the clarity of each pixel on the image is more in line with the actual clarity of each pixel on the image.

[0044] Step S110: Detect the clarity of each pixel on the real image, and generate a grayscale image corresponding to the real image according to the clarity of each pixel on the real image.

[0045] Step S120: detecting the clarity of each pixel on the composite image, and generating a grayscale image corresponding to the composite image according to the clarity of each pixel on the composite image.

[0046] Among them, Figure 6 As shown, after the image clarity detection model detects the clarity of each pixel on the image, it will generate a grayscale image according to the clarity of each pixel, and the clarity of the corresponding area is represented by the color depth of the grayscale image. Specifically, assuming that the clarity corresponding to each pixel is represented by 0-100, when generating the corresponding grayscale image according to each pixel, the clarity of each pixel can be directly used as the grayscale value of the pixel to generate the corresponding grayscale image, or the clarity can be mapped to 0-255. For example, the grayscale value corresponding to the pixel with a clarity of 0 is set to 0, the grayscale value corresponding to the pixel with a clarity of 20 is set to 51, and the grayscale value corresponding to the pixel with a clarity of 100 is set to 100. Of course, the grayscale value corresponding to the pixel with a higher clarity can also be set lower, for example, the grayscale value corresponding to the pixel with a clarity of 100 is set to 0.

[0047] The image clarity detection model can be a neural network model. In an embodiment of the present application, as an example, a U-Net-based convolutional network architecture can be adopted. On the one hand, a pre-trained VGG19 network is used to initialize the encoder so that the image clarity detection model can perform better feature representation in the initial stage of training; on the other hand, upsampling convolution is used in the decoder to avoid the influence of block effects, and auxiliary loss on scale is applied at each upsampling layer, so that multi-scale clarity detection of the image can be performed. In addition, after the last upsampling layer of the decoder, a convolution block with short jump connections is attached to refine the grayscale value range of the generated grayscale image.

[0048] Step S130: performing sharpness analysis on the grayscale value of each pixel on the grayscale image corresponding to the real image to obtain a first sharpness analysis result.

[0049] Step S140: performing sharpness analysis on each pixel on the real image according to the real out-of-focus area indication of the real image to obtain a second sharpness analysis result.

[0050] Step S150: Determine a first loss function according to the first sharpness analysis result and the second sharpness analysis result.

[0051] Among them, since the real out-of-focus area on the real image is indicated by artificially marked "sharpness" and "blur", and the grayscale value of the grayscale image corresponding to the real image is a continuous value within a certain range, when verifying the clarity detection result of the real image by the image clarity detection model, it is necessary to perform sharpness analysis on the real image and its corresponding grayscale image, and then verify to obtain the first loss function to train the image clarity detection model.

[0052] Specifically, a grayscale threshold can be set to convert the grayscale image corresponding to the real image into a binary image to obtain the first sharpness analysis result, and then the real out-of-focus area indication of each pixel on the real image is converted into the corresponding "0" and "1" (for example, if the first sharpness analysis result converts the pixel value of the pixel with high clarity to "0" and the pixel value of the pixel with low clarity to "1", it is necessary to convert the pixel value of the pixel indicating the real out-of-focus area as "clear" to "0" and the pixel value of the pixel indicating the real out-of-focus area as "blurred" to "1"), and use the obtained binary image as the second sharpness analysis result. When verifying the clarity detection result of the real image, it is possible to determine whether the clarity detection results of each pixel on the real image by the image clarity detection model are correct by determining whether the number of pixels with the same pixel value in the first sharpness analysis result and the second sharpness analysis result is the same. It is also possible to compare the pixel values ​​of the pixels at the same position in the first sharpness analysis result and the second sharpness analysis result, and determine whether the clarity detection result of the image clarity detection model for the pixel is correct by determining whether the pixel values ​​are the same.

[0053] Of course, you can also directly use a 1×1 convolution layer to traverse the real image and its corresponding grayscale image, and compare the grayscale value of the same pixel on the grayscale image with the grayscale threshold according to the actual out-of-focus area indication to determine whether the clarity detection result of the pixel is accurate. For example, when the higher the grayscale value of the pixel, the clearer the pixel is. If the actual out-of-focus area indication of the pixel is "clear", then only when the grayscale value of the pixel is greater than the grayscale threshold, it can be considered that the clarity detection result of the image clarity detection model for the pixel is correct.

[0054] In addition, the size of the grayscale threshold is closely related to the image clarity requirement. Assuming that the higher the grayscale value of a pixel is, the clearer the pixel is, and the larger the grayscale threshold is, the higher the image clarity requirement is. The trained image clarity detection model will also use higher standards to judge the image clarity when detecting the image clarity. Therefore, when training the image clarity detection model, the grayscale threshold can be set according to the performance of the camera device and the image clarity requirement. For example, if the performance of the camera device is poor and the image clarity requirement is low, a relatively low grayscale threshold can be set to train the image clarity detection model; if the performance of the camera device is good and the image clarity requirement is high, a relatively high grayscale threshold can be set to train the image clarity detection model.

[0055] The first loss function is a loss function for optimizing the image clarity detection model. The first loss function can be binary cross entropy loss, logarithmic loss, exponential loss, Hinge loss, etc. When training the image clarity detection model, experiments can be used to determine the loss function that best suits the current task.

[0056] In the embodiment of the present application, as an example, the first loss function may be a sigmoid cross entropy loss. If the size of the real image is W×H, then the first loss function L S As shown below:

[0057]

[0058] Among them, I B represents the real image, B(I B θ B ) represents the grayscale image corresponding to the real image, S(B(I B θ B );θ S ) i,j is the first sharpness analysis result corresponding to the pixel point (i, j) on the real image, b i,j is the second sharpness analysis result corresponding to the pixel point (i, j) on the real image, θ B is the learning parameter of the image definition detection model. In the process of training the image definition detection model, the first loss function L can be optimized S As the target, the parameter θ of the image clarity detection model B to update.

[0059] In addition, when the first sharpness analysis result is obtained by a neural network model (e.g., a neural network model constructed by 1×1 convolutional layers, each of which is followed by batch normalization and leaky ReLU layers), θ S is the learning parameter of the neural network model. SIn the process, the parameter θ can also be updated S To update the neural network model, the sharpness analysis result of the neural network model is more accurate. Of course, when the parameter θ S When an update is also required, the training parameters θ can be alternating B and parameter θ S The image clarity detection model and the neural network model are trained in a manner (i.e., in one round of training, one of the parameters is kept constant and the other parameter is updated; in the next round of training, the parameter that remained constant in the previous round of training is updated and the other parameter is kept constant).

[0060] Step S160: Analyze the composite image according to the composite defocus area indication of the composite image to generate a defocus grayscale image corresponding to the composite image, where the composite defocus area indication is generated according to the real defocus area indication.

[0061] Step S170: Calculate the difference between the grayscale value of each pixel on the defocused grayscale image corresponding to the synthetic image and the grayscale value of each pixel on the grayscale image corresponding to the synthetic image to determine the second loss function.

[0062] Among them, Figure 6 As shown, after the image clarity detection model performs clarity detection on the composite image, a corresponding grayscale image will be generated to characterize the clarity of each area on the composite image. In addition, referring to the description of the above step S100, the clarity of each pixel on the image changes gradually. When generating a composite image, in order to make the synthetic out-of-focus area indication more closely match the clarity of each pixel on the image, a corresponding grayscale value is generated for each pixel on the composite image according to the actual out-of-focus area indication and the generation process of the composite image as a synthetic out-of-focus area indication for each pixel. Therefore, when verifying the grayscale image corresponding to the composite image, the grayscale value of each pixel on the grayscale image and the corresponding synthetic out-of-focus area indication can be compared to determine whether the clarity detection of the composite image is correct.

[0063] Specifically, first, a corresponding defocus grayscale map is generated according to the synthetic defocus area indication. For example, when the synthetic defocus area indication is a grayscale value, the synthetic defocus area indication can be directly used as the grayscale value corresponding to each pixel point on the defocus grayscale map to generate the defocus grayscale map. When the synthetic defocus area indication has only two indication marks of "clear" and "blurred", when analyzing the synthetic image, a defocus grayscale map is generated according to the positional relationship between the area on the synthetic image where the synthetic defocus area indication is "clear" and the area where the synthetic defocus area indication is "blurred".

[0064] Secondly, the second loss function is obtained by traversing each pixel on the grayscale image and the defocused grayscale image corresponding to the synthetic image and calculating the difference between the grayscale values ​​of the corresponding pixels. The second loss function can be mean square error loss, mean absolute error loss, smooth absolute error loss, Huber loss, etc. The corresponding loss function can be selected according to the specific requirements of the image clarity detection model, such as the sensitivity of the corresponding outliers, the smoothness of the model, and the stability of the optimization algorithm.

[0065] In the embodiment of the present application, as an example, the second loss function is the mean square error loss. If the size of the synthesized image is W×H, the second loss function L B As shown in the following formula:

[0066]

[0067] Among them, I S represents the composite image, B(I S ;θ B ) i,j Represents the grayscale value corresponding to the pixel (i, j) on the grayscale image corresponding to the synthetic image, y i,j Indicates the grayscale value corresponding to pixel (i, j) on the out-of-focus grayscale image, L aux is the scale-assisted loss, λ aux is a balance parameter. In the process of training the image clarity detection model, the second loss function L can be minimized B As the target, the parameter θ of the image clarity detection model B to update.

[0068] In addition, the auxiliary network can be set to obtain the scale auxiliary loss L aux Specifically, the auxiliary network can be composed of two convolutional layers, where the number of kernels in the first layer varies with the level. When the image clarity detection model adopts a U-Net-based convolutional network architecture and uses an upsampling layer in the decoder, the scale-assisted loss L aux It can be shown as the following formula:

[0069]

[0070] Among them, B ι (I S θ B ,θ aux )=(B ι (I S θ B );θ aux ) is the result obtained by the auxiliary network after calculating the grayscale image corresponding to the synthetic image, y ι is the synthetic defocus map, L in formula (3) Bis the number of upsampling layers in the image clarity detection model.

[0071] Step S180: extracting image features of the defocused grayscale image corresponding to the synthesized image to obtain a first feature map.

[0072] Step S190: extracting image features of the grayscale image corresponding to the synthesized image to obtain a second feature map.

[0073] Step S200: Determine a third loss function according to the first feature map and the second feature map.

[0074] Among them, when obtaining the first feature map and the second feature map, the feature extraction of the defocused grayscale image and the grayscale image corresponding to the synthetic image can be performed through algorithms such as principal component analysis, linear discriminant analysis, image edge detection, convolutional neural network, recursive neural network, and generative adversarial network. In an embodiment of the present application, as an example, a pre-trained VGG19 network is used to extract features of the defocused grayscale image and the grayscale image corresponding to the synthetic image, and the third loss function is obtained by calculating the first feature map and the second feature map.

[0075] The third loss function can be Euclidean distance, Manhattan distance, Chebyshev distance, cosine similarity, etc. In the embodiment of the present application, as an example, when the pre-trained VGG19 network is used to extract features to obtain the corresponding feature map, and then the third loss function is determined according to the feature map, if the size of the synthesized image is W×H, then the third loss function L C As shown below:

[0076]

[0077] in, is the second feature map, is the first feature map, W l ×H l is the size of the feature map at the largest layer, and l-th is the pooling layer number of the VGG19 network. In the process of training the image clarity detection model, the third loss function L can be minimized. C As the target, the parameter θ of the image clarity detection model B to update.

[0078] Step S210: training the image clarity detection model according to the first loss function, the second loss function and the third loss function.

[0079] Among them, by optimizing the first loss function L S , the second loss function L B And the third loss function L C Parameters θ of the image clarity detection model BWhen training the image definition detection model, the first loss function L can be used to update the image definition detection model. S , the second loss function L B And the third loss function L C To update the image clarity detection model, specifically, first according to the parameter θ corresponding to one of the loss functions B After updating the image clarity detection model, the next round of training begins until the loss function converges. In the next round of training, the parameter θ corresponding to another loss function is used. B To update the image clarity detection model, finally, in the first loss function L S , the second loss function L B And the third loss function L C When both converge, the training of the image clarity detection model is completed. The first loss function L S , the second loss function L B And the third loss function L C The three parameters θ corresponding to these three loss functions B The image clarity model is updated by integrating it into a matrix, and then the next round of training begins until the first loss function L C , the second loss function L B And the third loss function L C If all converge, the training of the image clarity detection model can be completed.

[0080] In addition, when training the image clarity detection model, the Adam optimizer can be used to optimize the model, the batch size in the training process can be set to 4, the initial learning rate can be set to 0.0001, and the exponential decay rate can be set to 0.8 every 20 epochs.

[0081] In the above embodiment, first, the clarity of each pixel on the image is detected to obtain a corresponding grayscale image to realize the clarity detection of the corresponding image. The clarity of each area of ​​the image can be detected separately, and then the overall clarity of the image can be determined only based on the clarity of the area of ​​focus on the image. When the image clarity model is integrated into the camera device, the camera device can focus only on the area of ​​focus during the focusing process, effectively avoiding the influence of other areas on the focus of the camera device.

[0082] Secondly, in view of the difference between the real out-of-focus area indication and the synthetic out-of-focus area indication, the image clarity detection model is trained by obtaining loss functions by adopting different verification methods for the grayscale images corresponding to the real images and the grayscale images corresponding to the synthetic images. Specifically, for real images with only two labels of "clear" and "blurred", the sharpness analysis is performed on the corresponding real images and their corresponding grayscale images, and the first loss function is determined according to the sharpness analysis results. For synthetic images marked with grayscale values, the second loss function and the third loss function are determined by calculating the difference in the grayscale values ​​of the corresponding pixels on the synthetic image and its corresponding grayscale image and the distance between the two images in the feature space. Such a verification method can not only verify the detection results of the image clarity detection model to different degrees according to the complexity of the out-of-focus area indication, and then update the model more specifically, effectively improving the accuracy of the trained image clarity detection model, but also can update the image clarity detection model from different angles in one round of training, effectively improving the training speed of the model.

[0083] Since real images are more complex than synthetic images, although the image clarity detection model can detect the clarity changes between pixels on the synthetic image in the initial stage and generate a grayscale image with a wide distribution of grayscale values, it is difficult to detect the clarity changes between pixels on the real image. As a result, the grayscale values ​​of each pixel on the grayscale image corresponding to the real image may be concentrated in a smaller range, which will affect the convergence speed of the first loss function and thus affect the training speed of the image clarity detection model.

[0084] Therefore, in order to further improve the training speed of the image definition detection model, in some embodiments of the present application, the training method further includes:

[0085] Step S121: performing adversarial training according to the grayscale values ​​of the grayscale image corresponding to the real image and the grayscale image corresponding to the synthetic image, so that the grayscale image corresponding to the real image and the grayscale image corresponding to the synthetic image have the same grayscale value range.

[0086] Among them, adversarial training is trained using Generative Adversarial Networks (GANs). GANs are a framework composed of two neural networks (including generators and discriminators). The two networks compete with each other through an adversarial process, and the ultimate goal is to enable the generator to generate data that is realistic enough to be mistaken for real data. The purpose of the generator is to capture the data distribution of the training data and generate a data sample similar to the training data. The purpose of the discriminator is to distinguish between real data and fake data generated by the generator.

[0087] In the embodiment of the present application, only the discriminator in the GAN network is used to identify whether the grayscale image generated by the image clarity detection model is the grayscale image corresponding to the real image or the grayscale image corresponding to the synthetic image, and the loss function is determined according to the accuracy of the judgment result. Finally, the image clarity detection model is optimized by the loss function, so that the grayscale value ranges on the two grayscale images generated by the image clarity detection model according to the real image and the synthetic image are more similar. In addition, in the process of adversarial training, the grayscale image corresponding to the synthetic image can be used as the original data sample, and the grayscale image corresponding to the real image can be used as the data sample generated by the generator, so that the trained image clarity detection model can also detect the clarity changes of each pixel on the real image, and then generate a grayscale image with a wider grayscale value distribution range.

[0088] When adversarial training is performed based on the grayscale values ​​of the grayscale image, the grayscale image corresponding to the real image and the grayscale image corresponding to the synthetic image can be identified based on the grayscale histogram of the grayscale image (that is, the number of pixels at each grayscale level in the grayscale image). The grayscale image corresponding to the real image and the grayscale image corresponding to the synthetic image can also be identified based on the grayscale value range of the grayscale image, that is, the grayscale value range in the grayscale image is ensured to be the same, without unifying the number of pixels at each grayscale level.

[0089] In the embodiment of the present application, as an example, the discriminator used in adversarial training can be a convolutional neural network with four convolutional layers, and each convolutional layer is followed by a batch normalization layer and a leaky rectified linear unit (ReLU) activation. Before using the convolutional neural network to discriminate the grayscale image corresponding to the synthetic image and the grayscale image corresponding to the real image, the convolutional neural network needs to be trained into a discriminator. During the training process, the loss L of the discriminator is used. D To update the convolutional neural network. Loss L D It can be shown as follows:

[0090] L D =(z-1)·log(1-D(B last (I; θ B ),θ D ))-z·log(D(B last (I; θ B ),θ D )) (5)

[0091] Where z is a label used to characterize whether the input image I is a real image or a synthetic image. For example, if the input image I is a real image, then z = 0; if the input image I is a synthetic image, then z = 1. last (I; θ B) is the feature image finally output by the image definition detection model, that is, the grayscale image corresponding to the real image or the grayscale image corresponding to the synthetic image. In this training process, the parameter θ of the image definition detection model B Keep it unchanged, only the parameters θ of the convolutional neural network are changed D to update.

[0092] In the above embodiment, adversarial training is performed on the grayscale values ​​of the grayscale image corresponding to the real image and the grayscale values ​​of the grayscale image corresponding to the synthetic image, and the image clarity detection model is continuously optimized, so that the image clarity detection model can also detect the clarity changes of each pixel on the real image, thereby improving the image clarity detection accuracy of the image clarity detection model and accelerating the training speed of the image clarity detection model in the initial stage, thereby effectively accelerating the entire training process of the image clarity detection model.

[0093] In order to further improve the accuracy of the image definition detection model, in some embodiments of the present application, steps S121a to S121d may be used to replace step S121 in the above embodiment, specifically including the following:

[0094] Step S121a: Determine the grayscale value range of the grayscale image corresponding to the real image according to the grayscale value of the grayscale image corresponding to the real image, and obtain a first grayscale value range.

[0095] Step S121b: determining the grayscale value range of the grayscale image corresponding to the synthesized image according to the grayscale value of the grayscale image corresponding to the synthesized image, and obtaining a second grayscale value range.

[0096] Step S121c: Identify the grayscale image corresponding to the real image and the grayscale image corresponding to the synthetic image according to the first grayscale value range and the second grayscale value range, and determine a fourth loss function.

[0097] Among them, by traversing the grayscale values ​​of each pixel on the grayscale image, the grayscale value range of the grayscale image is obtained. The grayscale value range can be directly formed by the minimum grayscale value and the maximum grayscale value on the grayscale image, or by the minimum value and the maximum value of continuous grayscale values ​​on the grayscale image. Specifically, all grayscale values ​​on the grayscale image can be sorted in ascending order, and a preset difference value is set. If the difference between two adjacent grayscale values ​​is greater than the preset difference value, it is considered that the two grayscale values ​​are not continuous values, otherwise, the two grayscale values ​​are considered to be continuous values.

[0098] When training the image clarity detection model, the training device 4 identifies the grayscale image corresponding to the real image and the grayscale image corresponding to the synthetic image according to the first grayscale value range and the second grayscale value range obtained, that is, it determines whether the grayscale value range is obtained from the grayscale image corresponding to the real image or the grayscale image corresponding to the synthetic image according to the first grayscale value range. Finally, the recognition result is verified, that is, it is determined whether the grayscale image recognized according to the grayscale value range is correct, and the fourth loss function is obtained from the verification result. The fourth loss function can be a cross entropy loss function, a square loss function, an exponential loss function, etc. In the embodiment of the present application, as an example, the fourth loss function L adv It can be shown as follows:

[0099] L adv = -log(D(B last (I; θ B ),θ D )) (6)

[0100] Step S121d: training the image clarity detection model according to the fourth loss function until the fourth loss function converges.

[0101] Among them, when training the image clarity detection model, the discriminator parameter θ D Fixed, only the parameters θ of the image clarity detection model B Update until the fourth loss function L adv Convergence, that is, the fourth loss function L adv As the model is trained, it tends to a fixed value.

[0102] In the above embodiment, the grayscale image corresponding to the real image and the grayscale image corresponding to the synthetic image are identified through the first grayscale value range and the second grayscale value range, and the fourth loss function is obtained to train the image clarity detection model, so that the grayscale image corresponding to the real image and the grayscale image corresponding to the synthetic image generated by the image clarity detection model have the same grayscale value range, effectively reducing the difference between the two and improving the accuracy of the image clarity detection model.

[0103] In an actual scene, if there are multiple objects in the scene, and the distances between each object and the camera device are different, when the camera device is used to capture images of the scene, the positions of the corresponding camera lenses are different when objects at different distances are in a clear state in the image. For example, when the camera device focuses according to a device at a closer distance, objects at a closer distance will be in a clear state on the image captured by the camera device, while objects at a farther distance may be in a blurred state; when the camera device focuses according to a device at a farther distance, objects at a farther distance will be in a clear state on the image captured by the camera device, while objects at a closer distance may be in a blurred state. Therefore, when detecting the clarity of an image, as long as the area in the image where the camera device focuses is clear, the image is a clear image.

[0104] In order to enable the trained image clarity detection model to better detect the clarity of the image, in some embodiments of the present application, the real image includes a static image area and / or a dynamic image area, and the synthetic image is an image generated based on the static image area and / or the dynamic image area, the static image area has a first weight, and the dynamic image area has a second weight.

[0105] For monitoring camera equipment, when the camera 1 is required to take a fixed shot of a certain area, if the area corresponding to the stationary object in the area in the image captured by the camera 1 is clear, it means that the camera 1 has completed the focus. At this time, no matter whether there is a blurred moving object in the image, as long as the camera 1 continues to shoot the area, there is no need to adjust the focus. When the camera 1 is required to follow and shoot a moving object in a certain area, as long as the moving object is blurred in the image, no matter whether other objects in the image are clear or blurred, the camera 1 needs to adjust the focus until the moving object is in a clear state in the image, and the camera 1 is considered to have completed the focus.

[0106] Therefore, different weights can be set for different areas on the image according to the shooting requirements of the camera device 1 (i.e., whether the camera device 1 is to perform fixed shooting of a certain area or to follow and shoot a moving object), so that the image clarity detection model can not only detect the clarity of the image, but also focus on key areas on the image.

[0107] In practical applications, the camera device 1 used for monitoring is focused either on a stationary object in the shooting area or on a moving object in the shooting area. Therefore, the area where the stationary object is located in the image can be used as a static image area (i.e., an area where the content remains substantially unchanged in a series of images shot or observed continuously), and the area where the moving object is located in the image can be used as a dynamic image area (i.e., an area where the content changes over time in a series of images shot or observed continuously), and different weights can be set for the static image area and the dynamic image area.

[0108] When the camera device 1 needs to take a fixed shot of a certain area, the first weight can be set higher than the second weight, so that the image clarity detection model focuses more on the static area in the image, and the second weight can even be set to the lowest weight, so that the image clarity detection model ignores the dynamic area in the image when detecting the clarity of the image. Similarly, when the camera device 1 needs to track and shoot a dynamic object, the first weight can be set lower than the second weight, so that the image clarity detection model focuses more on the dynamic area in the image.

[0109] Therefore, in order to improve the accuracy of the image definition detection model, the first weight and the second weight may be applied to the training method of the image definition detection model. Specifically, step S130a may be used instead of step S130, which specifically includes the following:

[0110] Step S130a: Perform sharpness analysis on the grayscale value of each pixel on the grayscale image corresponding to the real image according to the first weight and the second weight to obtain a first sharpness analysis result.

[0111] Among them, when obtaining the first sharpness analysis result, the sharpness analysis can be performed according to the first weight and the second weight. Specifically, when the first sharpness analysis result is a binary image, when comparing the grayscale value of each pixel with the pre-set grayscale threshold, the grayscale value of each pixel can be calculated with the weight corresponding to the pixel, and then the calculated value can be compared with the grayscale threshold, or the grayscale threshold can be calculated with the weight corresponding to each pixel, and then the grayscale value corresponding to the pixel can be compared with the calculated value. The operation between the weight and the grayscale value or grayscale threshold can adopt one or more calculation methods such as addition, subtraction, multiplication, division, logarithm, exponentiation, etc.

[0112] Therefore, in order to improve the accuracy of the image definition detection model, the first weight and the second weight may be applied to the training method of the image definition detection model. Specifically, step S170a may be used instead of step S170, which specifically includes the following:

[0113] Step S170a: Determine a second loss function by calculating the difference between the grayscale value of each pixel on the defocused grayscale image corresponding to the synthetic image and the grayscale value of each pixel on the grayscale image corresponding to the synthetic image according to the first weight and the second weight.

[0114] Specifically, when calculating the difference between gray values, the difference between the gray values ​​corresponding to each pixel point and the weight corresponding to the pixel point can be operated, and then the second loss function can be determined based on the value obtained by the operation. Alternatively, the gray value corresponding to each pixel point and the weight corresponding to the pixel point can be operated first, and then the difference between the gray values ​​can be determined based on the value obtained by the operation. Similarly, the operation between the weight and the difference or gray value can be performed by one or more of the calculation methods such as addition, subtraction, multiplication, division, logarithm, exponent, etc.

[0115] Therefore, in order to improve the accuracy of the image definition detection model, the first weight and the second weight may be applied to the training method of the image definition detection model. Specifically, step S200a may be used instead of step S200, which specifically includes the following:

[0116] Step S200a: Calculate the first feature map and the second feature map according to the first weight and the second weight to determine the third loss function

[0117] Specifically, the first weight and the second weight can be respectively calculated with the first feature map and the second feature map to obtain two new feature maps, and then the two new feature maps are calculated to determine the third loss function. Alternatively, the first weight or the second weight corresponding to each pixel point can be added to the calculation process during the calculation of the first feature map and the second feature map.

[0118] In the above embodiment, a first weight is set for a static image area on an image, a second weight is set for a dynamic image area on an image, and when performing sharpness analysis and determining a loss function, the first weight and the second weight are combined to determine the sharpness analysis result and the loss function. When the image clarity detection model is trained according to the loss function, the model's attention to important areas on the image is increased, and the attention to non-important areas on the image is reduced. This allows the trained image clarity detection model to be applied to a camera device, so that a more accurate judgment can be made as to whether the camera device has completed focusing.

[0119] In order to further improve the accuracy of the image definition detection model, in some embodiments of the present application, steps S131 to S132 may be used instead of step S130, which specifically include the following:

[0120] Step S131: traverse each pixel point on the grayscale image corresponding to the real image through a 1×1 convolution layer.

[0121] Step S132: Compare the grayscale value of each pixel with a preset sharpness threshold to determine a first sharpness analysis result.

[0122] In order to further improve the accuracy of the image definition detection model, in some embodiments of the present application, steps S141 to S142 may be used instead of step S140, which specifically include the following:

[0123] Step S141: traverse each pixel point on the real image through a 1×1 convolutional layer.

[0124] Step S142: Obtain the actual out-of-focus area indication corresponding to each pixel point, and determine the second sharpness analysis result.

[0125] Among them, after the real image and its corresponding grayscale image are input into the convolutional neural network, the data of each pixel in the image can be obtained through the 1×1 convolution kernel, which can effectively fuse the information between different channels of each pixel. Moreover, the 1×1 convolution kernel contains only one parameter, which can realize complex feature transformation with less calculation to determine the sharpness analysis result. In addition, the 1×1 convolution layer will only change the depth of the image (that is, the number of channels), and will not change the spatial size of the image. The spatial size of the first sharpness analysis result and the second sharpness analysis result determined by the 1×1 convolution layer is the same as the original spatial size of the real image, which can effectively ensure that the receptive domain of the verification process (the receptive domain refers to the area that a neuron or feature detector in the neural network can perceive from the input image. The size and shape of the receptive domain determine the amount of spatial information that the neuron can capture from the input data) is the same as the receptive domain of the image clarity detection model.

[0126] In the above embodiment, the first sharpness analysis result and the second sharpness analysis result are obtained through a 1×1 convolutional layer, which can keep the sizes of the receptive fields of the image clarity detection model and the clarity verification process the same, thereby avoiding the situation where the trained image clarity detection model generates a smudged grayscale image as the receptive field of the clarity verification process becomes larger, thereby effectively improving the accuracy of the image clarity detection model.

[0127] In order to further improve the accuracy of the image definition detection model, in some embodiments of the present application, steps S151 to S152 may be used instead of step S150, which specifically include the following:

[0128] Step S151: Compare the first sharpness analysis result corresponding to each pixel point on the grayscale image corresponding to the real image with the second sharpness analysis result corresponding to each pixel point on the real image.

[0129] Step S152: Determine a first loss function according to the comparison result.

[0130] Among them, the first sharpness analysis results corresponding to each pixel point on the grayscale image corresponding to the real image are verified one by one, and the first loss function is determined according to the verification results. Specifically, the pixel values ​​of the pixel point at the same position in the first sharpness analysis result and the second sharpness analysis result are compared. As long as the pixel values ​​of the pixel points at the same position are the same, it can be considered that the clarity detection result of the pixel point by the image clarity detection model is correct. Finally, the first loss function is determined according to the clarity detection results of each pixel point on the real image.

[0131] In the above embodiment, the first loss function is determined by comparing the first sharpness analysis result and the second sharpness analysis result of each pixel point, which can densely verify the pixel points on the grayscale image corresponding to the real image, effectively improve the accuracy of the verification result, and further improve the accuracy of the image clarity detection model.

[0132] In order to further improve the accuracy of the image definition detection model, in some embodiments of the present application, step S201 and step S202 may be used instead of step S200, specifically including the following:

[0133] Step S201: Calculate the variance of the first feature map and the second feature map to obtain variance data.

[0134] Step S202: Determine a third loss function according to the variance data.

[0135] Among them, the first feature map and the second feature map can be traversed, and the variance of the pixel values ​​of the same pixel point in the first feature map and the second feature map can be calculated, and finally the third loss function can be determined according to the obtained variance data.

[0136] In the above embodiment, the third loss function is determined by variance data, which can increase the influence of outliers in the first feature map and the second feature map on the third loss function, so that the image clarity detection model pays more attention to reducing abnormal predictions, effectively reducing artifacts in the grayscale image, and improving the accuracy of the image clarity detection model.

[0137] After the image clarity detection model is trained by the training method of the image clarity detection model proposed in the above embodiment, the trained image clarity detection model can be applied to the focusing method of the camera device proposed in the present application. Specifically, the focusing method of the camera device provided in the embodiment of the present application is as follows: Figure 5 As shown, Figure 5 FIG. 1 is a flowchart of a focusing method for an image pickup device provided in a first embodiment of the present application, and the method is applied to an image pickup device 1. In the embodiment of the present application, the focusing method for an image pickup device can be executed by a controller (eg, processor 13) in the image pickup device 1. Figure 5 As shown, the method comprises the following steps:

[0138] Step S300: Acquire the current image captured by the camera lens 11.

[0139] The current moment image refers to the image captured by the camera lens 11 at the current moment, which may be the image of the light in the scene projected onto the image sensor 15 through the camera lens 11, that is, the image displayed on the display screen of the camera device 1 or the electronic device 2 at the current moment. Since whether the camera device 1 is in focus directly affects the clarity of the image captured by the camera lens 11, it is possible to determine whether the camera device 1 is in focus by acquiring the current moment image.

[0140] Step S310: Detect the clarity of each pixel on the image at the current moment through the image clarity detection model, and generate a grayscale image corresponding to the image at the current moment according to the clarity of each pixel on the image at the current moment through the image clarity detection model, wherein the image clarity detection model is an image clarity detection model obtained after training through the steps in the above-mentioned image clarity detection model training method embodiment.

[0141] Among them, the image clarity detection model is used to detect the clarity of each pixel on the image, such as Figure 6 As shown, Figure 6 A comparison diagram of the original image and the grayscale image generated by the image clarity detection model provided in the embodiment of the present application is shown. The image clarity detection model Figure 6 The clarity of each pixel on the left side of the image is detected, and then the clarity of each pixel is mapped into a grayscale value to generate Figure 6 The image shown on the right.

[0142] by Figure 6 For example, the higher the clarity of the pixel on the image, the darker the color in the grayscale image, and the lower the corresponding grayscale value. Assuming that 0 to 100 represents the clarity, and the higher the data, the higher the clarity, then Figure 6 The pixel with a resolution of 100 in the image on the left is Figure 6 The corresponding grayscale value in the image on the right is 0; Figure 6 The pixel with a resolution of 0 in the image on the left is Figure 6 The corresponding grayscale value in the image on the right is 255; Figure 6 The pixel with a resolution of 80 in the image on the left is Figure 6The corresponding grayscale value in the image on the right is 51, and so on. Of course, when generating a grayscale image based on the clarity of the pixel points, the higher the clarity of the pixel points, the higher the grayscale value can be used to represent the pixel points in the grayscale image, that is, the darker the color of the pixel points in the grayscale image, the lower the clarity corresponding to the pixel points. For example, the grayscale value corresponding to the pixel point with a clarity of 20 is 51, the grayscale value corresponding to the pixel point with a clarity of 80 is 204, and so on.

[0143] The image clarity detection model can be directly integrated into the camera device 1, for example, stored in an internal storage medium such as a memory 12 or a hard disk provided inside the camera device 1, or stored in an external storage medium such as a USB flash drive, a CD, a mobile hard disk, etc. connected to the camera device 1. When the computer program 14 is running, the image clarity detection model can be directly called by calling the program through an interface, a function, etc.; it can also be stored in a server device such as a server or a cloud server that is connected to the camera device 1 through a network 3 and can store program models. When the computer program 14 is running, a call signal is sent to the server device through the network 3 to call the image clarity detection model.

[0144] Step S320: Analyze the grayscale value of the grayscale image corresponding to the image at the current moment to determine the clarity detection result corresponding to the image at the current moment.

[0145] When analyzing the grayscale value of the grayscale image, the average grayscale value of each pixel in the image can be calculated, and then a threshold is set, and the average grayscale value is compared with the threshold to determine the clarity of the image at the current moment. Figure 6 For example, assuming that the higher the clarity of the pixel in the grayscale image, the lower the corresponding grayscale value, the threshold can be set to 25. When the average value of the grayscale values ​​of each pixel in the grayscale image is less than 25, the clarity detection result of the image at the current moment is clear; when the average value of the grayscale values ​​of each pixel in the grayscale image is greater than 25, the clarity detection result of the image at the current moment is blurred. In addition, if the clarity requirement of the image is high, the threshold can be set to a smaller value; if the clarity requirement of the image is low, the threshold can be set to a larger value. Of course, if the corresponding relationship between clarity and grayscale value is that the higher the clarity, the larger the grayscale value, then when the clarity requirement of the image is high, the threshold can be set to a larger value; when the clarity requirement of the image is low, the threshold can be set to a smaller value.

[0146] In addition, a threshold can be set to convert the grayscale image into a binary image. By comparing the number of black pixels and the number of white pixels in the binary image, the clarity of the image at the current moment can be determined based on the ratio between the two. Figure 6For example, the threshold value can be set to 25, and the pixel values ​​of the pixels with grayscale values ​​less than 25 in the grayscale image are set to 0, and the pixel values ​​of the pixels with grayscale values ​​greater than 25 are set to 1; of course, the pixel values ​​of the pixels with grayscale values ​​less than 25 in the grayscale image can also be set to 1, and the pixel values ​​of the pixels with grayscale values ​​greater than 25 can be set to 0. The specific conversion can be set according to actual needs. Similarly, different thresholds can be set according to different clarity requirements, and different thresholds can be set according to different corresponding relationships between clarity and grayscale values. The specific setting method is similar to the above-mentioned threshold setting method for judging clarity based on the average value of grayscale values, and will not be repeated here.

[0147] The number of black pixels and the number of white pixels in the binary image are counted, and the ratio between the number of black pixels and the number of white pixels is obtained. If the black pixels in the binary image correspond to the clear pixels in the image at the current moment, the larger the ratio between the number of black pixels and the number of white pixels, the higher the clarity of the image at the current moment; if the black pixels in the binary image correspond to the blurred pixels in the image at the current moment, the larger the ratio between the number of black pixels and the number of white pixels, the lower the clarity of the image at the current moment. Therefore, the clarity of the image at the current moment can be determined by the ratio between the number of black pixels and the number of white pixels.

[0148] In addition, the clarity of the image at the current moment can be used as a clarity detection result, so that the controller of the camera device 1 can determine whether it is necessary to continue to adjust the camera lens 11 based on the clarity of the image at the current moment. A clarity threshold can also be set to compare the clarity of the image at the current moment with the clarity threshold to obtain a result of "clear image" or "blurred image", and use this result as a clarity detection result.

[0149] Step S330: adjusting the focus of the camera lens according to the clarity detection result.

[0150] Among them, the controller of the camera device 1 directly adjusts the focus of the camera lens 11 according to the clarity detection result of the image at the current moment. Specifically, assuming that the clarity detection result is "clear image" or "blurred image", when the clarity detection result is clear image, it means that the clarity of the image currently captured by the camera lens 11 has met the clarity requirement of the monitoring screen of the camera device 1, that is, the camera device 1 has completed focusing; when the clarity detection result is blurred image, it means that the clarity of the image currently captured by the camera lens 11 has not met the clarity requirement of the monitoring screen of the camera device 1, and the camera lens 11 of the camera device 1 needs to continue to be adjusted for focusing.

[0151] During the adjustment process of the camera lens 11, Figure 7 As shown, Figure 7 The current moment image captured by the camera lens provided by the embodiment of the present application is shown. Even if a high-speed moving object appears in the shooting area, only a small part of the pixels in the current moment image are affected by the high-speed moving object and become blurred, while most of the other pixels will not be affected by the high-speed moving object, and these pixels will become clearer with the adjustment of the camera lens 11. Therefore, even if there is a small part of the blurred area in the image, as long as the clarity of most of the other areas meets the clarity requirement of the camera device 1, the overall clarity of the current moment image can also meet the clarity requirement of the camera device 1, and then it can be judged that the camera device 1 has completed the focus, and there is no need to continue to adjust the camera lens 11.

[0152] If the clarity detection result is the specific clarity of the image at the current moment, a clarity threshold can be set to compare the clarity detection result with the clarity threshold. When the clarity detection result is greater than or equal to the clarity threshold, it means that the clarity of the image at the current moment has met the clarity requirements of the captured image of the camera device 1, that is, the camera device 1 has completed the focus; when the clarity detection result is less than the clarity threshold, it means that the clarity of the image at the current moment has not met the clarity requirements of the captured image of the camera device 1, and the camera lens 11 needs to be adjusted to focus.

[0153] Existing camera equipment usually uses contrast focusing method to focus, mainly judging the focus situation according to the contrast of the object in the image collected by the camera. Its key modules are image clarity evaluation method and automatic focus adjustment method. Image clarity evaluation method mainly detects the clarity of the image by detecting the change degree of gray value of image pixels and the high-frequency component of the image. When the image is clear, the gray value of the image pixel changes more obviously and the high-frequency component of the image is more. Specifically, the clarity of the image can be detected by gradient function, gray difference function and discrete cosine transform. The automatic focus adjustment method is the peak search strategy of the focus clarity curve, which mainly includes hill climbing search method and exhaustive search method. Specifically, the position of the lens is adjusted with a larger step size, and the lens position and image clarity corresponding to each step are collected. Finally, the image clarity corresponding to different lens positions is compared, and the next round of search area is determined according to the comparison result, and the step size is reduced for the next round of search. When the step size is reduced to a certain extent, the lens is adjusted to the position with the highest image clarity found in the latest round of search process, and the focus of the camera can be completed.

[0154] Specifically, when the mechanical energy autofocus is performed using the hill climbing search method or the exhaustive search method, it is assumed that the camera lens 11 adjusts the focus according to the stationary objects in the shooting area (for example, the area corresponding to the road, flowers, trees, buildings, etc. in the image). When a high-speed moving object appears in the area shot by the camera device 1, Figure 7 As shown, the high-speed moving object ( Figure 7 The position of vehicles and trains moving at medium and high speeds will be blurred, even if the position of stationary objects in the image ( Figure 7 If the image at the current moment is relatively clear, the overall clarity of the detected image will be relatively low, which will have a greater impact on the determination of the next round of search areas, and thus cause the camera lens 11 to be unable to adjust to the position where the image is clearest. For example, when using the hill climbing search method, when a high-speed moving object suddenly appears during the adjustment of the camera lens 11, the clarity of the image at the current moment captured by the camera lens 11 will decrease. If the clarity of the image at the current moment is lower than the clarity of the image at the previous moment, even if the camera lens 11 has not passed the position with the highest clarity, the controller of the camera device 1 will determine that it has passed the clarity peak and perform the next round of search, which will cause the camera lens 11 to be unable to adjust to the position corresponding to the best clarity.

[0155] In the above embodiment, while the camera device 1 adjusts the camera lens 11, an image clarity detection model is used to detect the clarity of each pixel in the image captured by the camera lens 11 at the current moment to generate a corresponding grayscale image, and then the overall clarity of the image at the current moment is determined by analyzing the grayscale value of the grayscale image. The result of the image clarity check is more accurate, so that the controller of the camera device 1 can directly determine whether the camera device 1 has completed the focus based on the clarity obtained by the detection, without having to complete the focus of the camera device 1 by comparing the clarity of the image captured by the camera lens 11 corresponding to different lens positions, thereby effectively avoiding the influence of factors such as high-speed moving objects or strong light sources on the focus adjustment of the camera device 1, and reducing the situation of rotating the motor and reducing the occurrence of the motor backlash phenomenon.

[0156] In order to further avoid the influence of factors such as high-speed moving objects or strong light sources on the focus adjustment of the camera device, in some embodiments of the present application, such as Figure 8 As shown, Figure 8 FIG. 1 shows a flowchart of a focusing method for an image pickup device provided by a second embodiment of the present application, wherein the second embodiment only uses steps S321 to S323 instead of Figure 5 Step S320 in the embodiment specifically includes the following steps:

[0157] Step S321: binarize the grayscale image corresponding to the image at the current moment to generate a binary image corresponding to the image at the current moment.

[0158] Among them, although the blurriness in the image presents a state of continuous change, that is, a gradual change from a blurry area to a clear area in the image, the human eye has only two results when judging the clarity of the image: "blurry" and "clear". Therefore, in order to make the controller of the camera device 1 more consistent with the process of judging the clarity of the image when judging the clarity of the image, a grayscale threshold can be set to binarize the grayscale image corresponding to the image at the current moment, and obtain a binary image corresponding to the image at the current moment.

[0159] Specifically, if the grayscale value of the pixel in the grayscale image corresponding to the current moment image is higher, the clarity of the pixel is higher, then the grayscale value corresponding to the current moment image is Figure 2 When converting the grayscale value, the larger the grayscale threshold, the higher the requirement of the camera device 1 for the clarity, and the smaller the grayscale threshold, the lower the requirement of the camera device 1 for the clarity; if the grayscale value of the pixel point in the grayscale image corresponding to the current moment is higher, the clarity of the pixel point is lower, then the grayscale value of the pixel point in the grayscale image corresponding to the current moment is converted to grayscale. Figure 2 When the grayscale threshold is set, the smaller the grayscale threshold is, the lower the definition requirement of the camera device 1 is, and the larger the grayscale threshold is, the higher the definition requirement of the camera device 1 is. Therefore, different grayscale thresholds can be set for the camera device 1 according to the definition requirement of the camera device 1 in actual applications.

[0160] The area where the black pixel in the binary image corresponding to the current moment image is located may correspond to the clear area in the current moment image. For example, if the grayscale value of the pixel in the grayscale image corresponding to the current moment image is higher, the clarity of the pixel is higher. Then, when the grayscale value of the pixel is greater than or equal to the grayscale threshold, the pixel value of the pixel corresponding to the pixel in the binary image is set to "0". When the grayscale value of the pixel is less than the grayscale threshold, the pixel value of the pixel corresponding to the pixel in the binary image is set to "1" or "255". If the grayscale value of the pixel in the grayscale image corresponding to the current moment image is higher, the clarity of the pixel is lower. Then, when the grayscale value of the pixel is less than or equal to the grayscale threshold, the pixel value of the pixel corresponding to the pixel in the binary image is set to "0". When the grayscale value of the pixel is greater than the grayscale threshold, the pixel value of the pixel corresponding to the pixel in the binary image is set to "1" or "255".

[0161] The area where the black pixel in the binary image corresponding to the current moment image is located can correspond to the blurred area in the current moment image. For example, if the grayscale value of the pixel in the grayscale image corresponding to the current moment image is higher, the clarity of the pixel is higher, then when the grayscale value of the pixel is greater than or equal to the grayscale threshold, the pixel value of the pixel corresponding to the pixel in the binary image is set to "1" or "255", and when the grayscale value of the pixel is less than the grayscale threshold, the pixel value of the pixel corresponding to the pixel in the binary image is set to "0"; if the grayscale value of the pixel in the grayscale image corresponding to the current moment image is higher, the clarity of the pixel is lower, then when the grayscale value of the pixel is less than or equal to the grayscale threshold, the pixel value of the pixel corresponding to the pixel in the binary image is set to "1" or "255", and when the grayscale value of the pixel is greater than the grayscale threshold, the pixel value of the pixel corresponding to the pixel in the binary image is set to "0".

[0162] Step S322: Calculate the ratio of the number of black pixels to the number of white pixels in the binary image corresponding to the image at the current moment, and determine the clarity of the image at the current moment.

[0163] Among them, the ratio between the number of black pixels and white pixels in the binary image is used to characterize the proportion of the clear area and the blurred area in the image at the current moment. The higher the proportion of the clear area in the image at the current moment, the higher the clarity of the image at the current moment. As an example, when the area where the black pixels in the binary image are located is the clear area of ​​the image at the current moment, the larger the ratio between the number of black pixels and white pixels, the more black pixels there are in the binary image, that is, the larger the proportion of the clear area in the image at the current moment, the higher the clarity of the image at the current moment. At this time, the ratio between the number of black pixels and white pixels can be directly used as the clarity of the image at the current moment.

[0164] When the area where the white pixels in the binary image are located is the clear area of ​​the image at the current moment, the smaller the ratio between the number of black pixels and white pixels, the more white pixels there are in the binary image, that is, the larger the clear area in the image at the current moment, the higher the clarity of the image at the current moment. At this time, the inverse of the ratio between the number of black pixels and white pixels can be used as the clarity of the image at the current moment.

[0165] Step S323: Compare the clarity of the image at the current moment with a preset clarity threshold to determine a clarity detection result.

[0166] Among them, Figure 7As shown, fast-moving objects and strong light will only cause a small part of the image at the current moment to become blurred, while most of the other areas are already in a clear state. For the camera device 1, especially the monitoring camera device, the focus has been completed at this time. Therefore, when the clear area on the image is relatively large, it can be considered that the camera device 1 has completed the focus, and it is not necessary for every pixel on the image to be in a clear state. At this time, a preset clarity threshold can be set to determine whether the image at the current moment is clear enough, and then determine whether the camera device 1 has completed the focus.

[0167] When the clarity detection result is "image is clear" or "image is blurred", if the clarity of the image at the current moment is less than the preset clarity threshold, the clarity detection result is "image is blurred", and if the clarity of the image at the current moment is greater than or equal to the preset clarity threshold, the clarity detection result is "image is clear". Of course, the size relationship between the clarity of the image at the current moment and the preset clarity threshold can also be used as the clarity detection result, that is, the clarity detection result can be that the clarity of the image at the current moment is less than the preset clarity threshold, or that the clarity of the image at the current moment is greater than or equal to the preset clarity threshold. The controller of the camera device 1 determines whether the camera lens 11 needs to be adjusted according to the size relationship between the clarity of the image at the current moment and the preset clarity threshold.

[0168] Similarly, the higher the preset clarity threshold, the clearer the image captured by the camera lens 11 after the camera lens 11 completes the focus adjustment. Therefore, different preset clarity thresholds can be set for the camera device 1 according to the clarity requirements of the camera device 1 in actual applications.

[0169] In the above embodiment, the grayscale image corresponding to the image at the current moment is binarized to obtain a binary image, the black area and the white area in the binary image are used to characterize the clear area and the blurred area in the image at the current moment, and the clarity of the image at the current moment is determined by calculating the ratio between the number of black pixels and the number of white pixels in the binary image, that is, the clarity of the image at the current moment is determined by the ratio between the clear area and the blurred area in the image at the current moment, so that when the focus of the camera device 1 is adjusted, even if there is a blurred area caused by factors such as fast-moving objects or strong light sources in the image at the current moment, the controller of the camera device 1 can determine that the focus of the camera device 1 has been completed when the proportion of the clear area in the image at the current moment is large, thereby effectively avoiding the influence of factors such as fast-moving objects or strong light sources on the focus adjustment of the camera device 1.

[0170] When the current image captured by the camera lens 11 is blurred, such as Fig. 9 As shown, Fig. 9The schematic diagram shows the position state of the lens during the focus adjustment process of the camera device 1 provided by the embodiment of the present application. The camera lens 11 can usually be adjusted in two directions ( Fig. 9 However, within the adjustable area of ​​the camera lens 11, there is only one optimal focus position of the camera lens 11, that is, among the two directions in which the camera lens 11 can be adjusted, only one direction can adjust the camera lens 11 to the optimal focus position. Fig. 9 As shown, assuming that triangle A is the current position of the camera lens 11, and triangle B is the best focus position of the camera lens 11 in the current state, the camera lens 11 can reach the best focus position only if it is adjusted along the direction indicated by the arrow D. If the camera lens 11 is adjusted along the direction indicated by the arrow C, the image captured by the camera lens 11 will only become more and more blurred.

[0171] Therefore, in the process of focusing the camera device 1, in order to ensure that the camera lens 11 is focused in the correct direction, in some embodiments of the present application, Fig.10 FIG. 1 is a flowchart of a focusing method for an image pickup device provided by a third embodiment of the present application, wherein the third embodiment only uses steps S331 to S335b instead of Figure 8 Step S330 in the embodiment specifically includes the following steps:

[0172] Step S331: Determine whether the clarity detection result shows that the clarity of the image at the current moment is less than a preset clarity threshold.

[0173] If yes, it means that the image captured by the camera lens 11 is still in a blurred state, and the position of the camera lens 11 needs to be further adjusted, and step 332 is executed;

[0174] If not, it means that the image captured by the camera lens 11 is clear, that is, the camera device 1 has completed focusing, and step S340 is executed.

[0175] Step S332: If the clarity detection result is that the clarity of the image at the current moment is less than the preset clarity threshold, the clarity of the image at the previous moment is obtained.

[0176] Among them, Fig. 9As shown, assuming that the position of triangle A is the current position of camera lens 11, and the position of triangle B is the best focus position of camera lens 11, when the controller of camera device 1 detects that the image captured by camera lens 11 at the current moment is a blurred image, since the controller of camera device 1 cannot determine on which side of the current position the best focus position of camera lens 11 is located, that is, the controller of camera device 1 cannot determine which direction of the two directions indicated by arrow C and arrow D to move in order to adjust to the best focus position, camera lens 11 will be controlled to move randomly in the direction indicated by arrow C or the direction indicated by arrow D.

[0177] If the camera lens 11 moves in the direction indicated by the arrow D, its position will be closer and closer to the position of the triangle B, and the clarity of the image captured by the camera lens 11 will be higher and higher. If the camera lens 11 moves in the direction indicated by the arrow C, its position will be farther and farther away from the position of the triangle B, and the clarity of the image captured by the camera lens 11 will be lower and lower. Therefore, when adjusting the position of the camera lens 11, it is possible to determine whether the adjustment direction of the camera lens 11 is correct by judging whether the clarity of the current image captured by the camera lens 11 is higher than the clarity of the image at the previous moment, and then find the correct adjustment direction of the camera lens 11.

[0178] Step S333: Determine whether the definition at the previous moment is obtained.

[0179] If yes, it means that the position of the camera lens 11 has changed. The clarity of the image at the last moment can be combined to determine whether the current adjustment direction of the camera lens 11 is correct, and step S334 is executed;

[0180] If not, it means that the camera lens 11 is adjusted for the first time, and the camera lens 11 may be adjusted randomly in one direction, or step S336 may be executed.

[0181] Step S334: Determine whether the clarity of the image at the current moment is greater than the clarity of the image at the previous moment.

[0182] If yes, it means that the image captured by the camera lens 11 becomes clearer after adjustment, and the current adjustment direction of the camera lens 11 is correct. The camera lens 11 can continue to be adjusted in the same direction, and step S335a is executed;

[0183] If not, it means that the image captured after the camera lens 11 is adjusted becomes more blurred, and the current adjustment direction of the camera lens 11 is wrong. The adjustment direction of the camera lens 11 needs to be changed, and step S335b is executed.

[0184] Step S335a: If the clarity of the current image is greater than that of the previous image, continue to adjust the focus of the camera lens in the same direction as the previous moment until the clarity detection result shows that the clarity of the current image is greater than or equal to the preset clarity threshold.

[0185] Step S335b: If the clarity of the current image is less than or equal to the clarity of the previous image, continue to adjust the focus of the camera lens in the opposite direction of the previous moment until the clarity detection result shows that the clarity of the current image is greater than or equal to the preset clarity threshold.

[0186] Among them, Fig. 9 As shown, assuming that the position shown by triangle B is the best focus position of the camera lens 11, and the camera lens 11 at the previous moment is located at the position of triangle A, if the image at the current moment is an image obtained after the camera lens 11 moves in the direction shown by arrow D, then the camera lens 11 at the current moment is closer to the best focus position of the camera lens 11 than the camera lens 11 at the previous moment, that is, the camera lens 11 at the current moment is closer to the position of triangle B than the camera lens 11 at the previous moment. Therefore, the clarity of the image at the current moment will be greater than the clarity of the image at the previous moment, that is, the adjustment direction of the camera lens 11 is correct, and the camera lens 11 can continue to be adjusted in the same direction.

[0187] If the image at the current moment is an image acquired after the camera lens 11 moves in the direction indicated by the arrow C, the camera lens 11 at the current moment is farther away from the best focusing position of the camera lens 11 than the camera lens 11 at the previous moment, that is, the camera lens 11 at the current moment is farther away from the position of the triangle B than the camera lens 11 at the previous moment. Therefore, the clarity of the image at the current moment will be less than the clarity of the image at the previous moment, that is, the adjustment direction of the camera lens 11 is misplaced, and the current adjustment direction of the camera lens 11 needs to be changed, that is, the camera lens needs to continue to be adjusted in the opposite direction.

[0188] Step S340: The camera device completes focusing.

[0189] In the above embodiment, during the process of focusing adjustment of the camera lens 11, when the image captured by the camera lens 11 is a blurred image, the clarity of the image at the current moment is compared with the clarity of the image at the previous moment to determine whether the current focus adjustment direction of the camera lens 11 is correct. In this way, when the focus adjustment direction of the camera lens 11 is misplaced, the focus adjustment direction can be changed in time, without waiting until the camera lens 11 can no longer be adjusted to find that the focus adjustment direction is wrong and it is necessary to turn around and continue to adjust the position of the camera lens 11. The focusing speed of the camera lens 11 is faster.

[0190] In order to further improve the focusing adjustment rate of the camera equipment, such as Fig.10 As shown, the method also includes:

[0191] Step S336: If the definition of the image at the previous moment is not obtained, the current position of the camera lens 11 and the maximum adjustment stroke of the camera lens 11 are obtained.

[0192] Step S337 : determining the focus adjustment direction according to the current position of the camera lens 11 and the maximum adjustment stroke of the camera lens 11 .

[0193] Among them, Fig. 9 As shown, assuming that the camera lens 11 is at the position shown by triangle A, the maximum adjustment stroke of the camera lens 11 is 300, when the clarity of the current image captured by the camera lens 11 is less than the preset clarity threshold, the probability that the best focus position of the camera lens 11 is at each position between 0-300 on the X-axis is the same. However, because the distance between the current position of the camera lens 11 (i.e., the position where triangle A is located) and the position corresponding to 300 is greater than the distance between the position where triangle A is located and the position corresponding to 0, the best focus position of the camera lens 11 is more likely to be between triangle A and 300 on the X-axis than between 0 and triangle A on the X-axis.

[0194] Therefore, when the controller of the camera device 1 cannot determine the focus adjustment direction of the camera lens 11 according to the clarity of the image at the current moment and the clarity of the image at the previous moment, the adjustment direction can be determined according to the current position of the camera lens 11 and the maximum adjustment stroke of the camera lens 11. Specifically, the camera lens 11 can be adjusted in the direction of a larger adjustable stroke of the camera lens 11. For example, if the current position of the camera lens 11 is relatively close to the starting position of the camera lens 11, the camera lens 11 is adjusted in the direction away from the starting position of the camera lens 11. If the current position of the camera lens 11 is relatively far from the starting position of the camera lens 11, the camera lens 11 is adjusted in the direction close to the starting position of the camera lens 11.

[0195] As an example, Fig. 9 As shown, when the maximum adjustment stroke of the camera lens 11 is 300, if the current position of the camera lens 11 is the position of triangle A, then when the clarity of the image at the previous moment is not obtained, the camera lens 11 is adjusted along the direction indicated by the arrow D; if the current position of the camera lens 11 is the position of triangle B, then when the clarity of the image at the previous moment is not obtained, the camera lens 11 is adjusted along the direction indicated by the arrow C.

[0196] In the above embodiment, when the clarity of the image at the previous moment is not obtained, the adjustment direction of the camera lens 11 is determined by the current position and the maximum adjustment stroke of the camera lens 11, rather than directly and randomly determining the adjustment direction. This allows the camera lens 11 to be adjusted toward the optimal focus position with a greater probability, thereby reducing the need to change the adjustment direction due to an incorrect focus adjustment direction, thereby improving the focusing speed of the camera device 1.

[0197] In addition, if the image clarity of the current moment is lower than the preset clarity threshold due to the user adjusting the magnification of the camera lens 11 through the electronic device 2, the focus adjustment direction of the camera lens 11 can be determined according to the change in magnification. In this way, the focus adjustment direction of the camera lens 11 can be directly determined by the information sent by the electronic device 2, without having to determine the focus adjustment direction of the camera lens 11 through the clarity of the image at the previous moment, the current position of the camera lens 11, the maximum adjustment stroke of the camera lens 11, and other information, and the speed of focusing adjustment of the camera device is faster.

[0198] As an example, Fig. 9 As shown, assuming that the position shown by triangle A is the current position of the camera lens 11, if the camera lens 11 is further away from the position 0 on the X-axis, the smaller the magnification of the camera lens 11 is, then when the user manually zooms in on the image captured by the camera lens 11 on the electronic device 2, the electronic device 2 will send information to increase the magnification of the camera lens 11 to the controller of the camera device 1, so that the controller of the camera device 1 adjusts the camera lens 11 in the direction indicated by the arrow C; when the user manually zooms out on the image captured by the camera lens 11 on the electronic device 2, the electronic device 2 will send information to reduce the magnification of the camera lens 11 to the controller of the camera device 1, so that the controller of the camera device 1 adjusts the camera lens 11 in the direction indicated by the arrow D.

[0199] An embodiment of the present application provides a computer-readable storage medium, which stores a computer program. When the computer program is executed by a processor, it implements the training method of the above-mentioned image clarity detection model or the focusing method embodiment of the camera device.

[0200] An embodiment of the present application provides a computer program, which can be executed by a processor to implement the above-mentioned training method of the image clarity detection model or the focusing method embodiment of the camera device.

[0201] An embodiment of the present application provides a computer program product, which includes a computer program. When the computer program is executed by a processor, it implements the training method of the above-mentioned image clarity detection model or the focusing method embodiment of the camera device.

[0202] In several embodiments provided in the present application, if any function is implemented in the form of a software function module / unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, part or all of the technical solution of the present application can be embodied in the form of a software product, and the computer software product is stored in a storage medium, including a number of instructions for a computer device (which can be a personal computer, server or other electronic device) to perform all or part of the steps of the method described in each embodiment of the present application. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (Read-Only Memory, ROM), random access memory (RandomAccess Memory, RAM), disk or optical disk and other media that can store computer program code.

[0203] The algorithm or display provided here are not inherently related to any specific computer, virtual system or other equipment. Various general systems can also be used together with the teaching based on this. According to the above description, it is obvious to construct the structure required for this type of system. In addition, the present application embodiment is not directed to any specific programming language yet. It should be understood that various programming languages ​​can be utilized to realize the content of the present application described here, and the above description of specific languages ​​is to disclose the best mode of implementation of the present application.

[0204] It should be noted that the above embodiments illustrate the present application rather than limit the present application, and that those skilled in the art may design alternative embodiments without departing from the scope of the appended claims. In the claims, any reference symbol between brackets shall not be constructed as a limitation on the claims. The word "comprising" does not exclude the presence of elements or steps not listed in the claims. The word "one" or "an" preceding an element does not exclude the presence of multiple such elements. The present application may be implemented by means of hardware including several different elements and by means of a suitably programmed computer. In the claims that list several devices, several units or modules in these devices may be embodied by the same hardware item. The use of the words first, second, and third, etc. does not indicate any order. These words may be interpreted as names. The steps in the above embodiments, unless otherwise specified, should not be understood as limitations on the order of execution.

[0205] The above-described embodiments only express several implementation methods of the present application, and the descriptions thereof are relatively specific and detailed, but they cannot be understood as limiting the scope of the present application. It should be pointed out that, for a person of ordinary skill in the art, several variations and improvements can be made without departing from the concept of the present application, and these all belong to the protection scope of the present application. Therefore, the protection scope of the present application shall be subject to the attached claims.

Claims

1. A training method for an image clarity detection model, characterized in that: The method comprises: Acquire a first data set and a second data set, wherein the first data set includes at least one real image, and the second data set includes at least one synthetic image; Detecting the clarity of each pixel on the real image, and generating a grayscale image corresponding to the real image according to the clarity of each pixel on the real image; Detecting the clarity of each pixel on the composite image, and generating a grayscale image corresponding to the composite image according to the clarity of each pixel on the composite image; Performing sharpness analysis on the grayscale value of each pixel point on the grayscale image corresponding to the real image to obtain a first sharpness analysis result; Performing sharpness analysis on each pixel on the real image according to the real out-of-focus area indication of the real image to obtain a second sharpness analysis result; Determine a first loss function according to the first sharpness analysis result and the second sharpness analysis result; Analyze the synthetic image according to a synthetic out-of-focus area indication of the synthetic image to generate an out-of-focus grayscale image corresponding to the synthetic image, wherein the synthetic out-of-focus area indication is generated according to the real out-of-focus area indication; Calculating the difference between the grayscale value of each pixel point on the defocused grayscale image corresponding to the synthetic image and the grayscale value of each pixel point on the grayscale image corresponding to the synthetic image to determine a second loss function; Extracting image features of the out-of-focus grayscale image corresponding to the composite image to obtain a first feature map; Extracting image features of the grayscale image corresponding to the composite image to obtain a second feature map; Determine a third loss function according to the first feature map and the second feature map; The image clarity detection model is trained according to the first loss function, the second loss function and the third loss function.

2. The training method of the image definition detection model according to claim 1, characterized in that: The training method also includes: Adversarial training is performed based on the grayscale values ​​of the grayscale image corresponding to the real image and the grayscale image corresponding to the synthetic image, so that the grayscale image corresponding to the real image and the grayscale image corresponding to the synthetic image have the same grayscale value range.

3. The training method of the image definition detection model according to claim 2, characterized in that: The adversarial training is performed according to the grayscale value of the grayscale image corresponding to the real image and the grayscale value of the grayscale image corresponding to the synthetic image, specifically comprising: Determine the grayscale value range of the grayscale image corresponding to the real image according to the grayscale value of the grayscale image corresponding to the real image, and obtain a first grayscale value range; Determine the grayscale value range of the grayscale image corresponding to the synthetic image according to the grayscale value of the grayscale image corresponding to the synthetic image, to obtain a second grayscale value range; Identify a grayscale image corresponding to the real image and a grayscale image corresponding to the synthetic image according to the first grayscale value range and the second grayscale value range, and determine a fourth loss function; The image clarity detection model is trained according to the fourth loss function until the fourth loss function converges.

4. The training method of the image definition detection model according to claim 1, characterized in that: The real image includes a static image area and / or a dynamic image area; the synthetic image is an image generated according to the static image area and / or the dynamic image area; The static image area has a first weight, and the dynamic image area has a second weight.

5. The training method of the image definition detection model according to claim 4, characterized in that: The first sharpness analysis result is obtained by performing sharpness analysis on the grayscale value of each pixel point on the grayscale image corresponding to the real image according to the first weight and the second weight; The second loss function is determined by calculating the difference between the grayscale value of each pixel point on the defocused grayscale image corresponding to the synthetic image and the grayscale value of each pixel point on the grayscale image corresponding to the synthetic image according to the first weight and the second weight; The third loss function is determined by calculating the first feature map and the second feature map according to the first weight and the second weight.

6. The training method of the image definition detection model according to claim 1, characterized in that: The step of performing sharpness analysis on the grayscale value of each pixel point on the grayscale image corresponding to the real image to obtain a first sharpness analysis result includes: Traversing each pixel point on the grayscale image corresponding to the real image through a 1×1 convolutional layer; Compare the grayscale value of each pixel with a preset sharpness threshold to determine a first sharpness analysis result; The performing sharpness analysis on each pixel on the real image according to the real out-of-focus area indication to obtain a second sharpness analysis result includes: Traversing each pixel point on the real image through a 1×1 convolutional layer; The actual out-of-focus area indication corresponding to each pixel point is obtained to determine the second sharpness analysis result.

7. The training method of the image definition detection model according to claim 6, characterized in that: The determining a first loss function according to the first sharpness analysis result and the second sharpness analysis result includes: Compare the first sharpness analysis result of each pixel point on the grayscale image corresponding to the real image with the second sharpness analysis result of each pixel point corresponding to the real image; The first loss function is determined according to the comparison result.

8. The method for training an image definition detection model according to claim 1, characterized in that: The determining a third loss function according to the first feature map and the second feature map includes: Performing variance calculation on the first characteristic graph and the second characteristic graph to obtain variance data; The third loss function is determined according to the variance data.

9. A focusing method for a camera device, characterized in that: The method comprises: Get the current image captured by the camera lens; Detecting the clarity of each pixel on the image at the current moment by using an image clarity detection model, and generating a grayscale image corresponding to the image at the current moment according to the clarity of each pixel on the image at the current moment by using the image clarity detection model; Analyze the grayscale value of the grayscale image corresponding to the image at the current moment to determine the clarity detection result corresponding to the image at the current moment; Adjusting the focus of the camera lens according to the clarity detection result; The image definition detection model is an image definition detection model obtained by training using the image definition detection model training method according to any one of claims 1 to 8.

10. The focusing method of the camera device according to claim 9, characterized in that: The step of analyzing the grayscale value of the grayscale image corresponding to the image at the current moment to determine the definition detection result corresponding to the image at the current moment includes: Binarize the grayscale image corresponding to the image at the current moment to generate a binary image corresponding to the image at the current moment; Calculate the ratio of the number of black pixels to the number of white pixels in the binary image corresponding to the image at the current moment, and determine the clarity of the image at the current moment; The clarity of the image at the current moment is compared with a preset clarity threshold to determine the clarity detection result.

11. The focusing method of the camera device according to claim 10, characterized in that: The step of adjusting the focus of the camera lens according to the clarity detection result includes: If the clarity detection result is that the clarity of the image at the current moment is less than the preset clarity threshold, obtaining the clarity of the image at the previous moment; If the clarity of the image at the current moment is greater than the clarity of the image at the previous moment, continue to adjust the focus of the camera lens in the same direction as the previous moment until the clarity detection result shows that the clarity of the image at the current moment is greater than or equal to the preset clarity threshold; If the clarity of the image at the current moment is less than or equal to the clarity of the image at the previous moment, continue to adjust the focus of the camera lens in the opposite direction of the previous moment until the clarity detection result shows that the clarity of the image at the current moment is greater than or equal to the preset clarity threshold.

12. The focusing method of the camera device according to claim 11, characterized in that: The focusing method also includes: If the definition of the image at the previous moment is not obtained, then obtaining the current position of the camera lens and the maximum adjustment stroke of the camera lens; The focus adjustment direction is determined according to the current position of the camera lens and the maximum adjustment stroke of the camera lens.

13. A training device comprising a memory, a processor and a computer program stored in the memory, characterized in that: The processor executes the computer program to implement the training method of the image clarity detection model described in any one of claims 1 to 8.

14. A camera device, characterized in that: The camera device includes a camera lens, a memory and a processor; The camera lens is used to collect images; The memory is used to store computer programs; The processor executes the computer program to implement the focusing method of the imaging device according to any one of claims 9 to 12.

15. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, it implements the training method of the image clarity detection model described in any one of claims 1 to 8, or, when the computer program is executed by a processor, it implements the focusing method of the camera device described in any one of claims 9 to 12.