Automatic focusing method, device and equipment for on-line inspection camera and medium

By applying bilateral filters and Laplace operator algorithms in the online patrol camera, combined with preset optimization methods, the problem of poor autofocus effect in environments with low light intensity and high noise is solved, and a more efficient and accurate autofocus effect is achieved.

CN119946427AActive Publication Date: 2025-05-06SINOCHEM INFORMATION TECH CO LTD
View PDF 5 Cites 0 Cited by

Patent Information

Application Number
CN202510116125.9
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-01-24
Publication Date
2025-05-06
Estimated Expiration
2045-01-24

AI Technical Summary

Technical Problem

In environments with low light intensity and high noise, the existing autofocus method is not effective, resulting in inefficient acquisition of high-definition pictures.

Method used

An online patrol camera automatic focus method is adopted. By acquiring the image to be processed and applying a bilateral filter for denoising, the image clarity is calculated using the Laplace operator algorithm, and the target focal length is determined within the preset focal length range in combination with the preset optimization method to complete the auto focus.

Benefits of technology

In low light intensity and high noise environments, the accuracy and efficiency of autofocus are improved, ensuring that without doing too much useless search, the trapping of local maximums is avoided and better performance is achieved.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119946427A_ABST
    Figure CN119946427A_ABST
Patent Text Reader

Abstract

The invention relates to the technical field of camera focusing, and provides an automatic focusing method, device and equipment for an online inspection camera, and a medium. The method comprises the following steps: acquiring a to-be-processed image according to a target camera; according to the bilateral filter, obtaining a target intensity value of each pixel point of the to-be-processed image to obtain a de-noised image; obtaining the definition of the de-noised image according to a Laplace operator algorithm; and according to the initial focal length corresponding to the to-be-processed image, the definition of the de-noised image and a preset optimization method, determining a target focal length corresponding to the target camera in a preset focal length range, and completing automatic focusing. According to the method and the device, the situation of falling into a local maximum value is avoided as much as possible while excessive useless search is not performed.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present disclosure relates to the field of camera focusing technology, and in particular to an automatic focusing method, device, equipment and medium for an online inspection camera. Background Art

[0002] Video surveillance systems are an indispensable part of smart factories. A properly configured video surveillance system can greatly enhance the information management capabilities at work and improve the controllability of the production process, playing an important role in tasks such as online inspections and monitoring of unconventional operations. In recent years, with the development of video AI technology, the ease of use and versatility of video surveillance systems have made a qualitative leap. However, in actual use, whether it is manual online inspections or detection of violations through AI, the clarity of the video is the primary condition. When taking photos with an optical camera, the correct focal length directly affects the clarity of the photo. Therefore, even today when photography and computer vision technologies are highly developed and equipment can be highly automated through the Internet of Things, autofocus still plays a vital role in many places. Due to the high immediacy and high risk of working in smart factories, the autofocus methods used in these devices need to be able to focus quickly and independently to efficiently obtain high-definition images. Today, many types of autofocus methods have been put into use in various industries, and their principles are mostly based on quantifying the clarity in some way and finding the focal length that maximizes the clarity through some optimization algorithm. Commonly used clarity quantification methods include Sobel operator, Laplace operator, Tenengrad function, etc., but most of these methods are suitable for environments with good lighting and less image noise. In smart factories, environments with low light intensity and high noise (such as inside a boiler room) often occur, and the performance of these methods will be more or less affected. Summary of the invention

[0003] In view of this, the embodiments of the present disclosure provide an online inspection camera auto-focus method, device, equipment and medium to solve the problem in the prior art that the auto-focus effect is poor in an environment with low light intensity and high noise.

[0004] According to a first aspect of an embodiment of the present disclosure, there is provided an automatic focusing method for an online inspection camera, comprising: obtaining an image to be processed according to a target camera; wherein the image to be processed includes a plurality of pixels; each pixel has a corresponding initial intensity value; the focal length corresponding to the target camera when obtaining the image to be processed is the initial focal length; the initial focal length is any focal length within a preset focal length range; according to a bilateral filter, obtaining a target intensity value for each pixel of the image to be processed to obtain a denoised image; wherein the target intensity value is determined by the distance and intensity value difference between each pixel and each pixel adjacent to the pixel; the bilateral filter has a corresponding weight function; the weight function is used to determine the weight of the distance between the corresponding pixel and each pixel adjacent to the pixel when obtaining the target intensity value, and to determine the weight of the distance between the corresponding pixel and each pixel adjacent to the pixel. The weight of the intensity value difference between the corresponding pixel point and each pixel point adjacent to the pixel point is determined; the weight of the intensity value difference between each pixel point and each pixel point adjacent to the pixel point is related to the initial intensity value of the pixel point; according to the Laplace operator algorithm, the clarity of the denoised image is obtained; wherein the above-mentioned clarity is described according to the Laplace variance of the denoised image; according to the initial focal length corresponding to the image to be processed, the clarity of the denoised image and the preset optimization method, the target focal length corresponding to the target camera is determined within the preset focal length range to complete automatic focusing; wherein the Laplace variance of the denoised image corresponding to the above-mentioned target focal length is greater than the Laplace variance of the denoised image corresponding to each focal length within the preset focal length range except the target focal length, and the Laplace variance of the denoised image corresponding to the target focal length is greater than the preset Laplace variance threshold.

[0005] According to a second aspect of the embodiments of the present disclosure, an automatic focusing device for an online inspection camera is provided, comprising: an image acquisition unit, configured to acquire an image to be processed according to a target camera; wherein the image to be processed includes a plurality of pixels; each pixel has a corresponding initial intensity value; the focal length corresponding to the target camera when acquiring the image to be processed is the initial focal length; the initial focal length is any focal length within a preset focal length range; a denoising unit, configured to acquire a target intensity value for each pixel of the image to be processed according to a bilateral filter to obtain a denoised image; wherein the target intensity value is determined by the distance and intensity value difference between each pixel and each pixel adjacent to the pixel; the bilateral filter has a corresponding weight function; the weight function is used to determine the weight of the distance between the corresponding pixel and each pixel adjacent to the pixel when acquiring the target intensity value, and to determine the corresponding The weight of the intensity value difference between a pixel point and each pixel point adjacent to the pixel point; the weight of the intensity value difference between each pixel point and each pixel point adjacent to the pixel point is related to the initial intensity value of the pixel point; a clarity acquisition unit is configured to obtain the clarity of the denoised image according to the Laplace operator algorithm; wherein the above-mentioned clarity is described according to the Laplace variance of the denoised image; a target focal length determination unit is configured to determine the target focal length corresponding to the target camera within the preset focal length range according to the initial focal length corresponding to the image to be processed, the clarity of the denoised image and the preset optimization method, and complete automatic focusing; wherein the Laplace variance of the denoised image corresponding to the above-mentioned target focal length is greater than the Laplace variance of the denoised image corresponding to each focal length within the preset focal length range except the target focal length, and the Laplace variance of the denoised image corresponding to the target focal length is greater than the preset Laplace variance threshold.

[0006] According to a third aspect of an embodiment of the present disclosure, a computer device is provided, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the steps of the above method when executing the computer program.

[0007] According to a fourth aspect of the embodiments of the present disclosure, a computer-readable storage medium is provided, which stores a computer program, and when the computer program is executed by a processor, the steps of the above method are implemented.

[0008] Compared with the prior art, the embodiments of the present disclosure have the following beneficial effects: first, the weight of the intensity value difference between each pixel point and each pixel point adjacent to the pixel point in the present disclosure is related to the initial intensity value of the pixel point; so that the weight of the intensity value difference is associated with the initial intensity value of the pixel point, so that the distribution is more concentrated when the pixel intensity is low, and it is ensured that too many edges will not be accidentally filtered out under low light intensity conditions. The filter with such a structure is more suitable for occasions where the light intensity is unstable, and can have better performance than the traditional bilateral filter under low light intensity. Secondly, since clarity is used as a parameter to measure the focusing result, the Laplace variance is used in the present application to describe the image clarity; if there are many and clear edges in an image, the Laplace variance of the image will be relatively large, that is, the image will have a higher clarity, otherwise it will be a lower clarity, so that the clarity is quantified. Finally, according to the size of the Laplace variance and the preset Laplace variance threshold, the target focal length is determined within the focal length range of the color number. While ensuring that too much useless search is not performed, the present disclosure avoids the situation of falling into the local maximum as much as possible. BRIEF DESCRIPTION OF THE DRAWINGS

[0009] In order to more clearly illustrate the technical solutions in the embodiments of the present disclosure, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present disclosure. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.

[0010] Figure 1 is a schematic diagram of an application scenario of an online inspection camera auto-focus method according to some embodiments of the present disclosure;

[0011] Figure 2 is a flow chart of some embodiments of the online inspection camera auto-focus method according to the present disclosure;

[0012] Figure 3 is a flow chart of an embodiment of determining a target focal length of an online inspection camera auto-focus method according to the present disclosure;

[0013] Figure 4 is a flow chart of other embodiments of the online inspection camera auto-focus method according to the present disclosure;

[0014] Figure 5 It is a structural schematic diagram of some embodiments of the automatic focusing device of the online inspection camera according to the present disclosure;

[0015] Figure 6 It is a schematic diagram of the structure of an electronic device suitable for implementing some embodiments of the present disclosure. DETAILED DESCRIPTION

[0016] Embodiments of the present disclosure will be described in more detail below with reference to the accompanying drawings. Although certain embodiments of the present disclosure are shown in the accompanying drawings, it should be understood that the present disclosure can be implemented in various forms and should not be construed as being limited to the embodiments set forth herein. On the contrary, these embodiments are provided to provide a more thorough and complete understanding of the present disclosure. It should be understood that the drawings and embodiments of the present disclosure are only for exemplary purposes and are not intended to limit the scope of protection of the present disclosure.

[0017] It should also be noted that, for ease of description, only the parts related to the invention are shown in the drawings. In the absence of conflict, the embodiments and features in the embodiments of the present disclosure can be combined with each other.

[0018] It should be noted that the concepts such as "first" and "second" mentioned in the present disclosure are only used to distinguish different devices, modules or units, and are not used to limit the order or interdependence of the functions performed by these devices, modules or units.

[0019] It should be noted that the modifications of "one" and "plurality" mentioned in the present disclosure are illustrative rather than restrictive, and those skilled in the art should understand that unless otherwise clearly indicated in the context, it should be understood as "one or more".

[0020] The names of the messages or information exchanged between multiple devices in the embodiments of the present disclosure are only used for illustrative purposes and are not used to limit the scope of these messages or information.

[0021] The present disclosure will be described in detail below with reference to the accompanying drawings and in conjunction with embodiments.

[0022] Figure 1 It is a schematic diagram of an application scenario of the online inspection camera auto-focus method according to some embodiments of the present disclosure.

[0023] exist Figure 1 In the application scenario, first, the computing device 101 can obtain the image to be processed 102 according to the target camera. Secondly, the computing device 101 can obtain the target intensity value of each pixel of the image to be processed 102 according to the bilateral filter to obtain the denoised image 103. Then, the computing device 101 can obtain the clarity 104 of the denoised image 103 according to the Laplace operator algorithm. Finally, the computing device 101 can determine the target focal length corresponding to the target camera within the preset focal length range according to the initial focal length corresponding to the image to be processed 102, the clarity 104 of the denoised image and the preset optimization method, and complete the automatic focus, as shown in the reference numeral 105.

[0024] It should be noted that the computing device 101 can be hardware or software. When the computing device 101 is hardware, it can be implemented as a distributed cluster consisting of multiple servers or terminal devices, or it can be implemented as a single server or a single terminal device. When the computing device 101 is embodied as software, it can be installed in the hardware devices listed above. It can be implemented as multiple software or software modules for providing distributed services, for example, or it can be implemented as a single software or software module. No specific limitation is made here.

[0025] It should be understood that Figure 1 The number of computing devices in the embodiment is only illustrative. Any number of computing devices may be provided according to implementation requirements.

[0026] Figure 2 It is a flowchart of some embodiments of the online inspection camera auto-focus method according to the present disclosure. Figure 2 The online inspection camera auto-focus method can be Figure 1 The computing device 101 executes. Figure 2 As shown, the online inspection camera automatic focusing method includes:

[0027] Step S201, obtaining an image to be processed according to a target camera; wherein the image to be processed includes a plurality of pixels; each pixel has a corresponding initial intensity value; the focal length corresponding to the target camera when obtaining the image to be processed is the initial focal length; the initial focal length is any focal length within a preset focal length range.

[0028] In some embodiments, the target camera is an embedded camera module. Specifically, the target camera can realize data transmission with a controller (such as a single board computer) having a computing function by wired or wireless means. In one embodiment, an Arducam embedded camera module is used, which can be connected to a Raspberry Pi single board computer via a data cable, and after the configuration file path and the introduction of the relevant library, the parameters can be written into the camera-related motor by code, so as to achieve the purpose of controlling the camera. In addition, the target camera can adjust the focal length. In particular, the camera needs to support the method of writing the focal length value by code to modify the focal length to the corresponding value.

[0029] In some embodiments, step S201 further includes the following steps:

[0030] The first step is to obtain an initial image according to the target camera; wherein the initial image includes three channels of RGB.

[0031] Here, the initial image includes three channels: RGB. That is, at any time, the return value of the target camera is a 3×w×h matrix, where w and h are the width and height of the camera resolution respectively. For each pixel (i, j) in the image, the matrix returns the intensity values ​​of the three channels R, G, and B in the pixel corresponding to the position.

[0032] The second step is to perform grayscale processing on the initial image to obtain an image to be processed; wherein the image to be processed is a grayscale image.

[0033] Here, the original image is converted into a two-dimensional image, and the original image in RGB format is converted into a grayscale image, expressed in the format of a w×h matrix. For each pixel (i, j) in the image, the matrix returns the intensity value of the pixel corresponding to the position, and its value range is [0,255].

[0034] Step S202, according to the bilateral filter, obtain the target intensity value of each pixel of the image to be processed to obtain a denoised image; wherein the target intensity value is determined by the distance and intensity value difference between each pixel and each pixel adjacent to the pixel; the bilateral filter has a corresponding weight function; the weight function is used to determine the weight of the distance between the corresponding pixel and each pixel adjacent to the pixel when obtaining the target intensity value, and to determine the weight of the intensity value difference between the corresponding pixel and each pixel adjacent to the pixel; the weight of the intensity value difference between each pixel and each pixel adjacent to the pixel is related to the initial intensity value of the pixel.

[0035] In some embodiments, step S202 further includes the following steps:

[0036] The first step is to obtain each adjacent pixel point of each pixel point contained in the image to be processed.

[0037] The second step is to obtain the weight of each adjacent pixel of each pixel.

[0038] The third step is to perform weighted summation of the initial intensity values ​​of all adjacent pixels corresponding to each pixel according to the weight and initial intensity value of each adjacent pixel of each pixel, and obtain the target intensity value of each pixel of the image to be processed to obtain a denoised image.

[0039] Specifically, denoising of the image to be processed is achieved by means of a bilateral filter. For each pixel in the image to be processed, the bilateral filter replaces the intensity value of each pixel with the weighted average of the intensity values ​​of all adjacent pixels of the pixel, where the weight corresponding to each adjacent pixel depends on two points: the distance between the adjacent pixel and the pixel, and the intensity value difference between the adjacent pixel and the pixel. The calculation formula of the bilateral filter is determined by the weight function. In this embodiment, a bilateral filter (GaussianBilateral Filter) with Gaussian distribution as the weight function is selected. For pixel X, the formula is expressed as follows:

[0040]

[0041] Among them, Y is the pixel coordinate vector of the adjacent pixels of pixel X, is the output value of pixel X, that is, the target intensity value of pixel X; J(X) is the initial intensity value of pixel X; J(Y) is the initial intensity value of pixel Y; and are standard deviation constants, controlling the shape of the weight distribution related to distance and intensity, respectively. ||YX|| represents the Euclidean distance between two pixels, where N(X) represents the eight pixels adjacent to X, and the formula of C is as follows:

[0042]

[0043] It should be noted that compared with the traditional Gaussian bilateral filter, the filter in this embodiment has an additional multiplication of ‖J(X)‖ in the denominator of the intensity term. 2 This allows the weight of the intensity difference to be associated with the initial intensity value, making the distribution more concentrated when the pixel intensity is low, ensuring that too many edges are not accidentally filtered out in low light conditions. This structured filter is more suitable for situations with unstable light intensity and can perform better than traditional bilateral filters in low light conditions.

[0044] In a specific embodiment, step S202 includes: first, taking a pixel point X from the image to be processed; second, for each adjacent pixel point Y of X, calculating Add the results and divide by The final result is set as the target intensity value of pixel X. Repeat the above steps until every pixel in the image is traversed.

[0045] It should be noted that the bilateral filter can be replaced by other commonly used denoising algorithms, such as mean, median, Gaussian, Weiner, Fourier, etc.

[0046] Step S203, obtaining the clarity of the denoised image according to the Laplace operator algorithm; wherein the clarity is described according to the Laplace variance of the denoised image.

[0047] In some embodiments, step S203 further includes the following steps:

[0048] In the first step, the Laplace variance of the denoised image is obtained according to the target intensity value of each pixel contained in the denoised image and the average target intensity value of all pixels contained in the denoised image.

[0049] Here, the Laplacian operator is simple, easy to use, and effective. Its principle is straightforward and easy to understand. By definition, low-definition images will be more blurred, while high-definition images have more sharp edges. Therefore, the Laplacian operator is first used to extract edge information from the image. A relatively standard matrix is ​​used here:

[0050]

[0051] Specifically, first, according to the programming language of the script, use the convolution method in the corresponding machine learning or computer vision library to calculate the convolution of the input image and the above template (or directly use the provided method to calculate the Laplace operator of the image). Secondly, calculate the Laplace variance of the obtained image, and its formula is

[0052]

[0053] Among them, v is the Laplace variance, P is the set of all pixels in the denoised image, is the average intensity value of all pixels in the denoised image.

[0054] In the second step, the Laplace variance of the denoised image is determined as the clarity of the denoised image.

[0055] Since the Laplace operator can extract edge information by detecting the horizontal and vertical gradient values ​​in an image, if an image has many and clear edges, the Laplace variance of the image will be relatively large, and the image will be considered to have high definition, and vice versa. Therefore, the Laplace variance is used as an approximation of image clarity.

[0056] Step S204, according to the initial focal length corresponding to the image to be processed, the clarity of the denoised image and the preset optimization method, determine the target focal length corresponding to the target camera within the preset focal length range, and complete automatic focusing; wherein the Laplace variance of the denoised image corresponding to the above target focal length is greater than the Laplace variance of the denoised image corresponding to each focal length within the preset focal length range except the target focal length, and the Laplace variance of the denoised image corresponding to the target focal length is greater than the preset Laplace variance threshold.

[0057] In some embodiments, step S203 further includes the following steps:

[0058] Step a1, determining a first critical focal length within a preset focal length range according to a first preset interval and a composite search method; wherein the Laplace variance of the denoised image corresponding to the first critical focal length is greater than the Laplace variance of the denoised image corresponding to each focal length within the preset focal length range except the first critical focal length.

[0059] Step a2: If the Laplace variance of the denoised image corresponding to the above-mentioned key focal length is less than a preset Laplace variance threshold, a preset key focal length range is obtained according to the key focal length; wherein the preset key focal length range takes the key focal length as the center focal length, and the preset key focal length range is within the preset focal length range.

[0060] Step a3, obtaining a second preset interval according to a preset key focal length range; wherein the second preset interval is smaller than the first preset interval.

[0061] Step a4, determining a second critical focal length within a preset critical focal length range according to a second preset interval and a composite search method; wherein the Laplace variance of the denoised image corresponding to the second critical focal length is equal to or greater than the Laplace variance of the denoised image corresponding to each focal length within the preset focal length range except the second critical focal length.

[0062] Step a5: if the Laplace variance of the denoised image corresponding to the second key focal length is greater than a preset Laplace variance threshold, the second key focal length is determined as the target focal length to complete automatic focusing.

[0063] This embodiment uses a composite search method that combines global search and local search. Assuming that the initial focal length f of the target camera can be any real number between [0, F], there is an equation L(f), and for any input f, its output value is the Laplace variance value of the image captured by the camera at the focal length f. Therefore, finding the focal length that can maximize the image clarity is equivalent to finding the f value that maximizes L(f) in the domain [0, F] in this context.

[0064] Since the domain is limited and known, the specific steps are as follows Figure 3 As shown:

[0065] The first step is to set f = 0, S = s0, M = 0, MF = 0, and the domain is [0, F]. s0 is a constant.

[0066] The second step is to set the focal length to f, capture the image, remove noise and calculate the clarity to obtain L(f). If L(f)>M, then set M=L(f) and set MF=f.

[0067] The third step is to let f = f + S and repeat the second step until f is no longer in the domain.

[0068] The fourth step is to M=0,MF=0,let the domain be modified to Repeat steps 2 and 3 until f is no longer in the domain. n is a constant.

[0069] Repeat step 4 until L(f) is greater than a given threshold or the execution time exceeds a given threshold.

[0070] Specifically, this embodiment will roughly search the entire domain at a coarse interval and find the maximum value therein. Subsequently, this embodiment will perform a more detailed search again with the maximum focal length of this search as the center, and repeat this process. When the clarity exceeds a certain threshold, the autofocus is completed and the operation ends.

[0071] It should be noted that the Laplacian operator can be replaced by the Sobel operator, Gaussian Laplacian operator, CMSL and other convolution templates for edge extraction.

[0072] Figure 4 1 is a flowchart of another embodiment of the online inspection camera auto-focus method according to the present disclosure; the specific execution process is:

[0073] Step b1, set the focal length of the camera to F i .

[0074] Step b2: The camera captures an image P i .

[0075] Step b3: the obtained image P i Execute the denoising algorithm to obtain image P i ′.

[0076] Step b4, calculate the image P i The clarity of J i .

[0077] Step b5, record F i With J i If the given conditions are met, the focal length of the camera is set to F m , and terminate the script, otherwise set the camera's focal length to F i+1 , and repeat steps b2 to b5.

[0078] In summary, compared with the prior art, the advantages of the present disclosure are reflected in the following aspects: It has stronger environmental applicability. Compared with the traditional autofocus method, the present method is less affected by the non-ideal external environment, including low light intensity, high noise, lens distortion, etc., and is suitable for more complex working environments. It can achieve a balance between speed and search range. Compared with the traditional autofocus method, the present method can ensure that while not doing too much useless searching, it can avoid falling into the local maximum as much as possible.

[0079] All the above optional technical solutions can be arbitrarily combined to form optional embodiments of the present application, which will not be described one by one here.

[0080] The following are embodiments of the device disclosed herein, which can be used to execute the method embodiments disclosed herein. For details not disclosed in the device embodiments disclosed herein, please refer to the method embodiments disclosed herein.

[0081] Figure 5 Schematic diagram of the structure of some embodiments of the online inspection camera auto-focus device disclosed in the present invention. Figure 5 As shown, the online inspection camera autofocus device includes: an image acquisition unit 501, which is configured to acquire an image to be processed according to a target camera; wherein the above-mentioned image to be processed includes a plurality of pixels; each pixel has a corresponding initial intensity value; the focal length corresponding to the target camera when acquiring the image to be processed is the initial focal length; the initial focal length is any focal length within a preset focal length range; a denoising unit 502, which is configured to acquire a target intensity value of each pixel of the image to be processed according to a bilateral filter to obtain a denoised image; wherein the above-mentioned target intensity value is determined by the distance and intensity value difference between each pixel and each pixel adjacent to the pixel; the bilateral filter has a corresponding weight function; the above-mentioned weight function is used to determine the weight of the distance between the corresponding pixel and each pixel adjacent to the pixel when acquiring the target intensity value, and to determine the weight of the distance between the corresponding pixel and the image The weight of the intensity value difference between each pixel point adjacent to the pixel point; the weight of the intensity value difference between each pixel point and each pixel point adjacent to the pixel point is related to the initial intensity value of the pixel point; the clarity acquisition unit 503 is configured to obtain the clarity of the denoised image according to the Laplace operator algorithm; wherein the above clarity is described according to the Laplace variance of the denoised image; the target focal length determination unit 504 is configured to determine the target focal length corresponding to the target camera within the preset focal length range according to the initial focal length corresponding to the image to be processed, the clarity of the denoised image and the preset optimization method, and complete automatic focusing; wherein the Laplace variance of the denoised image corresponding to the above target focal length is greater than the Laplace variance of the denoised image corresponding to each focal length within the preset focal length range except the target focal length, and the Laplace variance of the denoised image corresponding to the target focal length is greater than the preset Laplace variance threshold.

[0082] In some optional implementations of some embodiments, the image acquisition unit 501 is configured as follows:

[0083] According to the target camera, an initial image is obtained; wherein the initial image includes three channels of RGB;

[0084] The initial image is gray-scaled to obtain an image to be processed; wherein the image to be processed is a gray-scale image.

[0085] In some optional implementations of some embodiments, the denoising unit 502 is configured as follows:

[0086] Obtain each adjacent pixel point of each pixel point contained in the image to be processed;

[0087] Get the weight of each adjacent pixel of each pixel;

[0088] According to the weight and initial intensity value of each adjacent pixel of each pixel, the initial intensity values ​​of all adjacent pixels corresponding to each pixel are weighted summed to obtain the target intensity value of each pixel of the image to be processed, so as to obtain a denoised image.

[0089] In some optional implementations of some embodiments, the clarity acquisition unit 503 is configured as follows:

[0090] According to the target intensity value of each pixel point contained in the denoised image and the average target intensity value of all the pixels contained in the denoised image, the Laplace variance of the denoised image is obtained;

[0091] The Laplace variance of the denoised image is determined as the sharpness of the denoised image.

[0092] In some optional implementations of some embodiments, the initial focal length is any real number within a preset focal length range.

[0093] In some optional implementations of some embodiments, the target focal length determining unit 504 is configured as follows:

[0094] Determine a first key focal length within a preset focal length range according to a first preset interval and a composite search method; wherein the Laplace variance of the denoised image corresponding to the first key focal length is greater than the Laplace variance of the denoised image corresponding to each focal length within the preset focal length range except the first key focal length;

[0095] If the Laplace variance of the denoised image corresponding to the above critical focal length is less than a preset Laplace variance threshold, a preset critical focal length range is obtained according to the critical focal length; wherein the preset critical focal length range takes the critical focal length as the center focal length, and the preset critical focal length range is within the preset focal length range;

[0096] According to the preset key focal length range, a second preset interval is obtained; wherein the second preset interval is smaller than the first preset interval;

[0097] Determine a second key focal length within a preset key focal length range according to a second preset interval and a composite search method; wherein the Laplace variance of the denoised image corresponding to the second key focal length is equal to or greater than the Laplace variance of the denoised image corresponding to each focal length within the preset focal length range except the second key focal length;

[0098] If the Laplace variance of the denoised image corresponding to the second key focal length is greater than a preset Laplace variance threshold, the second key focal length is determined as the target focal length to complete the automatic focusing.

[0099] In some optional implementations of some embodiments, the target camera is an embedded camera module.

[0100] It should be understood that the size of the serial numbers of the steps in the above embodiments does not mean the order of execution. The execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiments of the present disclosure.

[0101] Reference below Figure 6 , which shows an electronic device (eg, Figure 1 Schematic diagram of the structure of the computing device 101)600. Figure 6 The server shown is only an example and should not bring any limitation to the functions and scope of use of the embodiments of the present disclosure.

[0102] like Figure 6 As shown, the electronic device 600 may include a processing device (e.g., a central processing unit, a graphics processor, etc.) 601, which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) 602 or a program loaded from a storage device 608 to a random access memory (RAM) 603. In the RAM 603, various programs and data required for the operation of the electronic device 600 are also stored. The processing device 601, the ROM 602, and the RAM 603 are connected to each other via a bus 604. An input / output (I / O) interface 605 is also connected to the bus 604.

[0103] Typically, the following devices may be connected to the I / O interface 605: an input device 606 including, for example, a touch screen, a touch pad, a keyboard, a mouse, a camera, a microphone, an accelerometer, a gyroscope, etc.; an output device 607 including, for example, a liquid crystal display (LCD), a speaker, a vibrator, etc.; a storage device 608 including, for example, a magnetic tape, a hard disk, etc.; and a communication device 609. The communication device 609 may allow the electronic device 600 to communicate with other devices wirelessly or by wire to exchange data. Although Figure 6 The electronic device 600 is shown with various devices, but it should be understood that it is not required to implement or possess all the devices shown. More or fewer devices may be implemented or possessed instead. Figure 6 Each block shown in the figure may represent one device, or may represent multiple devices as required.

[0104] In particular, according to some embodiments of the present disclosure, the process described above with reference to the flowchart can be implemented as a computer software program. For example, some embodiments of the present disclosure include a computer program product, which includes a computer program carried on a computer-readable medium, and the computer program includes a program code for executing the method shown in the flowchart. In some such embodiments, the computer program can be downloaded and installed from the network through the communication device 609, or installed from the storage device 608, or installed from the ROM 602. When the computer program is executed by the processing device 601, the above-mentioned functions defined in the method of some embodiments of the present disclosure are executed.

[0105] It should be noted that the computer-readable medium in some embodiments of the present disclosure may be a computer-readable signal medium or a computer-readable storage medium or any combination of the two. The computer-readable storage medium may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or device, or any combination of the above. More specific examples of computer-readable storage media may include, but are not limited to: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In some embodiments of the present disclosure, the computer-readable storage medium may be any tangible medium containing or storing a program that can be used by or in combination with an instruction execution system, device or device. In some embodiments of the present disclosure, the computer-readable signal medium may include a data signal propagated in a baseband or as part of a carrier wave, in which a computer-readable program code is carried. This propagated data signal may take a variety of forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the above. The computer readable signal medium may also be any computer readable medium other than a computer readable storage medium, which may send, propagate or transmit a program for use by or in conjunction with an instruction execution system, apparatus or device. The program code contained on the computer readable medium may be transmitted using any suitable medium, including but not limited to: wires, optical cables, RF (radio frequency), etc., or any suitable combination of the above.

[0106] In some embodiments, the client and the server may communicate using any currently known or future developed network protocol such as HTTP (HyperText Transfer Protocol), and may be interconnected with any form or medium of digital data communication (e.g., a communication network). Examples of communication networks include a local area network ("LAN"), a wide area network ("WAN"), an internet (e.g., the Internet), and a peer-to-peer network (e.g., an ad hoc peer-to-peer network), as well as any currently known or future developed network.

[0107] The above-mentioned computer-readable medium may be included in the above-mentioned device; or it may exist independently and not be assembled into the electronic device. The above-mentioned computer-readable medium carries one or more programs. When the above-mentioned one or more programs are executed by the electronic device, the electronic device: obtains the image to be processed according to the target camera; wherein the above-mentioned image to be processed includes a plurality of pixels; each pixel has a corresponding initial intensity value; the focal length corresponding to the target camera when obtaining the image to be processed is the initial focal length; the initial focal length is any focal length within the preset focal length range; according to the bilateral filter, obtain the target intensity value of each pixel of the image to be processed to obtain a denoised image; wherein the above-mentioned target intensity value is determined by the distance and intensity value difference between each pixel and each pixel adjacent to the pixel; the bilateral filter has a corresponding weight function; the above-mentioned weight function is used to determine the distance and intensity value difference between the corresponding pixel and each pixel adjacent to the pixel when obtaining the target intensity value. The weight of the distance and the weight of the intensity value difference between the corresponding pixel point and each pixel point adjacent to the pixel point are determined; the weight of the intensity value difference between each pixel point and each pixel point adjacent to the pixel point is related to the initial intensity value of the pixel point; according to the Laplace operator algorithm, the clarity of the denoised image is obtained; wherein the above-mentioned clarity is described according to the Laplace variance of the denoised image; according to the initial focal length corresponding to the image to be processed, the clarity of the denoised image and the preset optimization method, the target focal length corresponding to the target camera is determined within the preset focal length range to complete automatic focusing; wherein the Laplace variance of the denoised image corresponding to the above-mentioned target focal length is greater than the Laplace variance of the denoised image corresponding to each focal length within the preset focal length range except the target focal length, and the Laplace variance of the denoised image corresponding to the target focal length is greater than the preset Laplace variance threshold.

[0108] Computer program code for performing the operations of some embodiments of the present disclosure may be written in one or more programming languages ​​or a combination thereof, including object-oriented programming languages ​​such as Java, Smalltalk, C++, and conventional procedural programming languages ​​such as "C" or similar programming languages. The program code may be executed entirely on the user's computer, partially on the user's computer, as a separate software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In cases involving a remote computer, the remote computer may be connected to the user's computer via any type of network, including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computer (e.g., via the Internet using an Internet service provider).

[0109] The flow chart and block diagram in the accompanying drawings illustrate the possible architecture, function and operation of the system, method and computer program product according to various embodiments of the present disclosure. In this regard, each square box in the flow chart or block diagram can represent a module, a program segment or a part of a code, and the module, the program segment or a part of the code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some implementations as replacements, the functions marked in the square box can also occur in a sequence different from that marked in the accompanying drawings. For example, two square boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each square box in the block diagram and / or flow chart, and the combination of the square boxes in the block diagram and / or flow chart can be implemented with a dedicated hardware-based system that performs a specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.

[0110] The units described in some embodiments of the present disclosure may be implemented by software or hardware. The units described may also be provided in a processor, for example, may be described as: a processor including an image acquisition unit, a denoising unit, a clarity acquisition unit, and a target focal length determination unit. The names of these units do not, in some cases, constitute limitations on the units themselves, for example, the acquisition unit may also be described as a "unit for acquiring an image to be processed according to a target camera".

[0111] The functions described above herein may be performed at least in part by one or more hardware logic components. For example, without limitation, exemplary types of hardware logic components that may be used include: field programmable gate arrays (FPGAs), application specific integrated circuits (ASICs), application specific standard products (ASSPs), systems on chip (SOCs), complex programmable logic devices (CPLDs), and the like.

[0112] The above descriptions are only some preferred embodiments of the present disclosure and an explanation of the technical principles used. Those skilled in the art should understand that the scope of the invention involved in the embodiments of the present disclosure is not limited to the technical solutions formed by a specific combination of the above-mentioned technical features, but should also cover other technical solutions formed by any combination of the above-mentioned technical features or their equivalent features without departing from the above-mentioned inventive concept. For example, the above-mentioned features are replaced with the technical features with similar functions disclosed in the embodiments of the present disclosure (but not limited to) and the technical solutions formed.

Claims

1. An automatic focusing method for an online inspection camera, characterized in that: The method comprises: According to the target camera, an image to be processed is obtained; wherein the image to be processed includes a plurality of pixels; each pixel has a corresponding initial intensity value; the focal length corresponding to the target camera when obtaining the image to be processed is the initial focal length; the initial focal length is any focal length within a preset focal length range; According to the bilateral filter, a target intensity value of each pixel of the image to be processed is obtained to obtain a denoised image; wherein the target intensity value is determined by the distance and intensity value difference between each pixel and each pixel adjacent to the pixel; the bilateral filter has a corresponding weight function; the weight function is used to determine the weight of the distance between the corresponding pixel and each pixel adjacent to the pixel and the weight of the intensity value difference between the corresponding pixel and each pixel adjacent to the pixel when obtaining the target intensity value; the weight of the intensity value difference between each pixel and each pixel adjacent to the pixel is related to the initial intensity value of the pixel; According to the Laplace operator algorithm, the clarity of the denoised image is obtained; wherein the clarity is described according to the Laplace variance of the denoised image; According to the initial focal length corresponding to the image to be processed, the clarity of the denoised image and the preset optimization method, the target focal length corresponding to the target camera is determined within the preset focal length range to complete automatic focusing; wherein the Laplace variance of the denoised image corresponding to the target focal length is greater than the Laplace variance of the denoised image corresponding to each focal length within the preset focal length range except the target focal length, and the Laplace variance of the denoised image corresponding to the target focal length is greater than the preset Laplace variance threshold.

2. The online inspection camera automatic focusing method according to claim 1, characterized in that: The step of obtaining the image to be processed according to the target camera includes: According to the target camera, an initial image is obtained; wherein the initial image includes three channels of RGB; Grayscale processing is performed on the initial image to obtain an image to be processed; wherein the image to be processed is a grayscale image.

3. The online inspection camera automatic focusing method according to claim 1, characterized in that: The step of obtaining a target intensity value of each pixel of the image to be processed according to the bilateral filter to obtain a denoised image includes: Obtain each adjacent pixel point of each pixel point contained in the image to be processed; Get the weight of each adjacent pixel of each pixel; According to the weight and initial intensity value of each adjacent pixel of each pixel, the initial intensity values ​​of all adjacent pixels corresponding to each pixel are weighted summed to obtain the target intensity value of each pixel of the image to be processed, so as to obtain a denoised image.

4. The online inspection camera automatic focusing method according to claim 1, characterized in that: The clarity of the denoised image is obtained according to the Laplace operator algorithm, including: According to the target intensity value of each pixel point contained in the denoised image and the average target intensity value of all the pixels contained in the denoised image, the Laplace variance of the denoised image is obtained; The Laplace variance of the denoised image is determined as the sharpness of the denoised image.

5. The online inspection camera automatic focusing method according to claim 1, characterized in that: The initial focal length is any real number within the preset focal length range.

6. The online inspection camera automatic focusing method according to claim 1, characterized in that: The method determines the target focal length corresponding to the target camera within the preset focal length range according to the initial focal length corresponding to the image to be processed, the clarity of the denoised image and the preset optimization method, and completes the automatic focusing; including: Determine a first key focal length within a preset focal length range according to a first preset interval and a composite search method; wherein the Laplace variance of the denoised image corresponding to the first key focal length is greater than the Laplace variance of the denoised image corresponding to each focal length within the preset focal length range except the first key focal length; If the Laplace variance of the denoised image corresponding to the key focal length is less than a preset Laplace variance threshold, a preset key focal length range is obtained according to the key focal length; wherein the preset key focal length range takes the key focal length as the center focal length, and the preset key focal length range is within the preset focal length range; According to the preset key focal length range, a second preset interval is obtained; wherein the second preset interval is smaller than the first preset interval; Determine a second key focal length within a preset key focal length range according to a second preset interval and a composite search method; wherein the Laplace variance of the denoised image corresponding to the second key focal length is equal to or greater than the Laplace variance of the denoised image corresponding to each focal length within the preset focal length range except the second key focal length; If the Laplace variance of the denoised image corresponding to the second key focal length is greater than a preset Laplace variance threshold, the second key focal length is determined as the target focal length to complete the automatic focusing.

7. The online inspection camera automatic focusing method according to claim 1, characterized in that: The target camera is an embedded camera module.

8. An automatic focusing device for an online inspection camera, characterized in that: The device comprises: The image acquisition unit is configured to acquire an image to be processed according to a target camera; wherein the image to be processed includes a plurality of pixels; each pixel has a corresponding initial intensity value; the focal length corresponding to the target camera when acquiring the image to be processed is the initial focal length; the initial focal length is any focal length within a preset focal length range; A denoising unit is configured to obtain a target intensity value of each pixel of the image to be processed according to a bilateral filter to obtain a denoised image; wherein the target intensity value is determined by the distance and intensity value difference between each pixel and each pixel adjacent to the pixel; the bilateral filter has a corresponding weight function; the weight function is used to determine the weight of the distance between the corresponding pixel and each pixel adjacent to the pixel and the weight of the intensity value difference between the corresponding pixel and each pixel adjacent to the pixel when obtaining the target intensity value; the weight of the intensity value difference between each pixel and each pixel adjacent to the pixel is related to the initial intensity value of the pixel; A clarity acquisition unit is configured to obtain the clarity of the denoised image according to a Laplace operator algorithm; wherein the clarity is described according to the Laplace variance of the denoised image; The target focal length determination unit is configured to determine the target focal length corresponding to the target camera within a preset focal length range according to the initial focal length corresponding to the image to be processed, the clarity of the denoised image and a preset optimization method, and complete automatic focusing; wherein the Laplace variance of the denoised image corresponding to the target focal length is greater than the Laplace variance of the denoised image corresponding to each focal length within the preset focal length range except the target focal length, and the Laplace variance of the denoised image corresponding to the target focal length is greater than a preset Laplace variance threshold.

9. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the computer program, the steps of the method according to any one of claims 1 to 7 are implemented.

10. A computer-readable storage medium storing a computer program, characterized in that: When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 7 are implemented.

Citation Information

Patent Citations

  • Focusing method

    CN106094162A

  • Automatic focusing method

    CN115002314A

  • Automatic focusing method and device, electronic equipment and storage medium

    CN115567778A

  • Mobile focusing method, scanning method and device of digital slice scanner

    CN115866395A

  • Automatic focusing method and device, electronic equipment and storage medium

    CN116828302A