Industrial camera adaptive focusing method and device

By designing an adaptive focus method in industrial cameras and combining image processing technology, the problem of inaccurate image definition evaluation caused by the lack of automatic focus algorithm in the prior art is solved, and higher image definition and detection effects are achieved.

CN120128797APending Publication Date: 2025-06-10INSPUR QILU SOFTWARE IND
View PDF 0 Cites 1 Cited by

Patent Information

Application Number
CN202510345133.0
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-03-24
Publication Date
2025-06-10

AI Technical Summary

Technical Problem

Due to the lack of automatic focus algorithm in the cable quality detection of existing industrial cameras, the image clarity evaluation is inaccurate and misjudgment is prone to occur, especially when the cable surface is smooth.

Method used

By designing an adaptive focus method in an industrial camera, using a computer-controlled lens to automatically zoom within a preset focal length range, combining image processing technology to separate the cable area, use an adaptive image sharpness algorithm to calculate the clarity of each photo, and take the focal length of the photo with the highest definition as the optimal focal length to achieve adaptive focus.

Benefits of technology

It improves the clarity of the image, enhances the detection effect of cable quality inspection, adapts to a variety of lighting environments and backgrounds, and improves the accuracy of image clarity evaluation.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120128797A_ABST
    Figure CN120128797A_ABST
Patent Text Reader

Abstract

The invention relates to the field of automatic focusing of industrial cameras, in particular to a self-adaptive focusing method and device for an industrial camera, a camera and a lens are connected with a computer through a serial port or an internet access, a focal length range empirical value corresponding to a cable diameter is stored in the computer, and after the cable diameter of a to-be-detected cable is determined before each time of detection, the focal length range empirical value of the to-be-detected cable is determined; the computer controls the lens to continuously and automatically zoom within the empirical value range, obtains a group of photos, records the focal length corresponding to each photo, analyzes the image features of each photo, separates the foreground and background of the image, obtains the cable area, needing to be focused, of the industrial camera, and calculates the definition of each photo by using a self-adaptive image definition algorithm. And taking the focal length of the picture with the highest definition as the optimal focal length, and adjusting the lens to the optimal focal length to complete adaptive focusing. Compared with the prior art, the cable image definition evaluation method can adapt to various illumination environments and backgrounds, and the accuracy of the cable image definition evaluation method is effectively improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of automatic focusing of industrial cameras, and specifically provides an adaptive focusing method and device for industrial cameras. Background Art

[0002] When using computer vision algorithms for cable quality inspection, the clarity of the photo is crucial for the quality inspection effect. Industrial cameras generally do not come with automatic focusing algorithms and need to be developed by users themselves. The core of the automatic focusing algorithm is the image clarity evaluation algorithm. An effective image clarity evaluation algorithm can accurately find the clearest photo and thus determine the focused focal length. Since the surface of the cable is made of smooth rubber material, the pixel values in the photo change little, lacking obvious features such as edges and textures.

[0003] When using traditional image clarity evaluation algorithms based on gradients and frequency domains to evaluate the clarity of the entire image, the difference between clear images and blurred images is small, and misjudgment is likely to occur. Summary of the Invention

[0004] The present invention aims at the above-mentioned deficiencies of the prior art and provides a practical adaptive focusing method for industrial cameras.

[0005] A further technical task of the present invention is to provide a reasonably designed, safe and applicable adaptive focusing device for industrial cameras.

[0006] The technical solution adopted by the present invention to solve its technical problems is as follows:

[0007] An adaptive focusing method for industrial cameras, where the camera and the lens are connected to a computer through a serial port or a network port. The computer stores the empirical value of the focal length range corresponding to the cable diameter. After determining the cable diameter to be detected before each detection, the computer controls the lens to continuously autofocus within this empirical value range, obtains a set of photos and records the focal length corresponding to each photo, analyzes the image features of each photo, separates the foreground and background of the image, obtains the cable area that the industrial camera needs to focus on, calculates the clarity of each photo using an adaptive image clarity algorithm, takes the focal length of the photo with the highest clarity as the optimal focal length, and adjusts the lens to the optimal focal length to complete adaptive focusing.

[0008] Further, the specific steps are as follows:

[0009] S1. Determine the cable diameter to be detected;

[0010] S2. Obtain the cable area adaptively through image processing;

[0011] S3. Calculate the clarity of the cable area;

[0012] S4. Calculate the clarity of the cable edge;

[0013] S5. Obtain the overall sharpness of the image through weighted processing;

[0014] S6. Take the focal length corresponding to the photo with the highest sharpness score as the optimal focal length.

[0015] Further, in step S1, the control program internally sets the range of focal length experience values corresponding to the wire diameter [f s , f l , divide it evenly [f s , f l interval into n parts, with an interval of δ = (f l -f s ) / n; the control program controls the automatic zoom lens to zoom n times according to the interval δ, and takes a photo after each zoom is completed to obtain the corresponding focal lengths [f 1 , f 2 , …, f n and the corresponding n photos [I 1 , I 2 , …, I n , for each photo I n Calculate the sharpness score of the picture.

[0016] Further, in step S2, specifically, use a Gaussian filter to remove photo noise and initialize the segmentation threshold T= ∑ i / N , where i is the gray value of each pixel and N is the number of pixels; segment the picture into R1 and R2 two regions; calculate the average gray value of R1 and R2 regions respectively t1 and t2 , update the threshold T to T = ( t1 +t 2 ) / 2, repeat the above steps until the change in the T value is less than the threshold Δ to obtain the foreground and background segmentation threshold T, and use the threshold T to binarize the photo and separate the cable region from the background.

[0017] Further, in step S3, specifically, the width of the cable area is calculated as w and the height is calculated as h according to the cable area obtained in step S2. If the ratio of w to h is greater than 1, the cable direction is the horizontal direction of the photo; otherwise, the cable direction is the vertical direction of the photo.

[0018] Locate the upper and lower edge positions of the cable along the horizontal direction of the cable using the Sobel operator of OpenCV to locate the cable area, and use the Laplacian operator of OpenCV to calculate the clarity of the cable area, which is recorded as the score. S 1 .

[0019] Further, in step S4, specifically, according to the cable direction and the upper and lower edge positions obtained in step S3, use the Sobel operator of OpenCV along the vertical direction of the cable to accumulate the gradient of each column of pixels as the clarity of the cable edge, which is recorded as the score. S2 .

[0020] Further, in step S5, the S 1 and S 2 calculated in step S3 and step S4 are weighted processed in a certain proportion to obtain the total image clarity score S = λS 1 +(1 - λ)S 2 , where λ is a number between (0, 1).

[0021] Further, in step S6, after repeating steps S2 to S3 for each photo to obtain the clarity of all photos, take the focal length corresponding to the photo with the highest clarity score as the optimal focal length, and the control program controls the lens to automatically zoom to this focal length to complete the adaptive focusing.

[0022] An industrial camera adaptive focusing device includes: at least one memory and at least one processor;

[0023] The at least one memory is used to store machine-readable programs;

[0024] The at least one processor is used to call the machine-readable program to execute an industrial camera adaptive focusing method.

[0025] Compared with the prior art, an industrial camera adaptive focusing method and device of the present invention have the following outstanding beneficial effects:

[0026] The present invention can adaptively adjust the lens focal length to ensure the clarity of the image, thereby improving the detection effect of cable quality inspection. It can adapt to a variety of lighting environments and backgrounds, effectively improving the accuracy of the cable image clarity evaluation method. BRIEF DESCRIPTION OF THE DRAWINGS

[0027] In order to more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the following will briefly introduce the drawings required for the description of the embodiments or the prior art. Obviously, the drawings in the following description are some embodiments of the present invention. For those of ordinary skill in the art, other drawings can be obtained based on these drawings without creative efforts.

[0028] Attached Figure 1 is a schematic flowchart of an adaptive focusing method for an industrial camera;

[0029] Attached Figure 2 is a specific schematic flowchart of an adaptive focusing method for an industrial camera. DETAILED DESCRIPTION OF THE EMBODIMENTS

[0030] In order to enable those skilled in the art of the present technology to better understand the solution of the present invention, the following further detailed description of the present invention is made in conjunction with specific embodiments. Obviously, the described embodiments are only a part of the embodiments of the present invention, rather than all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those of ordinary skill in the art without creative efforts belong to the scope of protection of the present invention.

[0031] The following gives a preferred embodiment:

[0032] As Figure 1 shown, in an adaptive focusing method for an industrial camera in this embodiment, the camera and the lens are connected to a computer through a serial port or a network port. The computer stores empirical values of the focal length range corresponding to the wire diameter of the cable. After determining the wire diameter of the cable to be detected before each detection, the computer controls the lens to continuously and automatically zoom within this empirical value range, obtains a set of photos and records the focal length corresponding to each photo, analyzes the image features of each photo, separates the foreground and background of the image, obtains the cable area that the industrial camera needs to focus on, calculates the clarity of each photo using an adaptive image clarity algorithm, takes the focal length of the photo with the highest clarity as the optimal focal length, and adjusts the lens to the optimal focal length to complete the adaptive focusing.

[0033] The specific process is as follows:

[0034] S1. Determine the wire diameter of the cable to be detected;

[0035] The control program internally stores the empirical value range of the focal length corresponding to the wire diameter [f s , f l , evenly divide [f s , f l interval into n parts, and the interval is δ= (f l -f s ) / n; The control program controls the auto-focus lens to zoom n times at intervals of δ. After each zoom is completed, a photo is taken to obtain the corresponding focal length [f 1 ,f 2 ,…,f n corresponding to the n photos [I 1 ,I 2 ,…,I n , for each photo I n Calculate the sharpness score of the picture.

[0036] S2. Obtain the cable area adaptively through image processing;

[0037] Specifically, use a Gaussian filter to remove photo noise and initialize the segmentation threshold T= ∑ i / N , where i is the gray value of each pixel and N is the number of pixels; segment the picture into R1 and R 2 two regions; calculate R 1 and R 2 the average gray value of the region t1 and t2 , update the threshold T to T = (t 1 + t 2 ) / 2, repeat the above steps until the change in the T value is less than the threshold Δ, obtain the foreground and background segmentation threshold T, binarize the photo using the threshold T, and separate the cable area from the background.

[0038] S3. Calculate the sharpness of the cable area;

[0039] Specifically, calculate the width of the cable area as w and the height as h according to the cable area obtained in step S2. If the ratio of w to h is greater than 1, the cable direction is the horizontal direction of the photo, otherwise the cable direction is the vertical direction of the photo;

[0040] Locate the upper and lower edge positions of the cable along the horizontal direction of the cable using the Sobel operator of OpenCV, so as to locate the cable area, and use the Laplacian operator of OpenCV to calculate the sharpness of the cable area, denoted as the score S 1 .

[0041] S4. Calculate the sharpness of the cable edge;

[0042] Specifically, according to the cable direction and the upper and lower edge positions obtained in step S3, the gradient of each column of pixels is accumulated in the vertical direction of the cable using the Sobel operator of OpenCV, and the sharpness of the cable edge is recorded as the score. S 2 。

[0043] S5. Perform weighted processing to obtain the total sharpness of the image;

[0044] Perform weighted processing on the results calculated in step S3 and step S4 S 1 and S 2 according to a certain ratio to obtain the total sharpness score of the image. S = λS 1 +(1 - λ)S 2 , where λ is a number between (0, 1).

[0045] S6. Take the focal length corresponding to the photo with the highest sharpness score as the optimal focal length;

[0046] After repeating steps S2 to S3 for each photo to obtain the sharpness of all photos, take the focal length corresponding to the photo with the highest sharpness score as the optimal focal length, and the control program controls the lens to automatically zoom to this focal length to complete the adaptive focusing.

[0047] Based on the above method, an industrial camera adaptive focusing device in this embodiment includes: at least one memory and at least one processor;

[0048] The at least one memory is used to store machine-readable programs;

[0049] The at least one processor is used to call the machine-readable program to execute an industrial camera adaptive focusing method.

[0050] The above specific implementation manners are only specific cases of the present invention. The patent protection scope of the present invention includes but is not limited to the above specific implementation manners. Any technical solution that conforms to the above specific implementation manners of the present invention and any appropriate changes or substitutions made by those of ordinary skill in the art shall fall within the patent protection scope of the present invention.

[0051] Although the embodiments of the present invention have been shown and described, for those of ordinary skill in the art, it can be understood that various changes, modifications, substitutions, and variations can be made to these embodiments without departing from the principles and spirits of the present invention. The scope of the present invention is defined by the appended claims and their equivalents.

Claims

1. An industrial camera adaptive focusing method, characterized in that: The camera and lens are connected to a computer via a serial port or a network port. The computer stores empirical values ​​of focal length ranges corresponding to cable diameters. After the diameter of the cable to be detected is determined before each detection, the computer controls the lens to continuously and automatically zoom within this empirical value range, obtains a group of photos and records the focal length corresponding to each photo, analyzes the image features of each photo, separates the foreground and background of the image, obtains the cable area that the industrial camera needs to focus on, uses an adaptive image clarity algorithm to calculate the clarity of each photo, takes the focal length of the photo with the highest clarity as the optimal focal length, and adjusts the lens to the optimal focal length to complete adaptive focusing.

2. The method for adaptive focusing of an industrial camera according to claim 1, characterized in that: The specific steps are as follows: S1. Determine the wire diameter of the cable to be tested; S2, adaptively obtaining the cable area through image processing; S3, calculating the cable area clarity; S4. Calculate the edge clarity of the cable; S5, weighted processing to obtain the total image clarity; S6. Take the focal length corresponding to the photo with the highest clarity score as the optimal focal length.

3. The method for adaptive focusing of an industrial camera according to claim 2, characterized in that: In step S1, the control program has a built-in focal length empirical value range corresponding to the wire diameter [f s ,f l ], evenly divided [f s ,f l ] The interval is n, and the interval is δ = (f l -f s ) / n; the control program controls the automatic zoom lens to zoom n times according to the interval δ, and takes a photo after each zoom is completed to obtain the corresponding focal length [f 1,f2,…,f n ] corresponding to n photos [I 1,I2,…,I n ], for each photo I n Calculate the clarity score of the image.

4. The method for adaptive focusing of an industrial camera according to claim 3, characterized in that: In step S2, a Gaussian filter is used to remove photo noise and initialize the segmentation threshold. T= ∑ i / N , where i is the grayscale value of each pixel, N is the number of pixels; according to the threshold T, the image is divided into R1 and R2 Two areas; calculated separately R1 and R2 The mean gray value of the area t1 and t2 , update the threshold T to T = ( t1 +t2) / 2, repeat the above steps until the T value changes less than the threshold Δ, and get the foreground and background segmentation threshold T. Use the threshold T to binarize the photo and separate the cable area from the background.

5. The method for adaptive focusing of an industrial camera according to claim 4, characterized in that: In step S3, specifically, the width of the cable area is calculated as w and the height is h according to the cable area obtained in step S2. If the ratio of w to h is greater than 1, the cable direction is the horizontal direction of the photo, otherwise the cable direction is the vertical direction of the photo; The Sobel operator of OpenCV is used to locate the upper and lower edges of the cable along the horizontal direction of the cable, thereby locating the cable area. The Laplacian operator of OpenCV is used to calculate the clarity of the cable area and record it as a score. S1 .

6. The method for adaptive focusing of an industrial camera according to claim 5, characterized in that: In step S4, according to the cable direction and upper and lower edge positions obtained in step S3, the Sobel operator of OpenCV is used to accumulate the gradient of each column of pixels in the vertical direction of the cable to record the clarity of the cable edge as a score. S 2.

7. The method for adaptive focusing of an industrial camera according to claim 6, characterized in that: In step S5, the values ​​calculated in step S3 and step S4 are S1 and S2 The total image clarity score is obtained by weighting according to a certain ratio. S = λS 1+(1-λ)S2, where λ is a number between (0,1).

8. The method for adaptive focusing of an industrial camera according to claim 7, characterized in that: In step S6, after repeating steps S2 to S3 for each photo to obtain the clarity of all photos, the focal length corresponding to the photo with the highest clarity score is taken as the optimal focal length, and the control program controls the lens to automatically zoom to the focal length to complete adaptive focusing.

9. An industrial camera adaptive focusing device, characterized in that: include: at least one memory and at least one processor; The at least one memory is used to store a machine-readable program; The at least one processor is configured to call the machine-readable program to execute the method according to any one of claims 1 to 8.

Citation Information

Cited By

  • Wafer defect detection method, wafer defect detection device, wafer defect detection equipment and storage medium

    CN121258957A