A lens focusing method, a code reading method, a device, and a code reading camera.
By establishing the correspondence between the pre-calibrated aiming spot position and the focusing parameters in the barcode reader camera, and combining coarse and fine adjustments, the problem of low focusing efficiency at long distances in barcode reader cameras is solved, achieving fast and accurate focusing.
Patent Information
- Application Number
- CN202411934742.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-25
- Publication Date
- 2026-01-06
- Estimated Expiration
- 2044-12-25
AI Technical Summary
Existing barcode scanners are inefficient at focusing from a distance, and traditional polling methods are too time-consuming, making it difficult to focus quickly and accurately.
By establishing a pre-calibrated correspondence between the position of the aiming spot in the image and the focus parameters, the current focus parameters are directly determined, and the focal length is adjusted within the fine-tuning range. This combination of coarse and fine adjustments improves focusing efficiency.
By establishing a pre-defined correspondence between the position of the light spot in the image and the focusing parameters, the current focusing parameters can be directly determined, and the focal length can be adjusted within the fine-tuning range. This reduces focusing time and improves the focusing efficiency and accuracy of the barcode reader camera.
Smart Images

Figure CN119886174B_ABST
Abstract
Description
Technical Field
[0001] This 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 Technology
[0002] A barcode reader camera typically includes an adjustable-focus lens and an image sensor to capture images of the barcode to be read. The camera also includes a processor to decode the acquired image and thus read the corresponding information. To accurately read barcodes, the camera must first be precisely focused to acquire a clear image of the barcode.
[0003] The relevant technology requires focusing the lens of the barcode reader camera through a polling method. That is, starting from the original value of the focal length, the camera adjusts the focus by one step at a time, starting with the preset minimum adjustable unit, until a clear image can be captured, thus completing the focusing.
[0004] This method works relatively quickly when the camera's working distance is short, requiring only a few focusing steps. However, at longer working distances, this polling method requires a large number of focusing steps. After each adjustment, an image needs to be acquired and its sharpness assessed, which takes a considerable amount of time to acquire a clear image, resulting in low focusing efficiency.
[0005] Therefore, improving the focusing efficiency of barcode reader cameras is an urgent problem to be solved. Summary of the Invention
[0006] The purpose of this 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] This application first provides a lens focusing method applied to a barcode reader camera, the barcode reader camera including: an adjustable focal length lens and a aiming light; the method includes:
[0008] Acquire the first current image captured by the lens at the current focal length;
[0009] Perform image recognition on the first current image to determine the position of the aiming spot emitted by the aiming light in the first current image;
[0010] By utilizing the pre-calibrated correspondence between the position of the aiming spot in the image and the focusing parameters, the current focusing parameters corresponding to the first current image are determined.
[0011] The lens is refocused using the current focusing parameters to obtain a second current image after the lens is refocused;
[0012] If the second current image does not meet the preset sharpness condition, the lens focal length is fine-tuned and the image is acquired within the preset fine-tuning range of the current focusing parameters, until the acquired image meets the preset sharpness condition.
[0013] Optionally, the calibration correspondence between the position of the aiming spot in the image and the focusing parameters is pre-calibrated using the following steps:
[0014] For each preset working distance, the focusing parameters used by the barcode reader when the target is at that working distance and the image captured by the barcode reader for the target meets the preset clarity conditions are determined as the focusing parameters corresponding to that working distance; wherein, each working distance is preset according to the range of distances that the barcode reader can detect;
[0015] For each preset working distance, when the target and the barcode reader are at that working distance, the position of the aiming spot in the image captured by the barcode reader for the target is taken as the position corresponding to that 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 spot in the image and the focusing parameters.
[0017] Optionally, the step of determining the focusing parameters used when the target is at a distance from the barcode reader camera at each preset working distance, and the image captured by the barcode reader camera for the target meets a preset clarity condition, as the focusing parameters corresponding to that working distance, includes:
[0018] For each preset working distance, when the target and the code reader camera are at that working distance, acquire the first calibration image of the target captured by the lens at the current focal length;
[0019] If the first calibration image does not meet the preset sharpness condition, the lens is focused and the image is acquired by polling until the acquired image meets the preset sharpness condition. Then, the focusing parameters used when acquiring the image are used as the focusing parameters corresponding to the working distance.
[0020] For each preset working distance, determining the position of the aiming spot in the image captured by the barcode reader camera at the target when the target is at that working distance includes:
[0021] For each preset working distance, acquire a second calibration image of the target captured by the lens at the current focal length;
[0022] Image recognition is performed on the second calibration image to determine the pixel coordinates of the center point of the aiming spot emitted by the aiming light in the second calibration image, which are then used as the pixel coordinates corresponding to the working distance.
[0023] For each preset working distance, the corresponding position and focusing parameters are recorded to obtain the calibration correspondence between the position of the aiming spot in the image and the focusing parameters, including:
[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 the number of focusing steps or the driving voltage value;
[0026] When the focusing parameter is the number of focusing steps, the process of focusing and acquiring images by polling the lens until the acquired image meets the preset sharpness condition, and then using the focusing parameters used when acquiring the image as the focusing parameters corresponding to the working distance, includes:
[0027] The lens is focused and image is acquired by polling until the acquired image meets the preset sharpness condition. The number of focusing steps used when acquiring the image is then used as the number of focusing steps corresponding to the working distance.
[0028] 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, including:
[0029] For each preset working distance, the driving voltage value mapped to the preset number of focusing steps is calculated using the mapping relationship between the preset number of focusing steps and the driving voltage value.
[0030] Record the pixel coordinates corresponding to the working distance and the determined driving voltage value to obtain the calibration correspondence between the position of the center point of the aiming spot in the image and the driving voltage value;
[0031] When the focusing parameter is a driving voltage value, the process of focusing and acquiring images by polling the lens until the acquired image meets a preset sharpness condition, and then using the focusing parameters used when acquiring the image as the focusing parameters corresponding to the working distance, includes:
[0032] The lens is focused and images are acquired by polling until the acquired image meets the preset sharpness condition. The driving voltage value used when acquiring the image is then used as the driving voltage value corresponding to the working distance.
[0033] 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, including:
[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 spot in the image and the driving voltage value.
[0035] Optionally, the fine-tuning based on a preset range of the current focusing parameters, within which the lens focal length is fine-tuned and image acquisition is performed until the acquired image meets the preset sharpness condition, includes:
[0036] Using a polling method, the lens is focused and images are acquired using various focusing parameters within the preset fine-tuning range of the current focusing parameters until the acquired image meets the preset sharpness condition.
[0037] Optionally, the focusing parameter is the number of focusing steps or the driving voltage value;
[0038] When the focusing parameter is the number of focusing steps, determining the current focusing parameter corresponding to the first current image by utilizing the pre-calibrated correspondence between the position of the aiming spot in the image and the focusing parameter includes:
[0039] The current focus step number corresponding to the first current image is determined by using the pre-calibrated correspondence between the position of the aiming spot in the image and the number of focus steps.
[0040] The step of focusing the lens using the current focusing parameters and acquiring the second current image after lens focusing includes:
[0041] The driving voltage value mapped to the current focusing step is calculated by using the preset mapping relationship between the number of focusing steps and the driving voltage value.
[0042] The lens is focused using the obtained driving voltage value, and a second current image is acquired after the lens is focused.
[0043] When the focusing parameter is a driving voltage value, determining the current focusing parameter corresponding to the first current image by utilizing the pre-calibrated correspondence between the position of the aiming spot in the image and the focusing parameter includes:
[0044] The current driving voltage value corresponding to the first current image is determined by using the pre-calibrated correspondence between the position of the aiming spot in the image and the driving voltage value.
[0045] The step of focusing the lens using the current focusing parameters and acquiring the second current image after lens focusing includes:
[0046] The lens is focused using the current driving voltage value to obtain a second current image after the lens is focused.
[0047] Optionally, determining the current focusing parameters corresponding to the first current image by utilizing the pre-calibrated correspondence between the position of the aiming spot in the image and the focusing parameters includes:
[0048] If the aiming spot does not exist 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 focusing parameters to obtain the current focusing parameters corresponding to the first current image.
[0049] This application also provides a code reading method applied to a code reading camera, the code reading camera including: an adjustable focal length lens and a aiming light; the method includes:
[0050] Acquire the first current image captured by the lens at the current focal length;
[0051] Perform image recognition on the first current image to determine the position of the aiming spot emitted by the aiming light in the first current image;
[0052] By utilizing the pre-calibrated correspondence between the position of the aiming spot in the image and the focusing parameters, the current focusing parameters corresponding to the first current image are determined.
[0053] The lens is refocused using the current focusing parameters to obtain a second current image after the lens is refocused;
[0054] If the second current image does not meet the preset sharpness condition, the lens focal length is fine-tuned and the image is acquired within the preset fine-tuning range of the current focusing parameters, until the acquired image meets the preset sharpness condition.
[0055] The code is read based on the image that meets the preset clarity requirements.
[0056] This application embodiment also provides a lens focusing device applied to a barcode reader camera, the barcode reader camera including: an adjustable focal length lens and a aiming light; the device includes:
[0057] The first image acquisition module is used to acquire the first current image captured by the lens at the current focal length;
[0058] The image recognition module is used to perform image recognition on the first current image and determine the position of the aiming spot emitted by the aiming light in the first current image;
[0059] The current focus parameter determination module is used to determine the current focus parameter corresponding to the first current image by using the pre-calibrated correspondence between the position of the aiming spot in the image and the focus parameter;
[0060] The second image acquisition module is used to focus the lens using the current focusing parameters and acquire the second current image after the lens is focused.
[0061] The fine-tuning module is used to fine-tune the focal length of the lens and acquire images within a preset fine-tuning range of the current focusing parameters, based on the preset fine-tuning range of the current focusing parameters, when the second current image does not meet the preset sharpness condition, until the acquired image meets the preset sharpness condition.
[0062] This application embodiment also provides a code reading device applied to a code reading camera, the code reading camera including: an adjustable focal length lens and a aiming light; the device includes:
[0063] The first image acquisition module is used to acquire the first current image captured by the lens at the current focal length;
[0064] The image recognition module is used to perform image recognition on the first current image and determine the position of the aiming spot emitted by the aiming light in the first current image;
[0065] The current focus parameter determination module is used to determine the current focus parameter corresponding to the first current image by using the pre-calibrated correspondence between the position of the aiming spot in the image and the focus parameter;
[0066] The second image acquisition module is used to focus the lens using the current focusing parameters and acquire the second current image after the lens is focused.
[0067] The fine-tuning module is used to fine-tune the focal length of the lens and acquire images within a preset fine-tuning range of the current focusing parameters, based on the preset fine-tuning range of the current focusing parameters, until the acquired image meets the preset sharpness conditions when the second current image does not meet the preset sharpness conditions.
[0068] The code reading module is used to read codes based on images that meet preset clarity conditions.
[0069] This application also provides a barcode reader camera, including:
[0070] Adjustable focus lens;
[0071] A sighting light is used to emit light to form a aiming spot;
[0072] Memory, used to store computer programs;
[0073] The processor, when executing the program stored in the memory, implements any of the lens focusing methods or any of the code reading methods described above.
[0074] This application also provides a computer-readable storage medium storing a computer program, which, when executed by a processor, implements any of the lens focusing methods or code reading methods described above.
[0075] The application also provides a computer program product containing instructions that, when run on a computer, cause 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 in this application:
[0077] The lens focusing method provided in this application first utilizes the pre-calibrated correspondence between the position of the aiming spot in the image and the focusing parameters to directly determine the current focusing parameters corresponding to the image currently acquired by the barcode reader camera. The lens is then coarsely adjusted using these current focusing parameters, and further fine-tuning of the lens's focal length can be performed within the fine-tuning range of these parameters to complete the focusing process. This application embodiment achieves focusing through two stages: coarse and fine. During the coarse adjustment, only the focusing parameters need to be adjusted, without acquiring an image, thus reducing the focusing time. Furthermore, the fine adjustment ensures focusing accuracy. Therefore, this solution improves the focusing efficiency of the barcode reader camera.
[0078] Of course, implementing any product or method of this application does not necessarily require achieving all of the advantages described above at the same time. Attached Figure Description
[0079] To more clearly illustrate the technical solutions in the embodiments of this application or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of this application. For those skilled in the art, other embodiments can be obtained based on these drawings.
[0080] Figure 1 A schematic flowchart of a first embodiment of the lens focusing method provided in this application;
[0081] Figure 2 This is a flowchart illustrating a second embodiment of the lens focusing method provided in this application.
[0082] Figure 3 for Figure 2 A flowchart illustrating the calibration process in the lens focusing method shown in the embodiment;
[0083] Figure 4 for Figure 2 Another flowchart illustrating the calibration process in the lens focusing method shown in the embodiment;
[0084] Figure 5 A schematic flowchart illustrating a third embodiment of the lens focusing method provided in this application.
[0085] Figure 6 for Figure 2 Another flowchart illustrating the calibration process in the lens focusing method shown in the embodiment;
[0086] Figure 7 This is a schematic flowchart of a code reading method provided in an embodiment of this application;
[0087] Figure 8 This is a schematic diagram of the lens focusing device provided in the embodiments of this application;
[0088] Figure 9 This is a schematic diagram of the structure of the code reading device provided in the embodiments of this application;
[0089] Figure 10 This is a schematic diagram of the structure of the barcode reader camera provided in an embodiment of this application. Detailed Implementation
[0090] The technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, and not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those skilled in the art based on this application are within the scope of protection of this application.
[0091] Because current barcode readers require long-distance barcode reading, their working distances range significantly, for example, from 20 centimeters to 18 meters. This makes traditional polling focusing methods unsuitable for such long-distance barcode reading scenarios.
[0092] To improve the focusing efficiency of a barcode reader camera, this application provides a lens focusing method, a barcode reading method, an apparatus, and a barcode reader camera. The lens focusing method and barcode reading method can be applied to a barcode reader camera, which includes an adjustable-focus lens and a targeting light.
[0093] The lens focusing method provided in the embodiments of this application will be described below.
[0094] like Figure 1 As shown, the lens focusing method provided in this application includes the following steps:
[0095] Step S101: Acquire the first current image captured by the lens at the current focal length;
[0096] Step S102: Perform image recognition on the first current image to determine the position of the aiming spot emitted by the aiming light in the first current image;
[0097] Step S103: Using the pre-calibrated calibration correspondence between the position of the aiming spot in the image and the focusing parameters, determine the current focusing parameters corresponding to the first current image;
[0098] Step S104: Focus the lens using the current focusing parameters and acquire the second current image after focusing.
[0099] Step S105: If the second current image does not meet the preset sharpness condition, the focal length of the lens is fine-tuned and the image is acquired within the fine-tuning range of the preset current focus parameters, until the acquired image meets the preset sharpness condition.
[0100] In this embodiment, the current focusing parameters corresponding to the image currently being captured by the barcode reader are directly determined by utilizing the pre-calibrated correspondence between the position of the aiming spot in the image and the focusing parameters. The lens is then coarsely adjusted using these current focusing parameters, and further fine-tuning of the lens's focal length can be performed within the fine-tuning range of these parameters to complete the focusing process. This embodiment achieves focusing through two stages: coarse and fine. During the coarse adjustment, only the focusing parameters need to be adjusted, without acquiring an image, thus reducing the focusing time. Furthermore, the fine adjustment ensures focusing accuracy. Therefore, this solution improves the focusing efficiency of the barcode reader.
[0101] The lens focusing method provided in this application embodiment is described below with reference to a specific implementation process. This method is applied to a barcode reader camera, which includes: an adjustable focal length lens and a aiming light; such as Figure 2 As shown, the method includes:
[0102] S201, acquire the first current image captured by the lens at the current focal length;
[0103] The lens in this embodiment may include a variable-focus lens. Applying different driving voltages to the variable-focus lens can change its shape, thereby altering the curvature of the lens and adjusting the focal length. The relative position between the lens and the aiming light in the barcode reader camera can be fixed. The aiming light can emit an aiming spot into the field of view of the barcode reader camera; this aiming spot can be circular. The aforementioned 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 recognized. The barcode reader camera in this embodiment can be used to read barcodes, which can be one-dimensional barcodes or two-dimensional barcodes (i.e., QR codes), etc.
[0104] In a specific scenario, the user can first use the aiming spot to align the barcode reader with the barcode to be identified, and then press the preset button on the surface of the barcode reader to issue a barcode reading command. At this time, the barcode reader can start to execute the steps of the embodiments of this application, that is, the barcode reader can first acquire an image at the current focal length to obtain the first current image.
[0105] S202, perform image recognition on the first current image to determine the position of the aiming spot emitted by the aiming light in the first current image;
[0106] The position of the aiming spot in the image can specifically be the pixel coordinates of the center point of the aiming spot in the image, including the horizontal coordinates (X coordinate) and the vertical coordinates (Y coordinate). The barcode reader camera can also be equipped with a processor and a memory. The memory can pre-store a computer program for image recognition algorithms. After acquiring the first current image, the processor in the barcode reader camera can call this algorithm to perform image recognition and determine the position of the aiming spot in the first current image.
[0107] In one implementation, the algorithm can be based on blob analysis. When the aiming spot is circular, a circle detection algorithm can also be used to determine the position of the aiming spot. For example, the circle detection algorithm can be an edge detection algorithm based on Hough transform; this embodiment does not impose specific limitations.
[0108] S203, when the focusing parameter is the number of focusing steps, the current number of focusing steps corresponding to the first current image is determined by using the pre-calibrated correspondence between the position of the aiming spot in the image and the number of focusing steps.
[0109] Among them, focusing parameters are those that control the focal length of the lens, and each focusing parameter uniquely corresponds to the focal length of the lens. For example, focusing parameters can be the number of focusing steps, or they can be the driving voltage value that controls the lens deformation in the lens.
[0110] Because the optical axis of the aiming lamp and the optical axis of the lens are not coaxial, when the aiming spot illuminates the barcode, its position in the image changes with the distance between the barcode reader and the barcode (i.e., the working distance). When the working distance is fixed, even if the lens focal length changes, the position of the center point of the aiming spot hardly changes. Furthermore, according to the imaging principle of a camera, when the lens's focusing parameters are fixed, its focal length is also fixed. At this point, 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 spot in the image and the focusing parameters used to capture a clear image. Thus, this embodiment can establish a calibration correspondence between the position of the aiming spot in the image and the focusing parameters during the calibration process. The specific calibration process will be described below.
[0111] The number of focus steps can be seen as the adjustment level of the lens focal length. For example, increasing the number of focus steps by one indicates that the lens focal length has increased by the smallest possible unit, while decreasing the number of focus steps by one indicates that the lens focal length has decreased by the smallest possible unit.
[0112] When the focusing parameter is the number of focusing steps, the calibration determines the correspondence between the position of the aiming spot in the image and the number of focusing steps. For example, the calibration correspondence obtained during the actual calibration process can be shown in the table below. In this table, the position and focusing parameter in the same row indicate that there is a correspondence between that position and that focusing parameter:
[0113] Table 1 - Calibration Correspondence Table
[0114] Focusing steps Location (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 a code reader camera, you can first determine the position of the aiming spot in the first current image, and then determine the number of focusing steps corresponding to the position of the aiming spot according to the calibration correspondence, which is used as the current number of focusing steps corresponding to the first current image.
[0116] S204: Calculates the driving voltage value mapped to the current focusing step using the preset mapping relationship between the focusing step number and the driving voltage value.
[0117] Currently, zoom lenses can adjust their focal length by varying the input drive voltage value. A mapping relationship exists between the number of focusing steps and the drive voltage value, typically expressed as: Drive voltage value = KStep × Number of focusing steps + VotageBias; where KStep and VotageBias are preset constants. For example, in a barcode scanner, KStep = 0.0445 and VotageBias = 33.9675. Since these two preset constants may differ for different lenses, depending on the manufacturer and model of the zoom lens, this is merely an example. Therefore, in this embodiment, after obtaining the current number of focusing steps, the current number of focusing steps can be substituted into this mapping relationship to obtain the mapped drive voltage value.
[0118] S205, use the obtained driving voltage value to focus the lens, acquire the second current image after the lens is focused, and execute step 208;
[0119] Understandably, since the calibration correspondence reflects the relationship between the position of the aiming spot in the image and the number of focusing steps when the acquired image is clear, and the time interval between the two frames acquired by the barcode reader is very short, the distance between the barcode reader and the barcode to be read will not change much when acquiring the second current image and the first current image. Therefore, the lens is focused according to the current number of focusing steps corresponding to the first current image, that is, the lens is focused using the obtained driving voltage value, and the acquired second current image is also likely to be an image with high clarity.
[0120] S206, when the focusing parameter is the driving voltage value, the current driving voltage value corresponding to the first current image is determined by using the pre-calibrated calibration correspondence between the position of the aiming spot in the image and the driving voltage value.
[0121] S207, use the current driving voltage value to focus the lens, acquire the second current image after the lens is focused, and execute step 208;
[0122] Regarding steps S206-S207: When the focusing parameter is the driving voltage value, for example, when the barcode reader camera can directly detect the driving voltage value used, the calibration correspondence between the position of the aiming spot in the image and the driving voltage value can be pre-calibrated, and then the driving voltage value can be directly used as the focusing parameter. In this way, when focusing is required, the driving voltage value can be adjusted directly without adjusting the number of focusing steps or converting the number of focusing steps into a driving voltage value, thereby further improving the focusing efficiency of the barcode reader camera.
[0123] S208, if the second current image does not meet the preset sharpness condition, based on the preset fine-tuning range of the current focusing parameters, within the fine-tuning range, fine-tuning the focal length of the lens and acquiring the image until the acquired image meets the preset sharpness condition.
[0124] To further ensure focusing accuracy, this embodiment first checks whether the second current image meets the preset sharpness condition. If not, it then fine-tunes the current focusing parameters until an image meeting the preset sharpness condition is acquired, thus completing focusing. In other words, when the focusing parameter is the number of focusing steps, the number of focusing steps is fine-tuned; when the focusing parameter is the driving voltage value, the driving voltage value is fine-tuned.
[0125] To determine whether an image meets the preset sharpness condition, a preset sharpness evaluation algorithm can be used to process the image to obtain a sharpness value. Then, it can be determined whether the obtained sharpness value is greater than a preset threshold. If it is greater, the preset sharpness condition is determined to be met; otherwise, it is determined that the preset sharpness condition is not met. The sharpness evaluation algorithm can be the Brenner gradient function, energy gradient function, etc., and this embodiment does not specify a particular algorithm.
[0126] To further ensure image clarity, this embodiment can divide the image into multiple parts, such as five parts: upper left, lower left, upper right, lower right, and center. Then, the sharpness value is calculated for each part of the image, and it is determined whether the sharpness value is greater than a preset threshold. If the sharpness value of each part is greater than the preset threshold, the image is determined to meet the preset sharpness condition; otherwise, it is determined that the preset sharpness condition is not met.
[0127] The fine-tuning range of the current focus parameter can be a pre-set numerical range that includes the current focus parameter. The specific range can be set based on experience and needs. For example, if the current focus parameter is the number of focus steps, the fine-tuning range can be from 30 steps less than the current focus parameter to 30 steps more. There are several ways to fine-tune the lens's focal length. For instance, a focus parameter can be randomly selected within the fine-tuning range of the current focus parameter. Then, the selected focus parameter can be used to adjust the lens's focal length, acquire an image, and check the sharpness of the acquired image. If the currently acquired image does not meet the preset sharpness condition, a previously unselected focus parameter can be randomly selected from the fine-tuning range until the sharpness of the acquired image meets the preset sharpness condition.
[0128] In one implementation, a polling method can be used to focus the lens and acquire images using various focusing parameters within the preset fine-tuning range of the current focusing parameters, until the acquired image meets the preset sharpness condition.
[0129] In other words, you can start from the minimum value within the current fine-tuning range of the focusing parameters, adjust the lens's focal length, acquire an image, and check the sharpness of the acquired image. Then, each time, increase a preset value. This preset value can be the smallest unit that the focusing parameters can be adjusted. For example, when the focusing parameter is the number of focus steps, you can increase it by one step each time; when the focusing parameter is the drive voltage value, you can increase it by the preset minimum voltage value each time, until the acquired image meets the preset sharpness condition. Alternatively, you can start from the maximum value within the current fine-tuning range of the focusing parameters and decrease the preset value each time. This polling method for fine-tuning the lens's focal length ensures that accurate focusing parameters within the fine-tuning range are not missed, thus improving the success rate of focusing.
[0130] In this embodiment, the current focusing parameters corresponding to the image currently being captured by the barcode reader are directly determined by utilizing the pre-calibrated correspondence between the position of the aiming spot in the image and the focusing parameters. The lens is then coarsely adjusted using these current focusing parameters, and further fine-tuning of the lens's focal length can be performed within the fine-tuning range of these parameters to complete the focusing process. This embodiment achieves focusing through two stages: coarse and fine. During the coarse adjustment, only the focusing parameters need to be adjusted, without acquiring an image, thus reducing the focusing time. Furthermore, the fine adjustment ensures focusing accuracy. Therefore, this solution improves the focusing efficiency of the barcode reader.
[0131] In one embodiment of this application, as Figure 3 As shown, 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, determine the focusing parameters used when the target and the barcode reader are at that working distance and the image acquired by the barcode reader for the target meets the preset clarity conditions, and use these focusing parameters as the working distance corresponding to that working distance; wherein, each working distance is preset according to the range of distances that the barcode reader can detect;
[0133] The aforementioned target can be a checkerboard target. For example, if the range of distance that the barcode reader camera can detect is 0-5 meters, multiple working distances can be selected within this range for calibration. Generally, when the distance is relatively small, the focal length changes significantly with distance, so more working distances can be set when the working distance is small. For example, the following working distances can be selected within the range of 0-5 meters: 164, 250, 350, 500, 700, 900, 1100, 1400, 1900, 2500, 3200, 4000, 5000 (unit: millimeters).
[0134] In practice, the barcode reader camera can be placed at various working distances above the target for focusing and image acquisition. This ensures that the camera acquires images that meet the preset sharpness requirements at each working distance, and the focusing parameters used to acquire the image meeting the preset sharpness requirements at each working distance are recorded as the focusing parameters corresponding to that working distance. These focusing parameters can be determined through polling, in which case the image meeting the preset sharpness requirements can be the image with the highest sharpness among all images acquired during the polling process.
[0135] S302, for each preset working distance, determine the position of the aiming spot in the image captured by the barcode reader camera for the target when the target is at that working distance, and use it as the position corresponding to that working distance;
[0136] Since the position of the center point of the aiming spot in the image is only related to the working distance and will not change with the focal length of the lens, in this step, any image collected during the calibration process for the working distance can be acquired, and image recognition can be performed on the image to determine the position of the aiming spot in the image.
[0137] S303 records the corresponding position and focusing parameters for each preset working distance, and obtains the calibration correspondence between the position of the aiming spot in the image and the focusing parameters.
[0138] This involves establishing the correspondence between the position and the focusing parameter corresponding to each working distance. For example, this can be recorded in a table, where the position and focusing parameter in the same row indicate a correspondence between that position and that focusing parameter. When the focusing parameter is the number of focus steps, and the position of the aiming spot in the image represents the pixel coordinates of the center point of the aiming spot in the image, the calibration correspondence obtained during 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 focusing parameters used to acquire images meeting preset clarity conditions at various working distances, and the position of the aiming spot in the image at that working distance. This means that when the focusing parameters used by the barcode reader camera to acquire an image correspond to the position of the aiming spot in the image at that time, the acquired image meets the preset clarity conditions. This provides a basis for determining the focusing parameters based on the calibration correspondence and the position of the aiming spot in the current image during subsequent barcode reading. This improves the focusing efficiency of the barcode reader camera during barcode reading.
[0143] In one embodiment of this application, as Figure 4 As shown, the calibration process may specifically include the following steps:
[0144] S401, for each preset working distance, when the target and the code reader camera are at that working distance, acquire the first calibration image of the target captured by the lens at the current focal length;
[0145] The current focal length can be any focal length. The first calibration image acquired at this time may or may not meet the preset sharpness condition. If the first calibration image meets the preset sharpness condition, the focusing parameters used to acquire the first calibration image can be directly used as the focusing parameters corresponding to this working distance.
[0146] S402, if the first calibration image does not meet the preset sharpness condition, the lens is focused and the image is acquired by polling until the acquired image meets the preset sharpness condition. Then, the focusing parameters used when acquiring the image are used as the focusing parameters corresponding to the working distance.
[0147] This step involves polling the lens within the range of the minimum to maximum focusing parameters of the barcode reader camera until an image that meets the preset sharpness condition is found. The focusing parameters used at this point are then used as the focusing parameters corresponding to that working distance. By polling the lens during the calibration process, the focusing parameters at which a clear image is accurately captured are not missed, ensuring the establishment of the calibration correspondence.
[0148] Since the focusing parameter can be either the number of focusing steps or the driving voltage value, when the focusing parameter is the number of focusing steps, the number of focusing steps used when acquiring the image can be used as the number of focusing steps corresponding to the working distance if the acquired image meets the preset sharpness condition; when the focusing parameter is the driving voltage value, the driving voltage value used when acquiring the image can be used as the driving voltage value corresponding to the working distance if the acquired image meets the preset sharpness condition.
[0149] S403, for each preset working distance, acquire the second calibration image of the target captured by the lens at the current focal length;
[0150] The second calibration image can be any image acquired during the calibration process for the working distance, such as the same image as the first calibration image.
[0151] S404, Perform image recognition on the second calibration image to determine the pixel coordinates of the center point of the aiming spot emitted by the aiming light in the second calibration image, and use it as the pixel coordinates corresponding to the working distance;
[0152] Experiments have shown that as the working distance increases, the X-coordinate of the center point of the aiming spot increases rapidly. At a certain distance, the X-coordinate tends to a constant value, and the focusing parameters also tend to a constant value, while the Y-coordinate remains almost unchanged throughout the process. Therefore, the pixel coordinates of the aiming spot can include only the X-coordinate, and the working distance to be calibrated can 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 parameters also tend to a constant value. Even if the distance that the barcode reader camera can detect is greater than 5 meters, the working distance can be selected between 0 and 5 meters for calibration.
[0153] Furthermore, the image recognition process can be referred to the above embodiments, and will not be repeated here.
[0154] S405 records the corresponding pixel coordinates and focusing parameters for each working distance, thus obtaining the calibration correspondence between the pixel coordinates of the center point of the aiming spot in the image and the focusing parameters.
[0155] When the focusing parameter is the number of focusing steps, for each working distance, the driving voltage value mapped to that working distance can be calculated using a preset mapping relationship between the number of focusing steps and the driving voltage value. Then, the pixel coordinates corresponding to that working distance and the determined driving voltage value are recorded to obtain the calibration correspondence between the position of the aiming spot's center point in the image and the driving voltage value. Alternatively, when the focusing parameter is the number of focusing steps, for each working distance, the corresponding pixel coordinates and driving voltage value can be recorded to obtain the calibration correspondence between the position of the aiming 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 spot in the image and the driving voltage value, when focusing is required during subsequent code reading, the corresponding driving voltage value can be directly determined based on this calibration correspondence without having to map the focusing steps again, which can further improve the focusing efficiency.
[0157] In this embodiment, during calibration, the lens is focused and images are acquired 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 spot emitted by the aiming light in the image. The pixel coordinates corresponding to each working distance are obtained. Finally, 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. This provides a basis for calibrating the calibration correspondence between the position of the aiming spot in the image and the focusing parameters.
[0158] Since the data recorded during the calibration process are all discrete, in one embodiment of this application, step S103 may include:
[0159] If there is no position of the aiming spot in the first current image among the positions included in the calibration correspondence, the current focusing parameters corresponding to the first current image are obtained by interpolation based on the positions included in the calibration correspondence and the corresponding focusing parameters.
[0160] Specifically, the positions included in the calibration correspondence can be the aforementioned X coordinates. The current focusing parameters can be obtained using linear interpolation. This involves taking each pair of adjacent positions in the calibration correspondence as the two endpoints of an interval, thus obtaining the intervals formed by the positions included in the calibration correspondence. This determines the interval to which the aiming spot's position in the first current image belongs. A linear function is then established based on the two endpoints of this interval and the corresponding focusing parameters. This function shows how the focusing parameters change with position within this interval. Finally, the position of the aiming spot in the first current image is substituted into this function to obtain the current focusing parameters.
[0161] In this embodiment, interpolation is performed based on the positions included in the calibration correspondence and their corresponding focusing parameters to obtain the current focusing parameters corresponding to the first current image. This provides a basis for determining the current focusing parameters corresponding to the first current image even when the aiming spot is not present in the first current image among the positions included in the calibration correspondence, making the solution applicable to various different situations.
[0162] To facilitate understanding, the following will be combined with... Figures 5-6 The focusing process and calibration process of the barcode reader camera are described in an exemplary manner.
[0163] like Figure 5 As shown, the focusing process of a barcode reader camera may include the following steps:
[0164] S501, point the barcode reader at the barcode to be read;
[0165] S502, locate the pixel coordinates of the aiming spot in the image of the barcode reader camera;
[0166] For example, a circle search algorithm can be used to determine the pixel coordinates of the center point of the aiming spot in the first current image captured by the barcode reader camera.
[0167] S503 uses the pixel coordinates to find the focus steps stored in the barcode reader camera;
[0168] That is, the current focusing parameters corresponding to the first current image are determined based on the pre-calibrated correspondence between the position of the aiming spot in the image and the focusing parameters;
[0169] S504: The number of focus steps is calculated using linear interpolation within a certain working distance range for pixel coordinates.
[0170] In other words, if there is no position of the aiming spot in the first current image among the positions included in the calibration correspondence, the current focus step number corresponding to the first current image is obtained by interpolation based on the positions included in the calibration correspondence and the corresponding focus steps.
[0171] S505, use this focus steps to adjust the focus distance of the barcode reader camera;
[0172] S506 can fine-tune the number of focus steps by polling within a certain range of positive and negative values of the number of focus steps.
[0173] That is, based on the preset fine-tuning range of the current focus steps, the focal length of the lens is fine-tuned and the image is acquired within this fine-tuning range.
[0174] S507, ultimately yields a clear image.
[0175] The following is combined with Figure 6 The calibration process is illustrated with an example. Figure 6 As shown, the process may include the following steps:
[0176] S601, set several working distances;
[0177] The S602 focuses in a polling manner at each working distance to find the best sharpness of the barcode reader camera and records the number of focusing steps at that time.
[0178] That is, for each preset working distance, the number of focusing steps used is determined when the target and the barcode reader are at that working distance, and the image captured by the barcode reader for the target meets the preset clarity conditions.
[0179] S603 uses a circle search algorithm to find the X and Y coordinates of the aiming spot in the camera image;
[0180] That is, for each preset working distance, when the target and the barcode reader are at that working distance, the pixel coordinates of the center point of the aiming spot in the image captured by the barcode reader for the target are determined.
[0181] S604 writes the focus steps, the corresponding X and Y coordinates, and the current working distance into the barcode reader 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, determine whether all preset working distances have been calibrated; if not, return to execute S602; if yes, end the calibration process.
[0184] In this embodiment, the current focusing parameters corresponding to the image currently being captured by the barcode reader are directly determined by utilizing the pre-calibrated correspondence between the position of the aiming spot in the image and the focusing parameters. The lens is then coarsely adjusted using these current focusing parameters, and further fine-tuning of the lens's focal length can be performed within the fine-tuning range of these parameters to complete the focusing process. This embodiment achieves focusing through two stages: coarse and fine. During the coarse adjustment, only the focusing parameters need to be adjusted, without acquiring an image, thus reducing the focusing time. Furthermore, the fine adjustment ensures focusing accuracy. Therefore, this solution improves the focusing efficiency of the barcode reader.
[0185] This application also provides a code reading method, which can be applied to a code reading camera, the code reading camera including: an adjustable focal length lens and a aiming light; such as Figure 7 As shown, the method may include the following steps:
[0186] S701, acquire the first current image captured by the lens at the current focal length;
[0187] S702, perform image recognition on the first current image to determine the position of the aiming spot emitted by the aiming light in the first current image;
[0188] S703, using the pre-calibrated calibration correspondence between the position of the aiming spot in the image and the focusing parameters, determines the current focusing parameters corresponding to the first current image;
[0189] S704 uses the current focusing parameters to focus the lens and acquires a second current image after the lens is focused;
[0190] S705, if the second current image does not meet the preset sharpness condition, based on the preset fine adjustment range of the current focus parameter, within the fine adjustment range, the focal length of the lens is fine-tuned and the image is acquired until the acquired image meets the preset sharpness condition.
[0191] The steps S701-S705 above are similar to steps S101-S105, and will not be repeated here.
[0192] S706 reads codes based on images that meet preset clarity conditions.
[0193] After acquiring an image that meets the preset clarity requirements, the barcode reader camera can use a processor to first identify whether there is a identifiable 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, by utilizing the pre-calibrated correspondence between the position of the aiming spot in the image and the focusing parameters, the current focusing parameters corresponding to the image currently acquired by the barcode reader are directly determined. Then, the focal length of the lens is fine-tuned within the fine-tuning range of the current focusing parameters. This reduces the range of focusing parameters to be determined, decreases the number of times the lens focal length needs to be adjusted, and also reduces the number of images to be acquired and detected. Therefore, this solution can improve the focusing efficiency of the barcode reader, and thus also improve the barcode reading efficiency of the barcode reader.
[0195] This application also provides a lens focusing device for use in a barcode reader camera, the barcode reader camera including: an adjustable focus lens and a aiming light; such as Figure 8 As shown, the device includes:
[0196] The first image acquisition module 801 is used to acquire the first current image captured by the lens at the current focal length;
[0197] Image recognition module 802 is used to perform image recognition on the first current image to determine the position of the aiming spot emitted by the aiming light in the first current image;
[0198] The current focus parameter determination module 803 is used to determine the current focus parameter corresponding to the first current image by using the pre-calibrated calibration correspondence between the position of the aiming spot in the image and the focus parameter;
[0199] The second image acquisition module 804 is used to focus the lens using the current focusing parameters and acquire the second current image after the lens is focused.
[0200] The fine-tuning module 805 is used to fine-tune the focal length of the lens and acquire an image within a preset fine-tuning range of the current focusing parameters, based on the preset fine-tuning range of the current focusing parameters, when the second current image does not meet the preset sharpness condition, until the acquired image meets the preset sharpness condition.
[0201] Optionally, the lens focusing device may further include a module for pre-calibrating the correspondence between the position of the aiming spot in the image and the focusing parameters:
[0202] The calibration parameter determination module is used to determine the focusing parameters used by the barcode reader camera when the target is at a distance from the barcode reader camera at each preset working distance, and when the image acquired by the barcode reader camera for the target meets a preset clarity condition. These focusing parameters are used as the focusing parameters corresponding to each working distance. Each working distance is preset based on the range of distances that the barcode reader camera can detect.
[0203] The calibration position determination module is used to determine, for each preset working distance, the position of the aiming spot in the image captured by the barcode reader camera for the target when the target is at that working distance, and to use that position as the position corresponding to that working distance;
[0204] The correspondence recording module is used to record the corresponding position and focusing parameters for each preset working distance, so as to obtain the calibration correspondence between the position of the aiming spot in the image and the focusing parameters.
[0205] Optionally, the calibration parameter determination module includes:
[0206] The first calibration image acquisition submodule is used to acquire a first calibration image of the target captured by the lens at the current focal length for each preset working distance, when the target and the code reader camera are at that working distance.
[0207] The parameter determination submodule is used to focus and acquire images of the lens by polling when the first calibration image does not meet the preset sharpness condition, until the acquired image meets the preset sharpness condition. Then, the focusing parameters used when acquiring the image are used as the focusing parameters corresponding to the working distance.
[0208] The calibration position determination module includes:
[0209] The second calibration image acquisition submodule is used to acquire a second calibration image of the target captured by the lens at the current focal length for each preset working distance;
[0210] The pixel coordinate determination submodule is used to perform image recognition on the second calibration image and determine the pixel coordinates of the center point of the aiming spot emitted by the aiming light in the second calibration image, which are used as the pixel coordinates corresponding to the working distance.
[0211] The mapping relationship record 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 the number of focusing steps or the driving voltage value;
[0214] When 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 captured image meets the preset sharpness condition. The number of focus steps used when capturing the image is then used as the number of focus steps corresponding to the working distance.
[0216] The correspondence record module includes:
[0217] The voltage calculation submodule is used to calculate the driving voltage value mapped to the number of focusing steps for each working distance by using the preset mapping relationship between the number of focusing steps and the driving voltage value.
[0218] The correspondence recording submodule is used to record the pixel coordinates corresponding to the working distance and the determined driving voltage value, so as to obtain the calibration correspondence between the position of the aiming spot in the image and the driving voltage value;
[0219] When the focusing parameter is a drive voltage value, the parameter determination submodule is specifically used for:
[0220] The lens is focused by polling until the acquired image meets the preset sharpness condition. The driving voltage value used when acquiring the image is then used as the driving voltage value corresponding to the working distance.
[0221] The correspondence record 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 spot in the image and the driving voltage value.
[0223] Optionally, the fine-tuning module 805 is specifically used for:
[0224] Using a polling method, the lens is focused and images are acquired by adjusting each focusing parameter within the preset fine-tuning range of the current focusing parameters until the acquired image meets the preset sharpness condition.
[0225] Optionally, the focusing parameter is the number of focusing steps or the driving voltage value;
[0226] When the focusing parameter is the number of focusing steps, the current focusing parameter determination module 603 is specifically used for:
[0227] The current focus step number corresponding to the first current image is determined by using the pre-calibrated correspondence between the position of the aiming spot in the image and the number of focus steps.
[0228] The second image acquisition module 804 includes:
[0229] The voltage value determination submodule is used to calculate the driving voltage value mapped to the current focusing step number by utilizing the preset mapping relationship between the focusing step number and the driving voltage value.
[0230] The second current image acquisition submodule is used to focus the lens using the obtained driving voltage value and acquire the second current image after the lens is focused.
[0231] When the focusing parameter is the driving voltage value, the current focusing parameter determination module 603 is specifically used for:
[0232] The current driving voltage value corresponding to the first current image is determined by using the pre-calibrated correspondence between the position of the aiming spot in the image and the 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 after the lens is focused.
[0235] Optionally, the current focusing parameter determination module 803 is specifically used for:
[0236] If the aiming spot does not exist 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 focusing parameters to obtain the current focusing parameters corresponding to the first current image.
[0237] This application also provides a code reading device applied to a code reading camera, the code reading camera including: an adjustable focal length lens and a aiming light; such as Figure 9 As shown, the device includes:
[0238] The first image acquisition module 901 is used to acquire the first current image captured by the lens at the current focal length;
[0239] 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] The current focus parameter determination module 903 is used to determine the current focus parameter corresponding to the first current image by using the pre-calibrated calibration correspondence between the position of the aiming spot in the image and the focus parameter;
[0241] The second image acquisition module 904 is used to focus the lens using the current focusing parameters and acquire the second current image after the lens is focused.
[0242] The fine-tuning module 905 is used to fine-tune the focal length of the lens and acquire an image within a preset fine-tuning range of the current focusing parameters, based on the preset fine-tuning range of the current focusing parameters, when the second current image does not meet the preset sharpness condition, until the acquired image meets the preset sharpness condition.
[0243] The code reading module 906 is used to read codes based on images that meet preset clarity conditions.
[0244] This application also provides a barcode reader camera, such as... Figure 10 As shown, it includes:
[0245] Adjustable focal length lens 1001;
[0246] Aiming light 1002 is used to emit light to form an aiming spot;
[0247] Memory 1003 is used to store computer programs;
[0248] The processor 1004 is used to execute the program stored in the memory 1003 to implement any of the lens focusing methods or any of the code reading methods described above.
[0249] Furthermore, the aforementioned code reader camera may also include a communication bus and / or a communication interface, and the processor 1004, the communication interface, and the memory 1003 communicate with each other through the communication bus.
[0250] The communication bus mentioned in the above electronic devices can be a Peripheral Component Interconnect (PCI) bus or an Extended Industry Standard Architecture (EISA) bus, etc. This communication bus can be divided into address bus, data bus, control bus, etc. For ease of illustration, only one thick line is used to represent it in the diagram, but this does not mean that there is only one bus or one type of bus.
[0251] The communication interface is used for communication between the aforementioned electronic devices and other devices.
[0252] The memory may include random access memory (RAM) or non-volatile memory (NVM), such as at least one disk storage device. Optionally, the memory may also be at least one storage device located remotely from the aforementioned processor.
[0253] The processors mentioned above can be general-purpose processors, including central processing units (CPUs), network processors (NPs), etc.; they can also be digital signal processors (DSPs), application-specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), or other programmable logic devices, discrete gate or transistor logic devices, or discrete hardware components.
[0254] In another embodiment provided in this application, a computer-readable storage medium is also provided, which stores a computer program that, when executed by a processor, implements any of the lens focusing methods or any of the code reading methods described above.
[0255] In another embodiment provided in this application, a computer program product containing instructions is also provided, which, when run on a computer, causes the computer to execute any of the lens focusing methods or any of the code reading methods described in the above embodiments.
[0256] In the above embodiments, implementation can be achieved entirely or partially through software, hardware, firmware, or any combination thereof. When implemented using software, it can be implemented entirely or partially 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, all or part of the processes or functions described in the embodiments of this application are generated. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions can be stored in a computer-readable storage medium or transmitted from one computer-readable storage medium to another. For example, the computer instructions can be transmitted from one website, computer, server, or data center to another website, computer, server, or data center via wired (e.g., coaxial cable, fiber optic, digital subscriber line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.) means. The computer-readable storage medium can be any available medium that a computer can access or a data storage device such as a server or data center that integrates one or more available media. The available medium can be a magnetic medium (e.g., floppy disk, hard disk, magnetic tape), an optical medium (e.g., DVD), or a solid-state drive (SSD), etc.
[0257] It should be noted that, in this document, relational terms such as "first" and "second" are used only to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Furthermore, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitations, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes said element.
[0258] The various embodiments in this specification are described in a related manner. Similar or identical parts between embodiments can be referred to mutually. Each embodiment focuses on describing the differences from other embodiments. In particular, the device, readable storage medium, and computer program embodiments are basically similar to the method embodiments, so the descriptions are relatively simple; relevant parts can be referred to the descriptions of the method embodiments.
[0259] The above description is merely a preferred embodiment of this application and is not intended to limit the scope of protection of this application. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of this application are included within the scope of protection of this application.
Claims
1. A method of focusing a lens, characterized by, The application is applied to a code reading camera, the code reading camera comprises a lens with adjustable focal length and a aiming light; the method comprises: acquiring a first current image collected by the lens at a current focal length; 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; determining the current focusing parameter corresponding to the first current image by using the pre-calibrated correspondence between the position of the aiming light spot in the image and the focusing parameter; focusing the lens by using the current focusing parameter to acquire a second current image collected by the lens after focusing; in the case that the second current image does not satisfy the preset definition condition, based on the preset fine tuning range of the current focusing parameter, fine tuning the focal length of the lens and image collection within the fine tuning range until the collected image satisfies the preset definition condition.
2. The method of claim 1, wherein, The correspondence between the position of the aiming light spot in the image and the focusing parameter is pre-calibrated by the following steps: for each preset working distance, the focusing parameter used when the target is at a distance of the working distance from the code reading camera and the image collected by the code reading camera for the target satisfies the preset definition condition is determined as the focusing parameter corresponding to the working distance; wherein each working distance is preset according to the range of distances that can be detected by the code reading camera; for each preset working distance, the position of the aiming light spot in the image collected by the code reading camera for the target when the target is at a distance of the working distance from the code reading camera is determined as the position corresponding to the working distance; for each preset working distance, the corresponding position and focusing parameter are recorded to obtain the correspondence between the position of the aiming light spot in the image and the focusing parameter.
3. The method of claim 2, wherein, The method for determining the focusing parameter corresponding to each preset working distance, wherein the target is at a distance of the working distance from the code reading camera and the image collected by the code reading camera for the target satisfies the preset definition condition, comprises: for each preset working distance, a first calibration image collected by the lens for the target at a current focal length is acquired when the target is at a distance of the working distance from the code reading camera; in the case that the first calibration image does not satisfy the preset definition condition, the lens is focused and the image is collected by polling until the collected image satisfies the preset definition condition, and the focusing parameter used when the image is collected is determined as the focusing parameter corresponding to the working distance; The method for determining the position of the aiming light spot in the image collected by the code reading camera for the target when the target is at a distance of the working distance from the code reading camera, as the position corresponding to the working distance, comprises: for each preset working distance, a second calibration image collected by the lens for the target at a current focal length is acquired; 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 comprises the following steps: The method comprises the following steps:
4. The method of claim 3, wherein, The focusing parameter is the focusing step or the driving voltage value; In the case that the focusing parameter is the focusing step, the lens is focused and the image is collected by polling until the collected image meets the preset definition condition, and the focusing parameter used when the image is collected is taken as the focusing parameter corresponding to the working distance, which comprises the following steps: The lens is focused and the image is collected by polling until the collected image meets the preset definition condition, and the focusing step used when the image is collected is taken as the focusing step corresponding to the working distance. The method comprises the following steps: For each working distance, the mapping relationship between the focusing step and the driving voltage value is used to calculate the driving voltage value corresponding to the focusing step of the working distance. The pixel coordinate and the determined driving voltage value corresponding to the working distance are recorded to obtain the mapping relationship between the position of the aiming light spot in the image and the driving voltage value. In the case that the focusing parameter is the driving voltage value, the lens is focused and the image is collected by polling until the collected image meets the preset definition condition, and the focusing parameter used when the image is collected is taken as the focusing parameter corresponding to the working distance, which comprises the following steps: The lens is focused and the image is collected by polling until the collected image meets the preset definition condition, and the driving voltage value used when the image is collected is taken as the driving voltage value corresponding to the working distance. The method comprises the following steps: For each working distance, the pixel coordinate and the driving voltage value corresponding to the working distance are recorded to obtain the mapping relationship between the position of the aiming light spot in the image and the driving voltage value.
5. The method of claim 1, wherein, The method comprises the following steps: The focusing parameter is the focusing step or the driving voltage value; 6. The method of claim 5, wherein, In the case that the focusing parameter is the focusing step, the lens is focused and the image is collected by polling until the collected image meets the preset definition condition, and the focusing parameter used when the image is collected is taken as the focusing parameter corresponding to the working distance, which comprises the following steps: The lens is focused and the image is collected by polling until the collected image meets the preset definition condition, and the focusing parameter used when the image is collected is taken as the focusing parameter corresponding to the working distance. The first current image corresponds to a current focusing step number is determined by using a preset calibration correspondence between a position of the aiming light spot in an image and a focusing step number. The lens is focused by using the current focusing parameter, and a second current image collected after focusing of the lens is acquired. A driving voltage value mapped by the current focusing step number is calculated by using a preset mapping relationship between focusing step numbers and driving voltage values. The lens is focused by using the obtained driving voltage value, and a second current image collected after focusing of the lens is acquired. In a case where the focusing parameter is a driving voltage value, the first current image corresponds to a current focusing parameter is determined by using a preset calibration correspondence between a position of the aiming light spot in an image and a focusing parameter. The first current image corresponds to a current driving voltage value is determined by using a preset calibration correspondence between a position of the aiming light spot in an image and a driving voltage value. The lens is focused by using the current focusing parameter, and a second current image collected after focusing of the lens is acquired. The lens is focused by using the current driving voltage value, and a second current image collected after focusing of the lens is acquired.
7. The method of claim 1, wherein, The first current image corresponds to a current focusing parameter is determined by using a preset calibration correspondence between a position of the aiming light spot in an image and a focusing parameter. In a case where the position of the aiming light spot in the first current image does not exist in each position included in the calibration correspondence, the first current image corresponds to a current focusing parameter is obtained by interpolation according to each position and a corresponding focusing parameter included in the calibration correspondence.
8. A code reading method characterized by comprising: The method is applied to a code reading camera, and the code reading camera comprises a lens with an adjustable focal length and a aiming lamp. A first current image collected by the lens at a current focal length is acquired. An image recognition is performed on the first current image to determine a position of an aiming light spot emitted by the aiming lamp in the first current image. The first current image corresponds to a current focusing parameter is determined by using a preset calibration correspondence between a position of the aiming light spot in an image and a focusing parameter. The lens is focused by using the current focusing parameter, and a second current image collected after focusing of the lens is acquired. In a case where the second current image does not satisfy a preset definition condition, a focal length of the lens is fine-tuned and an image is collected within a fine-tuning range of the current focusing parameter based on the preset fine-tuning range until the collected image satisfies the preset definition condition. Code reading is performed based on the image satisfying the preset definition condition.
9. A lens focusing device, characterized by comprising: The device is applied to a code reading camera, and the code reading camera comprises a lens with an adjustable focal length and a aiming lamp. A first current image collected by the lens at a current focal length is acquired. An image recognition is performed on the first current image to determine a position of an aiming light spot emitted by the aiming lamp in the first current image. The current focusing parameter determination module is configured to determine a current focusing parameter corresponding to the first current image by using a pre-labeled correspondence between a position of the aiming light spot in an image and a focusing parameter; The second image acquisition module is configured to focus the lens by using the current focusing parameter and acquire a second current image collected after focusing the lens; The fine adjustment module is configured to, in a case where the second current image does not satisfy a preset definition condition, fine adjust the focal length of the lens and collect an image within a preset fine adjustment range of the current focusing parameter until the collected image satisfies the preset definition condition.
10. A code reading apparatus characterized by comprising: The device is applied to a code reading camera, and the code reading camera includes a lens with an adjustable focal length and an aiming lamp. The first image acquisition module is configured to acquire a first current image collected by the lens at a current focal length. The image recognition module is configured to perform image recognition on the first current image and determine a position of the aiming light spot emitted by the aiming lamp in the first current image. The current focusing parameter determination module is configured to determine a current focusing parameter corresponding to the first current image by using a pre-labeled correspondence between a position of the aiming light spot in an image and a focusing parameter. The second image acquisition module is configured to focus the lens by using the current focusing parameter and acquire a second current image collected after focusing the lens. The fine adjustment module is configured to, in a case where the second current image does not satisfy a preset definition condition, fine adjust the focal length of the lens and collect an image within a preset fine adjustment range of the current focusing parameter until the collected image satisfies the preset definition condition. The code reading module is configured to perform code reading based on the image satisfying the preset definition condition.
11. A code reading camera characterized by The device includes: a lens with an adjustable focal length; an aiming lamp configured to emit light to form an aiming light spot; a memory configured to store a computer program; a processor configured to execute the program stored in the memory to implement the method in any one of claims 1-7 or claim 8.
12. A computer-readable storage medium, characterized in that, The computer readable storage medium stores a computer program, and the computer program is executed by the processor to implement the method in any one of claims 1-7 or claim 8.
13. A computer program product comprising instructions, characterized in that, When the computer program product runs on the computer, the computer is caused to execute the method in any one of claims 1-7 or claim 8.
Citation Information
Patent Citations
Focusing method and device, electronic equipment and storage medium
CN111432125A
Laser beam target coupling sensor
CN114089310A