Search focusing method of code reader and related equipment
By adjusting the search step length and conducting detailed searches within the adjustable focus range of the code reader, the problem of long automatic focus time of the code reader and easy to fall into local maximum value is solved, and fast and accurate focal length adjustment is achieved.
Patent Information
- Application Number
- CN202510402866.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-03-31
- Publication Date
- 2025-07-11
AI Technical Summary
The existing code readers have a long autofocus time and are prone to fall into local maximums, resulting in unsatisfactory results.
The focal length traversal is performed using the adjustable focus range based on the code reader. The image clear score is obtained through the first search step, the step length is adjusted to avoid the local maximum value, and a detailed search is carried out within the target interval to determine the focal length with the maximum image clear score.
Effectively reduces autofocus time, while ensuring accuracy, avoiding the fall of local maximum values, and improving the efficiency and accuracy of autofocus.
Smart Images

Figure CN120302154A_ABST
Abstract
Description
Technical Field
[0001] This application belongs to the technical field of barcode readers, and particularly relates to a search focusing method and related devices for a barcode reader. Background Art
[0002] Barcode readers have been widely used and developed in fields such as industrial automation, logistics, retail, and healthcare. Due to differences in barcode symbologies, barcode positions, and barcode sizes used in different products, autofocus technology is required to quickly adjust the focal length to ensure stable barcode reading at various working distances and angles, avoiding time waste and errors caused by manual focal length adjustment.
[0003] In the common autofocus search process, some algorithms can accurately adjust to the focal length when the image is clearest, but the autofocus time of the barcode reader is relatively long, or when significantly reducing the autofocus duration of the barcode reader, it is often easily trapped in local maxima due to the influence of the search step size, resulting in unsatisfactory results. Summary of the Invention
[0004] The embodiments of this application provide a search focusing method and related devices for a barcode reader to solve the problems of long autofocus time and easy entrapment in local maxima in the prior art.
[0005] The first aspect of the embodiments of this application provides a search focusing method for a barcode reader, including:
[0006] Based on the adjustable focal range of the barcode reader, starting from the first boundary value in the adjustable focal range as the initial focal length, moving the focal length according to the first search step size, and sequentially obtaining the image sharpness scores at each focal length until the focal length is moved to the second boundary value in the adjustable focal range, where the first search step size is adjusted according to the change in the image sharpness scores between adjacent focal lengths;
[0007] Based on the sequentially obtained image sharpness scores, obtain the focal length interval where the maximum peak of the image sharpness score is located;
[0008] Taking the focal length interval as the target interval, sequentially select a set number of focal lengths from the target interval according to the second search step size, and respectively obtain the image sharpness scores at each of the set number of focal lengths;
[0009] Determine the focal length with the highest image sharpness score as the target focal length.
[0010] The second aspect of the embodiments of this application provides a search focusing device for a barcode reader, including:
[0011] A first acquisition device, configured to move the focal length in accordance with a first search step starting from a first boundary value in the adjustable focal range based on the adjustable focal range of the barcode reader, and sequentially obtain the image sharpness scores at each focal length until the focal length is moved to a second boundary value in the adjustable focal range, wherein the first search step is adjusted according to the change in the image sharpness score between adjacent focal lengths;
[0012] A second acquisition device, configured to obtain the focal length interval where the maximum peak of the image sharpness score is located based on the sequentially obtained image sharpness scores;
[0013] A first determination module, configured to use the focal length interval as the target interval, sequentially select a set number of focal lengths from the target interval in accordance with a second search step, and respectively obtain the image sharpness scores at each of the set number of focal lengths;
[0014] A second determination module, configured to determine the focal length with the maximum image sharpness score as the target focal length.
[0015] A third aspect of the embodiments of the present application provides a computer device, including a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, the steps of the method described in the first aspect are implemented.
[0016] A fourth aspect of the embodiments of the present application provides a computer-readable storage medium storing a computer program, and when the computer program is executed by a processor, the steps of the method described in the first aspect are implemented.
[0017] A fifth aspect of the present application provides a computer program product, which when running on a computer device causes the computer device to execute the steps of the method described in the first aspect above.
[0018] As can be seen from the above, in the embodiment of the present application, the focal length traversal is performed based on the adjustable focal range of the barcode reader, the focal length is moved respectively according to the first search step length, the image sharpness scores at each focal length are obtained in sequence, and then based on the sequentially obtained image sharpness scores, the target focal length interval where the maximum peak of the image sharpness score is located is obtained from the adjustable focal range of the barcode reader, so as to achieve automatic focusing by one search. On this basis, a set number of focal lengths are sequentially selected from the target focal length interval according to the second search step length, and the image sharpness scores at each of the set number of focal lengths are obtained respectively. Finally, the focal length with the maximum image sharpness score is determined as the target focal length to achieve automatic focusing by secondary search. The combination of the two realizes the composite search automatic focusing of the barcode reader, which can effectively reduce the calculation time of the search focusing. Through hierarchical search automatic focusing, the problem that the focus search process falls into a local maximum is avoided, and the time used for automatic focusing can be effectively reduced while accurately focusing. BRIEF DESCRIPTION OF THE DRAWINGS
[0019] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the following will briefly introduce the drawings required for use in the embodiments or the description of the prior art. Obviously, the drawings in the following description are only some embodiments of the present application. For those of ordinary skill in the art, without creative efforts, other drawings can be obtained based on these drawings.
[0020] Figure 1 is the flowchart of a search focusing method for a barcode reader provided by an embodiment of the present application Figure 1 ;
[0021] Figure 2 is the flowchart of a search focusing method for a barcode reader provided by an embodiment of the present application Figure 2 ;
[0022] Figure 3 is the flowchart of the coarse search stage provided by an embodiment of the present application;
[0023] Figure 4 is a schematic diagram of the numerical change of the curve image sharpness score provided by an embodiment of the present application;
[0024] Figure 5 is the flowchart of the fine search stage provided by an embodiment of the present application;
[0025] Figure 6 is the structural diagram of a search focusing device for a barcode reader provided by an embodiment of the present application;
[0026] Figure 7 is the structural diagram of a computer device provided by an embodiment of the present application. DETAILED DESCRIPTION OF THE EMBODIMENTS
[0027] In the following description, for purposes of illustration and not limitation, specific details such as particular system architectures, technologies, etc. are set forth in order to provide a thorough understanding of embodiments of the present application. However, those skilled in the art will appreciate that the present application may be implemented in other embodiments without these specific details. In other instances, detailed descriptions of well-known systems, devices, circuits, and methods are omitted so as not to obscure the description of the present application with unnecessary details.
[0028] It should be understood that when used in this specification and the appended claims, the term "comprising" indicates the presence of the described features, integers, steps, operations, elements, and / or components, but does not preclude the presence or addition of one or more other features, integers, steps, operations, elements, components, and / or groups thereof.
[0029] It should also be understood that the terminology used in this specification of the present application is for the purpose of describing particular embodiments only and is not intended to limit the present application. As used in this specification of the present application and the appended claims, unless the context clearly dictates otherwise, the singular forms "a", "an", and "the" are intended to include the plural forms.
[0030] It should be further understood that the term "and / or" as used in this specification of the present application and the appended claims refers to any combination and all possible combinations of one or more of the associated listed items, and includes these combinations.
[0031] As used in this specification and the appended claims, the term "if" may be construed, depending on the context, as "when" or "once" or "in response to determining" or "in response to detecting". Similarly, the phrase "if determined" or "if [the described condition or event] is detected" may be construed, depending on the context, as meaning "once determined" or "in response to determining" or "once [the described condition or event] is detected" or "in response to detecting [the described condition or event]".
[0032] In a specific implementation, the computer device described in embodiments of the present application includes, but is not limited to, other portable devices such as a mobile phone, a laptop computer, or a tablet computer having a touch-sensitive surface (e.g., a touch screen display and / or a touchpad). It should also be understood that in some embodiments, the device is not a portable communication device, but a desktop computer having a touch-sensitive surface (e.g., a touch screen display and / or a touchpad).
[0033] In the following discussion, a computer device including a display and a touch-sensitive surface is described. However, it should be understood that the computer device may include one or more other physical user interface devices such as a physical keyboard, a mouse, and / or a joystick.
[0034] The computer device supports various application programs, such as one or more of the following: drawing application programs, presentation application programs, word processing application programs, website creation application programs, disc burning application programs, spreadsheet application programs, game application programs, telephone application programs, video conferencing application programs, email application programs, instant messaging application programs, exercise support application programs, photo management application programs, digital camera application programs, digital video camera application programs, web browsing application programs, digital music player application programs, and / or digital video player application programs.
[0035] Various application programs that can be executed on the computer device can use at least one common physical user interface device such as a touch-sensitive surface. One or more functions of the touch-sensitive surface and the corresponding information displayed on the computer device can be adjusted and / or changed between application programs and / or within the respective application programs. In this way, the common physical architecture of the computer device (e.g., the touch-sensitive surface) can support various application programs with a user interface that is intuitive and transparent to the user.
[0036] It should be understood that the magnitudes of the sequence numbers of the steps in this embodiment do not imply the order of execution. The order of execution of each process should be determined by its function and internal logic, and should not constitute any limitation to the implementation process of the embodiments of this application.
[0037] To illustrate the technical solutions described in this application, the following will be described through specific embodiments.
[0038] See Figure 1 , Figure 1 is the flowchart of a search focusing method for a barcode reader provided by an embodiment of this application Figure 1 . As Figure 1 shown, a search focusing method for a barcode reader, the method includes the following steps:
[0039] Step 101, based on the adjustable focus range of the barcode reader, starting from the first boundary value in the adjustable focus range as the starting focal length, moving the focal length according to the first search step size, and sequentially obtaining the image sharpness scores at each focal length until the focal length is moved to the second boundary value in the adjustable focus range.
[0040] Among them, the first search step size is adjusted according to the change of the image sharpness score between adjacent focal lengths.
[0041] The first boundary value can be the left boundary value of the adjustable focus range, and the second boundary value can be the right boundary value of the adjustable focus range. Or vice versa. Each time the focal length is moved according to the first search step size, the image sharpness score at the current focal length is obtained until the focus traversal is completed in the adjustable focus range.
[0042] Among them, the first search step size can be a fixed step size value or a value that changes as the focusing process progresses.
[0043] Combined with Figure 2 As shown, in an alternative embodiment, step 101 is based on the adjustable focusing range of the barcode reader. Starting from the first boundary value in the adjustable focusing range as the starting focal length, the focal length is moved according to the first search step size, and the image sharpness score at each focal length is obtained in sequence until the focal length is moved to the second boundary value in the adjustable focusing range, including:
[0044] Step 201: Starting from the first boundary value in the adjustable focusing range as the starting focal length, move the current focal length according to the first search step size, and calculate the image sharpness score of the barcode reader at the moved current focal length.
[0045] Step 202: Calculate the sharpness change measurement value based on the adjacent focal lengths and the image sharpness scores of the adjacent focal lengths.
[0046] The sharpness change measurement value can be the difference, ratio, etc. of the image sharpness scores of adjacent focal lengths.
[0047] Or, in an alternative embodiment, step 202 calculates the sharpness change measurement value based on the adjacent focal lengths and the image sharpness scores of the adjacent focal lengths, including:
[0048] Obtain the focal length difference between adjacent focal lengths and the score difference of the image sharpness scores of adjacent focal lengths; determine the ratio of the score difference to the focal length difference as the sharpness change measurement value.
[0049] Based on the difference between the image sharpness scores of adjacent focal lengths and the difference between the focal lengths of adjacent focal lengths, obtain the ratio of the score difference to the focal length difference as the sharpness change measurement value, providing an effective measurement of sharpness change.
[0050] Step 203: Based on the sharpness change measurement value, adjust the first search step size to the first target step size value, and return to execute the step of moving the current focal length according to the first search step size and calculating the image sharpness score of the barcode reader at the moved current focal length until the focal length is moved to the second boundary value in the adjustable focusing range.
[0051] Among them, the magnitude of the first target step size value is negatively correlated with the magnitude of the sharpness change measurement value.
[0052] Based on the sharpness change measurement value corresponding to adjacent focal lengths, adjust the first search step size. If the sharpness change measurement value indicates a large sharpness change, reduce the search step size; if the sharpness change measurement value indicates a small sharpness change, increase the search step size. Implement the focal length movement with an appropriate step size to ensure the effectiveness of the focal length search and, at the same time, ensure the efficiency of the focal length search.
[0053] In an optional implementation, the initialization data includes a first step size, a second step size, and a third step size with increasing values, as well as a first sharpness change measurement threshold and a second sharpness change measurement threshold with increasing values.
[0054] Optionally, step 203 adjusts the first search step size to a first target step size value based on the sharpness change measurement value, including:
[0055] When the first search step size is the second step size, if the sharpness change measurement value is less than the first sharpness change measurement threshold, then use the third step size as the first target step size value and adjust the first search step size to the first target step size value; the third step size is greater than the second step size;
[0056] If the sharpness change measurement value is greater than the second sharpness change measurement threshold, then use the first step size as the first target step size value and adjust the first search step size to the first target step size value; the second step size is greater than the first step size; the second sharpness change measurement threshold is greater than the first sharpness change measurement threshold;
[0057] If the sharpness change measurement value is greater than the first sharpness change measurement threshold and less than the second sharpness change measurement threshold, then keep the first search step size unchanged.
[0058] This process introduces multiple sharpness change measurement thresholds to form a threshold interval. By using different measurement thresholds to judge the magnitude of the sharpness change measurement value between adjacent focal lengths, when it is determined that the sharpness change measurement value between adjacent focal lengths falls into the interval formed by different measurement thresholds, the step size value of the first search step size is increased or decreased to a corresponding step size value, realizing effective search step size adjustment within the adjustable focal length range of the barcode reader, implementing effective focal length traversal movement, ensuring the effectiveness of the focal length search, and at the same time ensuring the efficiency of the focal length search. Step 102, based on the sequentially obtained image sharpness scores, obtains the focal length interval where the maximum peak of the image sharpness score is located.
[0059] Steps 101 to 102 implement the rough search stage in the search focusing method of the barcode reader.
[0060] Optionally, this stage uses an adaptive step - size search algorithm to screen out the focal - length interval where the maximum peak of the image sharpness score is located. Optionally, the embodiment of the present application can use the Tenengrad algorithm as the image sharpness evaluation algorithm F(x).
[0061] In some embodiments, combined with Figure 3 As shown, assume that the adjustable focal - length range of the barcode reader is [Min_Focus, Max_Focus]. Among them, the first boundary value can be Min_Focus, and the second boundary value can be Max_Focus. Initialize the small step - size S min , the medium step - size S mid , and the large step - size S max Respectively as the first step - size, the second step - size, and the third step - size. The small step - size, the medium step - size, and the large step - size can be specifically set to 0.5tf, tf, and 2tf respectively. Among them, the 2tf step - size is 2 times the original step - size, the tf step - size is 1 time the original step - size, the 0.5tf step - size is half of the original step - size, and the original step - size is the first search step - size.
[0062] When the barcode reader starts automatic focusing, first move the camera to the position with the focal - length value of Min_Focus (the first boundary value), calculate the image sharpness score value at this position, then increase the focal - length value by the step - size tf, calculate the image sharpness score value at this position, and calculate the absolute value of the slope according to the focal lengths and the image sharpness evaluation algorithm at these two positions, that is, obtain the sharpness change measurement value by taking the ratio of the focal - length difference between adjacent focal lengths to the score difference of the image sharpness scores of adjacent focal lengths. If the absolute value of the slope is relatively small, it means that the previously increased focal - length value has not brought an obvious change to the image sharpness quality, and the next step is to use the large step - size for focusing. If the absolute value of the slope is relatively large, it means that the previously increased focal - length value has brought a relatively large change to the image sharpness quality, and the next step is to use the small step - size for focusing until it is adjusted to the maximum focal - length Max_Focus (the second boundary value) of the barcode reader, and then stop the search.
[0063] During this process, record the calculated focal lengths and the corresponding image sharpness score values, traverse these data, and find the previous search focal length and the next search focal length when the image sharpness score value is the largest as the focal - length interval calculated in the fine - search stage.
[0064] As Figure 4 Shown, the first sharpness change measurement threshold and the second sharpness change measurement threshold can be the slope thresholds h1 and h2, where h2 > h1 。Calculate the slope h based on the current focal length, the previous focal length, and the corresponding image sharpness scores. For example, at focal length x1, h = (F1 - F0) / (x1 - x0); at focal length x2, h = (F2 - F1) / (x2 - x1); at focal length x3, h = (F3 - F2) / (x3 - x2), where the image sharpness score values corresponding to the focal lengths x0, x1, x2, x3 are F0, F1, F2, F3. The magnitude of the first search step h can be measured based on the first sharpness change measurement threshold and the second sharpness change measurement threshold, and the step size of the first search step h can be adjusted based on the measurement result.
[0065] During the judgment process, if h < h1, the next search step of the first search step can be adjusted to S max , if h1 < h < h2, the next search step of the first search step is determined to be S mid , if h > h2, the next search step of the first search step can be determined to be S min , and so on until the focal length value reaches Max_Focus, and the adjustable focus range is traversed. Based on all the calculated focal length values and the image sharpness score values at the focal length values, the focal length interval where the image sharpness score is the largest is finally determined as the focal length interval where the shaded area is located, and this focal length interval is used as the initial search interval in the fine search stage.
[0066] Step 103: Use the focal length interval as the target interval, and sequentially select a set number of focal lengths from the target interval according to the second search step, and respectively obtain the image sharpness scores at each of the set number of focal lengths.
[0067] Step 104: Determine the focal length with the largest image sharpness score as the target focal length.
[0068] During the implementation process, after obtaining the image sharpness scores at each of the set number of focal lengths, the magnitude relationship between the image sharpness scores can be determined, and based on this magnitude relationship, the focal length with the largest image sharpness score is determined as the target focal length from the set number of focal lengths.
[0069] In steps 103 and 104, a fine search is performed according to the focal length interval calculated in the coarse search stage.
[0070] In an optional implementation manner, determining the focal length with the largest image sharpness score as the target focal length includes:
[0071] In the case where the second search step is the minimum step of the reader, determine the focal length with the largest image sharpness score among the set number of focal lengths as the target focal length;
[0072] When the second search step size is not the minimum step size of the reader, a sub-interval is determined from the focal length interval as the target interval, the second search step size is adjusted down to a second target step size value, and the step of sequentially selecting a set number of focal lengths from the target interval according to the second search step size and respectively obtaining the image sharpness scores at each of the set number of focal lengths is returned for execution until the focal length with the maximum image sharpness score is determined from the set number of focal lengths and is determined as the target focal length.
[0073] Wherein, the second target step size value is greater than or equal to the minimum step size.
[0074] Optionally, when the second search step size is the minimum step size of the reader, in the implementation process of determining the focal length with the maximum image sharpness score among the set number of focal lengths as the target focal length, it may include:
[0075] When the second search step size is the minimum step size of the reader, if among the set number of sequentially selected focal lengths, the first focal length is the boundary value of the target interval and the image sharpness score at the first focal length is the maximum, then the first focal length is determined as the target focal length.
[0076] In an optional implementation manner, when the second search step size is not the minimum step size of the reader, determining a sub-interval from the focal length interval as the target interval includes:
[0077] When the second search step size is not the minimum step size of the reader, if among the set number of sequentially selected focal lengths, the first focal length is the left boundary of the target interval and the image sharpness score corresponding to the last focal length is the maximum, then the sub-interval obtained by adjusting the left boundary of the target interval from the first focal length to the last focal length is used as the target interval;
[0078] If among the set number of sequentially selected focal lengths, the first focal length is the left boundary of the target interval, the image sharpness score corresponding to the first focal length is the maximum, and the image sharpness score at the last focal length is the minimum, then the sub-interval obtained by adjusting the right boundary of the target interval to the last focal length is used as the target interval;
[0079] If among the set number of sequentially selected focal lengths, the first focal length is the left boundary of the target interval and the image sharpness score corresponding to the middle focal length is the maximum, then the sub-interval obtained by adjusting the right boundary of the target interval to the last focal length is used as the target interval.
[0080] In an optional implementation manner, adjusting the second search step size down to the second target step size value includes:
[0081] Determine the larger value between the minimum step size and half of the second search step size, and use the larger value as the second target step size value; adjust the second search step size down to the second target step size value.
[0082] In the above process, in order to improve the accuracy of the fine search, in combination with Figure 5 As shown, in this embodiment, taking the use of three focal length points as an example, the image sharpness score values of the three focal length points are used as the determination conditions for the hill climbing algorithm to conduct the search.
[0083] Assume that the fine search focal length interval is [Lfocus, Rfocus], the initial step size of the hill climbing algorithm is step (i.e., the second search step size), and the minimum moving focal length step size of the reader is minstep, which is the minimum step size value of the second search step size. Starting from Lfocus as the starting point of the fine search in the positive direction, calculate the image sharpness score values F(Lfocus), F(Lfocus + step), and F(Lfocus + 2step) corresponding to the focal length values Lfocus, Lfocus + step, and Lfocus + 2step.
[0084] When F(Lfocus) < F(Lfocus + step) < F(Lfocus + 2step), if step = minstep at this time, then return Lfocus + 2step as the final focal length search result, that is, in the case where the second search step size is the minimum step size of the reader, determine the focal length with the largest image sharpness score among the set number of focal lengths as the target focal length; otherwise, use [Lfocus + 2step, Rfocus] as the search interval, that is, the left boundary of the target interval is adjusted from the first focal length to the last focal length to obtain a sub-interval as the target interval, and continue the positive search with the focal length value Lfocus + 2step as the starting point.
[0085] When F(Lfocus) > F(Lfocus + step) > F(Lfocus + 2step), if step = minstep at this time, then return Lfocus as the final focal length search result, that is, in the case where the second search step size is the minimum step size of the reader, determine the focal length with the largest image sharpness score among the set number of focal lengths as the target focal length; otherwise, use [Lfocus, Lfocus + 2step] as the search interval, that is, the sub-interval obtained by adjusting the right boundary of the target interval to the last focal length as the target interval, step = max(step / 2, minstep), and start the reverse search in the reverse direction with Lfocus + 2step as the starting point.
[0086] If F(Lfocus) < F(Lfocus+step) > F(Lfocus+2step), then if step = minstep at this time, return Lfocus+step as the final focal length search result, that is, when the second search step size is the minimum step size of the reader, determine the focal length with the largest image clarity score among the set number of focal lengths as the target focal length; otherwise, use [Lfocus, Lfocus+2step] as the search interval, that is, adjust the right boundary of the target interval to the sub-interval obtained from the last focal length as the target interval, with step size step = max(step / 2, minstep), and reverse the direction to perform a reverse search starting from Lfocus+2step.
[0087] The above implementation process realizes the effective implementation of fine search in different situations, improves the accuracy of fine search, automatically focuses through hierarchical search, avoids the problem of the focus search process falling into local maxima, can effectively reduce the time used for autofocus while accurately focusing, and ensures the search focus effect.
[0088] The technical solution of the present invention will be described in detail below in conjunction with specific embodiments.
[0089] When the reader starts to perform autofocus search, first perform the coarse search stage.
[0090] Assume that the adjustable focal length range of the reader is [10mm, 50mm], and the initial step size tf is set to 2mm. Move the camera to the position with a focal length value of 10mm, and calculate the image clarity score value at this position. Then increase the focal length value by 2mm to 12mm, and calculate the image clarity score value at this position. Calculate the absolute value of the slope according to the focal lengths and the image clarity evaluation algorithm at these two positions. According to the size of the absolute value of the slope, use different step sizes for focusing until the maximum focal length of the reader, 50mm, is adjusted. During this process, record the calculated focal lengths and the corresponding image clarity score values, and find the previous search focal length and the next search focal length when the image clarity score value is the largest, as the focal length interval calculated in the fine search stage.
[0091] The global search algorithm search process needs to start from the minimum value of the focal length range, gradually move to the maximum value using an equal-length step size, and compare the image clarity scores during the movement to determine the focal length when the image is the clearest.
[0092] Then perform the fine search stage.
[0093] Assume that the fine search focal length range is [30mm, 38mm], the initial step size step of the hill climbing algorithm is set to 1mm, and the minimum moving focal length step size minstep of the reader is set to 0.1mm. Starting from 30mm as the starting point of the fine search and searching forward, calculate the image sharpness score values corresponding to the focal length values of 30mm, 31mm, and 32mm. According to the magnitude relationship of these three image sharpness score values, adjust the search range and step size until the focal length when the image is the clearest is found.
[0094] The hill climbing search algorithm starts from the minimum value of the focal length range, moves forward with a fixed step size and calculates the image sharpness score. Once the calculated current image sharpness score is smaller than the previous one, immediately adjust the moving direction, reduce the moving step size and move backward. Repeat this process until the focal length when the image is the clearest is found.
[0095] In this process, by combining the coarse search stage and the fine search stage, it can avoid the problem that when there are multiple peaks in the image score of an image, if the initial step size of the hill climbing search algorithm is too small, it is easy to fall into a local maximum, resulting in an incorrect result of the autofocus of the reader. Implementing autofocus with a composite search can effectively reduce the time used for autofocus and ensure the accuracy of focusing at the same time.
[0096] See Figure 6 , Figure 6 FIG. is a structural diagram of a search and focus device of a reader provided by an embodiment of the present application. For ease of description, only parts related to the embodiment of the present application are shown.
[0097] The search and focus device 600 of the reader includes:
[0098] A first acquisition device 601, configured to, based on the adjustable focal length range of the reader, use the first boundary value in the adjustable focal length range as the starting focal length, move the focal length according to the first search step size, and sequentially acquire the image sharpness score at each focal length until the focal length is moved to the second boundary value in the adjustable focal length range, where the first search step size is adjusted according to the change of the image sharpness score between adjacent focal lengths;
[0099] A second acquisition device 602, configured to, based on the sequentially acquired image sharpness scores, acquire the focal length interval where the maximum peak of the image sharpness score is located;
[0100] A first determination module 603, configured to use the focal length interval as the target interval, sequentially select a set number of focal lengths from the target interval according to the second search step size, and respectively acquire the image sharpness score at each focal length in the set number of focal lengths;
[0101] The second determination module 604 is configured to determine that the focal length with the maximum image clarity score is the target focal length.
[0102] Optionally, the first acquisition device 601 is specifically configured to:
[0103] Starting from the first boundary value in the adjustable focal length range as the starting focal length, move the current focal length according to the first search step size, and calculate the image clarity score of the reader at the moved current focal length;
[0104] Calculate the clarity change measurement value according to the adjacent focal lengths and the image clarity scores of the adjacent focal lengths;
[0105] Based on the clarity change measurement value, adjust the first search step size to the first target step size value, and return to execute the step of moving the current focal length according to the first search step size and calculating the image clarity score of the reader at the moved current focal length until the focal length is moved to the second boundary value in the adjustable focal length range, where the magnitude of the first target step size value is negatively correlated with the magnitude of the clarity change measurement value.
[0106] Optionally, the first acquisition device 601 is specifically configured to:
[0107] Obtain the focal length difference between adjacent focal lengths, and obtain the score difference of the image clarity scores of the adjacent focal lengths;
[0108] Determine the ratio of the score difference to the focal length difference as the clarity change measurement value.
[0109] Optionally, the first acquisition device 601 is specifically configured to:
[0110] When the first search step size is the second step size, if the clarity change measurement value is less than the first clarity change measurement threshold, then use the third step size as the first target step size value, and adjust the first search step size to the first target step size value; the third step size is greater than the second step size;
[0111] If the clarity change measurement value is greater than the second clarity change measurement threshold, then use the first step size as the first target step size value, and adjust the first search step size to the first target step size value; the second step size is greater than the first step size; the second clarity change measurement threshold is greater than the first clarity change measurement threshold;
[0112] If the clarity change measurement value is greater than the first clarity change measurement threshold and less than the second clarity change measurement threshold, then keep the first search step size unchanged.
[0113] Optionally, the second determination module 604 is specifically configured to:
[0114] When the second search step size is the minimum step size of the reader, determine the focal length with the largest image clarity score among the set number of focal lengths as the target focal length;
[0115] When the second search step size is not the minimum step size of the reader, determine a sub-interval from the focal length interval as the target interval, adjust the second search step size down to a second target step size value, and return to execute the step of sequentially selecting a set number of focal lengths from the target interval according to the second search step size, and respectively obtaining the image clarity scores under each of the set number of focal lengths, until the focal length with the largest image clarity score is determined from the set number of focal lengths as the target focal length, where the second target step size value is greater than or equal to the minimum step size.
[0116] Optionally, the second determination module 604 is specifically configured to:
[0117] When the second search step size is not the minimum step size of the reader, if among the set number of focal lengths selected sequentially, the first focal length is the left boundary of the target interval and the image clarity score corresponding to the last focal length is the largest, then use the sub-interval obtained by adjusting the left boundary of the target interval from the first focal length to the last focal length as the target interval;
[0118] If among the set number of focal lengths selected sequentially, the first focal length is the left boundary of the target interval, the image clarity score corresponding to the first focal length is the largest, and the image clarity score corresponding to the last focal length is the smallest, then use the sub-interval obtained by adjusting the right boundary of the target interval to the last focal length as the target interval;
[0119] If among the set number of focal lengths selected sequentially, the first focal length is the left boundary of the target interval and the image clarity score corresponding to the middle focal length is the largest, then use the sub-interval obtained by adjusting the right boundary of the target interval to the last focal length as the target interval.
[0120] Optionally, the second determination module 604 is specifically configured to:
[0121] Determine the larger value between the minimum step size and half of the second search step size, and use the larger value as the second target step size value;
[0122] Adjust the second search step size down to the second target step size value.
[0123] The search and focus device of the barcode reader provided by the embodiment of the present application can implement each process of the above-mentioned embodiment of the search and focus method of the barcode reader, and can achieve the same technical effect. To avoid repetition, it will not be described in detail here.
[0124] Figure 7 It is a structural diagram of a computer device provided by an embodiment of the present application. As shown in this figure, the computer device 7 of this embodiment includes: at least one processor 70 ( Figure 7 only one is shown), a memory 71, and a computer program 72 stored in the memory 71 and operable on the at least one processor 70. When the processor 70 executes the computer program 72, the steps in any of the above-mentioned method embodiments are implemented.
[0125] The computer device 7 can be a computing device such as a barcode reader, a desktop computer, a notebook, a palm computer, and a cloud server. The computer device 7 may include, but is not limited to, a processor 70 and a memory 71. Those skilled in the art can understand that Figure 7 it is only an example of the computer device 7 and does not constitute a limitation on the computer device 7. It may include more or fewer components than those shown in the figure, or combine some components, or different components. For example, the computer device may further include input / output devices, network access devices, buses, etc.
[0126] The processor 70 may be a central processing unit (CPU), or may also be other general-purpose processors, 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, discrete hardware components, etc. The general-purpose processor may be a microprocessor or the processor may also be any conventional processor, etc.
[0127] The memory 71 may be an internal storage unit of the computer device 7, such as the hard disk or memory of the computer device 7. The memory 71 may also be an external storage device of the computer device 7, such as a plug-in hard disk equipped on the computer device 7, a Smart Media Card (SMC), a Secure Digital (SD) card, a Flash Card, etc. Further, the memory 71 may also include both the internal storage unit of the computer device 7 and external storage devices. The memory 71 is used to store the computer program and other programs and data required by the computer device. The memory 71 may also be used to temporarily store data that has been output or is to be output.
[0128] Those skilled in the art can clearly understand that, for the convenience and brevity of description, only the above division of each functional unit and module is used as an example. In actual applications, the above functions can be allocated to different functional units and modules as needed, that is, the internal structure of the device can be divided into different functional units or modules to complete all or part of the functions described above. Each functional unit and module in the embodiments can be integrated into one processing unit, or each unit can exist physically alone, or two or more units can be integrated into one unit. The above integrated unit can be implemented in the form of hardware or in the form of a software functional unit. In addition, the specific names of each functional unit and module are only for the convenience of mutual distinction and do not limit the protection scope of this application. The specific working process of the units and modules in the above system can refer to the corresponding process in the foregoing method embodiments and will not be elaborated herein.
[0129] In the above embodiments, the descriptions of the various embodiments have their own emphases. For the parts not detailed or recorded in a certain embodiment, reference can be made to the relevant descriptions of other embodiments.
[0130] Those of ordinary skill in the art can realize that the units and algorithm steps of each example described in combination with the embodiments disclosed herein can be implemented by electronic hardware, or by a combination of computer software and electronic hardware. Whether these functions are executed in hardware or software depends on the specific application and design constraints of the technical solution. Professional technicians can use different methods to implement the described functions for each specific application, but such implementation should not be considered to exceed the scope of this application.
[0131] In the embodiments provided in the present application, it should be understood that the disclosed device / computer equipment and method can be implemented in other ways. For example, the device / computer equipment embodiments described above are merely illustrative. For example, the division of the modules or units is only a logical function division. In actual implementation, there may be other division methods. For example, multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the displayed or discussed couplings or direct couplings or communication connections to each other can be through some interfaces. The indirect couplings or communication connections of the devices or units can be in electrical, mechanical or other forms.
[0132] The units described as separate components may or may not be physically separated. The components displayed as units may or may not be physical units, that is, they can be located in one place, or they can be distributed to multiple network units. Some or all of the units can be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0133] In addition, in each embodiment of the present application, the functional units can be integrated in a processing unit, or each unit can exist physically alone, or two or more units can be integrated in one unit. The above integrated units can be implemented in the form of hardware or in the form of software functional units.
[0134] If the integrated module / unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, to implement all or part of the processes in the above method embodiments of the present application, it can also be completed by a computer program instructing relevant hardware. The computer program can be stored in a computer-readable storage medium. When the computer program is executed by a processor, the steps of the above method embodiments can be implemented. Among them, the computer program includes computer program code, and the computer program code can be in the form of source code, object code, executable file or some intermediate form, etc. The computer-readable medium can include: any entity or device that can carry the computer program code, recording medium, USB flash drive, mobile hard disk, magnetic disk, optical disk, computer memory, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), electrical carrier signal, telecommunication signal, and software distribution medium, etc. It should be noted that the content included in the computer-readable medium can be appropriately increased or decreased according to the requirements of legislation and patent practice in the jurisdiction. For example, in some jurisdictions, according to legislation and patent practice, the computer-readable medium does not include electrical carrier signals and telecommunication signals.
[0135] All or part of the processes in the methods of the above embodiments can also be implemented by a computer program product. When the computer program product runs on a computer device, the computer device is caused to execute the steps in the above method embodiments.
[0136] The above embodiments are only used to illustrate the technical solutions of the present application, rather than to limit them. Although the present application has been described in detail with reference to the foregoing embodiments, those of ordinary skill in the art should understand that: they can still modify the technical solutions recorded in the foregoing embodiments, or perform equivalent replacements on some of the technical features; and these modifications or replacements do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of the present application, and should all be included in the protection scope of the present application.
Claims
1. A search and focus method for a barcode reader, characterized in that, Including: Based on the adjustable focus range of the barcode reader, starting from the first boundary value in the adjustable focus range as the starting focal length, moving the focal length according to the first search step size, and sequentially obtaining the image sharpness scores at each focal length until the focal length is moved to the second boundary value in the adjustable focus range, wherein the first search step size is adjusted according to the change in the image sharpness score between adjacent focal lengths; Based on the sequentially obtained image sharpness scores, obtaining the focal length interval where the maximum peak value of the image sharpness score is located; Taking the focal length interval as the target interval, sequentially selecting a set number of focal lengths from the target interval according to the second search step size, and respectively obtaining the image sharpness scores at each of the set number of focal lengths; Determining the focal length with the maximum image sharpness score as the target focal length.
2. The method according to claim 1, wherein The step of, based on the adjustable focus range of the barcode reader, starting from the first boundary value in the adjustable focus range as the starting focal length, moving the focal length according to the first search step size, and sequentially obtaining the image sharpness scores at each focal length until the focal length is moved to the second boundary value in the adjustable focus range, includes: Starting from the first boundary value in the adjustable focus range as the starting focal length, moving the current focal length according to the first search step size, and calculating the image sharpness score of the barcode reader at the moved current focal length; Calculating a sharpness change measurement value according to the adjacent focal lengths and the image sharpness scores of the adjacent focal lengths; Based on the sharpness change measurement value, adjusting the first search step size to a first target step size value, and returning to execute the step of moving the current focal length according to the first search step size and calculating the image sharpness score of the barcode reader at the moved current focal length until the focal length is moved to the second boundary value in the adjustable focus range, wherein the magnitude of the first target step size value is negatively correlated with the magnitude of the sharpness change measurement value.
3. The method according to claim 2, wherein The step of calculating a sharpness change measurement value according to the adjacent focal lengths and the image sharpness scores of the adjacent focal lengths includes: Obtaining the focal length difference between the adjacent focal lengths and obtaining the score difference between the image sharpness scores of the adjacent focal lengths; Determining the ratio of the score difference to the focal length difference as the sharpness change measurement value.
4. The method according to claim 2, wherein The step of, based on the sharpness change measurement value, adjusting the first search step size to a first target step size value includes: When the first search step size is the second step size, if the sharpness change measurement value is less than the first sharpness change measurement threshold, taking the third step size as the first target step size value and adjusting the first search step size to the first target step size value; the third step size is greater than the second step size; If the sharpness change measurement value is greater than the second sharpness change measurement threshold, taking the first step size as the first target step size value and adjusting the first search step size to the first target step size value; the second step size is greater than the first step size; the second sharpness change measurement threshold is greater than the first sharpness change measurement threshold; If the clarity change measurement value is greater than the first clarity change measurement threshold and less than the second clarity change measurement threshold, the first search step size remains unchanged.
5. The method according to claim 1, wherein The determining the focal length with the maximum image clarity score as the target focal length includes: When the second search step size is the minimum step size of the code reader, determining the focal length with the maximum image clarity score among the set number of focal lengths as the target focal length; When the second search step size is not the minimum step size of the code reader, determining a sub - interval from the focal length interval as the target interval, adjusting the second search step size down to a second target step size value, and returning to execute the step of sequentially selecting a set number of focal lengths from the target interval according to the second search step size and respectively obtaining the image clarity scores for each focal length among the set number of focal lengths until determining the focal length with the maximum image clarity score among the set number of focal lengths as the target focal length, where the second target step size value is greater than or equal to the minimum step size.
6. The method according to claim 5, wherein The determining a sub - interval from the focal length interval as the target interval when the second search step size is not the minimum step size of the code reader includes: When the second search step size is not the minimum step size of the code reader, if among the set number of sequentially selected focal lengths, the first focal length is the left boundary of the target interval and the image clarity score corresponding to the last focal length is the maximum, then taking the sub - interval obtained by adjusting the left boundary of the target interval from the first focal length to the last focal length as the target interval; If among the set number of sequentially selected focal lengths, the first focal length is the left boundary of the target interval, the image clarity score corresponding to the first focal length is the maximum, and the image clarity score corresponding to the last focal length is the minimum, then taking the sub - interval obtained by adjusting the right boundary of the target interval to the last focal length as the target interval; If among the set number of sequentially selected focal lengths, the first focal length is the left boundary of the target interval and the image clarity score corresponding to the middle focal length is the maximum, then taking the sub - interval obtained by adjusting the right boundary of the target interval to the last focal length as the target interval.
7. The method according to claim 5, characterized in that, The adjusting the second search step size down to the second target step size value includes: Determining the larger value between the minimum step size and half of the second search step size, and taking the larger value as the second target step size value; Adjusting the second search step size down to the second target step size value.
8. A search and focus device for a barcode reader, characterized in that, Includes: A first acquisition device, configured to, based on the adjustable focal length range of the code reader, start from the first boundary value in the adjustable focal length range as the starting focal length, move the focal length according to the first search step size, and sequentially obtain the image clarity scores for each focal length until the focal length is moved to the second boundary value in the adjustable focal length range, where the first search step size is adjusted according to the change in the image clarity scores between adjacent focal lengths; A second acquisition device, configured to obtain a focal length interval where the maximum peak of the image sharpness score is located based on the sequentially acquired image sharpness scores; A first determination module, configured to use the focal length interval as a target interval, sequentially select a set number of focal lengths from the target interval according to a second search step size, and respectively obtain the image sharpness scores at each of the set number of focal lengths; A second determination module, configured to determine the focal length with the maximum image sharpness score as the target focal length.
9. A computer device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that, When the processor executes the computer program, the steps of the method according to any one of claims 1 to 7 are implemented.
10. A computer-readable storage medium storing a computer program, characterized in that, When the computer program is executed by the processor, the steps of the method according to any one of claims 1 to 7 are implemented.
Citation Information
Cited By
Focusing method and system of infrared camera
CN121357418A