Lens focusing method, code reading method and device and code reading camera
By using the pre-calibrated focus position and focus parameters for thick and thin focusing, the problem of low focus efficiency of code reading cameras at long distances is solved, and a faster and more accurate focus process is achieved.
Patent Information
- Application Number
- CN202411934742.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-25
- Publication Date
- 2025-04-25
- Estimated Expiration
- 2044-12-25
AI Technical Summary
The existing code reading cameras have low focus efficiency when working distances are long, resulting in large focus steps and long time.
By pre-calibrated calibration correspondence between the position of the aiming spot in the image and the focus parameters, the current focus parameters are directly determined for coarse adjustment, and fine adjustments are made within the fine adjustment range until the preset clarity conditions are met.
It improves the focus efficiency of the code reading camera, shortens the focus time, and ensures the accuracy of focus.
Smart Images

Figure CN119886174A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of machine vision technology, and in particular to a lens focusing method, a code reading method, a device, and a code reading camera. Background Art
[0002] The barcode reading camera usually includes a lens with adjustable focal length and an image sensor to collect the image of the barcode to be read. The barcode reading camera also includes a processor to decode the acquired image to read the corresponding information content. In order to accurately read the barcode, the barcode reading camera must first be controlled to focus accurately to obtain a clear image of the barcode to be read.
[0003] The related technology needs to focus the lens of the code reading camera through polling, that is, starting from the original value of the focal length, with a preset minimum adjustable unit as the step length, using polling to adjust one step length each time until a clear image can be captured, that is, focusing is completed.
[0004] In this way, when the working distance of the barcode reader is relatively close, the number of focusing steps is not very large, and the focusing can be completed quickly. However, when the working distance is relatively far, the number of focusing steps of this polling method is very large. After each adjustment, the image must be collected and judged whether the image is clear. Therefore, it takes a long time to collect a clear image, resulting in low focusing efficiency.
[0005] Therefore, how to improve the focusing efficiency of code reading cameras is an urgent problem to be solved. Summary of the invention
[0006] The purpose of the embodiments of the present application is to provide a lens focusing method, a code reading method, a device and a code reading camera to improve the focusing efficiency of the code reading camera. The specific technical solution is as follows:
[0007] The embodiment of the present application first provides a lens focusing method, which is applied to a barcode reading camera, wherein the barcode reading camera comprises: a lens with adjustable focal length and an aiming light; the method comprises:
[0008] Acquire a first current image captured by the lens at a current focal length;
[0009] Performing image recognition on the first current image to determine a position of an aiming light spot emitted by the aiming light in the first current image;
[0010] Determine the current focusing parameter corresponding to the first current image by using the calibration correspondence between the pre-calibrated position of the aiming light spot in the image and the focusing parameter;
[0011] Focusing the lens using the current focusing parameter to obtain a second current image captured after the lens is focused;
[0012] When the second current image does not meet the preset clarity condition, based on the preset fine-tuning range of the current focusing parameter, the focal length of the lens is fine-tuned and the image is captured within the fine-tuning range until the captured image meets the preset clarity condition.
[0013] Optionally, the calibration correspondence between the position of the aiming light spot in the image and the focusing parameter is pre-calibrated by the following steps:
[0014] For each preset working distance, determine the working distance between the target and the code reading camera, and when the image captured by the code reading camera for the target meets the preset clarity condition, the focusing parameter used is used as the focusing parameter corresponding to the working distance; wherein each working distance is preset according to the range of distances that the code reading camera can detect;
[0015] For each preset working distance, when determining the distance between the target and the code reading camera at the working distance, the position of the aiming light spot in the image captured by the code reading camera for the target is used as the position corresponding to the working distance;
[0016] For each preset working distance, the corresponding position and focusing parameters are recorded to obtain the calibration correspondence between the position of the aiming light spot in the image and the focusing parameters.
[0017] Optionally, for each preset working distance, determining the working distance between the target and the code reading camera, and when the image captured by the code reading camera for the target meets a preset clarity condition, the focusing parameter used as the focusing parameter corresponding to the working distance includes:
[0018] For each preset working distance, when the target is at the working distance from the code reading camera, a first calibration image captured by the lens at the current focal length for the target is obtained;
[0019] When the first calibration image does not meet the preset clarity condition, the lens is focused and the image is captured by polling until the captured image meets the preset clarity condition, and the focusing parameter used when the image is captured is used as the focusing parameter corresponding to the working distance;
[0020] For each preset working distance, when determining the working distance between the target and the code reading camera, the position of the aiming light spot in the image captured by the code reading camera for the target is used as the position corresponding to the working distance, including:
[0021] For each preset working distance, obtaining a second calibration image acquired by the lens at the current focal length for the target;
[0022] Performing image recognition on the second calibration image to determine the pixel coordinates of the center point of the aiming light spot emitted by the aiming light in the second calibration image as the pixel coordinates corresponding to the working distance;
[0023] The method of recording the corresponding position and focusing parameters for each preset working distance to obtain a calibration correspondence between the position of the aiming light spot in the image and the focusing parameters includes:
[0024] For each preset working distance, the corresponding pixel coordinates and focusing parameters are recorded to obtain the calibration correspondence between the pixel coordinates of the center point of the aiming spot in the image and the focusing parameters.
[0025] Optionally, the focusing parameter is a focusing step number or a driving voltage value;
[0026] In the case where the focusing parameter is the number of focusing steps, focusing the lens and capturing images by polling until the captured image meets the preset clarity condition, and using the focusing parameter used when capturing the image as the focusing parameter corresponding to the working distance, includes:
[0027] The lens is focused and the image is collected by polling until the collected image meets the preset clarity condition, and the number of focus steps used when collecting the image is used as the number of focus steps corresponding to the working distance;
[0028] The method of recording corresponding pixel coordinates and focusing parameters for each preset working distance to obtain a calibration correspondence between the pixel coordinates of the center point of the aiming spot in the image and the focusing parameters includes:
[0029] For each preset working distance, the driving voltage value mapped to the focusing step number corresponding to the working distance is calculated using the mapping relationship between the preset focusing step number and the driving voltage value;
[0030] Record the pixel coordinates corresponding to the working distance and the determined driving voltage value, and obtain the calibration correspondence between the position of the center point of the aiming light spot in the image and the driving voltage value;
[0031] In the case where the focusing parameter is a driving voltage value, focusing the lens and capturing images by polling until the captured image meets a preset clarity condition, and using the focusing parameter used when capturing the image as the focusing parameter corresponding to the working distance, includes:
[0032] The lens is focused and the image is collected by polling until the collected image meets the preset clarity condition, and the driving voltage value used when collecting the image is used as the driving voltage value corresponding to the working distance;
[0033] The method of recording corresponding pixel coordinates and focusing parameters for each preset working distance to obtain a calibration correspondence between the pixel coordinates of the center point of the aiming spot in the image and the focusing parameters includes:
[0034] For each working distance, the corresponding pixel coordinates and driving voltage values are recorded to obtain the calibration correspondence between the position of the center point of the aiming light spot in the image and the driving voltage value.
[0035] Optionally, the fine-tuning range of the current focus parameter is preset, and within the fine-tuning range, the focal length of the lens is fine-tuned and the image is captured until the captured image meets the preset clarity condition, including:
[0036] In a polling manner, the lens is focused and the image is captured using each focusing parameter within the fine-tuning range of the preset current focusing parameter, until the captured image meets the preset clarity condition.
[0037] Optionally, the focusing parameter is a focusing step number or a driving voltage value;
[0038] In the case where the focusing parameter is a focusing step number, determining the current focusing parameter corresponding to the first current image by using a calibration correspondence between a pre-calibrated position of the aiming light spot in the image and the focusing parameter includes:
[0039] Determine the current focusing step number corresponding to the first current image by using the calibration correspondence relationship between the position of the aiming light spot in the image and the focusing step number that is pre-calibrated;
[0040] The step of focusing the lens using the current focusing parameter to obtain a second current image acquired after the lens is focused includes:
[0041] Calculating the driving voltage value mapped by the current focusing step number by using a preset mapping relationship between the focusing step number and the driving voltage value;
[0042] Focusing the lens using the obtained driving voltage value, and acquiring a second current image captured after the lens is focused;
[0043] In the case where the focusing parameter is a driving voltage value, determining the current focusing parameter corresponding to the first current image by using a calibration correspondence between a pre-calibrated position of the aiming light spot in the image and the focusing parameter includes:
[0044] Determine a current driving voltage value corresponding to the first current image by using a calibration correspondence relationship between a pre-calibrated position of the aiming light spot in the image and a driving voltage value;
[0045] The step of focusing the lens using the current focusing parameter to obtain a second current image acquired after the lens is focused includes:
[0046] The lens is focused using the current driving voltage value to obtain a second current image captured after the lens is focused.
[0047] Optionally, determining the current focusing parameter corresponding to the first current image by using a calibration correspondence between a pre-calibrated position of the aiming light spot in the image and the focusing parameter includes:
[0048] When the position of the aiming light spot in the first current image does not exist in each position included in the calibration correspondence, interpolation is performed according to each position included in the calibration correspondence and the corresponding focusing parameters to obtain the current focusing parameters corresponding to the first current image.
[0049] The embodiment of the present application also provides a code reading method, which is applied to a code reading camera, wherein the code reading camera comprises: a lens with adjustable focal length and an aiming light; the method comprises:
[0050] Acquire a first current image captured by the lens at a current focal length;
[0051] Performing image recognition on the first current image to determine a position of an aiming light spot emitted by the aiming light in the first current image;
[0052] Determine the current focusing parameter corresponding to the first current image by using the calibration correspondence between the pre-calibrated position of the aiming light spot in the image and the focusing parameter;
[0053] Focusing the lens using the current focusing parameter to obtain a second current image captured after the lens is focused;
[0054] In the case where the second current image does not meet the preset clarity condition, based on a preset fine-tuning range of the current focus parameter, the focal length of the lens is fine-tuned and the image is captured within the fine-tuning range until the captured image meets the preset clarity condition;
[0055] Read codes based on images that meet preset clarity conditions.
[0056] The embodiment of the present application also provides a lens focusing device, which is applied to a barcode reading camera. The barcode reading camera includes: a lens with adjustable focal length and an aiming light; the device includes:
[0057] A first image acquisition module, used to acquire a first current image captured by the lens at a current focal length;
[0058] An image recognition module, used to perform image recognition on the first current image to determine a position of the aiming light spot emitted by the aiming light in the first current image;
[0059] a current focusing parameter determination module, configured to determine the current focusing parameter corresponding to the first current image by using a pre-calibrated correspondence between the position of the aiming light spot in the image and the focusing parameter;
[0060] A second image acquisition module, used to focus the lens using the current focusing parameters, and acquire a second current image captured after the lens is focused;
[0061] A fine-tuning module is used to, when the second current image does not meet the preset clarity condition, fine-tune the focal length of the lens and capture the image within the fine-tuning range of the preset current focusing parameter, until the captured image meets the preset clarity condition.
[0062] The embodiment of the present application further provides a code reading device, which is applied to a code reading camera, wherein the code reading camera comprises: a lens with adjustable focal length and an aiming light; the device comprises:
[0063] A first image acquisition module, used to acquire a first current image captured by the lens at a current focal length;
[0064] An image recognition module, used to perform image recognition on the first current image to determine a position of the aiming light spot emitted by the aiming light in the first current image;
[0065] a current focusing parameter determination module, configured to determine the current focusing parameter corresponding to the first current image by using a pre-calibrated correspondence between the position of the aiming light spot in the image and the focusing parameter;
[0066] A second image acquisition module, used to focus the lens using the current focusing parameters, and acquire a second current image captured after the lens is focused;
[0067] A fine-tuning module, configured to, if the second current image does not meet the preset clarity condition, fine-tune the focal length of the lens and capture an image within a preset fine-tuning range of the current focus parameter, until the captured image meets the preset clarity condition;
[0068] The code reading module is used to read codes based on images that meet preset clarity conditions.
[0069] The present application also provides a barcode reading camera, including:
[0070] Adjustable focus lens;
[0071] An aiming light, used for emitting light to form an aiming light spot;
[0072] Memory, used to store computer programs;
[0073] The processor is used to implement any of the above-mentioned lens focusing methods or any of the above-mentioned code reading methods when executing the program stored in the memory.
[0074] An embodiment of the present application further provides a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, any of the above-mentioned lens focusing methods or any of the above-mentioned code reading methods is implemented.
[0075] The application embodiment also provides a computer program product including instructions, which, when executed on a computer, enables the computer to execute any of the lens focusing methods or any of the code reading methods described above.
[0076] Beneficial effects of the embodiments of the present application:
[0077] The lens focusing method provided in the embodiment of the present application first uses the calibration correspondence between the position of the pre-calibrated aiming light spot in the image and the focusing parameters to directly determine the current focusing parameters corresponding to the image currently captured by the code reading camera, and uses the current focusing parameters to coarsely adjust the lens. The focal length of the lens can be further fine-tuned within the fine-tuning range of the current focusing parameters to complete the focusing. The embodiment of the present application performs focusing twice, coarse adjustment and fine adjustment. During the coarse adjustment process, only the focusing parameters need to be adjusted, and no image acquisition is required, thereby reducing the focusing time, and also ensuring the accuracy of focusing through fine adjustment. Therefore, this solution can improve the focusing efficiency of the code reading camera.
[0078] Of course, implementing any product or method of the present application does not necessarily require achieving all of the advantages described above at the same time. BRIEF DESCRIPTION OF THE DRAWINGS
[0079] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application, and for ordinary technicians in this field, other embodiments can also be obtained based on these drawings.
[0080] Figure 1 A schematic diagram of a flow chart of a first embodiment of a lens focusing method provided in an embodiment of the present application;
[0081] Figure 2 A schematic diagram of a flow chart of a second embodiment of the lens focusing method provided in an embodiment of the present application;
[0082] Figure 3 for Figure 2 A schematic flow chart of a calibration process in a lens focusing method in the illustrated embodiment;
[0083] Figure 4 for Figure 2 Another schematic flow chart of the calibration process in the lens focusing method in the illustrated embodiment;
[0084] Figure 5 A schematic flow chart of a third embodiment of the lens focusing method provided in an embodiment of the present application;
[0085] Figure 6 for Figure 2 Another schematic flow chart of the calibration process in the lens focusing method in the illustrated embodiment;
[0086] Figure 7 A schematic diagram of a flow chart of a code reading method provided in an embodiment of the present application;
[0087] Figure 8 A schematic diagram of the structure of a lens focusing device provided in an embodiment of the present application;
[0088] Fig. 9 A schematic diagram of the structure of a code reading device provided in an embodiment of the present application;
[0089] Fig.10 This is a schematic diagram of the structure of a barcode reading camera provided in an embodiment of the present application. DETAILED DESCRIPTION
[0090] The following will be combined with the drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field based on the present application belong to the scope of protection of the present application.
[0091] Since there is a need for long-distance code reading in current code reading cameras, the working distance of such code reading cameras has a wide range, for example, the working distance needs to be between 20 cm and 18 meters. As a result, the traditional polling focusing method is no longer applicable to such long-distance code reading scenarios.
[0092] In order to improve the focusing efficiency of a code reading camera, the embodiment of the present application provides a lens focusing method, a code reading method, a device and a code reading camera. The lens focusing method and the code reading method can be applied to a code reading camera, which includes: a lens with adjustable focal length and an aiming light.
[0093] The following first introduces the lens focusing method provided in the embodiment of the present application.
[0094] like Figure 1 As shown, the lens focusing method provided in the embodiment of the present application includes the following steps:
[0095] Step S101, acquiring a first current image captured by the lens at a current focal length;
[0096] Step S102, performing image recognition on the first current image to determine the position of the aiming light spot emitted by the aiming light in the first current image;
[0097] Step S103, determining the current focusing parameter corresponding to the first current image by using the calibration correspondence between the pre-calibrated position of the aiming light spot in the image and the focusing parameter;
[0098] Step S104, focusing the lens using the current focusing parameters, and acquiring a second current image captured after the lens is focused;
[0099] Step S105, when the second current image does not meet the preset clarity condition, based on the preset fine-tuning range of the current focus parameter, the focal length of the lens is fine-tuned and the image is captured within the fine-tuning range until the captured image meets the preset clarity condition.
[0100] In this embodiment, the calibration correspondence between the position of the pre-calibrated aiming light spot in the image and the focusing parameters is first used to directly determine the current focusing parameters corresponding to the image currently captured by the code reading camera, and the lens is coarsely adjusted using the current focusing parameters. The focal length of the lens can be further fine-tuned within the fine-tuning range of the current focusing parameters to complete the focusing. The embodiment of the present application performs two focusing steps, coarse adjustment and fine adjustment. During the coarse adjustment process, only the focusing parameters need to be adjusted, and no image acquisition is required. This reduces the focusing time, and the accuracy of the focusing is also ensured by fine adjustment. Therefore, this solution can improve the focusing efficiency of the code reading camera.
[0101] The lens focusing method provided in the embodiment of the present application is introduced below in combination with a specific implementation process. The method is applied to a barcode reading camera, which includes: a lens with adjustable focal length and an aiming light; Figure 2 As shown, the method includes:
[0102] S201, acquiring a first current image captured by the lens at a current focal length;
[0103] The lens in this embodiment may include a variable focus lens, and applying different driving voltages to the variable focus lens can change its shape, thereby changing the curvature of the lens, and further adjusting the focal length of the lens. The relative position between the lens and the aiming light in the code reading camera can be fixed. The aiming light can emit an aiming light spot into the camera field of view of the code reading camera, and the aiming light spot can be circular. The above-mentioned current focal length can be any focal length of the lens. The first current image can be an image captured for the barcode to be identified. The code reading camera in this embodiment can be used to read barcodes, and the barcode can be a one-dimensional barcode, a two-dimensional barcode (i.e., a QR code), etc.
[0104] In a specific scenario, the user can first use the aiming spot to aim the barcode reading camera at the barcode to be identified, and then press a preset button on the surface of the barcode reading camera to issue a barcode reading instruction. At this time, the barcode reading camera can start to execute the various steps of the embodiment of the present application, that is, the barcode reading camera can first capture an image at the current focal length to obtain a first current image.
[0105] S202, performing image recognition on the first current image to determine the position of the aiming light spot emitted by the aiming light in the first current image;
[0106] The position of the aiming light spot in the image may specifically be the pixel coordinates of the center point of the aiming light spot in the image, including the coordinates in the horizontal direction (i.e., the X coordinate) and the coordinates in the vertical direction (i.e., the Y coordinate). A processor and a memory may also be provided in the barcode reading camera, in which a computer program for an algorithm for image recognition may be pre-stored. After acquiring the first current image, the processor in the barcode reading camera may call the algorithm for image recognition to determine the position of the aiming light spot in the first current image.
[0107] In one implementation, the algorithm may be an algorithm based on Blob analysis. When the aiming spot is circular, a circle detection algorithm may be used to determine the position of the aiming spot. For example, the circle detection algorithm may be an edge detection algorithm based on Hough change, which is not specifically limited in this embodiment.
[0108] S203, when the focusing parameter is the focusing step number, using a pre-calibrated corresponding relationship between the position of the aiming light spot in the image and the focusing step number, determining a current focusing step number corresponding to the first current image;
[0109] The focus parameter is a parameter for controlling the focal length of the lens, and each focus parameter uniquely corresponds to the focal length of the lens. For example, the focus parameter can be the number of focus steps, or can be a driving voltage value for controlling the lens deformation in the lens.
[0110] Since the optical axis of the aiming light is not coaxial with the optical axis of the lens, when the aiming light spot is irradiated on the barcode, the position of the aiming light spot in the image will change with the change of the distance between the barcode reading camera and the barcode (i.e., the working distance). When the working distance is fixed, even if the focal length of the lens changes, the position of the center point of the aiming light spot will hardly change. In addition, according to the imaging principle of the camera, when the focusing parameters of the lens are fixed, its focal length is also fixed. At this time, the lens can capture a clear image of the barcode at a specific distance. Therefore, there is a certain correlation between the position of the aiming light spot in the image and the focusing parameters used when capturing a clear image. Therefore, this embodiment can establish a calibration correspondence between the position of the aiming light spot in the image and the focusing parameters during the calibration process. The specific calibration process will be introduced below.
[0111] The number of focus steps can be regarded as the gears for adjusting the focal length of the lens. For example, an increase of one in the focus step indicates that the focal length of the lens has increased by the smallest unit that can be increased, and a decrease of one in the focus step indicates that the focal length of the lens has decreased by the smallest unit that can be decreased.
[0112] When the focus parameter is the number of focus steps, the calibration is the calibration correspondence between the position of the aiming spot in the image and the number of focus steps. For example, the calibration correspondence obtained in the actual calibration process can be shown in the following table. The position and focus parameter in the same row in the table indicate that there is a correspondence between the position and the focus parameter:
[0113] Table 1- Calibration correspondence table
[0114] Focus steps Position (X, Y coordinates) 755 (111,427) 675 (296,427) 632 (397,427) 600 (478,425) 580 (532,424) 570 (562,425) 560 (581,423) 555 (600,425) 547 (619,424) 542 (631,425) 540 (640,425) 535 (646,424) 535 (651,424)
[0115] When using the code reading camera, the position of the aiming light spot in the first current image may be determined first, and then the number of focus steps corresponding to the position of the aiming light spot may be determined according to the calibration correspondence as the current number of focus steps corresponding to the first current image.
[0116] S204, calculating the driving voltage value mapped by the current focusing step number by using a preset mapping relationship between the focusing step number and the driving voltage value;
[0117] At present, the variable focus lens can adjust the focal length by different input driving voltage values. There may be a certain mapping relationship between the focus step number and the driving voltage value, and the mapping relationship can generally be expressed as: driving voltage value = KStep × focus step number + VotageBias; wherein KStep and VotageBias are preset constants. For example, in a barcode reading camera, KStep = 0.0445, VotageBias = 33.9675. Since these two preset constants may be different for different lenses, and are related to the manufacturers and models of different variable focus lenses, this is just an example. Therefore, after obtaining the current focus step number, this embodiment can bring the current focus step number into the mapping relationship to obtain the mapped driving voltage value.
[0118] S205, focusing the lens using the obtained driving voltage value, acquiring a second current image captured after the lens is focused, and executing step 208;
[0119] It can be understood that since the calibration correspondence reflects the relationship between the position of the aiming light spot in the image and the focusing steps when the captured image is clear, and the time interval between the two frames of images captured by the barcode reading camera is very short, when the second current image and the first current image are captured, the distance between the barcode reading camera and the barcode to be read will not change greatly. Therefore, the lens is focused according to the current focusing steps corresponding to the first current image, that is, the lens is focused using the obtained driving voltage value, and the captured second current image is also likely to be an image with higher clarity.
[0120] S206, when the focusing parameter is a driving voltage value, using a pre-calibrated correspondence between the position of the aiming light spot in the image and the driving voltage value, determining a current driving voltage value corresponding to the first current image;
[0121] S207, focusing the lens using the current driving voltage value, acquiring a second current image captured after the lens is focused, and executing step 208;
[0122] Regarding steps S206-S207: When the focus parameter is a driving voltage value, for example, when the barcode reading camera can directly detect the driving voltage value used, the calibration correspondence between the position of the aiming light spot in the image and the driving voltage value can be directly calibrated in advance, and then the driving voltage value can be directly used as the focus parameter. In this way, when focusing is required, the driving voltage value can be directly adjusted without adjusting the focusing steps and converting the focusing steps into the driving voltage value, thereby further improving the focusing efficiency of the barcode reading camera.
[0123] S208, when the second current image does not meet the preset clarity condition, based on the preset fine-tuning range of the current focus parameter, the focal length of the lens is fine-tuned and the image is captured within the fine-tuning range until the captured image meets the preset clarity condition.
[0124] In order to further ensure the accuracy of focusing, the present embodiment can first detect whether the second current image meets the preset clarity condition, and if not, fine-tune the current focus parameter until an image with the preset clarity condition is acquired and the focus is completed. That is, when the focus parameter is the focus step number, the focus step number is fine-tuned, and when the focus parameter is the drive voltage value, the drive voltage value is fine-tuned.
[0125] In order to determine whether the image meets the preset clarity condition, the image can be first processed using a preset clarity evaluation algorithm to obtain a clarity value, and then determine whether the obtained clarity value is greater than a preset threshold value. If it is greater, it is determined that the preset clarity condition is met, otherwise, it is determined that the preset clarity condition is not met. The clarity evaluation algorithm can be an algorithm such as a Brenner gradient function, an energy gradient function, etc., which is not specifically limited in this embodiment.
[0126] In order to further ensure the clarity of the image, the present embodiment may also divide the image into multiple parts, for example, into five parts: upper left, lower left, upper right, lower right and middle, and then calculate the clarity value of each part of the image respectively, and determine whether the clarity value is greater than a preset threshold. If the clarity values of each part are greater than the preset threshold, the preset clarity condition of the image is determined; otherwise, it is determined that the preset clarity condition is not met.
[0127] The fine-tuning range of the current focus parameter may be a preset numerical range including the current focus parameter, which may be set specifically according to experience and needs. For example, when the current focus parameter is the number of focus steps, the fine-tuning range of the current focus parameter may be a range from the current focus parameter minus 30 steps to plus 30 steps. There may be many ways to fine-tune the focal length of the lens. For example, a focus parameter may be randomly selected within the fine-tuning range of the current focus parameter, and then the selected focus parameter may be used to adjust the focal length of the lens, capture an image, and detect the clarity of the captured image. If the currently captured image does not meet the preset clarity condition, a focus parameter that has not been selected is randomly selected from the fine-tuning range until the clarity of the captured image meets the preset clarity condition.
[0128] In one implementation, a polling method may be used to focus the lens and capture images using various focus parameters within a preset fine-tuning range of the current focus parameter until the captured image meets a preset clarity condition.
[0129] That is to say, starting from the minimum value within the fine-tuning range of the current focusing parameter, the focal length of the lens can be adjusted, the image can be collected, and the clarity of the collected image can be detected. After that, the preset value can be increased each time. The preset value can be the minimum unit that the focusing parameter can be adjusted. For example, when the focusing parameter is the number of focusing steps, it can be increased by one step each time. When the focusing parameter is the driving voltage value, the preset minimum voltage value can be increased each time until the collected image meets the preset clarity condition. Of course, it is also possible to start from the maximum value within the fine-tuning range of the current focusing parameter and reduce the preset value each time. By fine-tuning the focal length of the lens in this polling manner, the accurate focusing parameters within the fine-tuning range will not be missed, which can improve the success rate of focusing.
[0130] In this embodiment, the calibration correspondence between the position of the pre-calibrated aiming light spot in the image and the focusing parameters is first used to directly determine the current focusing parameters corresponding to the image currently captured by the code reading camera, and the lens is coarsely adjusted using the current focusing parameters. The focal length of the lens can be further fine-tuned within the fine-tuning range of the current focusing parameters to complete the focusing. The embodiment of the present application performs two focusing steps, coarse adjustment and fine adjustment. During the coarse adjustment process, only the focusing parameters need to be adjusted, and no image acquisition is required. This reduces the focusing time, and the accuracy of the focusing is also ensured by fine adjustment. Therefore, this solution can improve the focusing efficiency of the code reading camera.
[0131] In one embodiment of the present application, Figure 3 As shown in FIG. 1 , the calibration correspondence between the position of the aiming spot in the image and the focusing parameters can be pre-calibrated using the following steps:
[0132] S301, for each preset working distance, determining the working distance between the target and the barcode reading camera, and when the image captured by the barcode reading camera for the target meets the preset clarity condition, the focusing parameter used as the focusing parameter corresponding to the working distance; wherein each working distance is preset according to the range of distances that the barcode reading camera can detect;
[0133] The above-mentioned target can be a checkerboard target. For example, when the range of the distance that the code reading camera can detect is 0 to 5 meters, multiple working distances can be selected within 0 to 5 meters for calibration. Generally, when the distance is relatively small, the focal length varies greatly with the distance, so more working distances can be set when the working distance is small. For example, the following working distances can be selected within 0 to 5 meters: 164, 250, 350, 500, 700, 900, 1100, 1400, 1900, 2500, 3200, 4000, 5000 (unit: mm).
[0134] In specific implementation, the barcode reading camera can be placed at each working distance above the target for focusing and image acquisition, so that the barcode reading camera can acquire images that meet the preset clarity conditions at each working distance, and the focusing parameters used when acquiring images that meet the preset clarity conditions at each working distance are recorded as the focusing parameters corresponding to the working distance. The focusing parameters can be determined by polling, and the image that meets the preset clarity conditions can also be the image with the highest clarity among the images acquired during the polling process.
[0135] S302, for each preset working distance, determining the position of the aiming light spot in the image captured by the barcode reading camera for the target when the target is at the working distance from the barcode reading camera, as the position corresponding to the working distance;
[0136] Since the position of the center point of the aiming light spot in the image is only related to the working distance and will not change due to the change of the focal length of the lens, in this step, any image collected during the calibration process for the working distance can be obtained and image recognition can be performed on the image to determine the position of the aiming light spot in the image.
[0137] S303, for each preset working distance, recording the corresponding position and focusing parameters, and obtaining a calibration correspondence between the position of the aiming light spot in the image and the focusing parameters.
[0138] That is to establish a correspondence between the position and the focus parameter corresponding to each working distance. For example, it can be recorded in the form of a table. The position and the focus parameter in the same row in the table indicate that there is a correspondence between the position and the focus parameter. When the focus parameter is the number of focus steps and the position of the aiming spot in the image indicates the pixel coordinates of the center point of the aiming spot in the image, the calibration correspondence obtained in the actual calibration process can be shown in the following table:
[0139] Table 2- Calibration correspondence table
[0140]
[0141]
[0142] In this embodiment, during calibration, a calibration correspondence is established based on the focus parameters used when an image that meets the preset clarity condition can be collected at each working distance, and the position of the aiming light spot in the image at the working distance, which means that when the focus parameters used by the barcode reader to collect images correspond to the position of the aiming light spot in the image at this time, the collected image meets the preset clarity condition, providing a basis for determining the focus parameters according to the calibration correspondence and the position of the aiming light spot in the current image in the subsequent barcode reading process. This improves the focusing efficiency of the barcode reader during the barcode reading process.
[0143] In one embodiment of the present application, Figure 4 As shown, the calibration process may specifically include the following steps:
[0144] S401, for each preset working distance, when the target is at the working distance from the barcode reading camera, obtaining a first calibration image captured by the lens at the current focal length for the target;
[0145] The current focal length can be any focal length, and the first calibration image collected at this time may or may not meet the preset clarity condition. If the first calibration image meets the preset clarity condition, the focus parameter used to collect the first calibration image can be directly used as the focus parameter corresponding to the working distance.
[0146] S402, when the first calibration image does not meet the preset clarity condition, focusing the lens and capturing images in a polling manner until the captured image meets the preset clarity condition, and using the focusing parameters used when capturing the image as the focusing parameters corresponding to the working distance;
[0147] In this step, the lens can be focused by polling in the range from the minimum value to the maximum value of the focus parameter of the code reading camera until an image that meets the preset clarity condition is found, and the focus parameter used at this time is used as the focus parameter corresponding to the working distance. During the calibration process, the lens is focused by polling, and the focus parameter when a clear image is accurately captured will not be missed, so as to ensure the establishment of the calibration correspondence relationship.
[0148] Since the focusing parameter can be the number of focusing steps or the driving voltage value, when the focusing parameter is the number of focusing steps, when the acquired image meets the preset clarity conditions, the number of focusing steps used when acquiring the image can be used as the number of focusing steps corresponding to the working distance; when the focusing parameter is the driving voltage value, when the acquired image meets the preset clarity conditions, the driving voltage value used when acquiring the image can be used as the driving voltage value corresponding to the working distance.
[0149] S403, for each preset working distance, obtaining a second calibration image captured by the lens at the current focal length for the target;
[0150] The second calibration image may be any image acquired during the calibration process for the working distance, for example, the second calibration image may be the same image as the first calibration image.
[0151] S404, performing image recognition on the second calibration image, determining the pixel coordinates of the center point of the aiming light spot emitted by the aiming light in the second calibration image as the pixel coordinates corresponding to the working distance;
[0152] As experiments show, when the working distance increases, the X coordinate of the center point of the aiming light spot increases rapidly. When it reaches a certain distance, the X coordinate tends to a constant value, the focusing parameter also tends to a constant value, and the Y coordinate hardly changes in the whole process. Therefore, the pixel coordinates of the aiming light spot may also include only the X coordinate, and the working distance to be calibrated may be preset accordingly. For example, when the working distance is greater than 5 meters, the X coordinate tends to a constant value, and the focusing parameter also tends to a constant value. Even if the distance that the code reading camera can detect is greater than 5 meters, the working distance may be selected from 0 to 5 meters for calibration.
[0153] In addition, the image recognition process can refer to the above embodiment and will not be described in detail here.
[0154] S405 , for each working distance, recording the corresponding pixel coordinates and focusing parameters, and obtaining a calibration correspondence between the pixel coordinates of the center point of the aiming light spot in the image and the focusing parameters.
[0155] In the case where the focusing parameter is the number of focusing steps, the driving voltage value mapped by the focusing steps corresponding to the working distance can be calculated by using the mapping relationship between the preset number of focusing steps and the driving voltage value for each working distance; then the pixel coordinates corresponding to the working distance and the determined driving voltage value are recorded to obtain the calibrated corresponding relationship between the position of the center point of the aiming light spot in the image and the driving voltage value. In the case where the focusing parameter is the number of focusing steps, the corresponding pixel coordinates and the driving voltage value can be recorded for each working distance to obtain the calibrated corresponding relationship between the position of the aiming light spot in the image and the driving voltage value.
[0156] By establishing a calibration correspondence between the position of the center point of the aiming light spot in the image and the driving voltage value, when focusing is required in the subsequent code reading process, the corresponding driving voltage value can be directly determined according to the calibration correspondence without mapping the focusing steps, which can further improve the focusing efficiency.
[0157] In this embodiment, during calibration, the lens is focused and the image is captured by polling to determine the focusing parameters corresponding to each working distance, as well as the pixel coordinates of the center point of the aiming light spot emitted by the aiming light in the image, to obtain the pixel coordinates corresponding to each working distance. Finally, for each working distance, the corresponding pixel coordinates and focusing parameters are recorded to obtain the calibrated correspondence between the pixel coordinates of the center point of the aiming light spot in the image and the focusing parameters, which provides a basis for implementing the calibrated correspondence between the position of the aiming light spot in the image and the focusing parameters.
[0158] Since the data recorded in the above calibration process are all discrete data, therefore, in an embodiment of the present application, the above step S103 may include:
[0159] When there is no position of the aiming spot in the first current image in each position included in the calibration correspondence, interpolation is performed according to each position included in the calibration correspondence and the corresponding focusing parameters to obtain the current focusing parameters corresponding to the first current image.
[0160] Specifically, each position included in the calibration correspondence may be the above-mentioned X coordinate. The current focusing parameter may be obtained by linear interpolation, that is, taking each two adjacent positions in the calibration correspondence as two endpoint values of an interval, obtaining an interval composed of each position included in the calibration correspondence, and then determining the interval to which the position of the aiming light spot in the first current image belongs, and establishing a linear function according to the two endpoint values of the interval and the corresponding focusing parameter, obtaining a function of the focus parameter varying with the position within the interval, and finally bringing the position of the aiming light spot in the first current image into the function, to obtain the current focusing parameter.
[0161] In this embodiment, the current focusing parameter corresponding to the first current image is obtained by interpolating the positions and the corresponding focusing parameters included in the calibration correspondence. When there is no position of the aiming spot in the first current image among the positions included in the calibration correspondence, a basis for implementing the determination of the current focusing parameter corresponding to the first current image is provided, so that the solution of the present application can be applied to a variety of different situations.
[0162] For ease of understanding, the following Figure 5-Figure 6 The focusing process and calibration process of the code reading camera are introduced by way of example.
[0163] like Figure 5 As shown, the focusing process of the barcode reading camera may include the following steps:
[0164] S501, aiming a barcode reading camera at a barcode to be read;
[0165] S502, finding the pixel coordinates of the aiming light spot in the image of the barcode reading camera;
[0166] For example, a circle search algorithm may be used to determine the pixel coordinates of the center point of the aiming light spot in the first current image captured by the code reading camera.
[0167] S503, using the pixel coordinates to find the focus step number stored in the barcode reading camera;
[0168] That is, according to the calibration correspondence between the position of the pre-calibrated aiming light spot in the image and the focusing parameter, the current focusing parameter corresponding to the first current image is determined;
[0169] S504, using linear interpolation to calculate the number of focus steps for pixel coordinates within a certain working distance range;
[0170] That is, when there is no position of the aiming spot in the first current image among the positions included in the calibration correspondence, interpolation is performed based on the positions included in the calibration correspondence and the corresponding focus steps to obtain the current focus step corresponding to the first current image.
[0171] S505, adjusting the focus distance of the barcode reading camera using the focus step number;
[0172] S506, fine-tuning the focus step number by polling within a certain range of the focus step number;
[0173] That is, based on the preset fine-tuning range of the current focus step number, the focal length of the lens is fine-tuned and the image is captured within the fine-tuning range.
[0174] S507, a clear image can be finally obtained.
[0175] Combine the following Figure 6 The calibration process is introduced as an example. Figure 6 As shown, the process may include the following steps:
[0176] S601, set several working distances;
[0177] S602, focusing in a polling manner at each working distance to find the best definition of the barcode reading camera, and recording the number of focusing steps at this time;
[0178] That is, for each preset working distance, the number of focusing steps used when the target is at the working distance from the barcode reading camera and the image captured by the barcode reading camera for the target meets the preset clarity condition is determined.
[0179] S603, using a circle search algorithm to search for the X and Y coordinates of the aiming spot in the camera image;
[0180] That is, for each preset working distance, when the target is at the working distance from the barcode reading camera, the pixel coordinates of the center point of the aiming light spot in the image captured by the barcode reading camera for the target are determined.
[0181] S604, writing the focus step number, the corresponding X, Y coordinates and the working distance at this time into the barcode reading camera;
[0182] That is, for each preset working distance, the corresponding pixel coordinates and focusing steps are recorded to obtain the calibration correspondence between the pixel coordinates of the center point of the aiming spot in the image and the focusing steps.
[0183] S605, determining whether all preset working distances have been calibrated; if not, returning to S602; if yes, ending the calibration process.
[0184] In this embodiment, the calibration correspondence between the position of the pre-calibrated aiming light spot in the image and the focusing parameters is first used to directly determine the current focusing parameters corresponding to the image currently captured by the code reading camera, and the lens is coarsely adjusted using the current focusing parameters. The focal length of the lens can be further fine-tuned within the fine-tuning range of the current focusing parameters to complete the focusing. The embodiment of the present application performs two focusing steps, coarse adjustment and fine adjustment. During the coarse adjustment process, only the focusing parameters need to be adjusted, and no image acquisition is required. This reduces the focusing time, and the accuracy of the focusing is also ensured by fine adjustment. Therefore, this solution can improve the focusing efficiency of the code reading camera.
[0185] The embodiment of the present application also provides a code reading method, which can be applied to a code reading camera, the code reading camera comprising: a lens with adjustable focal length and an aiming light; Figure 7 As shown, the method may include the following steps:
[0186] S701, acquiring a first current image captured by the lens at a current focal length;
[0187] S702, performing image recognition on the first current image to determine the position of the aiming light spot emitted by the aiming light in the first current image;
[0188] S703, determining a current focusing parameter corresponding to the first current image by using a pre-calibrated correspondence relationship between a position of the aiming light spot in the image and the focusing parameter;
[0189] S704, focusing the lens using the current focusing parameters, and acquiring a second current image captured after the lens is focused;
[0190] S705, when the second current image does not meet the preset clarity condition, based on a preset fine-tuning range of the current focus parameter, fine-tune the focal length of the lens and capture an image within the fine-tuning range until the captured image meets the preset clarity condition;
[0191] The above steps S701-S705 are similar to steps S101-S105 and will not be repeated here.
[0192] S706, reading a code based on the image that meets a preset definition condition.
[0193] After acquiring an image that meets the preset clarity condition, the barcode reading camera can use a processor to first identify whether there is a recognizable barcode in the image. If so, the image is decoded to obtain the information carried by the barcode in the image.
[0194] In this embodiment, the calibration correspondence between the position of the pre-calibrated aiming light spot in the image and the focusing parameter is used to directly determine the current focusing parameter corresponding to the image currently collected by the code reading camera, and then the focal length of the lens is fine-tuned within the fine-tuning range of the current focusing parameter. This can narrow the range of the focusing parameter to be determined, reduce the number of times the focal length of the lens is adjusted, and also reduce the images to be collected and detected. Therefore, this solution can improve the focusing efficiency of the code reading camera, thereby improving the efficiency of the code reading camera in reading codes.
[0195] The embodiment of the present application also provides a lens focusing device, which is applied to a barcode reading camera, wherein the barcode reading camera comprises: a lens with adjustable focal length and an aiming light; Figure 8 As shown, the device comprises:
[0196] A first image acquisition module 801 is used to acquire a first current image captured by the lens at a current focal length;
[0197] An image recognition module 802 is used to perform image recognition on the first current image to determine the position of the aiming light spot emitted by the aiming light in the first current image;
[0198] A current focusing parameter determination module 803, configured to determine the current focusing parameter corresponding to the first current image by using a pre-calibrated correspondence between the position of the aiming light spot in the image and the focusing parameter;
[0199] A second image acquisition module 804 is used to focus the lens using the current focusing parameters to acquire a second current image captured after the lens is focused;
[0200] The fine-tuning module 805 is used to, when the second current image does not meet the preset clarity condition, fine-tune the focal length of the lens and capture the image within the fine-tuning range of the preset current focusing parameter, until the captured image meets the preset clarity condition.
[0201] Optionally, the lens focusing device may further include the following module, which is used to pre-calibrate the calibration correspondence between the position of the aiming light spot in the image and the focusing parameter:
[0202] A calibration parameter determination module is used to determine, for each preset working distance, the distance between the target and the code reading camera, and the focusing parameter used when the image captured by the code reading camera for the target meets the preset clarity condition, as the focusing parameter corresponding to the working distance; wherein each working distance is preset according to the range of distances that the code reading camera can detect;
[0203] A calibration position determination module, used for determining, for each preset working distance, the position of the aiming light spot in the image captured by the code reading camera for the target when the target is at the working distance from the code reading camera, as the position corresponding to the working distance;
[0204] The corresponding relationship recording module is used to record the corresponding position and focusing parameters for each preset working distance, and obtain the calibrated corresponding relationship between the position of the aiming light spot in the image and the focusing parameters.
[0205] Optionally, the calibration parameter determination module includes:
[0206] A first calibration image acquisition submodule is used to acquire, for each preset working distance, a first calibration image captured by the lens at a current focal length for the target when the target is at the working distance from the barcode reading camera;
[0207] A parameter determination submodule, for, when the first calibration image does not meet the preset clarity condition, focusing the lens and acquiring the image by polling, until the acquired image meets the preset clarity condition, and using the focusing parameter used when acquiring the image as the focusing parameter corresponding to the working distance;
[0208] The calibration position determination module comprises:
[0209] A second calibration image acquisition submodule, used for acquiring, for each preset working distance, a second calibration image acquired by the lens at the current focal length for the target;
[0210] A pixel coordinate determination submodule, used to perform image recognition on the second calibration image, and determine the pixel coordinates of the center point of the aiming light spot emitted by the aiming light in the second calibration image as the pixel coordinates corresponding to the working distance;
[0211] The corresponding relationship recording module is specifically used for:
[0212] For each working distance, the corresponding pixel coordinates and focusing parameters are recorded to obtain the calibration correspondence between the pixel coordinates of the center point of the aiming spot in the image and the focusing parameters.
[0213] Optionally, the focusing parameter is a focusing step number or a driving voltage value;
[0214] In the case where the focusing parameter is the number of focusing steps, the parameter determination submodule is specifically used for:
[0215] The lens is focused by polling until the acquired image meets the preset clarity condition, and the number of focus steps used when acquiring the image is used as the number of focus steps corresponding to the working distance;
[0216] The corresponding relationship recording module includes:
[0217] A voltage calculation submodule, for calculating the driving voltage value mapped by the focusing step number corresponding to the working distance using a preset mapping relationship between the focusing step number and the driving voltage value for each working distance;
[0218] A corresponding relationship recording submodule is used to record the pixel coordinates corresponding to the working distance and the determined driving voltage value, and obtain a calibration corresponding relationship between the position of the aiming light spot in the image and the driving voltage value;
[0219] In the case where the focusing parameter is a driving voltage value, the parameter determination submodule is specifically used for:
[0220] The lens is focused by polling until the captured image meets the preset clarity condition, and the driving voltage value used when the image is captured is used as the driving voltage value corresponding to the working distance;
[0221] The corresponding relationship recording module is specifically used for:
[0222] For each working distance, the corresponding pixel coordinates and driving voltage values are recorded to obtain the calibration correspondence between the position of the aiming light spot in the image and the driving voltage value.
[0223] Optionally, the fine-tuning module 805 is specifically configured to:
[0224] In a polling manner, the lens is focused and the image is captured using each focusing parameter within the fine-tuning range of the preset current focusing parameter, until the captured image meets the preset clarity condition.
[0225] Optionally, the focusing parameter is a focusing step number or a driving voltage value;
[0226] When the focus parameter is the number of focus steps, the current focus parameter determination module 603 is specifically used to:
[0227] Determine the current focusing step number corresponding to the first current image by using the calibration correspondence relationship between the position of the aiming light spot in the image and the focusing step number that is pre-calibrated;
[0228] The second image acquisition module 804 includes:
[0229] A voltage value determination submodule, used to calculate the driving voltage value mapped by the current focusing step number by using a preset mapping relationship between the focusing step number and the driving voltage value;
[0230] A second current image acquisition submodule, used to focus the lens using the obtained driving voltage value, and acquire a second current image captured after the lens is focused;
[0231] When the focus parameter is a driving voltage value, the current focus parameter determination module 603 is specifically used to:
[0232] Determine a current driving voltage value corresponding to the first current image by using a calibration correspondence relationship between a pre-calibrated position of the aiming light spot in the image and a driving voltage value;
[0233] The second image acquisition module 804 is specifically used for:
[0234] The lens is focused using the current driving voltage value to obtain a second current image captured after the lens is focused.
[0235] Optionally, the current focusing parameter determination module 803 is specifically configured to:
[0236] When the position of the aiming light spot in the first current image does not exist in each position included in the calibration correspondence, interpolation is performed according to each position included in the calibration correspondence and the corresponding focusing parameters to obtain the current focusing parameters corresponding to the first current image.
[0237] The embodiment of the present application also provides a code reading device, which is applied to a code reading camera. The code reading camera includes: a lens with adjustable focal length and an aiming light; Fig. 9 As shown, the device comprises:
[0238] A first image acquisition module 901 is used to acquire a first current image captured by the lens at a current focal length;
[0239] An image recognition module 902 is used to perform image recognition on the first current image to determine the position of the aiming light spot emitted by the aiming light in the first current image;
[0240] A current focusing parameter determination module 903, configured to determine the current focusing parameter corresponding to the first current image by using a pre-calibrated correspondence relationship between the position of the aiming light spot in the image and the focusing parameter;
[0241] A second image acquisition module 904, configured to focus the lens using the current focusing parameters, and acquire a second current image captured after the lens is focused;
[0242] A fine-tuning module 905 is configured to, if the second current image does not meet the preset clarity condition, fine-tune the focal length of the lens and capture an image within a preset fine-tuning range of the current focus parameter, until the captured image meets the preset clarity condition;
[0243] The code reading module 906 is used to read codes based on images that meet a preset definition condition.
[0244] The present application also provides a barcode reading camera, such as Fig.10 As shown, including:
[0245] Adjustable focus lens 1001;
[0246] The aiming light 1002 is used to emit light to form an aiming light spot;
[0247] Memory 1003, used for storing computer programs;
[0248] The processor 1004 is used to implement any of the above-mentioned lens focusing methods or any of the above-mentioned code reading methods when executing the program stored in the memory 1003.
[0249] In addition, the barcode reading camera may further include a communication bus and / or a communication interface, and the processor 1004, the communication interface, and the memory 1003 communicate with each other via the communication bus.
[0250] The communication bus mentioned in the above electronic device can be a Peripheral Component Interconnect (PCI) bus or an Extended Industry Standard Architecture (EISA) bus, etc. The communication bus can be divided into an address bus, a data bus, a control bus, etc. For ease of representation, only one thick line is used in the figure, but it does not mean that there is only one bus or one type of bus.
[0251] The communication interface is used for communication between the above electronic device and other devices.
[0252] The memory may include a random access memory (RAM) or a non-volatile memory (NVM), such as at least one disk memory. Optionally, the memory may also be at least one storage device located away from the aforementioned processor.
[0253] The above-mentioned processor can be a general-purpose processor, including a central processing unit (CPU), a network processor (NP), etc.; it can also be a digital signal processor (DSP), an application specific integrated circuit (ASIC), a field programmable gate array (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components.
[0254] In another embodiment provided in the present application, a computer-readable storage medium is further provided, wherein a computer program is stored in the computer-readable storage medium, and when the computer program is executed by a processor, any of the above-mentioned lens focusing methods or any of the above-mentioned code reading methods is implemented.
[0255] In another embodiment provided in the present application, a computer program product including instructions is also provided. When the computer program product is run on a computer, the computer executes the lens focusing method or the code reading method described in any of the above embodiments.
[0256] In the above embodiments, it can be implemented in whole or in part by software, hardware, firmware or any combination thereof. When implemented using software, it can be implemented in whole or in part in the form of a computer program product. The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, the process or function described in the embodiment of the present application is generated in whole or in part. The computer may be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions may be stored in a computer-readable storage medium, or transmitted from one computer-readable storage medium to another computer-readable storage medium, for example, the computer instructions may be transmitted from a website site, computer, server or data center by wired (e.g., coaxial cable, optical fiber, digital subscriber line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.) mode to another website site, computer, server or data center. The computer-readable storage medium may be any available medium that a computer can access or a data storage device such as a server or data center that includes one or more available media integrated. The available medium may be a magnetic medium, (e.g., a floppy disk, a hard disk, a tape), an optical medium (e.g., a DVD), or a solid-state hard disk (SSD), etc.
[0257] It should be noted that, in this article, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, the elements defined by the sentence "comprise a ..." do not exclude the existence of other identical elements in the process, method, article or device including the elements.
[0258] Each embodiment in this specification is described in a related manner, and the same or similar parts between the embodiments can be referred to each other, and each embodiment focuses on the differences from other embodiments. In particular, for the device, readable storage medium, and computer program embodiments, since they are basically similar to the method embodiments, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiments.
[0259] The above description is only a preferred embodiment of the present application and is not intended to limit the protection scope of the present application. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present application are included in the protection scope of the present application.
Claims
1. A lens focusing method, characterized in that: Applied to a barcode reading camera, the barcode reading camera comprises: a lens with adjustable focal length and an aiming light; the method comprises: Acquire a first current image captured by the lens at a current focal length; Performing image recognition on the first current image to determine a position of an aiming light spot emitted by the aiming light in the first current image; Determine the current focusing parameter corresponding to the first current image by using the calibration correspondence between the pre-calibrated position of the aiming light spot in the image and the focusing parameter; Focusing the lens using the current focusing parameter to obtain a second current image captured after the lens is focused; When the second current image does not meet the preset clarity condition, based on the preset fine-tuning range of the current focusing parameter, the focal length of the lens is fine-tuned and the image is captured within the fine-tuning range until the captured image meets the preset clarity condition.
2. The method according to claim 1, characterized in that The calibration correspondence between the position of the aiming light spot in the image and the focusing parameter is pre-calibrated using the following steps: For each preset working distance, determine the working distance between the target and the code reading camera, and when the image captured by the code reading camera for the target meets the preset clarity condition, the focusing parameter used is used as the focusing parameter corresponding to the working distance; wherein each working distance is preset according to the range of distances that the code reading camera can detect; For each preset working distance, when determining the distance between the target and the code reading camera at the working distance, the position of the aiming light spot in the image captured by the code reading camera for the target is used as the position corresponding to the working distance; For each preset working distance, the corresponding position and focusing parameters are recorded to obtain the calibration correspondence between the position of the aiming light spot in the image and the focusing parameters.
3. The method according to claim 2, characterized in that For each preset working distance, determining the working distance between the target and the code reading camera, and when the image captured by the code reading camera for the target meets the preset clarity condition, the focusing parameter used as the focusing parameter corresponding to the working distance includes: For each preset working distance, when the target is at the working distance from the code reading camera, a first calibration image captured by the lens at the current focal length for the target is obtained; When the first calibration image does not meet the preset clarity condition, the lens is focused and the image is captured by polling until the captured image meets the preset clarity condition, and the focusing parameter used when the image is captured is used as the focusing parameter corresponding to the working distance; For each preset working distance, when determining the working distance between the target and the code reading camera, the position of the aiming light spot in the image captured by the code reading camera for the target is used as the position corresponding to the working distance, including: For each preset working distance, obtaining a second calibration image acquired by the lens at the current focal length for the target; Performing image recognition on the second calibration image to determine the pixel coordinates of the center point of the aiming light spot emitted by the aiming light in the second calibration image as the pixel coordinates corresponding to the working distance; The method of recording the corresponding position and focusing parameters for each preset working distance to obtain a calibration correspondence between the position of the aiming light spot in the image and the focusing parameters includes: For each preset working distance, the corresponding pixel coordinates and focusing parameters are recorded to obtain the calibration correspondence between the pixel coordinates of the center point of the aiming spot in the image and the focusing parameters.
4. The method according to claim 3, characterized in that The focusing parameter is the number of focusing steps or the driving voltage value; In the case where the focusing parameter is the number of focusing steps, focusing the lens and capturing images by polling until the captured image meets a preset clarity condition, and using the focusing parameter used when capturing the image as the focusing parameter corresponding to the working distance, includes: The lens is focused and the image is collected by polling until the collected image meets the preset clarity condition, and the number of focus steps used when collecting the image is used as the number of focus steps corresponding to the working distance; The method of recording corresponding pixel coordinates and focusing parameters for each preset working distance to obtain a calibration correspondence between the pixel coordinates of the center point of the aiming spot in the image and the focusing parameters includes: For each preset working distance, the driving voltage value mapped to the focusing step number corresponding to the working distance is calculated using the mapping relationship between the preset focusing step number and the driving voltage value; Record the pixel coordinates corresponding to the working distance and the determined driving voltage value, and obtain the calibration correspondence between the position of the center point of the aiming light spot in the image and the driving voltage value; In the case where the focusing parameter is a driving voltage value, focusing the lens and capturing images by polling until the captured image meets a preset clarity condition, and using the focusing parameter used when capturing the image as the focusing parameter corresponding to the working distance, includes: The lens is focused and the image is collected by polling until the collected image meets the preset clarity condition, and the driving voltage value used when collecting the image is used as the driving voltage value corresponding to the working distance; The method of recording corresponding pixel coordinates and focusing parameters for each preset working distance to obtain a calibration correspondence between the pixel coordinates of the center point of the aiming spot in the image and the focusing parameters includes: For each working distance, the corresponding pixel coordinates and driving voltage values are recorded to obtain the calibration correspondence between the position of the center point of the aiming light spot in the image and the driving voltage value.
5. The method according to claim 1, characterized in that The fine-tuning range of the current focus parameter is preset, and within the fine-tuning range, the focal length of the lens is fine-tuned and the image is captured until the captured image meets the preset clarity condition, including: In a polling manner, the lens is focused and the image is captured using each focusing parameter within the fine-tuning range of the preset current focusing parameter, until the captured image meets the preset clarity condition.
6. The method according to claim 5, characterized in that The focusing parameter is the number of focusing steps or the driving voltage value; In the case where the focusing parameter is a focusing step number, determining the current focusing parameter corresponding to the first current image by using a calibration correspondence between a pre-calibrated position of the aiming light spot in the image and the focusing parameter includes: Determine the current focusing step number corresponding to the first current image by using the calibration correspondence relationship between the position of the aiming light spot in the image and the focusing step number that is pre-calibrated; The step of focusing the lens using the current focusing parameter to obtain a second current image acquired after the lens is focused includes: Calculating the driving voltage value mapped by the current focusing step number by using a preset mapping relationship between the focusing step number and the driving voltage value; Focusing the lens using the obtained driving voltage value, and acquiring a second current image captured after the lens is focused; In the case where the focusing parameter is a driving voltage value, determining the current focusing parameter corresponding to the first current image by using a calibration correspondence between a pre-calibrated position of the aiming light spot in the image and the focusing parameter includes: Determine a current driving voltage value corresponding to the first current image by using a calibration correspondence relationship between a pre-calibrated position of the aiming light spot in the image and a driving voltage value; The step of focusing the lens using the current focusing parameter to obtain a second current image acquired after the lens is focused includes: The lens is focused using the current driving voltage value to obtain a second current image captured after the lens is focused.
7. The method according to claim 1, characterized in that The method of determining the current focusing parameter corresponding to the first current image by using the calibration correspondence between the pre-calibrated position of the aiming light spot in the image and the focusing parameter comprises: When the position of the aiming light spot in the first current image does not exist in each position included in the calibration correspondence, interpolation is performed according to each position included in the calibration correspondence and the corresponding focusing parameters to obtain the current focusing parameters corresponding to the first current image.
8. A code reading method, characterized in that: Applied to a barcode reading camera, the barcode reading camera comprises: a lens with adjustable focal length and an aiming light; the method comprises: Acquire a first current image captured by the lens at a current focal length; Performing image recognition on the first current image to determine a position of an aiming light spot emitted by the aiming light in the first current image; Determine the current focusing parameter corresponding to the first current image by using the calibration correspondence between the pre-calibrated position of the aiming light spot in the image and the focusing parameter; Focusing the lens using the current focusing parameter to obtain a second current image captured after the lens is focused; In the case where the second current image does not meet the preset clarity condition, based on a preset fine-tuning range of the current focus parameter, the focal length of the lens is fine-tuned and the image is captured within the fine-tuning range until the captured image meets the preset clarity condition; Read codes based on images that meet preset clarity conditions.
9. A lens focusing device, characterized in that: Applied to a barcode reading camera, the barcode reading camera comprises: a lens with adjustable focal length and an aiming light; the device comprises: A first image acquisition module, used to acquire a first current image captured by the lens at a current focal length; An image recognition module, used to perform image recognition on the first current image to determine a position of the aiming light spot emitted by the aiming light in the first current image; a current focusing parameter determination module, configured to determine the current focusing parameter corresponding to the first current image by using a pre-calibrated correspondence between the position of the aiming light spot in the image and the focusing parameter; A second image acquisition module, used to focus the lens using the current focusing parameters, and acquire a second current image captured after the lens is focused; A fine-tuning module is used to, when the second current image does not meet the preset clarity condition, fine-tune the focal length of the lens and capture the image within the fine-tuning range of the preset current focusing parameter, until the captured image meets the preset clarity condition.
10. A code reading device, characterized in that: Applied to a barcode reading camera, the barcode reading camera comprises: a lens with adjustable focal length and an aiming light; the device comprises: A first image acquisition module, used to acquire a first current image captured by the lens at a current focal length; An image recognition module, used to perform image recognition on the first current image to determine a position of the aiming light spot emitted by the aiming light in the first current image; a current focusing parameter determination module, configured to determine the current focusing parameter corresponding to the first current image by using a pre-calibrated correspondence between the position of the aiming light spot in the image and the focusing parameter; A second image acquisition module, used to focus the lens using the current focusing parameters, and acquire a second current image captured after the lens is focused; A fine-tuning module, configured to, if the second current image does not meet the preset clarity condition, fine-tune the focal length of the lens and capture an image within a preset fine-tuning range of the current focus parameter, until the captured image meets the preset clarity condition; The code reading module is used to read codes based on images that meet preset clarity conditions.
11. A code reading camera, characterized in that: include: Adjustable focus lens; An aiming light, used for emitting light to form an aiming light spot; Memory, used to store computer programs; A processor, for implementing the method described in any one of claims 1 to 7 or claim 8 when executing a program stored in a memory.
12. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the method according to any one of claims 1 to 7 or claim 8 is implemented.
13. A computer program product comprising instructions, characterized in that When the computer program product is run on a computer, the computer is enabled to execute the method according to any one of claims 1 to 7 or claim 8.
Citation Information
Patent Citations
Focusing method and device, electronic equipment and storage medium
CN111432125A
Laser beam target coupling sensor
CN114089310A
Focusing method and device, electronic equipment and storage medium
CN115150553A
Automatic focusing method and device, electronic equipment and storage medium
CN116723398A
Focusing adjustment method, system and equipment of contact lens full-inspection visual equipment and medium
CN118379360A