A camera focus state evaluation method, device, equipment and storage medium
By determining the edge line and center point of the crosshair focus map in machine vision, extracting a rectangular area, and calculating the average total gradient intensity, the problem of inaccurate focus state caused by changes in working distance during autofocus is solved, achieving higher evaluation accuracy and reliability.
Patent Information
- Application Number
- CN202411211419.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-08-30
- Publication Date
- 2026-02-06
- Estimated Expiration
- 2044-08-30
AI Technical Summary
In machine vision and optical imaging, changes in working distance during autofocus lead to changes in focus state, affecting the accuracy of image sharpness assessment. Existing technologies struggle to ensure accuracy when assessing focus state.
By determining the four edge lines and the center point of the captured crosshair focus image, four rectangular regions with the same length and width and the same offset relative to the center point are extracted, with the edge lines as the center lines. The average total gradient intensity is calculated, and if it is greater than a set threshold, the camera is judged to be in sharp focus.
This reduces the impact of changes in working distance on the evaluation results, and improves the accuracy and reliability of focus status assessment.
Smart Images

Figure CN119183010B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of machine vision industrial detection, and in particular to a camera focus state evaluation method, device, equipment and storage medium. BACKGROUND
[0002] In the field of machine vision and optical imaging technology, it is crucial to adjust the focus ring of the lens and the working distance to achieve the clearest imaging effect. Since there is an error in the judgment of the clear state by the human eye, it is particularly necessary to introduce an automatic focusing technology.
[0003] During the automatic focusing process, some lenses may be significantly affected by the change of the WD (Working Distance), which will cause the change of the focus state, and the accuracy of the human eye judgment will also be affected. In addition, the change of the WD may also cause the proportion of the pattern in the image to change, making it difficult to ensure accuracy when evaluating the focus state. SUMMARY
[0004] The present application provides a camera focus state evaluation method, device, equipment and storage medium, which uses the image center point to ensure the consistency of the intercepted area, thereby reducing the influence of the working distance change on the judgment result. At the same time, through the unified evaluation standard of the total gradient intensity of the area, the accuracy and reliability of the focus state evaluation are further improved.
[0005] In a first aspect, an embodiment of the present application provides a camera focus state evaluation method, which comprises:
[0006] In combination with the first aspect, in an implementation mode, the determination of the four edge lines of the cross focus graph and the image center point comprises:
[0007] A second rectangular area covering the edge line is intercepted in each of the four boundary areas of the cross focus graph;
[0008] The local edge line covered by each second rectangular area is identified, and the center point coordinates of the local edge line are determined;
[0009] A first straight line is formed by connecting the center points of the upper and lower local edge lines, a second straight line is formed by connecting the center points of the left and right local edge lines, and the image center point is determined according to the intersection of the first straight line and the second straight line.
[0010] In combination with the first aspect, in an implementation mode, the identification of the local edge line covered by each second rectangular area and the determination of the center point coordinates of the local edge line comprise:
[0011] Sobel edge detection is used for each second rectangular area to identify the local edge line covered by each second rectangular area.
[0012] Obtaining the row and column coordinates of all edge points of the local edge line, and calculating the center point coordinate of the local edge line through the row and column coordinates.
[0013] In combination with the first aspect, in an implementation manner, the method further includes:
[0014] calculating an inclination angle of the cross focus image relative to a horizontal line according to the first straight line and the second straight line;
[0015] performing rotation correction on the cross focus image according to the inclination angle.
[0016] In combination with the first aspect, in an implementation manner, the calculating the total gradient intensity of the four first rectangular regions and calculating the total gradient intensity mean value includes:
[0017] calculating the gradient amplitude of each pixel point in each first rectangular region, and summing the gradient amplitudes of all pixels to obtain the total gradient intensity of each first rectangular region;
[0018] calculating the total gradient intensity mean value according to the total gradient intensity of the four first rectangular regions.
[0019] In combination with the first aspect, in an implementation manner, the calculating the gradient amplitude of each pixel point in each first rectangular region includes:
[0020] calculating the horizontal gradient component and the vertical gradient component of each pixel using a Sobel operator;
[0021] calculating the gradient amplitude of each pixel according to the horizontal gradient component and the vertical gradient component.
[0022] In combination with the first aspect, in an implementation manner, the method further includes:
[0023] determining whether the machine table for collecting the cross focus image is horizontal by comparing whether the total gradient intensity of the four first rectangular regions is consistent.
[0024] The second aspect provides a camera focus state evaluation device, and the camera focus state evaluation device includes:
[0025] a calculation module configured to determine four edge lines and an image center point of a collected cross focus image;
[0026] a cutting module configured to cut out four first rectangular regions with the corresponding edge lines as the center lines, the same length and width, and the same offset from the image center point according to the four edge lines and the image center point;
[0027] a judging module configured to calculate total gradient intensity of the four first rectangular regions and calculate a total gradient intensity average, and determine that the camera is in focus if the total gradient intensity average is greater than a set threshold.
[0028] In a third aspect, an embodiment of the present application provides a camera focus state evaluation device, which comprises a processor, a memory, and a camera focus state evaluation program stored in the memory and executable by the processor, wherein the camera focus state evaluation program, when executed by the processor, implements the steps of the camera focus state evaluation method described above.
[0029] In a fourth aspect, a computer readable storage medium, which stores a camera focus state evaluation program, wherein the camera focus state evaluation program, when executed by a processor, implements the steps of the camera focus state evaluation method described above.
[0030] The technical scheme provided by the embodiments of the present application has at least the following beneficial effects:
[0031] The camera focus state evaluation method in the present application determines four edge lines of a cross focus image and an image center point; according to the four edge lines and the image center point, four first rectangular regions are intercepted, which have the same length and width and the same offset from the image center point and take the corresponding edge lines as the center lines; total gradient intensity of the four first rectangular regions is calculated and a total gradient intensity average is calculated, and if the total gradient intensity average is greater than a set threshold, it is determined that the camera is in focus.
[0032] That is, the present application uses the image center point to ensure the consistency of the intercepted regions, thereby reducing the influence of the working distance change on the evaluation result. At the same time, through the unified evaluation standard of the total gradient intensity of the regions, the accuracy and reliability of the focus state evaluation are further improved. BRIEF DESCRIPTION OF DRAWINGS
[0033] Figure 1 A flowchart of an embodiment of the camera focus state evaluation method of the present application;
[0034] Figure 2 A schematic diagram of determining the edge lines of the cross focus image of the present application;
[0035] Figure 3 A schematic diagram of determining the image center point of the cross focus image of the present application;
[0036] Figure 4 A schematic diagram of intercepting the first rectangular region based on the image center point of the present application;
[0037] Figure 5 A structural block diagram of an embodiment of the camera focus state evaluation device of the present application;
[0038] Figure 6 This is a schematic diagram of the hardware structure of the camera focus status evaluation device involved in the embodiments of this application. Detailed Implementation
[0039] To enable those skilled in the art to better understand the present application, the technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present application, and not all embodiments. Based on the embodiments in the present application, all other embodiments obtained by those of ordinary skill in the art without creative effort are within the scope of protection of the present application.
[0040] To make the objectives, technical solutions, and advantages of this application clearer, the embodiments of this application will be described in further detail below with reference to the accompanying drawings.
[0041] In a first aspect, embodiments of this application provide a method for evaluating camera focus status.
[0042] In one embodiment, reference is made to Figure 1 , Figure 1 This is a schematic flowchart illustrating an embodiment of the camera focus state evaluation method of this application. Figure 1 As shown, the camera focus status evaluation method includes:
[0043] S1. Determine the four edge lines and the center point of the acquired crosshair focus image;
[0044] Specifically, step S1 includes:
[0045] S11. Extract a second rectangular area covering the edge line from each of the four boundary areas of the cross-shaped focus image;
[0046] See Figure 2 As shown, the crosshair focus map includes four regions, with the boundary line between each pair of adjacent regions. In this embodiment, a second rectangular region covering the boundary line is extracted from each boundary region. Figure 2 The red rectangular area in the diagram, and the four second rectangular areas can be positioned arbitrarily and their sizes can be different, as long as they can cover part of the edge line.
[0047] S12. Identify the local edge lines covered by each second rectangular region and determine the coordinates of the center point of the local edge lines;
[0048] Specifically, this embodiment uses Sobel edge detection for each second rectangular region to identify the local edge line covered by each second rectangular region; obtains the row and column coordinates of all edge points of the local edge line, and calculates the coordinates of the center point of the local edge line using the row and column coordinates.
[0049] Sobel edge detection is an algorithm widely used in image processing, which highlights the edges in the image by calculating the spatial gradient of image brightness. See Figure 2 The green circle is the center point of the local edge line.
[0050] S13, connect the center points of the upper and lower two local edge lines to form a first straight line, and connect the center points of the left and right two local edge lines to form a second straight line, and determine the image center point according to the intersection of the first straight line and the second straight line.
[0051] See Figure 3 The two blue straight lines are the first straight line and the second straight line, and the intersection point between the blue lines (the red circle in the center) is the image center point.
[0052] It is worth noting that Figure 3 The blue straight line in Figure 2 The green straight line in the rectangular frame is coincident, and can be considered as an edge line, that is, extending in four directions along the two blue straight lines with the image center point as the starting point.
[0053] S2, according to the four edge lines and the image center point, four first rectangular regions are cut out, which are the same in length and width and have the same offset from the image center point, and the corresponding edge line is the center line;
[0054] Different from the above-mentioned second rectangular region, the cutting of the first rectangular region is more strictly limited, see Figure 4 The first rectangular region is a narrow rectangular region, and the length and width of the four first rectangular regions are equal, and the edge line is the center line (green line in Figure 4 ), and the four first rectangular regions have the same offset from the image center point, which is mainly to maintain uniformity to some extent for subsequent accurate evaluation of the focusing state.
[0055] Preferably, in order to facilitate processing, before cutting the first rectangular region, it further comprises:
[0056] According to the inclination angle of the cross focus chart relative to the horizontal line, the cross focus chart is rotated and corrected according to the inclination angle, so that the cross focus chart is horizontal.
[0057] S3, calculate the total gradient strength of the four first rectangular regions and calculate the total gradient strength average, if the total gradient strength average is greater than a set threshold, the camera is judged to be in sharp focus.
[0058] In the embodiment, first, the gradient amplitude of each pixel point in each first rectangular region is calculated, and the gradient amplitudes of all pixels are summed to obtain the total gradient strength of each first rectangular region; then the total gradient strength mean value is calculated according to the total gradient strengths of the four first rectangular regions.
[0059] Specifically, the embodiment calculates the horizontal gradient component gx and the vertical gradient component gy of each pixel using the Sobel operator; then the gradient amplitude of each pixel is calculated according to the formula: sqrt(gx(:).^2+gy(:).^2). Finally, the gradient amplitudes of all pixels are summed to obtain the total gradient strength of the first rectangular region.
[0060] wherein, gx: the horizontal gradient component matrix calculated by applying the Sobel operator, each element of which represents the horizontal gradient value of each pixel point in the cropped region cropImg (the first rectangular region). The size of the matrix gx is the same as that of cropImg.
[0061] gy: the vertical gradient component matrix calculated by applying the Sobel operator, each element of which represents the vertical gradient value of each pixel point in the cropped region cropImg. The size of the matrix gy is the same as that of cropImg.
[0062] gx(:): an operation of flattening the horizontal gradient matrix gx into a column vector. The flattening process arranges all elements in gx in a column-first order into a one-dimensional column vector.
[0063] gy(:): an operation of flattening the vertical gradient matrix gy into a column vector. The flattening process arranges all elements in gy in a column-first order into a one-dimensional column vector.
[0064] It is worth noting that the threshold value for evaluating the focusing state of the image can be reasonably set according to the actual situation, which is not limited in the embodiment.
[0065] In addition, after calculating the total gradient strengths of the four first rectangular regions, the level of the machine can also be judged by the consistency of the total gradient strengths, that is, the closer the four total gradient strengths, the higher the level of the machine, so that whether the machine is level can be accurately evaluated based on this.
[0066] In summary, the camera focusing state evaluation method in the application determines the four edge lines of the cross focusing graph collected and the image center point; according to the four edge lines and the image center point, four first rectangular regions are intercepted, which have the corresponding edge lines as the center lines, the same length and width, and the same offset from the image center point; the total gradient strengths of the four first rectangular regions are calculated and the total gradient strength mean value is calculated, and if the total gradient strength mean value is greater than a set threshold value, it is judged that the camera is in sharp focus.
[0067] That is, the present application uses the image center point to ensure the consistency of the intercept region, thereby reducing the influence of the working distance change on the evaluation result. Meanwhile, through the unified evaluation standard of the total gradient intensity of the region, the accuracy and reliability of the focus state evaluation are further improved.
[0068] In a second aspect, the embodiments of the present application further provide a camera focus state evaluation device.
[0069] In an embodiment, the camera focus state evaluation device comprises a calculation module, an intercept module and a judgment module. Figure 5 , Figure 5 An embodiment of the functional modules of the camera focus state evaluation device of the present application is shown in the figure. As shown in the figure, the camera focus state evaluation device comprises a calculation module, an intercept module and a judgment module. Figure 5
[0070] The calculation module is configured to determine the four edge lines of the cross focus image and the image center point.
[0071] The intercept module is configured to intercept four first rectangular regions with the corresponding edge lines as the center lines, the same length and width and the same offset from the image center point according to the four edge lines and the image center point.
[0072] The judgment module is configured to calculate the total gradient intensity of the four first rectangular regions and the total gradient intensity mean value, and if the total gradient intensity mean value is greater than a set threshold value, it is determined that the camera is in sharp focus.
[0073] Further, in an embodiment, the calculation module determines the four edge lines of the cross focus image and the image center point, comprising:
[0074] A second rectangular region covering the edge line is intercepted in each of the four boundary regions of the cross focus image;
[0075] The local edge line covered by each second rectangular region is identified, and the center point coordinates of the local edge line are determined.
[0076] The center points of the upper and lower local edge lines are connected to form a first straight line, and the center points of the left and right local edge lines are connected to form a second straight line. The image center point is determined according to the intersection of the first straight line and the second straight line.
[0077] Further, in an embodiment, the calculation module identifies the local edge line covered by each second rectangular region and determines the center point coordinates of the local edge line, comprising:
[0078] Sobel edge detection is used for each second rectangular region to identify the local edge line covered by each second rectangular region.
[0079] Obtain the row and column coordinates of all edge points of the local edge line, and calculate the center point coordinates of the local edge line through the row and column coordinates.
[0080] Further, in an embodiment, the calculation module is further configured to:
[0081] Calculate an inclination angle of the cross focus image relative to a horizontal line according to the first straight line and the second straight line.
[0082] Perform rotation correction on the cross focus image according to the inclination angle.
[0083] Further, in an embodiment, the judging module calculates a total gradient intensity of the four first rectangular regions and calculates a total gradient intensity mean value, including:
[0084] Calculate the gradient amplitude of each pixel point in each first rectangular region, and sum the gradient amplitudes of all pixels to obtain the total gradient intensity of each first rectangular region.
[0085] Calculate the total gradient intensity mean value according to the total gradient intensities of the four first rectangular regions.
[0086] Further, in an embodiment, the judging module calculates the gradient amplitude of each pixel point in each first rectangular region, including:
[0087] Calculate the horizontal gradient component and the vertical gradient component of each pixel using the Sobel operator.
[0088] Calculate the gradient amplitude of each pixel according to the horizontal gradient component and the vertical gradient component.
[0089] Further, in an embodiment, the judging module is further configured to:
[0090] Determine whether the machine table for collecting the cross focus image is horizontal by comparing whether the total gradient intensities of the four first rectangular regions are consistent.
[0091] The functions of each module in the camera focus state evaluation device correspond to the steps in the camera focus state evaluation method embodiments, and the functions and implementation processes will not be described here.
[0092] In a third aspect, the embodiments of the present application provide a camera focus state evaluation device. The camera focus state evaluation device can be a personal computer (PC), a notebook computer, a server, or other devices with data processing functions.
[0093] Reference Figure 6 , Figure 6A schematic diagram of a hardware structure of a camera focus state evaluation device involved in an embodiment of the present application is shown in FIG. 1. In an embodiment of the present application, the camera focus state evaluation device can include a processor, a memory, a communication interface, and a communication bus.
[0094] The communication bus can be of any type, used to interconnect the processor, the memory, and the communication interface.
[0095] The communication interface includes an input / output (I / O) interface, a physical interface, and a logical interface, etc. used to interconnect devices inside the camera focus state evaluation device, and an interface used to interconnect the camera focus state evaluation device with other devices (e.g. other computing devices or user devices). The physical interface can be an Ethernet interface, a fiber interface, an ATM interface, etc. The user device can be a display, a keyboard, etc.
[0096] The memory can be various types of storage media, such as random access memory (RAM), read-only memory (ROM), non-volatile RAM (NVRAM), flash memory, optical storage, hard disk, programmable ROM (PROM), erasable PROM (EPROM), electrically erasable PROM (EEPROM), etc.
[0097] The processor can be a general-purpose processor, which can invoke a camera focus state evaluation program stored in the memory and execute the camera focus state evaluation method provided by the embodiments of the present application. For example, the general-purpose processor can be a central processing unit (CPU). The method executed by the camera focus state evaluation program when invoked can refer to the embodiments of the camera focus state evaluation method of the present application, which will not be described here.
[0098] Those skilled in the art can understand that the hardware structure shown in FIG. 1 does not constitute a limitation on the present application, and can include more or fewer components than shown, or combine certain components, or different component arrangements. Figure 6
[0099] In a fourth aspect, the embodiments of the present application also provide a readable storage medium.
[0100] The application can store a camera focus state evaluation program on a readable storage medium, wherein the camera focus state evaluation program, when executed by a processor, implements the steps of the camera focus state evaluation method described above.
[0101] The method implemented when the camera focus state evaluation program is executed can refer to the embodiments of the camera focus state evaluation method of the application, which will not be described herein.
[0102] It should be noted that the serial numbers of the embodiments of the application described above are only for description, and do not represent the advantages and disadvantages of the embodiments.
[0103] From the above description of the embodiments, those skilled in the art can clearly understand that the above-mentioned embodiment method can be implemented by means of software and a general hardware platform as required, and of course, it can also be implemented by hardware, but in many cases, the former is a better implementation. Based on such understanding, the technical solutions of the application can be embodied in the form of a software product, which is stored in a storage medium (such as a ROM / RAM, a magnetic disk, or an optical disk) as described above, and includes a plurality of instructions for causing a terminal device to execute the methods described in the various embodiments of the application.
[0104] The terms "include" and "have" and any variations thereof in the specification and claims of the application and the above-described drawings are intended to cover the non-exclusive inclusion. For example, a process, method, system, product, or device including a series of steps or units is not limited to the listed steps or units, but can optionally include steps or units not listed, or can optionally include other steps or units inherent to the process, method, product, or device. The terms "first", "second", and "third" and the like descriptions are used to distinguish different objects, and do not represent the order or limit the types of "first", "second", and "third".
[0105] In the description of the embodiments of the application, "exemplary", "for example", or "for instance" is used to mean as an example, illustration, or description. Any embodiment or design scheme described as "exemplary", "for example", or "for instance" in the embodiments of the application should not be interpreted as more preferred or more advantageous than other embodiments or design schemes. Rather, the words "exemplary", "for example", or "for instance" are intended to present the relevant concept in a specific manner.
[0106] In the description of the embodiments of the present application, unless otherwise specified, " / " means the meaning of or, for example, A / B can mean A or B; "and / or" in the text only describes the relationship of the associated objects, which means that there can be three relationships, for example, A and / or B, which can represent: A exists alone, A and B exist together, and B exists alone, in addition, in the description of the embodiments of the present application, "multiple" means two or more than two.
[0107] In some of the processes described in the embodiments of the present application, a plurality of operations or steps are included in a specific order, but it should be understood that these operations or steps can be executed or executed in parallel without the order in which they appear in the embodiments of the present application, and the serial number of the operation is only used to distinguish different operations, and the serial number itself does not represent any execution order. In addition, these processes can include more or fewer operations, and these operations or steps can be executed in sequence or in parallel, and these operations or steps can be combined.
[0108] The above is only the preferred embodiment of the present application, and does not limit the patent scope of the present application, and any equivalent structure or equivalent process transformation using the content of the specification and drawings of the present application, or directly or indirectly applied to other related technical fields, are also included in the patent protection scope of the present application.
Claims
1. A method of evaluating a focus state of a camera, characterized by, The camera focus state evaluation method comprises: determining four edge lines and an image center point of the collected cross focus image; according to the four edge lines and the image center point, four first rectangular regions are intercepted, each of which has the corresponding edge line as the middle line, the same length and width, and the same offset relative to the image center point; calculating the total gradient intensity of the four first rectangular regions and calculating the total gradient intensity mean value, if the total gradient intensity mean value is greater than a set threshold, it is judged that the camera is in sharp focus; the determination of the four edge lines and the image center point of the collected cross focus image comprises: respectively intercepting a second rectangular region covering the edge line in the four boundary regions of the cross focus image; identifying the local edge line covered by each second rectangular region and determining the center point coordinates of the local edge line; connecting the center points of the upper and lower two local edge lines to form a first straight line, and connecting the center points of the left and right two local edge lines to form a second straight line, and determining the image center point according to the intersection of the first straight line and the second straight line.
2. The camera focus state evaluation method of claim 1, wherein, the identification of the local edge line covered by each second rectangular region and the determination of the center point coordinates of the local edge line comprise: using Sobel edge detection on each second rectangular region to identify the local edge line covered by each second rectangular region; obtaining the row and column coordinates of all edge points of the local edge line, and calculating the center point coordinates of the local edge line through the row and column coordinates.
3. The camera focus state evaluation method of claim 1, wherein, It also includes: calculating the inclination angle of the cross focus image relative to the horizontal line according to the first straight line and the second straight line; rotating the cross focus image according to the inclination angle.
4. The camera focus state evaluation method of claim 1, wherein, the calculation of the total gradient intensity of the four first rectangular regions and the calculation of the total gradient intensity mean value comprise: calculating the gradient amplitude of each pixel point in each first rectangular region, and summing the gradient amplitudes of all pixels to obtain the total gradient intensity of each first rectangular region; calculating the total gradient intensity mean value according to the total gradient intensity of the four first rectangular regions.
5. The camera focus state evaluation method of claim 4, wherein, the calculation of the gradient amplitude of each pixel point in each first rectangular region comprises: using Sobel operator to calculate the horizontal gradient component and the vertical gradient component of each pixel; calculating the gradient amplitude of each pixel according to the horizontal gradient component and the vertical gradient component.
6. The camera focus state evaluation method of claim 1, wherein, It also includes: determining whether the total gradient intensity of the four first rectangular regions is consistent by comparison, to determine whether the machine collecting the cross focus image is horizontal.
7. A camera focus state evaluation apparatus characterized by comprising: The camera focus state evaluation device comprises: a calculation module for determining four edge lines and an image center point of the collected cross focus image; a cutting module for cutting out four first rectangular regions according to the four edge lines and the image center point, each of which has the corresponding edge line as the middle line, the same length and width, and the same offset relative to the image center point; a judgment module for calculating the total gradient intensity of the four first rectangular regions and calculating the total gradient intensity mean value, if the total gradient intensity mean value is greater than a set threshold, it is judged that the camera is in sharp focus; the determination of the four edge lines and the image center point of the collected cross focus image comprises: respectively intercepting a second rectangular region covering the edge line in the four boundary regions of the cross focus image; identifying the local edge line covered by each second rectangular region and determining the center point coordinates of the local edge line; A first straight line is formed by connecting the center points of the upper and lower partial edge lines, and a second straight line is formed by connecting the center points of the left and right partial edge lines. The image center point is determined according to the intersection of the first straight line and the second straight line.
8. A camera focus state evaluation apparatus characterized by comprising: The camera focus state evaluation device includes a processor, a memory, and a camera focus state evaluation program stored on the memory and executable by the processor, wherein the camera focus state evaluation program, when executed by the processor, implements the steps of the camera focus state evaluation method according to any one of claims 1 to 6.
9. A computer-readable storage medium, characterized in that, The computer readable storage medium has stored thereon a camera focus state evaluation program, wherein the camera focus state evaluation program, when executed by a processor, implements the steps of the camera focus state evaluation method according to any one of claims 1 to 6.
Citation Information
Patent Citations
Fisheye camera performance parameter test method and device, computer device and storage medium
CN109194954A
Variable-step automatic focusing method and system
CN109521547A