WO2023280285A1 - 对焦方法、装置及存储介质 - Google Patents

对焦方法、装置及存储介质 Download PDF

Info

Publication number
WO2023280285A1
WO2023280285A1 PCT/CN2022/104462 CN2022104462W WO2023280285A1 WO 2023280285 A1 WO2023280285 A1 WO 2023280285A1 CN 2022104462 W CN2022104462 W CN 2022104462W WO 2023280285 A1 WO2023280285 A1 WO 2023280285A1
Authority
WO
WIPO (PCT)
Prior art keywords
lens
score
code
code reading
maximum value
Prior art date
Application number
PCT/CN2022/104462
Other languages
English (en)
French (fr)
Inventor
金一鸣
Original Assignee
杭州海康机器人股份有限公司
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by 杭州海康机器人股份有限公司 filed Critical 杭州海康机器人股份有限公司
Priority to KR1020237044950A priority Critical patent/KR20240013880A/ko
Priority to JP2023580583A priority patent/JP2024525462A/ja
Priority to EP22837030.0A priority patent/EP4369247A1/en
Publication of WO2023280285A1 publication Critical patent/WO2023280285A1/zh

Links

Images

Classifications

    • GPHYSICS
    • G02OPTICS
    • G02BOPTICAL ELEMENTS, SYSTEMS OR APPARATUS
    • G02B7/00Mountings, adjusting means, or light-tight connections, for optical elements
    • G02B7/28Systems for automatic generation of focusing signals
    • G02B7/36Systems for automatic generation of focusing signals using image sharpness techniques, e.g. image processing techniques for generating autofocus signals
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04NPICTORIAL COMMUNICATION, e.g. TELEVISION
    • H04N23/00Cameras or camera modules comprising electronic image sensors; Control thereof
    • H04N23/60Control of cameras or camera modules
    • H04N23/67Focus control based on electronic image sensor signals
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06KGRAPHICAL DATA READING; PRESENTATION OF DATA; RECORD CARRIERS; HANDLING RECORD CARRIERS
    • G06K7/00Methods or arrangements for sensing record carriers, e.g. for reading patterns
    • G06K7/10Methods or arrangements for sensing record carriers, e.g. for reading patterns by electromagnetic radiation, e.g. optical sensing; by corpuscular radiation
    • G06K7/10544Methods or arrangements for sensing record carriers, e.g. for reading patterns by electromagnetic radiation, e.g. optical sensing; by corpuscular radiation by scanning of the records by radiation in the optical part of the electromagnetic spectrum
    • G06K7/10792Special measures in relation to the object to be scanned
    • G06K7/10801Multidistance reading
    • G06K7/10811Focalisation
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06KGRAPHICAL DATA READING; PRESENTATION OF DATA; RECORD CARRIERS; HANDLING RECORD CARRIERS
    • G06K7/00Methods or arrangements for sensing record carriers, e.g. for reading patterns
    • G06K7/10Methods or arrangements for sensing record carriers, e.g. for reading patterns by electromagnetic radiation, e.g. optical sensing; by corpuscular radiation
    • G06K7/14Methods or arrangements for sensing record carriers, e.g. for reading patterns by electromagnetic radiation, e.g. optical sensing; by corpuscular radiation using light without selection of wavelength, e.g. sensing reflected white light
    • G06K7/1404Methods for optical code recognition
    • G06K7/1408Methods for optical code recognition the method being specifically adapted for the type of code
    • G06K7/14172D bar codes
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04NPICTORIAL COMMUNICATION, e.g. TELEVISION
    • H04N17/00Diagnosis, testing or measuring for television systems or their details
    • H04N17/002Diagnosis, testing or measuring for television systems or their details for television cameras
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04NPICTORIAL COMMUNICATION, e.g. TELEVISION
    • H04N23/00Cameras or camera modules comprising electronic image sensors; Control thereof
    • H04N23/50Constructional details
    • H04N23/54Mounting of pick-up tubes, electronic image sensors, deviation or focusing coils
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04NPICTORIAL COMMUNICATION, e.g. TELEVISION
    • H04N23/00Cameras or camera modules comprising electronic image sensors; Control thereof
    • H04N23/60Control of cameras or camera modules
    • H04N23/67Focus control based on electronic image sensor signals
    • H04N23/673Focus control based on electronic image sensor signals based on contrast or high frequency components of image signals, e.g. hill climbing method
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04NPICTORIAL COMMUNICATION, e.g. TELEVISION
    • H04N23/00Cameras or camera modules comprising electronic image sensors; Control thereof
    • H04N23/60Control of cameras or camera modules
    • H04N23/695Control of camera direction for changing a field of view, e.g. pan, tilt or based on tracking of objects
    • GPHYSICS
    • G02OPTICS
    • G02BOPTICAL ELEMENTS, SYSTEMS OR APPARATUS
    • G02B7/00Mountings, adjusting means, or light-tight connections, for optical elements
    • G02B7/02Mountings, adjusting means, or light-tight connections, for optical elements for lenses
    • G02B7/04Mountings, adjusting means, or light-tight connections, for optical elements for lenses with mechanism for focusing or varying magnification
    • G02B7/08Mountings, adjusting means, or light-tight connections, for optical elements for lenses with mechanism for focusing or varying magnification adapted to co-operate with a remote control mechanism
    • GPHYSICS
    • G03PHOTOGRAPHY; CINEMATOGRAPHY; ANALOGOUS TECHNIQUES USING WAVES OTHER THAN OPTICAL WAVES; ELECTROGRAPHY; HOLOGRAPHY
    • G03BAPPARATUS OR ARRANGEMENTS FOR TAKING PHOTOGRAPHS OR FOR PROJECTING OR VIEWING THEM; APPARATUS OR ARRANGEMENTS EMPLOYING ANALOGOUS TECHNIQUES USING WAVES OTHER THAN OPTICAL WAVES; ACCESSORIES THEREFOR
    • G03B13/00Viewfinders; Focusing aids for cameras; Means for focusing for cameras; Autofocus systems for cameras
    • G03B13/32Means for focusing
    • G03B13/34Power focusing
    • G03B13/36Autofocus systems

Definitions

  • the present application relates to the technical field of image acquisition, and in particular to a focusing method, device and storage medium.
  • code-reading cameras for reading two-dimensional codes and barcodes are widely used in industrial scenarios such as express logistics.
  • the distance between the code-reading camera and the working plane often changes.
  • an auto-focus method can usually be used to quickly focus the code-reading camera on the working plane.
  • the lens of the code-reading camera moves to a position, a frame of image is collected at the position. Afterwards, the image clarity score of the collected image is calculated by using the image autocorrelation method or the image high-frequency component method. In this way, after obtaining the image clarity score when the lens of the code-reading camera is in multiple positions, the position with the highest image clarity score is taken as the best position of the lens, and then the lens is driven to move to the best position to complete autofocus .
  • the embodiment of the present application provides a focusing method, device and storage medium, which can ensure the success rate of code reading after focusing while ensuring the clarity of the focusing code reading camera. Described technical scheme is as follows:
  • a focusing method comprising:
  • Focusing is done according to the best position of said lens.
  • the determining the optimal position of the lens according to the image clarity scores and code reading scores of the multiple positions includes:
  • Focusing is done according to the best position of said lens.
  • the obtaining the image clarity score and the code reading score when the lens of the code reading camera is in multiple positions includes:
  • the starting point of search is the starting point or the end point of the travel of the lens
  • the starting point of the travel of the lens is the target of the lens and the object to be read
  • the position point where the vertical distance of the surface is the largest, and the stroke end point of the lens is the position point where the vertical distance between the lens and the target surface is the smallest;
  • the determining at least one rough position of the lens from the multiple positions according to the image clarity scores at the multiple positions includes:
  • the first position is used as the rough position of the lens.
  • the determining at least one rough position of the lens from the multiple positions according to the image clarity scores at the multiple positions includes:
  • the determined second position is used as at least one rough position of the lens.
  • the determining the optimal position of the lens according to at least one rough position of the lens and the code reading scores at the multiple positions includes:
  • the optimal position of the lens is determined.
  • the determining the optimal position of the lens according to the local maximum value of the code reading score in each candidate search interval includes:
  • the position corresponding to the local maximum value of the code-reading score in the candidate search interval is used as the Optimal position of the lens
  • the maximum value among the local maximum values of code reading scores in multiple candidate search intervals is used as the global maximum value; if the position corresponding to the global maximum value is one, the The position corresponding to the global maximum value is used as the optimal position of the lens. If there are multiple positions corresponding to the global maximum value, each of the multiple positions corresponding to the global maximum value is determined to be a candidate for itself. The distance between the rough positions corresponding to the search interval, and the position with the smallest distance between the rough positions corresponding to the candidate search interval in which it is located is taken as the best position of the lens.
  • the focusing according to the best position of the lens includes:
  • the lens is driven to move to the best position of the lens to complete focusing.
  • a focusing device comprising:
  • An acquisition module configured to acquire image clarity scores and code reading scores when the lens of the code reading camera is in multiple positions, and the code reading scores are used to characterize the code reading success rate of the code reading camera;
  • a determination module configured to determine the optimal position of the lens according to the image clarity scores and code reading scores at the multiple positions
  • the focusing module is used for focusing according to the optimal position of the lens.
  • the determining module includes:
  • a first determining module configured to determine at least one rough position of the lens from the plurality of positions according to the image sharpness scores at the plurality of positions;
  • the second determination module is used to determine the optimal position of the lens according to at least one rough position of the lens and the code reading scores at the plurality of positions;
  • the acquiring module is mainly used for:
  • the starting point of search is the starting point or the end point of the travel of the lens
  • the starting point of the travel of the lens is the target of the lens and the object to be read
  • the position point where the vertical distance of the surface is the largest, and the stroke end point of the lens is the position point where the vertical distance between the lens and the target surface is the smallest;
  • the first determination module is mainly used for:
  • the first position is used as the rough position of the lens.
  • the first determination module is mainly used for:
  • the determined second position is used as at least one rough position of the lens.
  • the second determination module is mainly used for:
  • the optimal position of the lens is determined.
  • the second determining module is mainly further configured to:
  • the position corresponding to the local maximum value of the code-reading score in the candidate search interval is used as the Optimal position of the lens
  • the maximum value among the local maximum values of code reading scores in multiple candidate search intervals is used as the global maximum value; if the position corresponding to the global maximum value is one, the The position corresponding to the global maximum value is used as the optimal position of the lens. If there are multiple positions corresponding to the global maximum value, each of the multiple positions corresponding to the global maximum value is determined to be a candidate for itself. The distance between the rough positions corresponding to the search interval, and the position with the smallest distance between the rough positions corresponding to the candidate search interval in which it is located is taken as the best position of the lens.
  • the focusing module is mainly used for:
  • the lens is driven to move to the best position of the lens to complete focusing.
  • a focusing device in another aspect, the device includes a control unit, a motor, a lens and a moving mechanism;
  • the moving mechanism drives the lens to move in a direction perpendicular to the mirror surface of the lens
  • the control unit is connected to the motor, and the control unit is used to execute any one of the methods described above, so as to control the motor to drive the moving mechanism to drive the lens to move to complete focusing.
  • a computer device in another aspect, includes a processor, a communication interface, a memory, and a communication bus, and the processor, the communication interface, and the memory complete mutual communication through the communication bus , the memory is used to store computer programs, and the processor is used to execute the programs stored in the memory, so as to realize the steps of the aforementioned focusing method.
  • a computer-readable storage medium wherein a computer program is stored in the storage medium, and when the computer program is executed by a processor, the steps of the aforementioned focusing method are implemented.
  • a computer program product containing instructions, which, when run on a computer, causes the computer to execute the steps of the aforementioned focusing method.
  • automatic focusing is performed according to the image clarity score and the code reading score when the lens of the code reading camera is in different positions. Since the code-reading score can represent the code-reading success rate of the code-reading camera, the embodiment of the present application actually evaluates the focusing effect of the lens at different positions by combining the image clarity and code-reading effect of the code-reading camera. To determine the best position of the lens and then complete the automatic focus, in this way, not only the clarity of the image collected by the code-reading camera after the focus is completed, but also the success rate of code-reading by the code-reader camera after the focus is completed.
  • FIG. 1 is a system architecture diagram involved in a focusing method provided by an embodiment of the present application
  • FIG. 2 is a schematic structural diagram of a focusing device provided by an embodiment of the present application.
  • Fig. 3a is a flowchart of a focusing method provided by an embodiment of the present application.
  • Fig. 3b is a flow chart of another focusing method provided by the embodiment of the present application.
  • Fig. 4 is a kind of image sharpness score curve chart provided by the embodiment of the present application.
  • Fig. 5a is a schematic structural diagram of another focusing device provided by an embodiment of the present application.
  • Fig. 5b is a schematic structural diagram of another focusing device provided by an embodiment of the present application.
  • Fig. 6a is a schematic structural diagram of a computer device provided by an embodiment of the present application.
  • Fig. 6b is a schematic structural diagram of another computer device provided by an embodiment of the present application.
  • the focusing method provided in the embodiment of the present application can be applied to industrial scenarios involving reading of two-dimensional codes or barcodes.
  • a code-reading camera is installed on the gantry above the express automatic conveyor belt, and the two-dimensional code or barcode on the upper surface of the express package is read by the code-reading camera to sort the express package.
  • the code reading can be adjusted through the focusing method provided by the embodiment of the application The distance between the lens of the camera and the upper surface of the express package enables fast autofocus.
  • a code-reading camera is installed on the production line in the factory, and the two-dimensional code or barcode on the product on the production line is read by the code-reading camera to realize the storage of product information.
  • the distance between the code-reading camera and the surface where the product’s QR code or barcode is located may change.
  • the focusing method provided in the embodiment adjusts the distance between the lens of the code-reading camera and the upper surface of the express package, thereby realizing fast automatic focusing.
  • a stationary reference object can be placed under the lens of the code-reading camera, and then the code-reading camera can be controlled by the reference object. focusing. After the code-reading camera has focused, the code-reading camera is ready for use. In the subsequent process of using the code-reading camera, the object to be read passes under the lens of the code-reading camera. If the height difference between the object to be read and the aforementioned reference object for focusing is large, the The code-reading camera performs re-focusing. In this case, fast auto-focusing can be achieved through the focusing method provided by the embodiment of the present application.
  • the above are only two possible application scenarios provided by the embodiment of the present application.
  • the embodiment of the present application can also be used in other industrial code reading scenarios requiring auto-focus, which is not limited in the embodiment of the present application.
  • FIG. 1 is a structural diagram of an image acquisition system provided by an embodiment of the present application. As shown in FIG. 1 , the image acquisition system includes a code reading camera 101 , a conveyor belt 102 and an object 103 to be read on the conveyor belt 102 .
  • the code-reading camera 101 may be installed on a door frame above the conveyor belt 102 . Moreover, the lens of the code reading camera 101 faces the target surface of the object to be read 103 on the conveyor belt 102 .
  • the target surface refers to the plane where the two-dimensional code or the barcode is located. In the express logistics industry, usually, the target surface is the upper surface of the express package when it is on the conveyor belt 102, that is, the surface of the express package away from the conveyor belt. Of course, in other possible scenarios, the target surface may also be the side of the object 103 to be read, which is not limited in this embodiment of the present application.
  • the code reading camera 101 may start image acquisition when a trigger signal is detected. Among them, the code reading camera 101 firstly adjusts the position of the lens by moving the lens.
  • adjusting the position of the lens refers to adjusting the overall position of the lens, or it may refer to adjusting the local position of the lens, but the focal length of the code reading camera should be adjusted accordingly. It changes with the adjustment of the position of the lens.
  • the centroid of the lens may be adjusted while keeping the shape of the lens unchanged, and in another possible implementation manner, the lens is a T-Lens (variable focus) lens Or liquid lens, then can be under the situation that keeps the centroid position of the lens unchanged, adjust the relative position between each point inside the lens, namely change the shape of the adjusted lens.
  • T-Lens variable focus
  • liquid lens liquid lens
  • adjusting the centroid of the lens is used as an example for illustration, and the principle of changing the shape of the lens is completely the same, and will not be repeated here.
  • the distance between the lens and the target surface of the object to be read also changes, so adjusting the distance of the center of mass of the lens also means adjusting the distance between the lens and the target surface of the object to be read , whenever a distance is adjusted, the code-reading camera can collect an image of the object to be read, and calculate the image clarity score and code-reading score when the lens is in multiple positions based on the collected images, and then according to the lens in multiple positions The image clarity score and code reading score at the time, and determine the best position of the lens from the multiple positions.
  • An image acquisition in this paper can be only one image or multiple images.
  • the image clarity score is used to indicate the clarity of the image
  • the code reading score is used to indicate the quality of the QR code and barcode in the image.
  • the image clarity score is used to indicate the overall clarity of the multiple images
  • the code reading score is used to indicate the overall quality of the two-dimensional codes and barcodes in the multiple images.
  • the sharpness score it may be to determine the respective sharpness of the plurality of images to obtain an image sharpness score representing the mean value of the sharpness of all images, or to determine the clearest image from the multiple images. , generating an image sharpness score that represents how sharp this sharpest image is.
  • the code-reading camera drives the lens to move to the optimal position for focusing by controlling the motor.
  • the code reading camera 101 can capture the image of the two-dimensional code or the barcode on the target surface of the object to be read 103, and read the two-dimensional code or the barcode.
  • FIG. 2 shows a schematic structural diagram of a focusing device 200 applied to a code reading camera.
  • the focusing device 200 includes a control unit 201 , a motor 202 , a lens 203 and a moving mechanism 204 .
  • control unit 201 is connected with the motor 202 .
  • the lens 203 may be located in a moving mechanism 204, as shown in FIG. 2 .
  • the lens 203 is connected to a moving mechanism 204 (not shown in FIG. 2 ).
  • the motor 202 is connected to the moving mechanism 204, so that the control unit 201 can control the motor 202 to drive the moving mechanism 204 to move.
  • the movement of the moving mechanism 204 drives the lens 203 to move.
  • the moving mechanism 204 can drive the lens 203 to move in a direction perpendicular to the mirror surface of the lens 203, that is, to move in the direction of the optical axis of the mirror surface (hereinafter referred to as the axis of the mirror surface), and the movable stroke of the moving mechanism 204 is certain. of.
  • the lens 203 will also move along an axis perpendicular to its mirror surface, and the stroke of the lens 203 is also constant.
  • the control unit 201 first controls the motor 202 to drive the moving mechanism 204 to drive the lens 203 to continuously move along the specified search direction according to the specified search step size, so as to search for a rough position of the lens 203 .
  • the specified search step size can be a fixed step size, or a variable step size.
  • the search step size is fixed to 1 unit step size, and in another In a possible embodiment, the initial search step size is 2 unit steps, and decreases as the image definition score increases.
  • the control unit 201 After obtaining the rough position of the lens 203, the control unit 201 determines the best position of the lens 203 according to the code reading scores of the lens 203 at each position determined by the lens 203 during the rough search process, and then calculates the current position of the lens 203. The moving distance from the position to the best position and the moving direction of the focus. Afterwards, the control unit 201 controls the motor 202 to drive the moving mechanism 204 to move the lens 203 along the focus moving direction to reach the best position, so as to complete the focus.
  • the code reading camera also includes other necessary camera components such as an image sensor, a light filter component, and a supplementary light device, which will not be described in this embodiment of the present application.
  • Fig. 3 is a flow chart of a focusing method provided by an embodiment of the present application. This method can be applied to a code-reading camera, or can be applied to an electronic device independent of the code-reading camera and capable of controlling the code-reading camera to focus. Example Specifically, it can be applied to the control unit of the code-reading camera shown in FIG. 2 . Referring to Fig. 3, this method comprises the steps:
  • Step 301 Obtain the image clarity score and code reading score when the lens of the code reading camera is in multiple positions, and the code reading score is used to represent the code reading success rate of the code reading camera.
  • the code-reading score can represent the code-reading success rate of the code-reading camera.
  • the code reading camera after the code reading camera starts to focus, it first acquires the image clarity score and the code reading score of the lens at the starting point of the search.
  • search starting point refers to that the lens starts to move from the search starting point after starting to focus.
  • the search starting point may be the starting point of the travel of the lens, or the end of the travel of the lens of the code reading camera.
  • the starting point of the travel of the lens is the position point where the vertical distance between the lens and the target surface of the object to be read is the largest
  • the end point of the travel of the lens is the position point where the vertical distance between the lens and the target surface is the smallest. That is to say, when the moving mechanism in the code-reading camera drives the lens to move away from the target surface in a direction perpendicular to the mirror surface of the lens, and moves to the point where it cannot continue to move, the distance between the lens and the target surface is the largest. At this point, the position of the lens is the starting point of the lens' travel.
  • the moving mechanism in the code-reading camera drives the lens to move toward the target surface in a direction perpendicular to the mirror surface of the lens, and moves to the point where it can no longer move, the distance between the lens and the target surface is the smallest, and , the position of the lens is the end of the lens' stroke.
  • the code-reading camera adjusts the position of the lens to the starting point or the end point of the stroke before auto-focusing is required each time.
  • the code-reading camera can collect images when the lens is at the starting point of the search, and use the image autocorrelation method or image high-frequency component method or other methods for calculating the image clarity score, and use the collected images at this position to calculate the lens position.
  • the image clarity score at this location wherein, the higher the image definition score, the higher the clarity of the collected image will be when the image is collected when the lens is at this position.
  • the code-reading camera can also calculate the code-reading score of the barcode in the image collected at the starting point of the search based on the ISO15416 standard, or calculate the QR code in the image collected at the starting point of the search according to the ISO15415 standard code reading score.
  • the higher the code reading score the better the code reading effect when the image is read when the lens is in this position.
  • the code reading camera can control the motor to drive the lens to move continuously from the search starting point. Every time the lens moves to a position, the code reading camera calculates an image clarity score and a code reading score while the lens is in that position.
  • the code reading camera controls the motor to drive the lens to move along the specified search direction according to the specified search step from the search starting point.
  • the image clarity score and code reading score are obtained once.
  • the specified search direction is the direction from the starting point of the shot to the end of the shot; when the starting point of the search is the end point of the shot, the specified search direction is from the end point of the shot to The direction of the start of the trip.
  • the lens of the code reading camera can be located in a moving mechanism or connected to the moving mechanism, and the movement of the moving mechanism drives the lens to move.
  • the moving mechanism moves along a direction perpendicular to the mirror surface of the lens, and the movable stroke of the moving mechanism is certain.
  • the lens will also move along a direction perpendicular to its own mirror surface, and the stroke of the lens is also constant.
  • the lens may move according to a specified search step, and the specified search step is the distance for moving the lens once.
  • the specified search step size can be manually set. Wherein, the smaller the specified search step size is, the higher the search accuracy is, and the larger the specified search step size is, the higher the search efficiency is.
  • the lens when the code-reading camera starts to focus, the lens may be neither at the starting point nor at the end of the stroke, in this case, the code-reading camera can control the lens to move from the current position Go to the starting point or end point of the shot, and then move along the specified search direction according to the specified search step from the starting point or end point of the shot according to the method described above.
  • the code reading camera can collect an image at that position, and use the image autocorrelation method or image high-frequency component method or other methods to calculate the image clarity score
  • the method uses the collected image at the position to calculate the image sharpness score when the lens is at the position.
  • the code-reading camera can also calculate the code-reading score of the barcode in the image collected at the position based on the ISO15416 standard, or calculate the reading score of the two-dimensional code in the image collected at the position according to the ISO15415 standard. code scoring.
  • Step S302 Determine the best position of the lens according to the image clarity scores and code reading scores at multiple positions.
  • the best position judgment method can be different according to different application scenarios, but the image clarity score and code reading score of the best position should be as high as possible, and the image clarity score of any other position is lower than the image clarity score of the best position score, or, the reading score is lower than that of the best position.
  • the comprehensive score of each position is determined according to the image clarity scores and code reading scores at multiple positions, and the position with the highest comprehensive score is determined as the best position of the lens.
  • the comprehensive score of each position is obtained by weighting and summing the image clarity score and the code reading score of the position. /or set by experience.
  • step 302 includes two steps: step 3021 and step 3022:
  • step 3021 according to the image sharpness scores at the multiple positions, determine at least one rough position of the lens from the multiple positions.
  • the code reading camera can calculate the image clarity score and reading value after the lens moves once. code scoring. Based on this, the code-reading camera can obtain an image sharpness score at the moved position during the lens movement process, that is, to judge the change trend of all the acquired image clarity scores with the movement of the lens. If as the lens moves, the acquired multiple image sharpness scores show a trend of becoming larger and then smaller, and the latest acquired image clarity score is higher than the maximum value among the multiple acquired image clarity scores.
  • the code reading camera further judges whether the code reading score at the first position corresponding to the maximum value among the obtained multiple image clarity scores is greater than the second threshold. If it is greater than the second threshold, the code reading camera takes the first position as the rough position of the lens.
  • the code-reading camera can draw the relationship between the acquired image clarity scores and the corresponding position curve. If the image sharpness score on the relationship curve shows a trend of becoming larger first and then smaller, the code reading camera calculates the maximum value of the acquired multiple image sharpness scores and the image sharpness at the current position of the lens The difference between the scores, and then calculate the ratio of the difference to the maximum value among the plurality of image clarity scores, and the ratio is the reduction ratio. If the drop ratio is greater than the first threshold, it is determined that the drop ratio has reached the first threshold, and it is considered that the lens position with the highest image clarity has been found.
  • the code-reading camera can further use the code-reading score to identify Determine the best position for the lens.
  • the code-reading camera can use the first position as the rough position of the searched lens.
  • the code-reading camera may stop moving the lens, that is, stop searching for a rough position of the lens.
  • the first threshold is a preset ratio value, and the ratio value may be 20%, 40% or other values, which is not limited in this embodiment of the present application.
  • the second threshold may be a predetermined value not greater than the minimum value of the code reading score when there is a two-dimensional code or barcode in the field of view of the code reading camera.
  • the second threshold may be 0, 1, 2 and other values, This embodiment of the present application does not limit it.
  • the code-reading camera can continue to drive the lens to move to obtain the image clarity score and code-reading score at the next position, and repeat the above judgment process.
  • the lens may not need to move to all positions along the specified search direction, and the code reading camera can search for a rough position. In this way, the search time can be reduced and the search efficiency can be improved.
  • the code-reading camera can also be clear according to the acquired images at all positions during the lens movement process after the lens moves from the start point to the end point or from the end point to the start point A degree score is used to determine at least one rough location of the shot.
  • the relationship curve between the multiple positions of the code reading camera and the image clarity scores at the multiple positions during the moving process and the image clarity scores at the multiple positions can be drawn; at least A peak image clarity score; determine a second position whose corresponding code reading score is greater than a second threshold from at least one position corresponding to at least one image clarity score peak; use the determined second position as at least one rough position of the lens .
  • the relationship curves between the image clarity scores at multiple positions obtained by the code reading camera drawing lens from the search start point to the search end point and the multiple positions can be drawn.
  • the code reading camera obtains the peak value of the image clarity score at each peak point in the relationship curve, so as to obtain at least one peak value of the image clarity score.
  • the peak value of the image clarity score may be determined from the relationship curve based on any peak-finding algorithm, which is not limited in this application.
  • the code reading camera judges whether the code reading score at the position corresponding to each image clarity score peak value is greater than the second threshold, and assigns the corresponding code reading score greater than the second threshold to the position as a second position. At this time, there may be one or more determined second positions, and the code reading camera may use the determined second position as at least one rough position.
  • Fig. 4 is a graph showing a relationship between multiple positions and image clarity scores at the multiple positions according to an embodiment of the present application.
  • the code reading camera can obtain the peak value of each peak point, thereby obtaining 3 peak points S1, S2 and S3 of the image sharpness score.
  • the code reading camera judges whether the code reading score at the position corresponding to each peak value is greater than the second threshold. Assuming that the second threshold is 0, the code reading scores at position A corresponding to S1 and position C corresponding to S3 are both greater than 0, and the code reading score at position B corresponding to S2 is equal to 0, then the code reading camera will compare position A and position C as the rough position of the lens.
  • the code reading camera can obtain the maximum value of the image clarity score from at least one peak value of the image clarity score, and use the position corresponding to the maximum value of the image clarity score as the best position of the lens, and then refer to step 304 The realization of the method, focusing according to the best position of the lens.
  • Step 3022 Determine the optimal position of the lens according to at least one rough position of the lens and the code reading scores at multiple positions.
  • the code reading camera After obtaining at least one rough position of the lens, the code reading camera conducts a fine search for the at least one rough position and other positions near the rough position according to the obtained multiple code reading scores, so as to determine the best position of the lens.
  • the code reading camera first determines the candidate search interval corresponding to each rough position, and the candidate search interval is the lens position interval centered on the corresponding rough position; the code reading corresponding to each position included in each candidate search interval In scoring, determine the local maximum value of the code reading score in each candidate search interval; determine the best position of the lens according to the local maximum value of the code reading score in each candidate search interval.
  • this rough position is called the first rough position.
  • the code-reading camera takes the first rough position as the center, and specifies the distance forward and backward along the specified search direction, so that A candidate search interval corresponding to the first rough position is formed. Wherein, the specified distance is greater than the specified search step size.
  • the position S is centered forward L and backward L along the specified search direction to form a candidate search interval [S-L, S+L], wherein S is greater than L.
  • the code reading camera After determining the candidate search interval corresponding to the first rough position, for each position where the lens moves in the candidate search interval, the code reading camera can obtain the code reading score at the corresponding position, and from the acquired The maximum value is determined in the code-reading score, and the maximum value is the local maximum value of the code-reading score in the candidate search interval. It should be noted that if there is one rough position, there is also one corresponding candidate search interval, and thus, the obtained local maximum value of the reading score is also one. Although there is one local maximum value of the code-reading score, there may be one or more positions corresponding to the local maximum value of the code-reading score.
  • the reading score at one position may be the local maximum value, or there may be multiple positions at which the reading score is the same, all of which are the local maximum value of the reading score. Based on this, if there is one candidate search interval, and the position corresponding to the local maximum value of the code reading score in the candidate search interval is also one, the code reading camera can directly use the position corresponding to the local maximum value of the code reading score as the lens Best location.
  • the code reading camera can select from multiple positions corresponding to the local maximum value of the code reading score in the candidate search interval , select the third position closest to the rough position corresponding to the candidate search interval, and use the third position as the best position of the shot.
  • the obtained local maximum value of the code-reading score is also multiple.
  • the maximum value of the code score local maximum value is obtained to obtain the global maximum value. At this time, there may be one position corresponding to the global maximum value, or there may be multiple positions.
  • the position corresponding to the global maximum value is directly used as the best position of the lens, and if there are multiple positions corresponding to the global maximum value, then it is determined that the global maximum value corresponds to The distance between each position of the corresponding position and the rough position corresponding to the candidate search interval where the corresponding position is located, and the position with the smallest distance between the rough positions corresponding to the candidate search interval where the corresponding position is located is taken as the best position of the lens.
  • a is located in the candidate search interval U1
  • the rough position corresponding to U1 is M
  • b is located in the candidate search interval U2
  • U2 corresponds to
  • the rough position is N
  • c is located in the candidate search interval U3
  • the rough position corresponding to U3 is Q
  • the code reading camera calculates the distance between a and M to obtain the first distance
  • the second distance calculates the distance between c and Q to obtain the third distance. Compare the size of the first distance, the second distance and the third distance, assuming that the first distance is the smallest, then take a as the best position of the lens.
  • the code reading camera can acquire the image sharpness score of the lens at the search starting point when the lens is at the search starting point, and subsequently, starting from the search starting point, each time the code reading camera The lens moves once according to the specified search step, and the code reading camera can obtain the image clarity score at the position where the lens moves.
  • the specified search step used here is referred to as the first search step.
  • the code-reading camera can obtain an image sharpness score at the moved position during the movement of the lens, that is, judge the change trend of all the acquired image sharpness scores with the movement of the lens. If as the lens moves, the acquired multiple image sharpness scores show a trend of becoming larger and then smaller, and the latest acquired image clarity score is higher than the maximum value among the multiple acquired image clarity scores. If the decrease ratio of the value reaches the first threshold, the position corresponding to the maximum value among the obtained multiple image clarity scores is used as the rough position searched.
  • the code-reading camera can refer to the methods described in the aforementioned steps 3021 and 3022, and obtain the image clarity scores at all positions during the process of moving the lens from the start point to the end point or from the end point to the start point. wherein at least one peak value of the image sharpness score is obtained, and at least one position corresponding to the at least one peak value of the image sharpness is used as at least one rough position.
  • the code reading camera can refer to the method introduced in this step to determine the candidate search interval corresponding to each rough position. After that, for the candidate search interval corresponding to each rough position, the code-reading camera can control the lens to start from one end point of the candidate search interval, and move to the other end point of the candidate search interval according to the second search step, wherein, the second The search step size is smaller than the aforementioned first search step size used when performing a rough position search.
  • the code reading camera can collect an image, and calculate the code reading score of the lens at the moved position according to the collected image. In this way, the code-reading camera can obtain the code-reading scores at multiple positions where the lens is in each candidate search interval.
  • the code-reading camera can determine the local maximum value of the code-reading score in each candidate search interval according to the code-reading scores at multiple positions in each candidate search interval, and then refer to the method introduced in this step, according to each The local maximum value of the code reading score in the candidate search interval determines the best position of the lens, which will not be repeated here.
  • Step 303 Focusing according to the best position of the lens.
  • the code-reading camera can calculate the distance difference between the current position of the lens and the optimal position of the lens, and obtain the moving distance that the lens needs to move. At the same time, the code-reading camera can also determine whether the direction from the current position of the lens to the best position of the lens is the direction from the start of the stroke to the end of the stroke, or the direction from the end of the stroke to the start of the stroke, and the determined direction As the camera's subsequent movement direction.
  • the code-reading camera controls the motor to drive the lens to move the moving distance along the moving direction to reach the best position of the lens to complete the focusing.
  • automatic focusing is performed according to the image clarity score and the code reading score when the lens of the code reading camera is in different positions. Since the code-reading score can represent the code-reading success rate of the code-reading camera, the embodiment of the present application actually evaluates the focusing effect of the lens at different positions by combining the image clarity and code-reading effect of the code-reading camera. To determine the best position of the lens and then complete the automatic focus, in this way, not only the clarity of the image collected by the code-reading camera after the focus is completed, but also the success rate of code-reading by the code-reader camera after the focus is completed.
  • the positions corresponding to the peak value of the image clarity score may be filtered out without code-reading scores, so as to obtain at least one rough position.
  • at least one rough position obtained is a position where a two-dimensional code or a barcode exists in the field of view, which avoids the influence of a false image sharpness peak and improves the focusing success rate.
  • Fig. 5a is a schematic structural diagram of a focusing device 500 provided by an embodiment of the present application.
  • the focusing device 500 may be implemented as part or all of a code-reading camera by software, hardware or a combination of the two.
  • the apparatus 500 includes: an acquiring module 501 , a determining module 502 and a focusing module 503 .
  • the obtaining module 501 is used to obtain the image clarity score and code reading score when the lens of the code reading camera is in multiple positions, and the code reading score is used to represent the code reading success rate of the code reading camera;
  • a determination module 502 configured to determine the optimal position of the lens according to the image clarity scores at multiple positions
  • a focus module 503, configured to focus according to the best position of the lens.
  • the determination module 502 includes:
  • the first determination module 5021 is configured to determine at least one rough position of the lens from multiple positions according to the image sharpness scores at the multiple positions;
  • the second determination module 5022 is used to determine the optimal position of the lens according to at least one rough position of the lens and the code reading scores at multiple positions;
  • the acquiring module 501 is mainly used for:
  • the starting point of the search is the starting point or end point of the travel of the lens.
  • the starting point of the travel of the lens is the position where the vertical distance between the lens and the target surface of the object to be read is the largest. point, the end point of the travel of the lens is the point where the vertical distance between the lens and the target surface is the smallest;
  • the specified search direction refers to the direction from the starting
  • the specified search direction refers to the direction from the end of the travel of the camera to the start of the travel
  • the first determining module 5021 is mainly used for:
  • the sharpness scores of multiple acquired images tend to increase first and then become smaller, and the latest acquired image sharpness score is higher than the multiple If the descending ratio of the maximum value in a plurality of image clarity scores reaches the first threshold, it is judged whether the code reading score at the first position corresponding to the maximum value in multiple image clarity scores is greater than the second threshold;
  • the first position is taken as the rough position of the lens.
  • the first determining module 5021 is mainly used for:
  • the determined second position is used as at least one rough position of the lens.
  • the second determining module 5022 is mainly used for:
  • the optimal position of the shot is determined.
  • the second determination module 5022 is also mainly used to:
  • the position corresponding to the local maximum value of the code reading score in the candidate search interval is one, then the position corresponding to the local maximum value of the code reading score in the candidate search interval is taken as the best position of the shot;
  • the candidate search interval If there is one candidate search interval, and there are multiple positions corresponding to the local maximum value of the code-reading score in the candidate search interval, then from the multiple positions corresponding to the local maximum value of the code-reading score in the candidate search interval, select the candidate search interval.
  • the rough position corresponding to the interval is the third position closest to the distance, and the third position is taken as the best position of the lens;
  • the maximum value among the local maximum values of reading scores in multiple candidate search intervals will be used as the global maximum value; if the position corresponding to the global maximum value is one, then the position corresponding to the global maximum value will be As the optimal position of the lens, if there are multiple positions corresponding to the global maximum, determine the distance between each of the multiple positions corresponding to the global maximum and the rough position corresponding to the candidate search interval where it is located, and The position with the smallest distance between the rough positions corresponding to the candidate search interval where it is located is taken as the optimal position of the shot.
  • the focusing module 503 is mainly used for:
  • the optimal position of the lens and the current position of the lens determine the focus moving direction and moving distance of the lens
  • the lens is driven to move to the best position of the lens to complete the focus.
  • automatic focusing is performed according to the image clarity score and the code reading score when the lens of the code reading camera is in different positions. Since the code-reading score can represent the code-reading success rate of the code-reading camera, the embodiment of the present application actually evaluates the focusing effect of the lens at different positions by combining the image clarity and code-reading effect of the code-reading camera. To determine the best position of the lens and then complete the automatic focus, in this way, not only the clarity of the image collected by the code-reading camera after the focus is completed, but also the success rate of code-reading by the code-reader camera after the focus is completed.
  • the focusing device provided in the above-mentioned embodiment performs focusing
  • the division of the above-mentioned functional modules is used as an example for illustration.
  • the internal structure of the system is divided into different functional modules to complete all or part of the functions described above.
  • the focusing device provided by the above-mentioned embodiment and the focusing method embodiment belong to the same idea, and the specific implementation process thereof is detailed in the method embodiment, and will not be repeated here.
  • Fig. 6a is a schematic structural diagram of a computer device provided by an embodiment of the present application.
  • the code-reading camera in the foregoing embodiments can be realized by the computer device.
  • the computer device 600 includes: a processor 601 and a memory 602 .
  • the processor 601 may include one or more processing cores, such as a 4-core processor, an 8-core processor, and the like.
  • Processor 601 can adopt at least one hardware form in DSP (Digital Signal Processing, digital signal processing), FPGA (Field-Programmable Gate Array, field programmable gate array), PLA (Programmable Logic Array, programmable logic array) accomplish.
  • Processor 601 may also include a main processor and a coprocessor, and the main processor is a processor for processing data in a wake-up state, also known as a CPU (Central Processing Unit, central processing unit); the coprocessor is Low-power processor for processing data in standby state.
  • CPU Central Processing Unit, central processing unit
  • the coprocessor is Low-power processor for processing data in standby state.
  • the processor 601 may be integrated with a GPU (Graphics Processing Unit, image processor), and the GPU is used for rendering and drawing the content that needs to be displayed on the display screen.
  • the processor 601 may also include an AI (Artificial Intelligence, artificial intelligence) processor, where the AI processor is used to process computing operations related to machine learning. It should be noted that the control unit in the focusing device 200 shown in FIG. 2 may be realized by the processor 601 .
  • Memory 602 may include one or more computer-readable storage media, which may be non-transitory.
  • the memory 602 may also include high-speed random access memory and non-volatile memory, such as one or more magnetic disk storage devices and flash memory storage devices.
  • the non-transitory computer-readable storage medium in the memory 602 is used to store at least one instruction, and the at least one instruction is used to be executed by the processor 601 to implement the focusing method provided by the method embodiment in this application .
  • the computer device 600 may optionally further include: a peripheral device interface 603 and at least one peripheral device.
  • the processor 601, the memory 602, and the peripheral device interface 603 may be connected through buses or signal lines.
  • Each peripheral device can be connected to the peripheral device interface 603 through a bus, a signal line or a circuit board.
  • the peripheral device includes: at least one of a radio frequency circuit 604 , a display screen 605 , a camera component 606 , an audio circuit 607 , a positioning component 608 and a power supply 609 .
  • the peripheral device interface 603 may be used to connect at least one peripheral device related to I/O (Input/Output, input/output) to the processor 601 and the memory 602.
  • the processor 601, memory 602 and peripheral device interface 603 are integrated on the same chip or circuit board; in some other embodiments, any one of the processor 601, memory 602 and peripheral device interface 603 or The two can be implemented on a separate chip or circuit board, which is not limited in this embodiment.
  • the radio frequency circuit 604 is used to receive and transmit RF (Radio Frequency, radio frequency) signals, also called electromagnetic signals.
  • the radio frequency circuit 604 communicates with the communication network and other communication devices through electromagnetic signals.
  • the radio frequency circuit 604 converts electrical signals into electromagnetic signals for transmission, or converts received electromagnetic signals into electrical signals.
  • the radio frequency circuit 604 includes: an antenna system, an RF transceiver, one or more amplifiers, a tuner, an oscillator, a digital signal processor, a codec chipset, a subscriber identity module card, and the like.
  • the radio frequency circuit 604 can communicate with other terminals through at least one wireless communication protocol.
  • the wireless communication protocol includes but is not limited to: metropolitan area network, mobile communication networks of various generations (2G, 3G, 4G and 5G), wireless local area network and/or WiFi (Wireless Fidelity, wireless fidelity) network.
  • the radio frequency circuit 604 may also include circuits related to NFC (Near Field Communication, short distance wireless communication), which is not limited in this application.
  • the display screen 605 is used to display a UI (User Interface, user interface).
  • the UI can include graphics, text, icons, video, and any combination thereof.
  • the display screen 605 also has the ability to collect touch signals on or above the surface of the display screen 605 .
  • the touch signal can be input to the processor 601 as a control signal for processing.
  • the display screen 605 can also be used to provide virtual buttons and/or virtual keyboards, also called soft buttons and/or soft keyboards.
  • the display screen 605 there may be one display screen 605, which is arranged on the front panel of the computer device 600; in other embodiments, there may be at least two display screens 605, which are respectively arranged on different surfaces of the computer device 600 or in a folding design
  • the display screen 605 may be a flexible display screen, which is arranged on the curved surface or the folded surface of the computer device 600 . Even, the display screen 605 can also be set as a non-rectangular irregular figure, that is, a special-shaped screen.
  • the display screen 605 can be made of LCD (Liquid Crystal Display, liquid crystal display), OLED (Organic Light-Emitting Diode, organic light-emitting diode) and other materials.
  • the camera assembly 606 is used to capture images or videos.
  • the camera assembly 606 may include the aforementioned focusing device 200 shown in FIG. 2 .
  • the camera assembly may also include an image sensor, a filter assembly, a supplementary light device, and the like.
  • the image sensor is used to generate and output an image signal through exposure.
  • the filter assembly is used to filter the visible light entering the camera assembly in a specific wavelength band.
  • the supplementary light device is used for supplementary light during the exposure process of the image sensor.
  • Audio circuitry 607 may include a microphone and speakers.
  • the microphone is used to collect sound waves of the user and the environment, and convert the sound waves into electrical signals and input them to the processor 601 for processing, or input them to the radio frequency circuit 604 to realize voice communication.
  • the microphone can also be an array microphone or an omnidirectional collection microphone.
  • the speaker is used to convert the electrical signal from the processor 601 or the radio frequency circuit 604 into sound waves.
  • the loudspeaker can be a conventional membrane loudspeaker or a piezoelectric ceramic loudspeaker. When the speaker is a piezoelectric ceramic speaker, it is possible not only to convert electrical signals into sound waves audible to humans, but also to convert electrical signals into sound waves inaudible to humans for purposes such as distance measurement.
  • the positioning component 608 is used to locate the current geographic location of the computer device 600, so as to realize navigation or LBS (Location Based Service, location-based service).
  • the positioning component 608 may be a positioning component based on the GPS (Global Positioning System, Global Positioning System) of the United States, the Beidou system of China, the Grenax system of Russia or the Galileo system of the European Union.
  • the power supply 609 is used to supply power to various components in the computer device 600 .
  • the power source 609 can be alternating current, direct current, disposable batteries or rechargeable batteries.
  • the rechargeable battery may support wired charging or wireless charging.
  • the rechargeable battery can also be used to support fast charging technology.
  • Fig. 6b does not constitute a limitation to the computer device 600, and may include more or less components than shown in the figure, or combine certain components, or adopt different component arrangements.
  • the embodiment of the present application also provides a non-transitory computer-readable storage medium.
  • the computer device can execute the focusing method provided in the above embodiment.
  • the computer readable storage medium may be ROM, RAM, CD-ROM, magnetic tape, floppy disk, optical data storage device, and the like.
  • the computer-readable storage medium mentioned in the embodiment of the present application may be a non-volatile storage medium, in other words, may be a non-transitory storage medium.
  • the embodiment of the present application also provides a computer program product including instructions, which, when running on a computer device, causes the computer device to execute the focusing method provided in the foregoing embodiments.

Landscapes

  • Engineering & Computer Science (AREA)
  • Multimedia (AREA)
  • Signal Processing (AREA)
  • Physics & Mathematics (AREA)
  • Electromagnetism (AREA)
  • Health & Medical Sciences (AREA)
  • General Health & Medical Sciences (AREA)
  • Computer Vision & Pattern Recognition (AREA)
  • General Physics & Mathematics (AREA)
  • Artificial Intelligence (AREA)
  • Toxicology (AREA)
  • Theoretical Computer Science (AREA)
  • Optics & Photonics (AREA)
  • Biomedical Technology (AREA)
  • Automatic Focus Adjustment (AREA)
  • Studio Devices (AREA)
  • Focusing (AREA)

Abstract

本申请实施例公开了一种对焦方法、装置及存储介质,属于图像采集技术领域。在本申请实施例中,根据读码相机的镜头处于不同位置时的图像清晰度评分和读码评分来进行自动对焦。由于读码评分能够表征读码相机的读码成功率,因此,本申请实施例实际上是结合读码相机的图像清晰度和读码效果对镜头处于不同位置时的对焦效果进行评价,以此来确定镜头的最佳位置进而完成自动对焦,这样,不仅能够保证对焦完成后的读码相机采集的图像的清晰度,还能够保证对焦完成后读码相机的读码成功率。

Description

对焦方法、装置及存储介质
本申请要求于2021年07月08日提交中国专利局、申请号为202110771982.4发明名称为“对焦方法、装置及存储介质”的中国专利申请的优先权,其全部内容通过引用结合在本申请中。
技术领域
本申请涉及图像采集技术领域,特别涉及一种对焦方法、装置及存储介质。
背景技术
当前,用于读取二维码、条形码的读码相机被广泛的应用于快递物流等工业场景中。在采用读码相机读码时,读码相机到工作平面的距离经常会发生变化,在这种情况下,通常可以采用自动对焦的方法使读码相机快速对焦到工作平面上。
相关技术中,在读码相机自动对焦的过程中,每当读码相机的镜头移动至一个位置,则在该位置处采集一帧图像。之后,采用图像自相关法或图像高频分量法计算采集的图像的图像清晰度评分。如此,在获取到读码相机的镜头处于多个位置时的图像清晰度评分之后,将图像清晰度评分最高的位置作为镜头的最佳位置,进而驱动镜头移动至该最佳位置以完成自动对焦。
发明内容
本申请实施例提供了一种对焦方法、装置及存储介质,在保证对焦后的读码相机的清晰度的同时,还能保证对焦后的读码成功率。所述技术方案如下:
一方面,提供了一种对焦方法,所述方法包括:
获取读码相机的镜头处于多个位置时的图像清晰度评分和读码评分,所述读码评分用于表征所述读码相机的读码成功率;
根据所述多个位置的图像清晰度评分和读码评分,确定所述镜头的最佳位置;
根据所述镜头的最佳位置进行对焦。
在一种可能的实现方式中,所述根据所述多个位置的图像清晰度评分和读码评分,确定所述镜头的最佳位置,包括:
根据所述多个位置处的图像清晰度评分,从所述多个位置中确定所述镜头的至少一个粗略位置;
根据所述镜头的至少一个粗略位置和所述多个位置处的读码评分,确定所述镜头的最佳位置;
根据所述镜头的最佳位置进行对焦。
在一种可能的实现方式中,所述获取读码相机的镜头处于多个位置时的图像清晰度评分和读码评分, 包括:
获取所述镜头在搜索起点处的图像清晰度评分和读码评分,所述搜索起点为所述镜头的行程起点或行程终点,所述镜头的行程起点为所述镜头与待读码物体的目标表面的垂直距离最大时所处的位置点,所述镜头的行程终点为所述镜头与所述目标表面的垂直距离最小时所处的位置点;
控制所述镜头从所述搜索起点起按照指定搜索步长沿着指定搜索方向移动,其中,当所述搜索起点为所述镜头的行程起点时,所述指定搜索方向是指从所述镜头的行程起点到行程终点的方向,当所述搜索起点为所述镜头的行程终点时,所述指定搜索方向是指从所述镜头的行程终点到行程起点的方向;
每当所述镜头移动所述指定搜索步长后,获取所述镜头移动后的图像清晰度评分和读码评分。
在一种可能的实现方式中,所述根据多个位置处的图像清晰度评分,从所述多个位置中确定所述镜头的至少一个粗略位置,包括:
在所述镜头沿着所述指定搜索方向移动的过程中,如果随着所述镜头的移动,已获取的多个图像清晰度评分呈先变大后变小的变化趋势,且最近一次获取的图像清晰度评分相对于所述多个图像清晰度评分中的最大值的下降比例达到第一阈值,则判断所述多个图像清晰度评分中的最大值对应的第一位置处的读码评分是否大于第二阈值;
如果所述第一位置处的读码评分大于所述第二阈值,则将所述第一位置作为所述镜头的粗略位置。
在一种可能的实现方式中,所述根据所述多个位置处的图像清晰度评分,从所述多个位置中确定所述镜头的至少一个粗略位置,包括:
绘制所述多个位置与所述多个位置处的图像清晰度评分的关系曲线;
从所述关系曲线中获取至少一个图像清晰度评分峰值;
从所述至少一个图像清晰度评分峰值对应的至少一个位置中确定对应的读码评分大于第二阈值的第二位置;
将确定出的第二位置作为所述镜头的至少一个粗略位置。
在一种可能的实现方式中,所述根据所述镜头的至少一个粗略位置和所述多个位置处的读码评分,确定所述镜头的最佳位置,包括:
确定每个粗略位置对应的候选搜索区间,所述候选搜索区间为以相应的粗略位置为中心的镜头位置区间;
从每个候选搜索区间包含的各个位置对应的读码评分中,确定每个候选搜索区间内的读码评分局部最大值;
根据每个候选搜索区间内的读码评分局部最大值,确定所述镜头的最佳位置。
在一种可能的实现方式中,所述根据每个候选搜索区间内的读码评分局部最大值,确定所述镜头的最佳位置,包括:
如果所述候选搜索区间为一个,且所述候选搜索区间内的读码评分局部最大值对应的位置为一个,则将所述候选搜索区间内的读码评分局部最大值对应的位置作为所述镜头的最佳位置;
如果所述候选搜索区间为一个,且所述候选搜索区间内的读码评分局部最大值对应的位置为多个,则从所述候选搜索区间内的读码评分局部最大值对应的多个位置中,选择与所述候选搜索区间对应的粗略位置距离最近的第三位置,将所述第三位置作为所述镜头的最佳位置;
如果所述候选搜索区间为多个,则将多个候选搜索区间内的读码评分局部最大值中的最大值作为全局最大值,如果所述全局最大值对应的位置为一个,则将所述全局最大值对应的位置作为所述镜头的最佳位置,如果所述全局最大值对应的位置有多个,则确定所述全局最大值对应的多个位置中的每个位置与自身所在的候选搜索区间对应的粗略位置之间的距离,并将与自身所在的候选搜索区间对应的粗略位置之间的距离最小的位置作为所述镜头的最佳位置。
在一种可能的实现方式中,所述根据所述镜头的最佳位置进行对焦,包括:
根据所述镜头的最佳位置和所述镜头的当前位置,确定所述镜头的对焦移动方向和移动距离;
根据所述镜头的对焦移动方向和移动距离,驱动所述镜头移动至所述镜头的最佳位置以完成对焦。
另一方面,提供了一种对焦装置,所述装置包括:
获取模块,用于获取读码相机的镜头处于多个位置时的图像清晰度评分和读码评分,所述读码评分用于表征所述读码相机的读码成功率;
确定模块,用于根据所述多个位置处的图像清晰度评分和读码评分,确定所述镜头的最佳位置;
对焦模块,用于根据所述镜头的最佳位置进行对焦。
在一种可能的实现方式中,所述确定模块,包括:
第一确定模块,用于根据所述多个位置处的图像清晰度评分,从所述多个位置中确定所述镜头的至少一个粗略位置;
第二确定模块,用于根据所述镜头的至少一个粗略位置和所述多个位置处的读码评分,确定所述镜头的最佳位置;
在一种可能的实现方式中,所述获取模块主要用于:
获取所述镜头在搜索起点处的图像清晰度评分和读码评分,所述搜索起点为所述镜头的行程起点或行程终点,所述镜头的行程起点为所述镜头与待读码物体的目标表面的垂直距离最大时所处的位置点,所述镜头的行程终点为所述镜头与所述目标表面的垂直距离最小时所处的位置点;
控制所述镜头从所述搜索起点起按照指定搜索步长沿着指定搜索方向移动,其中,当所述搜索起点为所述镜头的行程起点时,所述指定搜索方向是指从所述镜头的行程起点到行程终点的方向,当所述搜索起点为所述镜头的行程终点时,所述指定搜索方向是指从所述镜头的行程终点到行程起点的方向;
每当所述镜头移动所述指定搜索步长后,获取所述镜头移动后的图像清晰度评分和读码评分。
在一种可能的实现方式中,所述第一确定模块主要用于:
在所述镜头沿着所述指定搜索方向移动的过程中,如果随着所述镜头的移动,已获取的多个图像清晰度评分呈先变大后变小的变化趋势,且最近一次获取的图像清晰度评分相对于所述多个图像清晰度评分中的最大值的下降比例达到第一阈值,则判断所述多个图像清晰度评分中的最大值对应的第一位置处的读码评分是否大于第二阈值;
如果所述第一位置处的读码评分大于所述第二阈值,则将所述第一位置作为所述镜头的粗略位置。
在一种可能的实现方式中,所述第一确定模块主要用于:
绘制所述多个位置与所述多个位置处的图像清晰度评分的关系曲线;
从所述关系曲线中获取至少一个图像清晰度评分峰值;
从所述至少一个图像清晰度评分峰值对应的至少一个位置中确定对应的读码评分大于第二阈值的第二位置;
将确定出的第二位置作为所述镜头的至少一个粗略位置。
在一种可能的实现方式中,所述第二确定模块主要用于:
确定每个粗略位置对应的候选搜索区间,所述候选搜索区间为以相应的粗略位置为中心的镜头位置区间;
从每个候选搜索区间包含的各个位置对应的读码评分中,确定每个候选搜索区间内的读码评分局部最大值;
根据每个候选搜索区间内的读码评分局部最大值,确定所述镜头的最佳位置。
在一种可能的实现方式中,所述第二确定模块主要还用于:
如果所述候选搜索区间为一个,且所述候选搜索区间内的读码评分局部最大值对应的位置为一个,则将所述候选搜索区间内的读码评分局部最大值对应的位置作为所述镜头的最佳位置;
如果所述候选搜索区间为一个,且所述候选搜索区间内的读码评分局部最大值对应的位置为多个,则从所述候选搜索区间内的读码评分局部最大值对应的多个位置中,选择与所述候选搜索区间对应的粗略位置距离最近的第三位置,将所述第三位置作为所述镜头的最佳位置;
如果所述候选搜索区间为多个,则将多个候选搜索区间内的读码评分局部最大值中的最大值作为全局最大值,如果所述全局最大值对应的位置为一个,则将所述全局最大值对应的位置作为所述镜头的最佳位置,如果所述全局最大值对应的位置有多个,则确定所述全局最大值对应的多个位置中的每个位置与自身所在的候选搜索区间对应的粗略位置之间的距离,并将与自身所在的候选搜索区间对应的粗略位置之间的距离最小的位置作为所述镜头的最佳位置。
在一种可能的实现方式中,所述对焦模块主要用于:
根据所述镜头的最佳位置和所述镜头的当前位置,确定所述镜头的对焦移动方向和移动距离;
根据所述镜头的对焦移动方向和移动距离,驱动所述镜头移动至所述镜头的最佳位置以完成对焦。
另一方面,提供一种对焦装置,所述装置包括控制单元、电机、镜头和移动机构;
其中,所述移动机构带动所述镜头在垂直于所述镜头的镜面的方向上移动;
所述控制单元与所述电机连接,所述控制单元用于执行前述任一项所述的方法,以控制所述电机驱动所述移动机构带动所述镜头移动完成对焦。
另一方面,提供了一种计算机设备,所述计算机设备包括处理器、通信接口、存储器和通信总线,所述处理器、所述通信接口和所述存储器通过所述通信总线完成相互间的通信,所述存储器用于存放计算机程序,所述处理器用于执行所述存储器上所存放的程序,以实现前述的对焦方法的步骤。
另一方面,提供了一种计算机可读存储介质,所述存储介质内存储有计算机程序,所述计算机程序被处理器执行时实现前述的对焦方法的步骤。
另一方面,提供了一种包含指令的计算机程序产品,当其在计算机上运行时,使得计算机执行前述的对焦方法的步骤。
本申请提供的技术方案至少可以带来以下有益效果:
在本申请实施例中,根据读码相机的镜头处于不同位置时的图像清晰度评分和读码评分来进行自动对焦。由于读码评分能够表征读码相机的读码成功率,因此,本申请实施例实际上是结合读码相机的图像清晰度和读码效果对镜头处于不同位置时的对焦效果进行评价,以此来确定镜头的最佳位置进而完成自动对焦,这样,不仅能够保证对焦完成后的读码相机采集的图像的清晰度,还能够保证对焦完成后读码相机的读码成功率。
附图说明
为了更清楚地说明本申请实施例和现有技术的技术方案,下面对实施例和现有技术中所需要使用的附图作简单地介绍,显而易见地,下面描述中的附图仅仅是本申请的一些实施例,对于本领域普通技术人员来讲,在不付出创造性劳动的前提下,还可以根据这些附图获得其他的附图。
图1是本申请实施例提供的一种对焦方法所涉及的系统架构图;
图2是本申请实施例提供的一种对焦装置的结构示意图;
图3a是本申请实施例提供的一种对焦方法流程图;
图3b是本申请实施例提供的另一种对焦方法流程图;
图4是本申请实施例提供的一种图像清晰度评分曲线图;
图5a是本申请实施例提供的另一种对焦装置的结构示意图;
图5b是本申请实施例提供的又一种对焦装置的结构示意图;
图6a是本申请实施例提供的一种计算机设备的结构示意图;
图6b是本申请实施例提供的另一种计算机设备的结构示意图。
具体实施方式
为使本申请的目的、技术方案、及优点更加清楚明白,以下参照附图并举实施例,对本申请进一步详细说明。显然,所描述的实施例仅仅是本申请一部分实施例,而不是全部的实施例。基于本申请中的实施例,本领域普通技术人员在没有作出创造性劳动前提下所获得的所有其他实施例,都属于本申请保护的范围。
在对本申请实施例提供的对焦方法进行详细的解释说明之前,先对本申请实施例的应用场景进行介绍。
本申请实施例提供的对焦方法可以应用于部署有涉及到二维码或条形码读取的工业场景中。例如,在物流转运中心,在快递自动传送带上方的门架上安装有读码相机,通过该读码相机读取快递包裹的上表面的二维码或条形码,以对快递包裹进行分拣。其中,由于不同的快递包裹的高度也不同,因此,读码相机到不同快递包裹的上表面的距离也在变化,在这种情况下,即可以通过本申请实施例提供的对焦方法调整读码相机的镜头与快递包裹的上表面之间的距离,从而实现快速自动对焦。再例如,在工厂中的生产流水线上安装有读码相机,通过该读码相机读取生产流水线上的产品上的二维码或条形码,以实现产品信息的入库。在这种情况下,可能会由于生产流水线结构调整或者是读码相机重新安装等因素,导致读码相机到产品的二维码或条形码所在表面的距离发生变化,此时,即可以通过本申请实施例提供的对焦方法调整读码相机的镜头与快递包裹的上表面之间的距离,从而实现快速自动对焦。
示例性地,在上述介绍的应用场景中,在将读码相机部署好之后,首先可以将一个静止的参考物体摆放在读码相机的镜头下方,之后,通过该参考物体对该读码相机进行调焦。在读码相机对焦完成之后,该读码相机即可以投入使用。后续在使用该读码相机的过程中,待读码的物体经过该读码相机的镜头下方,如果该待读码的物体与前述用于调焦的参考物体的高度差距较大,则可以对该读码相机进行重新对焦,在这种情况下,即可以通过本申请实施例提供的对焦方法来实现快速自动对焦。
上述仅是本申请实施例提供的两种可能的应用场景,本申请实施例还可以用于其他需要进行自动对焦的工业读码场景,本申请实施例对此不做限定。
接下来对本申请实施例所涉及的系统架构进行介绍。
图1是本申请实施例提供的一种图像采集系统的架构图。如图1所示,该图像采集系统包括读码相机101、传送带102和位于传送带102上的待读码物体103。
其中,读码相机101可以安装在传送带102上方的门架上。并且,该读码相机101的镜头朝向传送带102上的待读码物体103的目标表面。其中,该目标表面是指二维码或条形码所在的平面。在快递物 流行业,通常,该目标表面为快递包裹位于传送带102上时的上表面,即快递包裹背离传送带的表面。当然,在其他可能的场景中,该目标表面也可能为待读码物体103的侧面,本申请实施例对此不做限定。
需要说明的是,在本申请实施例中,读码相机101可以在检测到触发信号时开始进行图像采集。其中,读码相机101首先通过移动镜头来调整镜头的位置,本申请中调整镜头的位置是指调整镜头整体的位置,也可以是指调整镜头局部的位置,但是应当使得读码相机的焦距随着镜头的位置的调整而变化。示例性的,在一种可能的实现方式中,可以是在保持镜头形状不变的情况下,调整镜头的质心,在另一种可能的实现方式中,镜头为T-Lens(可变焦)镜头或液体镜头,则可以是在保持镜头的质心位置不变的情况下,调整镜头内部各点之间的相对位置,即改变调整镜头的形状。
下文中为描述方便,仅以调整镜头的质心的情况为例进行说明,对于改变镜头的形状的情况原理完全相同,在此不再赘述。由于随着质心的位置的改变,镜头与待读码物体的目标表面之间的距离也随之改变,因此调整镜头的质心的距离也即调整镜头与待读码物体的目标表面之间的距离,每当调整一个距离,则读码相机可以对待读码物体进行一次图像采集,根据采集到的图像计算镜头处于多个位置时的图像清晰度评分和读码评分,进而根据镜头处于多个位置时的图像清晰度评分和读码评分,从该多个位置中确定镜头的最佳位置,本文中的一次图像采集可以是仅采集一张图像,也可以是采集多张图像,对于采集一张图像的情况,图像清晰度评分用于表示该一张图像的清晰程度,读码评分用于表示该一张图像中二维码和条码的质量。对于采集多张图像的情况,图像清晰度评分用于表示该多张图像的整体清晰程度,读码评分用于表示该多张图像中二维码和条码的整体质量。以清晰度评分为例,可以是分别确定该多张图像各自的清晰度,得到用于表示所有图像的清晰程度的均值的图像清晰度评分,也可以是从该多张图像中确定出最清晰的图像,生成用于表示该最清晰的图像的清晰程度的图像清晰度评分。之后,读码相机通过控制电机来驱动镜头移动到该最佳位置进行对焦。在对焦完成之后,读码相机101可以采集待读码物体103的目标表面上的二维码或条形码的图像,并对二维码或条形码进行读取。
在一种可能的实现方式中,图2示出了一种应用于读码相机的对焦装置200的结构示意图。如图2所示,该对焦装置200包括控制单元201、电机202、镜头203和移动机构204。
其中,该控制单元201与电机202连接。镜头203可以位于移动机构204中,如图2所示。或者,该镜头203与移动机构204连接(图2中未示出)。电机202与移动机构204连接,这样,控制单元201可以控制电机202驱动移动机构204移动。通过该移动机构204的移动,从而带动镜头203移动。其中,该移动机构204可以带动镜头203在垂直于镜头203的镜面的方向上移动,即在镜面的光轴(下文称镜面的轴)方向上移动,并且,移动机构204能够移动的行程是一定的。这样,在该移动机构204的带动下,镜头203也将沿着垂直于自身镜面的轴进行移动,并且,镜头203的行程也是一定的。
在本申请实施例中,控制单元201首先控制电机202驱动移动机构204带动镜头203按照指定搜索步长,沿着指定搜索方向不断移动,以搜索镜头203的粗略位置。其中,指定搜索步长可以是一个固定的步长,也可以是一个变化的步长,示例性的,在一种可能的实施例中,搜索步长固定为1个单位步长,在另一种可能的实施例中,搜索步长初始时为2个单位步长,并且随着图像清晰度评分的上升而下降。
在得到镜头203的粗略位置之后,控制单元201根据镜头203在粗略搜索过程中确定的镜头203 处于各个位置上的读码评分,确定镜头203的最佳位置,进而计算从镜头203当前所处的位置到该最佳位置的移动距离和对焦移动方向。之后,控制单元201控制电机202驱动移动机构204带着该镜头203沿着该对焦移动方向运动移动距离,到达该最佳位置,以完成对焦。
需要说明的是,读码相机除了包括上述对焦装置200之外,还包括诸如图像传感器、滤光组件、补光装置等其他相机必备组件,本申请实施例对此不再赘述。
接下来对本申请实施例提供的对焦方法进行详细的解释说明。
图3是本申请实施例提供的一种对焦方法的流程图,该方法可以应用于读码相机中,也可以应用于独立于读码相机并且具备控制读码相机进行对焦的电子设备中,示例性地,可以应用于图2所示的读码相机的控制单元中。参见图3,该方法包括如下步骤:
步骤301:获取读码相机的镜头处于多个位置时的图像清晰度评分和读码评分,该读码评分用于表征读码相机的读码成功率。
可以理解的是,读码相机采集到的图像中二维码或条码的质量越高,则读码相机的读码成功率越高,因此读码评分能够表征读码相机的读码成功率。
在本申请实施例中,读码相机在开始对焦后,首先获取镜头在搜索起点处的图像清晰度评分和读码评分。其中,所谓搜索起点是指开始对焦后,镜头从该搜索起点开始移动。
示例性地,该搜索起点可以为镜头的行程起点,也可以为读码相机的镜头的行程终点。其中,镜头的行程起点为镜头与待读码物体的目标表面的垂直距离最大时所处的位置点,镜头的行程终点为镜头与目标表面的垂直距离最小时所处的位置点。也即是,当读码相机中的移动机构带动镜头在垂直与镜头的镜面的方向上向着远离目标表面的方向移动时,移动至无法再继续移动时,该镜头距离该目标表面的距离最大,此时,该镜头所处的位置即为该镜头的行程起点。相应地,当读码相机中的移动机构带动镜头在垂直与镜头的镜面的方向上向着靠近目标表面的方向移动时,移动至无法再继续移动时,该镜头距离该目标表面的距离最小,此时,该镜头所处的位置即为该镜头的行程终点。并且,为便于读码相机进行对焦,在一种可能的实现方式中,读码相机在每次需要自动对焦之前,将镜头的位置调整至行程起点或行程终点。
读码相机可以在镜头处于该搜索起点时采集图像,并采用图像自相关法或图像高频分量法或其他用于计算图像清晰度评分的方法,利用采集到的该位置处的图像计算镜头处于该位置时的图像清晰度评分。其中,图像清晰度评分越高,则说明在镜头处于这个位置的情况下进行图像采集时,采集到的图像的清晰程度将越高。
与此同时,读码相机还可以基于ISO15416标准计算在该搜索起点处采集到的图像中的条形码的读码评分,或者,根据ISO15415标准计算在该搜索起点处采集到的图像中的二维码的读码评分。其中,读码评分越高,则说明在镜头处于这个位置的情况下对图像进行读码时的读码效果越好。
在获取到搜索起点处的图像清晰度评分和读码评分之后,读码相机可以控制电机驱动镜头从该搜索起点起不断移动。每当镜头移动到一个位置,读码相机计算镜头处于该位置时的图像清晰度评分和读码评分。
示例性地,读码相机控制电机驱动镜头从该搜索起点起按照指定搜索步长沿着指定搜索方向移动。这样,每当镜头移动指定搜索步长后,即获取一次图像清晰度评分和读码评分。其中,当搜索起点为镜头的行程起点时,该指定搜索方向为从镜头的行程起点到行程终点的方向,当搜索起点为镜头的行程终点时,则该指定搜索方向为从镜头的行程终点到行程起点的方向。
需要说明的是,由前文中介绍可知,读码相机中的镜头可以位于一个移动机构中或与该移动机构连接,通过该移动机构的移动,从而带动镜头移动。其中,该移动机构沿着垂直于镜头的镜面的方向移动,并且,移动机构能够移动的行程是一定的。这样,在该移动机构的带动下,镜头也将沿着垂直于自身的镜面的方向进行移动,并且,镜头的行程也是一定的。其中,镜头在移动过程中,可以按照指定搜索步长进行移动,该指定搜索步长即为镜头移动一次的距离。并且,在本申请实施例中,该指定搜索步长可以进行人为设置。其中,该指定搜索步长越小,则搜索精度越高,该指定搜索步长越大,则搜索效率越高。
在一种可能的实施例中,读码相机在开始对焦时,镜头可能既不处于行程起点,也不处于行程终点,在这种情况下,读码相机可以控制镜头从当前所处的位置移动至该镜头的行程起点或行程终点,之后,按照上述介绍的方法,从该镜头的行程起点或行程终点起,按照指定搜索步长沿着指定搜索方向移动。
在镜头移动的过程中,每当镜头移动到一个位置,则读码相机可以采集一张该位置处的图像,并采用图像自相关法或图像高频分量法或其他用于计算图像清晰度评分的方法,利用采集到的该位置处的图像计算镜头处于该位置时的图像清晰度评分。
与此同时,读码相机还可以基于ISO15416标准计算在该位置处采集到的图像中的条形码的读码评分,或者,根据ISO15415标准计算在该位置处采集到的图像中的二维码的读码评分。
需要说明的是,在一些可能的场景中,当镜头移动到一个位置后,在该位置处,读码相机的视野中可能不存在二维码或条形码,在这种情况下,读码相机根据在该位置处采集到的图像计算得到的读码评分将为0或者其他比较小的数值。
步骤S302,:根据多个位置处的图像清晰度评分和读码评分,确定镜头的最佳位置。
最佳位置的判断方式根据应用场景的不同可以不同,但是最佳位置的图像清晰度评分和读码评分应当尽可能高,并且其他任意位置的图像清晰度评分低于最佳位置的图像清晰度评分,或者,读码评分低于最佳位置的读码评分。
示例性的,在一种可能的实现方式中,根据多个位置处的图像清晰度评分和读码评分,确定各位置的综合评分,并将综合评分最高的位置确定为镜头的最佳位置。
其中,每个位置的综合评分为对该位置的图像清晰度评分和读码评分进行加权求和得到,加权求和时图像清晰度评分的权重和读码评分的权重可以是用户根据实际需求和/或经验设置的。
在另一种可能的实现方式中,如图3b所示,步骤302包括步骤3021和步骤3022两个步骤:
其中,步骤3021:根据多个位置处的图像清晰度评分,从多个位置中确定镜头的至少一个粗略位置。
在一种可能的实现方式中,由前述步骤301中的介绍可知,每当镜头按照指定搜索步长沿着指定搜 索方向移动一次,读码相机可以计算一次镜头移动后的图像清晰度评分和读码评分。基于此,读码相机可以在镜头移动的过程中,每在移动后的位置处获取到一个图像清晰度评分,即判断一次已获取到的所有图像清晰度评分随着镜头的移动的变化趋势。如果随着镜头的移动,已获取到的多个图像清晰度评分呈现先变大后变小的趋势,且最近一次获取的图像清晰度评分相对于已获取的多个图像清晰度评分中的最大值的下降比例达到第一阈值,则读码相机进一步的判断已获取的多个图像清晰度评分中的最大值对应的第一位置处的读码评分是否大于第二阈值。如果大于第二阈值,则读码相机将第一位置作为镜头的粗略位置。
需要说明的是,每当镜头移动到一个位置,读码相机获取到镜头在该位置处的图像清晰度评分时,读码相机可以绘制已获取到的各个图像清晰度评分与对应的位置的关系曲线。如果该关系曲线上的图像清晰度评分呈现先变大后变小的趋势,则读码相机计算已获取到的多个图像清晰度评分中的最大值与镜头当前所处位置处的图像清晰度评分之间的差值,之后,计算该差值与该多个图像清晰度评分中的最大值的比例,该比例即为下降比例。如果该下降比例大于第一阈值,则确定下降比例达到了第一阈值,认为已经找到了图像清晰度最高时的镜头位置,此时,读码相机可以进一步的判断多个图像清晰度评分中最大值对应的第一位置处的读码评分是否大于第二阈值。如果第一位置处的读码评分大于第二阈值,则说明当镜头处于第一位置时,读码相机的视野中存在二维码或条形码,后续,读码相机能够进一步的通过读码评分来确定镜头的最佳位置。在这种情况下,读码相机可以将该第一位置作为搜索到的镜头的粗略位置。相应地,读码相机可以停止移动镜头,也即,停止搜索镜头的粗略位置。
需要说明的是,第一阈值是预先设定的一个比例值,该比例值可以为20%、40%或其他数值,本申请实施例对此不做限定。第二阈值可以是预先确定的一个不大于读码相机的视野中存在二维码或条码时读码评分的最小值的数值,示例性地,第二阈值可以为0、1、2等数值,本申请实施例对此不做限定。
当然,如果绘制得到的图像清晰度评分和镜头的位置之间的关系曲线上图像清晰度评分没有呈现先变大后变小的变化趋势,或者,虽然呈现了先变大后变小的变化趋势,但是镜头当前所处位置处的图像清晰度评分相较于已获取的多个图像清晰度评分中的最大值的下降比例未达到第一阈值,或者是已获取的多个图像清晰度评分中的最大值对应的第一位置处的读码评分不大于第二阈值,此时,读码相机可以继续驱动镜头移动以获取下一个位置处的图像清晰度评分和读码评分,并重复上述判断过程。
由此可见,在上文的实现方式中,镜头可能不需要沿着指定搜索方向移动完所有位置,读码相机即能够搜索到一个粗略位置。这样,能够减少搜索时间,提高搜索效率。
在另一种可能的实现方式中,读码相机也可以在镜头从行程起点移动至移动终点或者是从行程终点移动到行程起点后,根据获取到的镜头移动过程中的所有位置处的图像清晰度评分来确定镜头的至少一个粗略位置。
示例性地,在该种实现方式中,可以绘制读码相机绘制镜头在移动过程中所处的多个位置与该多个位置处的图像清晰度评分的关系曲线;从该关系曲线中获取至少一个图像清晰度评分峰值;从至少一个图像清晰度评分峰值对应的至少一个位置中确定对应的读码评分大于第二阈值的第二位置;将确定出的第二位置作为镜头的至少一个粗略位置。
其中,可以绘制读码相机绘制镜头从搜索起点开始到搜索终点为止获取到的多个位置处的图像清晰度评分和该多个位置的关系曲线。这样,绘制得到的关系曲线上可能会存在一个或者多个峰点。在这种情况下,读码相机获取该关系曲线中每个峰点处的图像清晰度评分峰值,从而得到至少一个图像清晰度评分峰值。
图像清晰度评分峰值可以是基于任意寻峰算法从关系曲线中确定得到的,本申请对此不作任何限定。
在获取到至少一个图像清晰度评分峰值之后,读码相机判断每个图像清晰度评分峰值对应的位置处的读码评分是否大于第二阈值,并将对应的读码评分大于第二阈值的位置作为第二位置。此时,确定出的第二位置可能有一个,也可能有多个,读码相机可以将确定出的第二位置作为至少一个粗略位置。
图4是本申请实施例示出的一种多个位置和多个位置处的图像清晰度评分的关系曲线图。如图4中所示,该曲线中存在3个峰点,读码相机可以获取每个峰点的峰值,从而得到3个图像清晰度评分峰值S1,S2和S3。之后,读码相机判断每个峰值对应的位置处的读码评分是否大于第二阈值。假设第二阈值为0,S1对应的位置A和S3对应的位置C处的读码评分均大于0,而S2对应的位置B处的读码评分等于0,则读码相机将位置A和位置C作为镜头的粗略位置。
在一些可能的情况中,在判断每个图像清晰度评分峰值对应的位置处的读码评分是否大于第二阈值时,有可能每个图像清晰度评分峰值对应的位置处的读码评分均不大于第二阈值,这样,将无法得到读码评分大于第二阈值的位置,也即,第二位置的个数为0。在这种情况下,读码相机可以从至少一个图像清晰度评分峰值中获取图像清晰度评分最大值,将该图像清晰度评分最大值对应的位置作为镜头的最佳位置,进而参考步骤304中的实现方式,根据该镜头的最佳位置进行对焦。
步骤3022:根据镜头的至少一个粗略位置和多个位置处的读码评分,确定镜头的最佳位置。
在得到镜头的至少一个粗略位置后,读码相机根据获取的多个读码评分对至少一个粗略位置以及粗略位置附近的其他位置进行精细搜索,以确定镜头的最佳位置。
示例性地,读码相机首先确定每个粗略位置对应的候选搜索区间,该候选搜索区间为以相应的粗略位置为中心的镜头位置区间;从每个候选搜索区间包含的各个位置对应的读码评分中,确定每个候选搜索区间内的读码评分局部最大值;根据每个候选搜索区间内的读码评分局部最大值,确定镜头的最佳位置。
以任一粗略位置为例,为了方便描述,将该粗略位置称为第一粗略位置,读码相机以第一粗略位置为中心,沿着指定搜索方向向前指定距离,向后指定距离,从而构成第一粗略位置对应的候选搜索区间。其中,该指定距离大于指定搜索步长。
例如,假设第一粗略位置为S,则以该位置S为中心沿着指定搜索方向向前L,向后L,从而构成候选搜索区间[S-L,S+L],其中,S大于L。
在确定第一粗略位置对应的候选搜索区间之后,对于该候选搜索区间内包括的镜头移动时所处过的每个位置,读码相机可以获取相应位置处的读码评分,并从获取到的读码评分中确定最大值,该最大值即为该候选搜索区间内的读码评分局部最大值。需要说明的是,如果粗略位置为一个,则对应的候选搜索区间也为一个,这样,得到的读码评分局部最大值也为一个。虽然读码评分局部最大值为一个,但是 读码评分局部最大值对应的位置可能有一个,也可能有多个。也就是说,可能有一个位置处的读码评分为该局部最大值,或者,也可能有多个位置处的读码评分均相同,均为该读码评分局部最大值。基于此,如果候选搜索区间为一个,且该候选搜索区间内的读码评分局部最大值对应的位置也为一个,则读码相机可以直接将该读码评分局部最大值对应的位置作为镜头的最佳位置。如果候选搜索区间为一个,且该候选搜索区间内的读码评分局部最大值对应的位置为多个,则读码相机可以从该候选搜索区间内的读码评分局部最大值对应的多个位置中,选择与该候选搜索区间对应的粗略位置距离最近的第三位置,将该第三位置作为镜头的最佳位置。
如果粗略位置为多个,则对应的候选搜索区间为多个,得到的读码评分局部最大值也为多个,在这种情况下,读码相机首先确定该多个候选搜索区间内的读码评分局部最大值中的最大值,得到全局最大值。此时,该全局最大值对应的位置可能有一个,也可能有多个。基于此,如果该全局最大值对应的位置有一个,则直接将该全局最大值对应的位置作为镜头的最佳位置,如果该全局最大值对应的位置有多个,则确定该全局最大值对应的每个位置与相应位置所在的候选搜索区间对应的粗略位置之间的距离,将与自身所在的候选搜索区间对应的粗略位置之间的距离最小的位置作为镜头的最佳位置。
例如,假设全局最大值对应的位置有3个,分别为a、b、c,其中,a位于候选搜索区间U1内,U1对应的粗略位置为M,b位于候选搜索区间U2内,U2对应的粗略位置为N,c位于候选搜索区间U3内,U3对应的粗略位置为Q,则读码相机计算a与M之间的距离,得到第一距离,计算b与N之间的距离,得到第二距离,计算c与Q之间的距离,得到第三距离。比较第一距离、第二距离和第三距离的大小,假设第一距离最小,则将a作为镜头的最佳位置。
在一些可能的实现方式中,在步骤301中,读码相机在镜头处于搜索起点时可以获取镜头在该搜索起点处的图像清晰度评分,后续,从该搜索起点开始,每当读码相机的镜头按照指定搜索步长移动一次,读码相机可以获取镜头移动后所处的位置处的图像清晰度评分。其中,为了区分,将此处所采用的指定搜索步长称为第一搜索步长。
如此,读码相机可以在镜头移动的过程中,每在移动后的位置处获取到一个图像清晰度评分,即判断一次已获取到的所有图像清晰度评分随着镜头的移动的变化趋势。如果随着镜头的移动,已获取到的多个图像清晰度评分呈现先变大后变小的趋势,且最近一次获取的图像清晰度评分相对于已获取的多个图像清晰度评分中的最大值的下降比例达到第一阈值,则将已获取到的多个图像清晰评分中的最大值对应的位置作为搜索到的粗略位置。
或者,读码相机可以参考前述步骤3021和步骤3022中介绍的方法,从镜头从行程起点移动至行程终点或者是从行程终点移动至行程起点的过程中获取到的所有位置处的图像清晰度评分中,获取至少一个图像清晰度评分峰值,将至少一个图像清晰度峰值对应的至少一个位置作为至少一个粗略位置。
在得到至少一个粗略位置之后,对于每个粗略位置,读码相机可以参考本步骤中介绍的方法确定每个粗略位置对应的候选搜索区间。之后,对于每个粗略位置对应的候选搜索区间,读码相机可以控制镜头从该候选搜索区间的一个端点开始,按照第二搜索步长向该候选搜索区间的另一个端点移动,其中,第二搜索步长小于前述进行粗略位置搜索时所采用的第一搜索步长。每当移动第二搜索步长之后,读码 相机可以采集一次图像,并根据采集到的图像计算镜头在移动后的位置处的读码评分。如此,读码相机即可以获取到镜头处于每个候选搜索区间内的多个位置处的读码评分。之后,读码相机可以根据每个候选搜索区间内的多个位置处的读码评分,确定每个候选搜索区间内的读码评分局部最大值,进而参考本步骤中介绍的方法,根据每个候选搜索区间内的读码评分局部最大值,确定镜头的最佳位置,此处不再赘述。
步骤303:根据镜头的最佳位置进行对焦。
在确定镜头的最佳位置之后,读码相机可以计算镜头当前所处的位置和镜头的最佳位置之间的距离差值,得到镜头所需移动的移动距离。与此同时,读码相机还可以确定从镜头当前所处的位置到镜头的最佳位置的方向是从行程起点到行程终点的方向,还是从行程终点到行程起点的方向,并将确定的方向作为镜头后续的移动方向。
在确定镜头的移动距离和移动方向之后,读码相机控制电机驱动镜头沿着该移动方向运动移动距离,到达镜头的最佳位置,从而完成对焦。
在本申请实施例中,根据读码相机的镜头处于不同位置时的图像清晰度评分和读码评分来进行自动对焦。由于读码评分能够表征读码相机的读码成功率,因此,本申请实施例实际上是结合读码相机的图像清晰度和读码效果对镜头处于不同位置时的对焦效果进行评价,以此来确定镜头的最佳位置进而完成自动对焦,这样,不仅能够保证对焦完成后的读码相机采集的图像的清晰度,还能够保证对焦完成后读码相机的读码成功率。
另外,在本申请实施例中,在找到图像清晰度评分峰值之后,可以将图像清晰度评分峰值所对应的位置中不存在读码评分的位置筛除,从而得到至少一个粗略位置。这样,得到的至少一个粗略位置均为视野内存在二维码或条形码的位置,避免了伪图像清晰度峰值带来的影响,提高了对焦成功率。
接下来对本申请实施例提供的对焦装置进行介绍。
图5a是本申请实施例提供的一种对焦装置500的结构示意图,该对焦装置500可以由软件、硬件或者两者的结合实现成为读码相机的部分或者全部。请参考图5,该装置500包括:获取模块501、确定模块502和对焦模块503。
获取模块501,用于获取读码相机的镜头处于多个位置时的图像清晰度评分和读码评分,读码评分用于表征读码相机的读码成功率;
确定模块502,用于根据多个位置处的图像清晰度评分,确定镜头的最佳位置;
对焦模块503,用于根据镜头的最佳位置进行对焦。
在一种可能的实现方式中,如图5b所示,确定模块502包括:
第一确定模块5021,用于根据多个位置处的图像清晰度评分,从多个位置中确定镜头的至少一个粗略位置;
第二确定模块5022,用于根据镜头的至少一个粗略位置和多个位置处的读码评分,确定镜头的最佳位置;
在一种可能的实现方式中,获取模块501主要用于:
获取镜头在搜索起点处的图像清晰度评分和读码评分,搜索起点为镜头的行程起点或行程终点,镜头的行程起点为镜头与待读码物体的目标表面的垂直距离最大时所处的位置点,镜头的行程终点为镜头与目标表面的垂直距离最小时所处的位置点;
控制镜头从搜索起点起按照指定搜索步长沿着指定搜索方向移动,其中,当搜索起点为镜头的行程起点时,指定搜索方向是指从镜头的行程起点到行程终点的方向,其中,当搜索起点为镜头的行程终点时,指定搜索方向是指从镜头的行程终点到行程起点的方向;
每当镜头移动指定搜索步长后,获取镜头移动后的图像清晰度评分和读码评分。
在一种可能的实现方式中,第一确定模块5021主要用于:
在镜头沿着指定搜索方向移动的过程中,如果随着镜头的移动,获取的多个图像清晰度评分呈先变大后变小的变化趋势,且最近一次获取的图像清晰度评分相对于多个图像清晰度评分中的最大值的下降比例达到第一阈值,则判断多个图像清晰度评分中的最大值对应的第一位置处的读码评分是否大于第二阈值;
如果第一位置处的读码评分大于第二阈值,则将第一位置作为镜头的粗略位置。
在一种可能的实现方式中,第一确定模块5021主要用于:
绘制多个位置与多个位置处的图像清晰度评分的关系曲线;
从关系曲线中获取至少一个图像清晰度评分峰值;
从至少一个图像清晰度评分峰值对应的至少一个位置中确定对应的读码评分大于第二阈值的第二位置;
将确定出的第二位置作为镜头的至少一个粗略位置。
在一种可能的实现方式中,第二确定模块5022主要用于:
确定每个粗略位置对应的候选搜索区间,候选搜索区间为以相应的粗略位置为中心的镜头位置区间;
从每个候选搜索区间包含的各个位置对应的读码评分中,确定每个候选搜索区间内的读码评分局部最大值;
根据每个候选搜索区间内的读码评分局部最大值,确定镜头的最佳位置。
在一种可能的实现方式中,第二确定模块5022主要还用于:
如果候选搜索区间为一个,且候选搜索区间内的读码评分局部最大值对应的位置为一个,则将候选搜索区间内的读码评分局部最大值对应的位置作为镜头的最佳位置;
如果候选搜索区间为一个,且候选搜索区间内的读码评分局部最大值对应的位置为多个,则从候选搜索区间内的读码评分局部最大值对应的多个位置中,选择与候选搜索区间对应的粗略位置距离最近的第三位置,将第三位置作为镜头的最佳位置;
如果候选搜索区间为多个,则将多个候选搜索区间内的读码评分局部最大值中的最大值作为全局最大值,如果全局最大值对应的位置为一个,则将全局最大值对应的位置作为镜头的最佳位置,如果全局最大值对应的位置有多个,则确定全局最大值对应的多个位置中的每个位置与自身所在的候选搜索区间对应的粗略位置之间的距离,并将与自身所在的候选搜索区间对应的粗略位置之间的距离最小的位置作 为镜头的最佳位置。
在一种可能的实现方式中,对焦模块503主要用于:
根据镜头的最佳位置和镜头的当前位置,确定镜头的对焦移动方向和移动距离;
根据镜头的对焦移动方向和移动距离,驱动镜头移动至镜头的最佳位置以完成对焦。
在本申请实施例中,根据读码相机的镜头处于不同位置时的图像清晰度评分和读码评分来进行自动对焦。由于读码评分能够表征读码相机的读码成功率,因此,本申请实施例实际上是结合读码相机的图像清晰度和读码效果对镜头处于不同位置时的对焦效果进行评价,以此来确定镜头的最佳位置进而完成自动对焦,这样,不仅能够保证对焦完成后的读码相机采集的图像的清晰度,还能够保证对焦完成后读码相机的读码成功率。
需要说明的是:上述实施例提供的对焦装置在进行对焦时,仅以上述各功能模块的划分进行举例说明,实际应用中,可以根据需要而将上述功能分配由不同的功能模块完成,即将装置的内部结构划分成不同的功能模块,以完成以上描述的全部或者部分功能。另外,上述实施例提供的对焦装置与对焦方法实施例属于同一构思,其具体实现过程详见方法实施例,这里不再赘述。
图6a是本申请实施例提供的一种计算机设备的结构示意图。前述实施例中的读码相机即可以通过该计算机设备来实现。
通常,该计算机设备600包括有:处理器601和存储器602。
处理器601可以包括一个或多个处理核心,比如4核心处理器、8核心处理器等。处理器601可以采用DSP(Digital Signal Processing,数字信号处理)、FPGA(Field-Programmable Gate Array,现场可编程门阵列)、PLA(Programmable Logic Array,可编程逻辑阵列)中的至少一种硬件形式来实现。处理器601也可以包括主处理器和协处理器,主处理器是用于对在唤醒状态下的数据进行处理的处理器,也称CPU(Central Processing Unit,中央处理器);协处理器是用于对在待机状态下的数据进行处理的低功耗处理器。在一些实施例中,处理器601可以集成有GPU(Graphics Processing Unit,图像处理器),GPU用于负责显示屏所需要显示的内容的渲染和绘制。一些实施例中,处理器601还可以包括AI(Artificial Intelligence,人工智能)处理器,该AI处理器用于处理有关机器学习的计算操作。需要说明的是,前述图2所示的对焦装置200中的控制单元即可以通过处理器601来实现。
存储器602可以包括一个或多个计算机可读存储介质,该计算机可读存储介质可以是非暂态的。存储器602还可包括高速随机存取存储器,以及非易失性存储器,比如一个或多个磁盘存储设备、闪存存储设备。在一些实施例中,存储器602中的非暂态的计算机可读存储介质用于存储至少一个指令,该至少一个指令用于被处理器601所执行以实现本申请中方法实施例提供的对焦方法。
在一些实施例中,如图6b所示,计算机设备600还可选包括有:外围设备接口603和至少一个外围设备。处理器601、存储器602和外围设备接口603之间可以通过总线或信号线相连。各个外围设备可以通过总线、信号线或电路板与外围设备接口603相连。具体地,外围设备包括:射频电路604、显示屏605、摄像头组件606、音频电路607、定位组件608和电源609中的至少一种。
外围设备接口603可被用于将I/O(Input/Output,输入/输出)相关的至少一个外围设备连接到处 理器601和存储器602。在一些实施例中,处理器601、存储器602和外围设备接口603被集成在同一芯片或电路板上;在一些其他实施例中,处理器601、存储器602和外围设备接口603中的任意一个或两个可以在单独的芯片或电路板上实现,本实施例对此不加以限定。
射频电路604用于接收和发射RF(Radio Frequency,射频)信号,也称电磁信号。射频电路604通过电磁信号与通信网络以及其他通信设备进行通信。射频电路604将电信号转换为电磁信号进行发送,或者,将接收到的电磁信号转换为电信号。在一种可能的实现方式中,射频电路604包括:天线系统、RF收发器、一个或多个放大器、调谐器、振荡器、数字信号处理器、编解码芯片组、用户身份模块卡等等。射频电路604可以通过至少一种无线通信协议来与其它终端进行通信。该无线通信协议包括但不限于:城域网、各代移动通信网络(2G、3G、4G及5G)、无线局域网和/或WiFi(Wireless Fidelity,无线保真)网络。在一些实施例中,射频电路604还可以包括NFC(Near Field Communication,近距离无线通信)有关的电路,本申请对此不加以限定。
显示屏605用于显示UI(User Interface,用户界面)。该UI可以包括图形、文本、图标、视频及其它们的任意组合。当显示屏605是触摸显示屏时,显示屏605还具有采集在显示屏605的表面或表面上方的触摸信号的能力。该触摸信号可以作为控制信号输入至处理器601进行处理。此时,显示屏605还可以用于提供虚拟按钮和/或虚拟键盘,也称软按钮和/或软键盘。在一些实施例中,显示屏605可以为一个,设置计算机设备600的前面板;在另一些实施例中,显示屏605可以为至少两个,分别设置在计算机设备600的不同表面或呈折叠设计;在另一些实施例中,显示屏605可以是柔性显示屏,设置在计算机设备600的弯曲表面上或折叠面上。甚至,显示屏605还可以设置成非矩形的不规则图形,也即异形屏。显示屏605可以采用LCD(Liquid Crystal Display,液晶显示屏)、OLED(Organic Light-Emitting Diode,有机发光二极管)等材质制备。
摄像头组件606用于采集图像或视频。其中,该摄像头组件606可以包括前述图2中所示的对焦装置200。除此之外,该摄像头组件中还可以包括图像传感器、滤光组件、补光装置等。其中,图像传感器用于通过曝光产生并输出图像信号。滤光组件用于对进入到摄像头组件的可见光进行特定波段的滤光。补光装置用于在图像传感器曝光的过程中进行补光。
音频电路607可以包括麦克风和扬声器。麦克风用于采集用户及环境的声波,并将声波转换为电信号输入至处理器601进行处理,或者输入至射频电路604以实现语音通信。出于立体声采集或降噪的目的,麦克风可以为多个,分别设置在计算机设备600的不同部位。麦克风还可以是阵列麦克风或全向采集型麦克风。扬声器则用于将来自处理器601或射频电路604的电信号转换为声波。扬声器可以是传统的薄膜扬声器,也可以是压电陶瓷扬声器。当扬声器是压电陶瓷扬声器时,不仅可以将电信号转换为人类可听见的声波,也可以将电信号转换为人类听不见的声波以进行测距等用途。
定位组件608用于定位计算机设备600的当前地理位置,以实现导航或LBS(Location Based Service,基于位置的服务)。定位组件608可以是基于美国的GPS(Global Positioning System,全球定位系统)、中国的北斗系统、俄罗斯的格雷纳斯系统或欧盟的伽利略系统的定位组件。
电源609用于为计算机设备600中的各个组件进行供电。电源609可以是交流电、直流电、一次性 电池或可充电电池。当电源609包括可充电电池时,该可充电电池可以支持有线充电或无线充电。该可充电电池还可以用于支持快充技术。
本领域技术人员可以理解,图6b中示出的结构并不构成对计算机设备600的限定,可以包括比图示更多或更少的组件,或者组合某些组件,或者采用不同的组件布置。
本申请实施例还提供了一种非临时性计算机可读存储介质,当所述存储介质中的指令由计算机设备的处理器执行时,使得计算机设备能够执行上实施例提供的对焦方法。例如,该计算机可读存储介质可以是ROM、RAM、CD-ROM、磁带、软盘和光数据存储设备等。
值得注意的是,本申请实施例提到的计算机可读存储介质可以为非易失性存储介质,换句话说,可以是非瞬时性存储介质。
本申请实施例还提供了一种包含指令的计算机程序产品,当其在计算机设备上运行时,使得计算机设备执行上述实施例提供的对焦方法。
以上所述仅为本申请的较佳实施例,并不用以限制本申请,凡在本申请的精神和原则之内,所做的任何修改、等同替换、改进等,均应包含在本申请保护的范围之内。

Claims (12)

  1. 一种对焦方法,其特征在于,所述方法包括:
    获取读码相机的镜头处于多个位置时的图像清晰度评分和读码评分,所述读码评分用于表征所述读码相机的读码成功率;
    根据所述多个位置的图像清晰度评分和读码评分,确定所述镜头的最佳位置;
    根据所述镜头的最佳位置进行对焦。
  2. 根据权利要求1所述的方法,其特征在于,所述根据所述多个位置的图像清晰度评分和读码评分,确定所述镜头的最佳位置,包括:
    根据所述多个位置处的图像清晰度评分,从所述多个位置中确定所述镜头的至少一个粗略位置;
    根据所述镜头的至少一个粗略位置和所述多个位置处的读码评分,确定所述镜头的最佳位置;
    根据所述镜头的最佳位置进行对焦。
  3. 根据权利要求2所述的方法,其特征在于,所述获取读码相机的镜头处于多个位置时的图像清晰度评分和读码评分,包括:
    获取所述镜头在搜索起点处的图像清晰度评分和读码评分,所述搜索起点为所述镜头的行程起点或行程终点,所述镜头的行程起点为所述镜头与待读码物体的目标表面的垂直距离最大时所处的位置点,所述镜头的行程终点为所述镜头与所述目标表面的垂直距离最小时所处的位置点;
    控制所述镜头从所述搜索起点起按照指定搜索步长沿着指定搜索方向移动,其中,当所述搜索起点为所述镜头的行程起点时,所述指定搜索方向是指从所述镜头的行程起点到行程终点的方向,当所述搜索起点为所述镜头的行程终点时,所述指定搜索方向是指从所述镜头的行程终点到行程起点的方向;
    每当所述镜头移动所述指定搜索步长后,获取所述镜头移动后的图像清晰度评分和读码评分。
  4. 根据权利要求3所述的方法,其特征在于,所述根据所述多个位置处的图像清晰度评分,从所述多个位置中确定所述镜头的至少一个粗略位置,包括:
    在所述镜头沿着所述指定搜索方向移动的过程中,如果随着所述镜头的移动,已获取的多个图像清晰度评分呈先变大后变小的变化趋势,且最近一次获取的图像清晰度评分相对于所述多个图像清晰度评分中的最大值的下降比例达到第一阈值,则判断所述多个图像清晰度评分中的最大值对应的第一位置处的读码评分是否大于第二阈值;
    如果所述第一位置处的读码评分大于所述第二阈值,则将所述第一位置作为所述镜头的粗略位置。
  5. 根据权利要求2所述的方法,其特征在于,所述根据所述多个位置处的图像清晰度评分,从所述多个位置中确定所述镜头的至少一个粗略位置,包括:
    绘制所述多个位置与所述多个位置处的图像清晰度评分的关系曲线;
    从所述关系曲线中获取至少一个图像清晰度评分峰值;
    从所述至少一个图像清晰度评分峰值对应的至少一个位置中确定对应的读码评分大于第二阈值的第二位置;
    将确定出的第二位置作为所述镜头的至少一个粗略位置。
  6. 根据权利要求2所述的方法,其特征在于,所述根据所述镜头的至少一个粗略位置和所述多个位置处的读码评分,确定所述镜头的最佳位置,包括:
    确定每个粗略位置对应的候选搜索区间,所述候选搜索区间为以相应的粗略位置为中心的镜头位置区间;
    从每个候选搜索区间包含的各个位置对应的读码评分中,确定每个候选搜索区间内的读码评分局部最大值;
    根据每个候选搜索区间内的读码评分局部最大值,确定所述镜头的最佳位置。
  7. 根据权利要求6所述的方法,其特征在于,所述根据每个候选搜索区间内的读码评分局部最大值,确定所述镜头的最佳位置,包括:
    如果所述候选搜索区间为一个,且所述候选搜索区间内的读码评分局部最大值对应的位置为一个,则将所述候选搜索区间内的读码评分局部最大值对应的位置作为所述镜头的最佳位置;
    如果所述候选搜索区间为一个,且所述候选搜索区间内的读码评分局部最大值对应的位置为多个,则从所述候选搜索区间内的读码评分局部最大值对应的多个位置中,选择与所述候选搜索区间对应的粗略位置距离最近的第三位置,将所述第三位置作为所述镜头的最佳位置;
    如果所述候选搜索区间为多个,则将多个候选搜索区间内的读码评分局部最大值中的最大值作为全局最大值,如果所述全局最大值对应的位置为一个,则将所述全局最大值对应的位置作为所述镜头的最佳位置,如果所述全局最大值对应的位置有多个,则确定所述全局最大值对应的多个位置中的每个位置与自身所在的候选搜索区间对应的粗略位置之间的距离,并将与自身所在的候选搜索区间对应的粗略位置之间的距离最小的位置作为所述镜头的最佳位置。
  8. 根据权利要求1所述的方法,其特征在于,所述根据所述镜头的最佳位置进行对焦,包括:
    根据所述镜头的最佳位置和所述镜头的当前位置,确定所述镜头的对焦移动方向和移动距离;
    根据所述镜头的对焦移动方向和移动距离,驱动所述镜头移动至所述镜头的最佳位置以完成对焦。
  9. 一种对焦装置,其特征在于,所述装置包括:
    获取模块,用于获取读码相机的镜头处于多个位置时的图像清晰度评分和读码评分,所述读码评分用于表征所述读码相机的读码成功率;
    确定模块,用于根据所述多个位置处的图像清晰度评分和读码评分,确定所述镜头的最佳位置;
    对焦模块,用于根据所述镜头的最佳位置进行对焦。
  10. 根据权利要求9所述的装置,其特征在于,所述确定模块,包括:
    第一确定模块,用于根据所述多个位置处的图像清晰度评分,从所述多个位置中确定所述镜头的至少一个粗略位置;
    第二确定模块,用于根据所述镜头的至少一个粗略位置和所述多个位置处的读码评分,确定所述镜头的最佳位置;
    获取模块主要用于:获取所述镜头在搜索起点处的图像清晰度评分和读码评分,所述搜索起点为所述镜头的行程起点或行程终点,所述镜头的行程起点为所述镜头与待读码物体的目标表面的垂直距离最远时所处的位置点,所述镜头的行程终点为所述镜头与所述目标表面的垂直距离最近时所处的位置点;控制所述镜头从所述搜索起点起按照指定搜索步长沿着指定搜索方向移动,其中,当所述搜索起点为所述镜头的行程起点时,所述指定搜索方向是指从所述镜头的行程起点到行程终点的方向,当所述搜索起点为所述镜头的行程终点时,所述指定搜索方向是指从所述镜头的行程终点到行程起点的方向;每当所述镜头移动所述指定搜索步长后,获取所述镜头移动后的图像清晰度评分和读码评分;
    所述第一确定模块主要用于:在所述镜头沿着所述指定搜索方向移动的过程中,如果随着所述镜头的移动,已获取的所述多个图像清晰度评分呈先变大后变小的变化趋势,且最近一次获取的图像清晰度评分相对于所述多个图像清晰度评分中的最大值的下降比例达到第一阈值,则判断所述多个图像清晰度评分中的最大值对应的第一位置是否的读码评分是否大于第二阈值;如果所述第一位置的读码评分大于第二阈值,则将所述第一位置作为所述镜头的粗略位置;
    或者,所述第一确定模块主要用于:绘制所述多个位置与所述多个位置处的图像清晰度评分的关系曲线;从所述图像清晰度评分的关系曲线中获取至少一个图像清晰度评分峰值;从所述至少一个图像清晰度评分峰值对应的至少一个位置中确定对应的读码评分大于第二阈值的第二位置;将确定出的第二位置作为所述镜头的至少一个粗略位置;
    所述第二确定模块主要用于:确定每个粗略位置对应的候选搜索区间,所述候选搜索区间为以相应的粗略位置为中心的镜头位置区间;从每个候选搜索区间包含的各个位置对应的读码评分中,确定每个候选搜索区间内的读码评分局部最大值;根据确定的读码评分局部最大值,确定所述镜头的最佳位置;
    所述第二确定模块主要还用于:如果所述候选搜索区间为一个,且所述候选搜索区间内的读码评分局部最大值对应的位置为一个,则将所述候选搜索区间内的读码评分局部最大值对应的位置作为所述镜头的最佳位置;如果所述候选搜索区间内为一个,且所述候选搜索区间内的读码评分局部最大值对应的位置为多个,则从所述候选搜索区间内的读码评分局部最大值对应的多个位置中,选择与所述候选搜索区间对应的粗略位置距离最近的第三位置,将所述第三位置作为所述镜头的最佳位置;如果所述候选搜索区间为多个,则将多个候选搜索区间内的读码评分局部最大值中的最大值作为全局最大值,如果所述全局最大值对应的位置为一个,则将所述全局最大值对应的位置作为所述镜头的最佳位置,如果所述全局最大值对应的位置有多个,则确定所述全局最大值对应的多个位置中的每个位置与自身所在的候选搜 索区间对应的粗略位置之间的距离,并将与自身所在的候选搜索区间对应的粗略位置之间的距离最小的位置作为所述镜头的最佳位置;
    所述对焦模块主要用于:根据所述镜头的最佳位置和所述镜头的当前位置,确定所述镜头的对焦移动方向和移动距离;根据所述镜头的对焦移动方向和移动距离,驱动所述镜头移动至所述镜头的最佳位置以完成对焦。
  11. 一种对焦装置,其特征在于,所述对焦装置包括控制单元、电机、镜头和移动机构;
    其中,所述移动机构带动所述镜头在垂直于所述镜头的镜面的方向上移动;
    所述控制单元与所述电机连接,所述控制单元用于执行权利要求1-8中任一项所述的方法,以控制所述电机驱动所述移动机构带动所述镜头移动完成对焦。
  12. 一种计算机可读存储介质,其特征在于,所述计算机可读存储介质内存储有计算机程序,所述计算机程序被处理器执行时实现权利要求1-8任一所述方法的步骤。
PCT/CN2022/104462 2021-07-08 2022-07-07 对焦方法、装置及存储介质 WO2023280285A1 (zh)

Priority Applications (3)

Application Number Priority Date Filing Date Title
KR1020237044950A KR20240013880A (ko) 2021-07-08 2022-07-07 포커싱 방법, 디바이스 및 저장 매체
JP2023580583A JP2024525462A (ja) 2021-07-08 2022-07-07 合焦方法、装置及び記憶媒体
EP22837030.0A EP4369247A1 (en) 2021-07-08 2022-07-07 Focusing method and apparatus, and storage medium

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN202110771982.4A CN113364986B (zh) 2021-07-08 2021-07-08 对焦方法、装置及存储介质
CN202110771982.4 2021-07-08

Publications (1)

Publication Number Publication Date
WO2023280285A1 true WO2023280285A1 (zh) 2023-01-12

Family

ID=77538921

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2022/104462 WO2023280285A1 (zh) 2021-07-08 2022-07-07 对焦方法、装置及存储介质

Country Status (5)

Country Link
EP (1) EP4369247A1 (zh)
JP (1) JP2024525462A (zh)
KR (1) KR20240013880A (zh)
CN (1) CN113364986B (zh)
WO (1) WO2023280285A1 (zh)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN116320749A (zh) * 2023-05-23 2023-06-23 无锡前诺德半导体有限公司 摄像头的控制方法、摄像系统、移动终端和存储介质

Families Citing this family (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113364986B (zh) * 2021-07-08 2022-08-09 杭州海康机器人技术有限公司 对焦方法、装置及存储介质
CN114169479A (zh) * 2021-12-31 2022-03-11 深圳市前海研祥亚太电子装备技术有限公司 一种智能读码器

Citations (9)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN202838362U (zh) * 2012-08-07 2013-03-27 重庆春涵科技发展有限公司 二维码识别系统
CN105578029A (zh) * 2015-09-01 2016-05-11 闽南师范大学 一种多尺度变步长的自动对焦搜索算法据传输装置和方法
CN106056027A (zh) * 2016-05-25 2016-10-26 努比亚技术有限公司 一种实现远距离扫描二维码的终端、系统和方法
CN107358234A (zh) * 2017-07-17 2017-11-17 上海青橙实业有限公司 识别码的识别方法及装置
CN109214225A (zh) * 2018-07-04 2019-01-15 青岛海信移动通信技术股份有限公司 一种图形条码的扫描方法、装置、移动终端和存储介质
CN109670362A (zh) * 2017-10-16 2019-04-23 上海商米科技有限公司 条码扫描方法和装置
US20200034591A1 (en) * 2018-07-24 2020-01-30 Cognex Corporation System and method for auto-focusing a vision system camera on barcodes
CN111432125A (zh) * 2020-03-31 2020-07-17 合肥英睿系统技术有限公司 一种对焦方法、装置及电子设备和存储介质
CN113364986A (zh) * 2021-07-08 2021-09-07 杭州海康机器人技术有限公司 对焦方法、装置及存储介质

Family Cites Families (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US7769219B2 (en) * 2006-12-11 2010-08-03 Cytyc Corporation Method for assessing image focus quality
US8636212B2 (en) * 2011-08-24 2014-01-28 Metrologic Instruments, Inc. Decodable indicia reading terminal with indicia analysis functionality
JP6326759B2 (ja) * 2012-11-30 2018-05-23 株式会社リコー 画像記録システム、画像書き換えシステム及び画像記録方法
CN212552294U (zh) * 2020-07-03 2021-02-19 孙杰 一种两用式激光直接标识工作站
CN112001200A (zh) * 2020-09-01 2020-11-27 杭州海康威视数字技术股份有限公司 识别码识别方法、装置、设备、存储介质和系统

Patent Citations (9)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN202838362U (zh) * 2012-08-07 2013-03-27 重庆春涵科技发展有限公司 二维码识别系统
CN105578029A (zh) * 2015-09-01 2016-05-11 闽南师范大学 一种多尺度变步长的自动对焦搜索算法据传输装置和方法
CN106056027A (zh) * 2016-05-25 2016-10-26 努比亚技术有限公司 一种实现远距离扫描二维码的终端、系统和方法
CN107358234A (zh) * 2017-07-17 2017-11-17 上海青橙实业有限公司 识别码的识别方法及装置
CN109670362A (zh) * 2017-10-16 2019-04-23 上海商米科技有限公司 条码扫描方法和装置
CN109214225A (zh) * 2018-07-04 2019-01-15 青岛海信移动通信技术股份有限公司 一种图形条码的扫描方法、装置、移动终端和存储介质
US20200034591A1 (en) * 2018-07-24 2020-01-30 Cognex Corporation System and method for auto-focusing a vision system camera on barcodes
CN111432125A (zh) * 2020-03-31 2020-07-17 合肥英睿系统技术有限公司 一种对焦方法、装置及电子设备和存储介质
CN113364986A (zh) * 2021-07-08 2021-09-07 杭州海康机器人技术有限公司 对焦方法、装置及存储介质

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN116320749A (zh) * 2023-05-23 2023-06-23 无锡前诺德半导体有限公司 摄像头的控制方法、摄像系统、移动终端和存储介质
CN116320749B (zh) * 2023-05-23 2023-08-11 无锡前诺德半导体有限公司 摄像头的控制方法、摄像系统、移动终端和存储介质

Also Published As

Publication number Publication date
CN113364986A (zh) 2021-09-07
JP2024525462A (ja) 2024-07-12
EP4369247A1 (en) 2024-05-15
CN113364986B (zh) 2022-08-09
KR20240013880A (ko) 2024-01-30

Similar Documents

Publication Publication Date Title
WO2023280285A1 (zh) 对焦方法、装置及存储介质
KR102324921B1 (ko) 매크로 이미징 방법 및 단말기
EP3828769B1 (en) Image processing method and apparatus, terminal and computer-readable storage medium
US10877353B2 (en) Continuous autofocus mechanisms for image capturing devices
US10701260B2 (en) Focusing method, apparatus, computer readable storage medium and terminal
KR20190014638A (ko) 전자 기기 및 전자 기기의 제어 방법
CN103871051A (zh) 图像处理方法、装置和电子设备
CN109254564A (zh) 物品搬运方法、装置、终端及计算机可读存储介质
KR20140140855A (ko) 촬영 장치의 자동 초점 조절 방법 및 장치
CN107613208B (zh) 一种对焦区域的调节方法及终端、计算机存储介质
CN105323491B (zh) 图像拍摄方法及装置
CN102595044A (zh) 具有防手震照相功能的电子装置及其照相方法
US10250795B2 (en) Identifying a focus point in a scene utilizing a plurality of cameras
WO2005032371A1 (ja) 目画像撮像装置
CN113012211B (zh) 图像采集方法、装置、系统、计算机设备及存储介质
US20170187950A1 (en) Imaging device and focus control method
CN206962934U (zh) 用于终端设备的拍摄组件
CN110891132B (zh) 包括折射率层的设备、相机模块和图像传感器封装件
CN110602381B (zh) 景深检测方法、装置、存储介质及终端
KR20150133597A (ko) 이동 단말기 및 이의 제어 방법
US20190056574A1 (en) Camera, and image display apparatus including the same
CN114299997A (zh) 音频数据处理方法、装置、电子设备、存储介质及产品
JP2009251679A (ja) 撮像装置及び画像認識方法
CN117812235A (zh) 投影仪的焦距调整方法、装置、设备及存储介质
WO2020073663A1 (zh) 一种应用于终端设备的对焦方法、装置和终端设备

Legal Events

Date Code Title Description
ENP Entry into the national phase

Ref document number: 20237044950

Country of ref document: KR

Kind code of ref document: A

WWE Wipo information: entry into national phase

Ref document number: 1020237044950

Country of ref document: KR

ENP Entry into the national phase

Ref document number: 2023580583

Country of ref document: JP

Kind code of ref document: A

WWE Wipo information: entry into national phase

Ref document number: 2022837030

Country of ref document: EP

NENP Non-entry into the national phase

Ref country code: DE

WWE Wipo information: entry into national phase

Ref document number: 11202400115R

Country of ref document: SG