Online inspection camera automatic focusing method, device, equipment and medium
By combining bilateral filters and the Laplacian operator, the autofocus method is optimized, solving the problem of insufficient sharpness in low light intensity and high noise environments, and realizing more efficient high-definition image acquisition in smart factories.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- SINOCHEM INFORMATION TECH CO LTD
- Filing Date
- 2025-01-24
- Publication Date
- 2026-06-02
AI Technical Summary
Existing technologies do not perform well in environments with low light intensity and high noise, which affects the clarity of video surveillance systems.
A method combining bilateral filters and Laplacian operators is employed to obtain the target intensity value of each pixel in the image, use a weighting function to process image noise, and combine the Laplacian variance to describe sharpness, thereby optimizing the target focal length within the focal length range.
In low-light and high-noise environments, it improves the applicability and sharpness of autofocus, reduces the trapping of local maxima, and achieves faster and more efficient high-definition image acquisition.
Smart Images

Figure CN119946427B_ABST
Abstract
Description
Technical Field
[0001] This disclosure relates to the field of camera focusing technology, and in particular to methods, apparatus, equipment and media for automatic focusing of online inspection cameras. Background Technology
[0002] Video surveillance systems are an indispensable component of smart factories. A well-configured video surveillance system can significantly enhance information management capabilities and improve the controllability of the production process, playing a crucial role in tasks such as online inspections and monitoring of non-routine operations. In recent years, with the development of video AI technology, the ease of use and versatility of video surveillance systems have achieved a qualitative leap. However, in practical applications, whether for manual online inspections or AI-based detection of violations, video clarity remains paramount. When taking photos with an optical camera, the correct focal length directly affects the image's clarity. Therefore, even with today's highly advanced photographic and computer vision technologies, and equipment capable of high automation through the Internet of Things, autofocus still plays a vital role in many areas. Due to the high immediacy and high risk of work in smart factories, the autofocus methods used in these devices need to achieve rapid and independent focusing to efficiently acquire high-resolution images. Currently, many autofocus methods are used in various industries, most of which are based on quantifying sharpness in some way and using optimization algorithms to find the focal length that maximizes sharpness. Commonly used clear quantification methods include the Sobel operator, the Laplacian operator, and the Tenengrad function, but these methods are mostly suitable for environments with good lighting and low image noise. In smart factories, environments with low lighting and high noise (such as inside boiler rooms) are common, and the performance of these methods will be affected to some extent. Summary of the Invention
[0003] In view of this, the present disclosure provides an online inspection camera autofocus method, apparatus, device and medium to solve the problem of poor autofocus performance in environments with low light intensity and high noise in the prior art.
[0004] A first aspect of this disclosure provides an automatic focusing method for an online inspection camera, comprising: acquiring an image to be processed based on a target camera; wherein the image to be processed contains a plurality of pixels; each pixel has a corresponding initial intensity value; the focal length of 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; acquiring a target intensity value of each pixel in the image to be processed based on 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 it; 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 it when acquiring the target intensity value, and to determine the weight of the distance between the corresponding pixel and each pixel adjacent to it. The weights of the intensity differences between a given pixel and each of its neighboring pixels are determined; the weights of the intensity differences between each pixel and each of its neighboring pixels are related to the initial intensity value of that pixel; the sharpness of the denoised image is obtained according to the Laplacian operator algorithm; wherein the sharpness is described by the Laplacian variance of the denoised image; based on the initial focal length of the image to be processed, the sharpness of the denoised image, and the preset optimization method, the target focal length corresponding to the target camera is determined within a preset focal length range to complete autofocus; wherein the Laplacian variance of the denoised image corresponding to the target focal length is greater than the Laplacian variance of the denoised image corresponding to each focal length other than the target focal length within the preset focal length range, and the Laplacian variance of the denoised image corresponding to the target focal length is greater than a preset Laplacian variance threshold.
[0005] A second aspect of this disclosure provides an autofocus device for an online inspection camera, comprising: an image acquisition unit configured to acquire an image to be processed based on a target camera; wherein the image to be processed contains a plurality of pixels; each pixel has a corresponding initial intensity value; the focal length of 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; and a denoising unit configured to acquire a target intensity value of each pixel in the image to be processed based on a bilateral filter to obtain a denoised image; wherein the target intensity value is determined by the distance and intensity difference between each pixel and each pixel adjacent to it; 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 it when acquiring the target intensity value, and to determine the weight of the corresponding pixel. The weight of the intensity difference between a pixel and each of its adjacent pixels is related to the initial intensity value of the pixel. A sharpness acquisition unit is configured to obtain the sharpness of the denoised image according to a Laplacian operator algorithm; wherein the sharpness is described by the Laplacian 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 a preset focal length range based on the initial focal length of the image to be processed, the sharpness of the denoised image, and a preset optimization method, and complete automatic focusing; wherein the Laplacian variance of the denoised image corresponding to the target focal length is greater than the Laplacian variance of the denoised image corresponding to each focal length other than the target focal length within the preset focal length range, and the Laplacian variance of the denoised image corresponding to the target focal length is greater than a preset Laplacian variance threshold.
[0006] A third aspect of this disclosure provides a computer device including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the computer program to implement the steps of the method described above.
[0007] A fourth aspect of this disclosure provides a computer-readable storage medium storing a computer program that, when executed by a processor, implements the steps of the above-described method.
[0008] The beneficial effects of this disclosure compared to the prior art are as follows: First, in this disclosure, the weight of the intensity difference between each pixel and each of its adjacent pixels is related to the initial intensity value of the pixel; this establishes a correlation between the weight of the intensity difference and the initial intensity value of the pixel, making the distribution more concentrated when the pixel intensity is low, ensuring that too many edges are not accidentally filtered out in low light intensity. A filter with this structure is more adaptable to situations with unstable light intensity and performs better than traditional bilateral filters in low light intensity. Second, since sharpness is a parameter for measuring focusing results, this application uses Laplacian variance to describe image sharpness; if an image has many sharp edges, the Laplacian variance of that image will be relatively large, meaning the image will have high sharpness, and vice versa, making sharpness quantifiable. Finally, by determining the target focal length within the range of color number focal lengths based on the magnitude of the Laplacian variance and a preset Laplacian variance threshold, this disclosure ensures that unnecessary searches are not performed while minimizing the occurrence of getting trapped in local maxima. Attached Figure Description
[0009] To more clearly illustrate the technical solutions in the embodiments of this disclosure, the accompanying drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the accompanying drawings described below are only some embodiments of this disclosure. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0010] Figure 1 This is a schematic diagram of an application scenario of an online inspection camera autofocus method according to some embodiments of the present disclosure;
[0011] Figure 2 This is a flowchart of some embodiments of the online inspection camera autofocus method according to the present disclosure;
[0012] Figure 3 This is a flowchart of an embodiment of the online inspection camera autofocus method according to the present disclosure for determining the target focal length;
[0013] Figure 4 This is a flowchart of some other embodiments of the online inspection camera autofocus method according to the present disclosure;
[0014] Figure 5 These are schematic diagrams illustrating the structure of some embodiments of the online inspection camera autofocus device according to this disclosure;
[0015] Figure 6 This is a schematic diagram of the structure of an electronic device suitable for implementing some embodiments of the present disclosure. Detailed Implementation
[0016] Embodiments of this disclosure will now be described in more detail with reference to the accompanying drawings. While some embodiments of this disclosure are shown in the drawings, it should be understood that this disclosure can be implemented in various forms and should not be construed as limited to the embodiments set forth herein. Rather, these embodiments are provided to provide a more thorough and complete understanding of this disclosure. It should be understood that the accompanying drawings and embodiments of this disclosure are for illustrative purposes only and are not intended to limit the scope of protection of this disclosure.
[0017] It should also be noted that, for ease of description, only the parts relevant to the invention are shown in the accompanying drawings. Unless otherwise specified, the embodiments and features described in this disclosure can be combined with each other.
[0018] It should be noted that the concepts of "first" and "second" mentioned in this disclosure are used only to distinguish different devices, modules or units, and are not used to limit the order of functions performed by these devices, modules or units or their interdependencies.
[0019] It should be noted that the terms "a" and "a plurality of" used in this disclosure are illustrative rather than restrictive, and those skilled in the art should understand that, unless otherwise expressly indicated in the context, they should be understood as "one or more".
[0020] The names of messages or information exchanged between multiple devices in the embodiments of this disclosure are for illustrative purposes only and are not intended to limit the scope of such messages or information.
[0021] This disclosure will now be described in detail with reference to the accompanying drawings and embodiments.
[0022] Figure 1 This is a schematic diagram of an application scenario of an online inspection camera autofocus method according to some embodiments of the present disclosure.
[0023] exist Figure 1 In the application scenario, firstly, the computing device 101 can acquire the image 102 to be processed based on the target camera. Secondly, the computing device 101 can acquire the target intensity value of each pixel in the image 102 to be processed based on a bilateral filter to obtain a denoised image 103. Then, the computing device 101 can obtain the sharpness 104 of the denoised image 103 based on the Laplacian operator algorithm. Finally, the computing device 101 can determine the target focal length corresponding to the target camera within a preset focal length range based on the initial focal length corresponding to the image 102 to be processed, the sharpness 104 of the denoised image, and a preset optimization method, thus completing automatic focusing, as shown by reference numeral 105 in the attached figure.
[0024] It should be noted that the aforementioned computing device 101 can be either 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 as a single server or a single terminal device. When the computing device 101 is software, it can be installed in the hardware devices listed above. It can be implemented as, for example, multiple software programs or software modules used to provide distributed services, or as a single software program or software module. No specific limitations are made here.
[0025] It should be understood that Figure 1 The number of computing devices shown is merely illustrative. Any number of computing devices can be used depending on implementation needs.
[0026] Figure 2 This is a flowchart of some embodiments of the online inspection camera autofocus method according to the present disclosure. Figure 2 The autofocus method for online inspection cameras can be provided by Figure 1 The computing device 101 performs the operation. For example... Figure 2 As shown, the autofocus method of this online inspection camera includes:
[0027] Step S201: Acquire an image to be processed based on the target camera; wherein the image to be processed contains a number of pixels; each pixel has a corresponding initial intensity value; the focal length of 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.
[0028] In some embodiments, the target camera is an embedded camera module. Specifically, the target camera can transmit data with a controller (such as a single-board computer) that has computing capabilities, either wired or wirelessly. In one embodiment, using the Arducam embedded camera module, it can connect to a Raspberry Pi single-board computer via a data cable. After configuring the configuration file path and importing the relevant libraries, parameters can be written into the camera's related motors via code to control the camera. Additionally, the target camera can adjust its focus. Specifically, the camera needs to support modifying the focus to a corresponding value by writing the focus value via code.
[0029] In some embodiments, step S201 further includes the following step:
[0030] The first step is to acquire an initial image based on the target camera; the initial image includes the three channels of RGB.
[0031] Here, the initial image includes the RGB channels. That is, at any given time, the target camera returns 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 R, G, and B channels for that pixel location.
[0032] The second step is to perform grayscale processing on the initial image to obtain the image to be processed; wherein, the image to be processed is a grayscale image.
[0033] Here, the initial image is converted into a grayscale image by performing a two-dimensional operation, which is expressed as a w×h matrix. For each pixel (i,j) in the image, the matrix returns the intensity value of the pixel at that position, with a value range of [0,255].
[0034] Step S202: Based on the bilateral filter, obtain the target intensity value of each pixel in the image to be processed to obtain a denoised image; wherein, the target intensity value is determined by the distance and intensity difference between each pixel and each of its neighboring pixels; 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 of its neighboring pixels and the weight of the intensity difference between the corresponding pixel and each of its neighboring pixels when obtaining the target intensity value; the weight of the intensity difference between each pixel and each of its neighboring pixels is related to the initial intensity value of the pixel.
[0035] In some embodiments, step S202 further includes the following step:
[0036] The first step is to obtain each neighboring pixel of each pixel in the image to be processed.
[0037] The second step is to obtain the weight of each neighboring pixel for each pixel.
[0038] The third step is to perform a weighted sum of the initial intensity values of all adjacent pixels corresponding to each pixel based on the weight and initial intensity value of each pixel, so as to obtain the target intensity value of each pixel in the image to be processed, and thus obtain the denoised image.
[0039] Specifically, noise reduction of the image is achieved using a bilateral filter. For each pixel in the image, the bilateral filter replaces the intensity value of each pixel with the weighted average of the intensity values of all its neighboring pixels. The weight of each neighboring pixel depends on two factors: the distance between the neighboring pixels and the current pixel, and the difference in intensity values between the neighboring pixels and the current pixel. The calculation formula for the bilateral filter is determined by the weighting function. In this embodiment, a Gaussian Bilateral Filter with a Gaussian distribution as the weighting function is selected. For pixel X, the formula is expressed as follows:
[0040]
[0041] Where Y is the pixel coordinate vector of the neighboring pixels of pixel X. J(X) is the output value of pixel X, i.e., 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 Both are standard deviation constants, controlling the shape of the distance- and intensity-related weight distributions, respectively. ||YX|| represents the Euclidean distance between two pixels, where N(X) represents the 8 pixels adjacent to X, and C is expressed as follows:
[0042]
[0043] It should be noted that, compared to traditional Gaussian bilateral filters, the filter in this embodiment additionally multiplies the denominator of the intensity term by ‖J(X)‖. 2 This allows the weight of the intensity difference to be correlated with the initial intensity value, resulting in a more concentrated distribution when pixel intensity is low, ensuring that too many edges are not accidentally filtered out in low light conditions. Filters with this structure are more suitable for environments with unstable light intensity and perform better than traditional bilateral filters in low light.
[0044] In one specific embodiment, step S202 includes: first, taking a pixel X from the image to be processed; second, for each adjacent pixel Y of X, calculating... Sum the results and then divide by Then set the final result as the target intensity value of pixel X. Repeat the above steps until every pixel in the image has been traversed.
[0045] It should be noted that the bilateral filter can be replaced with other commonly used denoising algorithms, such as mean, median, Gaussian, Weiner, Fourier, etc.
[0046] Step S203: Obtain the sharpness of the denoised image according to the Laplacian operator algorithm; wherein the sharpness is described by the Laplacian variance of the denoised image.
[0047] In some embodiments, step S203 further includes the following steps:
[0048] The first step is to obtain the Laplacian variance of the denoised image based on the target intensity value of each pixel in the denoised image and the average target intensity value of all pixels in the denoised image.
[0049] Here, the Laplacian operator is characterized by its simplicity, ease of use, and effectiveness; its principle is straightforward and easy to understand. By definition, low-resolution images are more blurry, while conversely, high-resolution images have more distinct and 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, based on the script's programming language, the convolution method from the corresponding machine learning or computer vision library is used to calculate the convolution between the input image and the template (or the provided method is used to directly calculate the Laplacian operator for the image). Second, the Laplacian variance of the resulting image is calculated, using the formula:
[0052]
[0053] Where v is the Laplacian variance, and P is the set of all pixels in the denoised image. This represents the average intensity value of all pixels in the denoised image.
[0054] The second step is to determine the Laplacian variance of the denoised image as the sharpness of the denoised image.
[0055] Since the Laplacian operator can extract edge information by detecting the horizontal and vertical gradient values in an image, if an image has many sharp edges, its Laplacian variance will be relatively large, and the image will be considered to have high sharpness, and vice versa. Therefore, the Laplacian variance is used as an approximation of image sharpness.
[0056] Step S204: Based on 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 to complete autofocus; wherein, the Laplacian variance of the denoised image corresponding to the target focal length is greater than the Laplacian variance of the denoised image corresponding to each focal length other than the target focal length within the preset focal length range, and the Laplacian variance of the denoised image corresponding to the target focal length is greater than the preset Laplacian variance threshold.
[0057] In some embodiments, step S203 further includes the following steps:
[0058] Step a1: Determine the first key focal length within the preset focal length range according to the first preset interval and the composite search method; wherein, the Laplacian variance of the denoised image corresponding to the first key focal length is greater than the Laplacian variance of the denoised image corresponding to each focal length other than the first key focal length within the preset focal length range.
[0059] Step a2: If the Laplacian variance of the denoised image corresponding to the above key focal length is less than the preset Laplacian variance threshold, then a preset key focal length range is obtained based on the key focal length; wherein, the preset key focal length range is centered on the key focal length, and the preset key focal length range is within the preset focal length range.
[0060] Step a3: Obtain the second preset interval based on the preset key focal length range; wherein the second preset interval is smaller than the first preset interval.
[0061] Step a4: Determine the second key focal length within the preset key focal length range according to the second preset interval and composite search method; wherein, the Laplacian variance of the denoised image corresponding to the second key focal length is equal to or greater than the Laplacian variance of the denoised image corresponding to each focal length other than the second key focal length within the preset focal length range.
[0062] Step a5: If the Laplacian variance of the denoised image corresponding to the second key focal length is greater than the preset Laplacian variance threshold, then the second key focal length is determined as the target focal length, and autofocus is completed.
[0063] This embodiment uses a composite search method combining global and local search. Assuming the initial focal length *f* of the target camera can take any real number between [0, F], then we have the equation L(f), where for any input *f*, the output value is the Laplacian variance of the image captured by the camera at focal length *f*. Therefore, finding the focal length that maximizes image sharpness in this context is equivalent to finding the value of *f* that maximizes L(f) within the domain [0, F].
[0064] Since the domain is finite and known, the specific steps are as follows: Figure 3 As shown:
[0065] First, let f = 0, S = s0, M = 0, MF = 0, and the domain be [0, F]. s0 is a constant.
[0066] The second step is to set the focal length to f, capture an image, denoise it, and calculate the sharpness to obtain L(f). If L(f) > M, then let M = L(f) and let 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] Fourth step, order With M = 0 and MF = 0, let the domain be modified to... Repeat steps two and three until f is no longer in the domain. n is a constant.
[0069] Repeat step 4 until L(f) is greater than the given threshold, or the execution time exceeds the given threshold.
[0070] Specifically, this embodiment performs a coarse search across the entire domain at relatively wide intervals and identifies the maximum value. Then, using the maximum focal length found in this search as the center, a more refined search is performed, and this process is repeated. When the sharpness exceeds a certain threshold, autofocus is complete, and the operation ends.
[0071] It should be noted that the Laplacian operator can be replaced with the Sobel operator, the Gaussian Laplacian operator, CMSL, and other convolutional templates for edge extraction.
[0072] Figure 4 This is a flowchart of some other embodiments of the online inspection camera autofocus method according to this disclosure; the specific execution flow is as follows:
[0073] Step b1, set the camera's focal length to F. i .
[0074] Step b2, the camera captures an image P. i .
[0075] Step b3, process the obtained image P i Perform a denoising algorithm to obtain image P i ′.
[0076] Step b4, calculate image P i The clarity of J i .
[0077] Step b5, record F i With J i If the given conditions are met, then set the camera's focal length to F. m And terminate the script; otherwise, set the camera's focal length to F. i+1 And repeat steps b2 through b5.
[0078] In summary, the advantages of this disclosure compared to existing technologies are as follows: It has stronger environmental adaptability. Compared to traditional autofocus methods, this method is less affected by unfavorable external environments, including low light intensity, high noise, and lens distortion, making it suitable for more complex working environments. It achieves a balance between speed and search range. Compared to traditional autofocus methods, this method ensures that it avoids unnecessary searches while minimizing the risk of getting trapped in local maxima.
[0079] All of the above-mentioned optional technical solutions can be combined in any way to form the optional embodiments of this application, and will not be described in detail here.
[0080] The following are embodiments of the apparatus disclosed herein, which can be used to execute embodiments of the method disclosed herein. For details not disclosed in the apparatus embodiments of this disclosure, please refer to the embodiments of the method disclosed herein.
[0081] Figure 5 These are schematic diagrams illustrating the structure of some embodiments of the online inspection camera autofocus device according to this disclosure. Figure 5 As shown, the online inspection camera autofocus device includes: an image acquisition unit 501, configured to acquire an image to be processed based on a target camera; wherein the image to be processed contains a plurality of pixels; each pixel has a corresponding initial intensity value; the focal length of 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, configured to acquire the target intensity value of each pixel in the image to be processed based on a bilateral filter, so as to obtain a denoised image; wherein the target intensity value is determined by the distance and intensity difference between each pixel and each pixel adjacent to it; 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 it when acquiring the target intensity value, and to determine the weight of the distance between the corresponding pixel and the pixel adjacent to it. The weight of the intensity difference between each adjacent pixel; the weight of the intensity difference between each pixel and each adjacent pixel is related to the initial intensity value of the pixel; the sharpness acquisition unit 503 is configured to obtain the sharpness of the denoised image according to the Laplacian operator algorithm; wherein the sharpness is described by the Laplacian 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 a preset focal length range according to the initial focal length corresponding to the image to be processed, the sharpness of the denoised image and a preset optimization method, and complete the autofocus; wherein the Laplacian variance of the denoised image corresponding to the target focal length is greater than the Laplacian variance of the denoised image corresponding to each focal length other than the target focal length within the preset focal length range, and the Laplacian variance of the denoised image corresponding to the target focal length is greater than a preset Laplacian variance threshold.
[0082] In some optional implementations of some embodiments, the image acquisition unit 501 described above is configured as follows:
[0083] Based on the target camera, acquire an initial image; wherein the initial image includes three channels: RGB.
[0084] The initial image is processed to obtain the image to be processed; wherein, the image to be processed is a grayscale image.
[0085] In some optional implementations of some embodiments, the denoising unit 502 is configured as follows:
[0086] Obtain each neighboring pixel of each pixel in the image to be processed;
[0087] Obtain the weight of each neighboring pixel for each pixel;
[0088] Based on the weights and initial intensity values of each neighboring pixel of each pixel, the initial intensity values of all neighboring pixels corresponding to each pixel are weighted and summed to obtain the target intensity value of each pixel in the image to be processed, so as to obtain the denoised image.
[0089] In some optional implementations of certain embodiments, the aforementioned sharpness acquisition unit 503 is configured as follows:
[0090] The Laplacian variance of the denoised image is obtained by using the target intensity value of each pixel in the denoised image and the average target intensity value of all pixels in the denoised image.
[0091] The Laplacian variance of the denoised image is used to determine the sharpness of the denoised image.
[0092] In some alternative implementations of some embodiments, the initial focal length is any real number within a preset focal length range.
[0093] In some optional implementations of certain embodiments, the target focal length determination unit 504 is configured as follows:
[0094] According to the first preset interval and the composite search method, a first key focal length is determined within a preset focal length range; wherein, the Laplacian variance of the denoised image corresponding to the first key focal length is greater than the Laplacian variance of the denoised image corresponding to each focal length other than the first key focal length within the preset focal length range.
[0095] If the Laplacian variance of the denoised image corresponding to the above key focal length is less than the preset Laplacian variance threshold, then a preset key focal length range is obtained based on the key focal length; wherein, the preset key focal length range is centered on the key focal length, and the preset key focal length range is within the preset focal length range.
[0096] A second preset interval is obtained based on a preset key focal length range; wherein the second preset interval is smaller than the first preset interval.
[0097] According to the second preset interval and composite search method, a second key focal length is determined within a preset key focal length range; wherein, the Laplacian variance of the denoised image corresponding to the second key focal length is equal to or greater than the Laplacian variance of the denoised image corresponding to each focal length other than the second key focal length within the preset focal length range.
[0098] If the Laplacian variance of the denoised image corresponding to the second key focal length is greater than the preset Laplacian variance threshold, then the second key focal length is determined as the target focal length, and autofocus is completed.
[0099] In some alternative implementations of certain embodiments, the target camera described above is an embedded camera module.
[0100] It should be understood that the sequence number of each step in the above embodiments does not imply 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 this disclosure.
[0101] The following is for reference. Figure 6 It illustrates electronic devices suitable for implementing some embodiments of this disclosure (e.g., Figure 1 A schematic diagram of the structure of the computing device 101)600. Figure 6 The server shown is merely an example and should not be construed as limiting the functionality and scope of the embodiments of this disclosure.
[0102] like Figure 6 As shown, electronic device 600 may include a processing unit (e.g., central processing unit, graphics processor, etc.) 601, which can perform various appropriate actions and processes according to a program stored in read-only memory (ROM) 602 or a program loaded from storage device 608 into random access memory (RAM) 603. The RAM 603 also stores various programs and data required for the operation of electronic device 600. The processing unit 601, ROM 602, and RAM 603 are interconnected via bus 604. Input / output (I / O) interface 605 is also connected to bus 604.
[0103] Typically, the following devices can be connected to I / O interface 605: input devices 606 including, for example, touchscreens, touchpads, keyboards, mice, cameras, microphones, accelerometers, gyroscopes, etc.; output devices 607 including, for example, liquid crystal displays (LCDs), speakers, vibrators, etc.; storage devices 608 including, for example, magnetic tapes, hard disks, etc.; and communication devices 609. Communication device 609 allows electronic device 600 to communicate wirelessly or wiredly with other devices to exchange data. Although Figure 6 An electronic device 600 with various devices is shown; however, it should be understood that it is not required to implement or possess all of the devices shown. More or fewer devices may be implemented or possessed alternatively. Figure 6 Each box shown can represent a device or multiple devices as needed.
[0104] In particular, according to some embodiments of this disclosure, the processes described above with reference to the flowcharts can be implemented as computer software programs. For example, some embodiments of this disclosure include a computer program product comprising a computer program carried on a computer-readable medium, the computer program containing program code for performing the methods shown in the flowcharts. In such embodiments, the computer program can be downloaded and installed from a network via a communication device 609, or installed from a storage device 608, or installed from a ROM 602. When the computer program is executed by the processing device 601, it performs the functions defined above in the methods of some embodiments of this disclosure.
[0105] It should be noted that, in some embodiments of this disclosure, the computer-readable medium described above may be a computer-readable signal medium or a computer-readable storage medium, or any combination thereof. A computer-readable storage medium may be, for example,—but not limited to—an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination thereof. More specific examples of a computer-readable storage medium may include, but are not limited to: an electrical connection having one or more wires, a portable computer disk, a hard disk, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fiber, portable compact disk read-only memory (CD-ROM), optical storage device, magnetic storage device, or any suitable combination thereof. In some embodiments of this disclosure, a computer-readable storage medium may be any tangible medium containing or storing a program that can be used by or in conjunction with an instruction execution system, apparatus, or device. In some embodiments of this disclosure, a computer-readable signal medium may include a data signal propagated in baseband or as part of a carrier wave, carrying computer-readable program code. Such propagated data signals may take various forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination thereof. A computer-readable signal medium can be any computer-readable medium other than a computer-readable storage medium, which can send, propagate, or transmit a program for use by or in connection with an instruction execution system, apparatus, or device. The program code contained on the computer-readable medium can be transmitted using any suitable medium, including but not limited to: wires, optical fibers, RF (radio frequency), etc., or any suitable combination thereof.
[0106] In some implementations, clients and servers can communicate using any currently known or future-developed network protocol such as HTTP (Hypertext Transfer Protocol) and can interconnect with digital data communication (e.g., communication networks) of any form or medium. Examples of communication networks include local area networks (“LANs”), wide area networks (“WANs”), the Internet (e.g., the Internet of Things), and peer-to-peer networks (e.g., ad hoc peer-to-peer networks), as well as any currently known or future-developed networks.
[0107] The aforementioned computer-readable medium may be included in the aforementioned device; or it may exist independently and not assembled into the electronic device. The aforementioned computer-readable medium carries one or more programs that, when executed by the electronic device, cause the electronic device to: acquire an image to be processed based on a target camera; wherein the image to be processed contains a plurality of pixels; each pixel has a corresponding initial intensity value; the focal length of 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; acquire a target intensity value for each pixel of the image to be processed based on a bilateral filter to obtain a denoised image; wherein the target intensity value is determined by the distance and intensity difference between each pixel and each of its adjacent pixels; the bilateral filter has a corresponding weight function; the weight function is used to determine the distance and intensity difference between the corresponding pixel and each of its adjacent pixels when acquiring the target intensity value. The weights of distance and intensity differences between a given pixel and its neighbors are determined. The weight of the intensity difference between each pixel and its neighbors is related to the initial intensity value of that pixel. The sharpness of the denoised image is obtained using the Laplacian operator algorithm. The sharpness is described by the Laplacian variance of the denoised image. Based on the initial focal length of the image to be processed, the sharpness of the denoised image, and the preset optimization method, the target focal length of the target camera is determined within a preset focal length range to complete autofocus. The Laplacian variance of the denoised image corresponding to the target focal length is greater than the Laplacian variance of the denoised image corresponding to each focal length other than the target focal length within the preset focal length range, and the Laplacian variance of the denoised image corresponding to the target focal length is greater than a preset Laplacian variance threshold.
[0108] Computer program code for performing operations of some embodiments of this disclosure can be written in one or more programming languages or a combination thereof, including object-oriented programming languages such as Java, Smalltalk, and C++, and conventional procedural programming languages such as the "C" language or similar programming languages. The program code can be executed entirely on the user's computer, partially on the user's computer, as a standalone 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 remote computers, the remote computer can 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 can be connected to an external computer (e.g., via the Internet using an Internet service provider).
[0109] The flowcharts and block diagrams in the accompanying drawings illustrate the architecture, functionality, and operation of possible implementations of systems, methods, and computer program products according to various embodiments of this disclosure. In this regard, each block in a flowchart or block diagram may represent a module, segment, or portion of code containing one or more executable instructions for implementing a specified logical function. It should also be noted that in some alternative implementations, the functions indicated in the blocks may occur in a different order than those indicated in the drawings. For example, two consecutively indicated blocks may actually be executed substantially in parallel, and they may sometimes be executed in reverse order, depending on the functions involved. It should also be noted that each block in the block diagrams and / or flowcharts, and combinations of blocks in the block diagrams and / or flowcharts, can be implemented using a dedicated hardware-based system that performs the specified function or operation, or using a combination of dedicated hardware and computer instructions.
[0110] The units described in some embodiments of this disclosure can be implemented in software or hardware. The described units can also be housed in a processor; for example, a processor may be described as including an image acquisition unit, a noise reduction unit, a sharpness acquisition unit, and a target focal length determination unit. The names of these units do not necessarily limit the specific unit; for example, an acquisition unit may also be described as "a unit that acquires an image to be processed based on a target camera."
[0111] The functions described above in this document can be performed, at least in part, by one or more hardware logic components. For example, exemplary types of hardware logic components that can be used, without limitation, include: Field Programmable Gate Arrays (FPGAs), Application-Specific Integrated Circuits (ASICs), Application Standard Products (ASSPs), System-on-Chip (SoCs), Complex Programmable Logic Devices (CPLDs), and so on.
[0112] The above description is merely a selection of preferred embodiments of this disclosure and an explanation of the technical principles employed. Those skilled in the art should understand that the scope of the invention involved in the embodiments of this disclosure is not limited to technical solutions formed by specific combinations of the above-described technical features, but should also cover other technical solutions formed by arbitrary combinations of the above-described technical features or their equivalents without departing from the above-described inventive concept. For example, technical solutions formed by substituting the above-described features with (but not limited to) technical features with similar functions disclosed in the embodiments of this disclosure.
Claims
1. An automatic focusing method for an online inspection camera, characterized in that, The method includes: According to the target camera, an image to be processed is acquired; wherein, the image to be processed contains a number of pixels; each pixel has a corresponding initial intensity value; the focal length of 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; According to a bilateral filter, the target intensity value of each pixel in the image to be processed is obtained to obtain a denoised image; wherein, the target intensity value is determined by the distance and intensity difference between each pixel and each of its neighboring pixels; 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 of its neighboring pixels and the weight of the intensity difference between the corresponding pixel and each of its neighboring pixels when obtaining the target intensity value; the weight of the intensity difference between each pixel and each of its neighboring pixels is related to the initial intensity value of the pixel; the bilateral filter additionally multiplies the intensity term by a factor in the denominator. J(X) is the initial intensity value of pixel X; The sharpness of the denoised image is obtained according to the Laplacian operator algorithm; wherein the sharpness is described according to the Laplacian variance of the denoised image. Based on the initial focal length corresponding to the image to be processed, the sharpness 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 autofocus; wherein, the Laplacian variance of the denoised image corresponding to the target focal length is greater than the Laplacian variance of the denoised image corresponding to each focal length other than the target focal length within the preset focal length range, and the Laplacian variance of the denoised image corresponding to the target focal length is greater than the preset Laplacian variance threshold. The step involves determining the target focal length of the target camera within a preset focal length range based on the initial focal length of the image to be processed, the clarity of the denoised image, and a preset optimization method, thereby completing automatic focusing; including: According to the first preset interval and the composite search method, a first key focal length is determined within a preset focal length range; wherein, the Laplacian variance of the denoised image corresponding to the first key focal length is greater than the Laplacian variance of the denoised image corresponding to each focal length other than the first key focal length within the preset focal length range. If the Laplacian variance of the denoised image corresponding to the key focal length is less than a preset Laplacian variance threshold, then a preset key focal length range is obtained based on the key focal length; wherein, the preset key focal length range is centered on the key focal length, and the preset key focal length range is within the preset focal length range. A second preset interval is obtained based on a preset key focal length range; wherein the second preset interval is smaller than the first preset interval. According to the second preset interval and the composite search method, the second key focal length is determined within the preset key focal length range; wherein, the Laplacian variance of the denoised image corresponding to the second key focal length is equal to or greater than the Laplacian variance of the denoised image corresponding to each focal length other than the second key focal length within the preset focal length range; the composite search method combines global search and local search. If the Laplacian variance of the denoised image corresponding to the second key focal length is greater than the preset Laplacian variance threshold, then the second key focal length is determined as the target focal length, and autofocus is completed.
2. The online inspection camera autofocus method according to claim 1, characterized in that, The step of acquiring the image to be processed based on the target camera includes: An initial image is acquired based on the target camera; wherein the initial image includes three channels: RGB. The initial image is processed into grayscale to obtain the image to be processed; wherein the image to be processed is a grayscale image.
3. The online inspection camera autofocus method according to claim 1, characterized in that, The step of obtaining the target intensity value of each pixel in the image to be processed based on the bilateral filter to obtain the denoised image includes: Obtain each neighboring pixel of each pixel in the image to be processed; Obtain the weight of each neighboring pixel for each pixel; Based on the weights and initial intensity values of each neighboring pixel of each pixel, the initial intensity values of all neighboring pixels corresponding to each pixel are weighted and summed to obtain the target intensity value of each pixel in the image to be processed, so as to obtain the denoised image.
4. The online inspection camera autofocus method according to claim 1, characterized in that, The process of obtaining the sharpness of the denoised image based on the Laplacian operator algorithm includes: The Laplacian variance of the denoised image is obtained by using the target intensity value of each pixel in the denoised image and the average target intensity value of all pixels in the denoised image. The Laplacian variance of the denoised image is used to determine the sharpness of the denoised image.
5. The online inspection camera autofocus 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 autofocus method according to claim 1, characterized in that, The target camera is an embedded camera module.
7. An automatic focusing device for an online inspection camera, characterized in that, The device includes: The image acquisition unit is configured to acquire an image to be processed based on a target camera; wherein the image to be processed contains a number of pixels; each pixel has a corresponding initial intensity value; the focal length of 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 for each pixel of the image to be processed based on a bilateral filter to obtain a denoised image; wherein the target intensity value is determined by the distance and intensity difference between each pixel and each of its neighboring pixels; 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 of its neighboring pixels and the weight of the intensity difference between the corresponding pixel and each of its neighboring pixels when obtaining the target intensity value; the weight of the intensity difference between each pixel and each of its neighboring pixels is related to the initial intensity value of the pixel; the bilateral filter additionally multiplies the intensity term by a factor. J(X) is the initial intensity value of pixel X; The sharpness acquisition unit is configured to obtain the sharpness of the denoised image according to the Laplacian operator algorithm; wherein the sharpness is described according to the Laplacian 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 based on the initial focal length corresponding to the image to be processed, the sharpness of the denoised image, and a preset optimization method, thereby completing automatic focusing; wherein, the Laplacian variance of the denoised image corresponding to the target focal length is greater than the Laplacian variance of the denoised image corresponding to each focal length other than the target focal length within the preset focal length range, and the Laplacian variance of the denoised image corresponding to the target focal length is greater than a preset Laplacian variance threshold; The target focal length determination unit is configured as follows: According to the first preset interval and the composite search method, a first key focal length is determined within a preset focal length range; wherein, the Laplacian variance of the denoised image corresponding to the first key focal length is greater than the Laplacian variance of the denoised image corresponding to each focal length other than the first key focal length within the preset focal length range. If the Laplacian variance of the denoised image corresponding to the key focal length is less than a preset Laplacian variance threshold, then a preset key focal length range is obtained based on the key focal length; wherein, the preset key focal length range is centered on the key focal length, and the preset key focal length range is within the preset focal length range. A second preset interval is obtained based on a preset key focal length range; wherein the second preset interval is smaller than the first preset interval. According to the second preset interval and the composite search method, the second key focal length is determined within the preset key focal length range; wherein, the Laplacian variance of the denoised image corresponding to the second key focal length is equal to or greater than the Laplacian variance of the denoised image corresponding to each focal length other than the second key focal length within the preset focal length range; the composite search method combines global search and local search. If the Laplacian variance of the denoised image corresponding to the second key focal length is greater than the preset Laplacian variance threshold, then the second key focal length is determined as the target focal length, and autofocus is completed.
8. 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, it implements the steps of the method as described in any one of claims 1 to 6.
9. A computer-readable storage medium storing a computer program, characterized in that, When the computer program is executed by a processor, it implements the steps of the method as described in any one of claims 1 to 6.