CN111641781B - Automatic focusing method and device and electronic equipment - Google Patents

Automatic focusing method and device and electronic equipment Download PDF

Info

Publication number
CN111641781B
CN111641781B CN202010449914.1A CN202010449914A CN111641781B CN 111641781 B CN111641781 B CN 111641781B CN 202010449914 A CN202010449914 A CN 202010449914A CN 111641781 B CN111641781 B CN 111641781B
Authority
CN
China
Prior art keywords
focusing
focus
peak
auxiliary
value
Prior art date
Legal status (The legal status 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 status listed.)
Active
Application number
CN202010449914.1A
Other languages
Chinese (zh)
Other versions
CN111641781A (en
Inventor
谢伟
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Zhejiang Dahua Technology Co Ltd
Original Assignee
Zhejiang Dahua Technology Co Ltd
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 Zhejiang Dahua Technology Co Ltd filed Critical Zhejiang Dahua Technology Co Ltd
Priority to CN202010449914.1A priority Critical patent/CN111641781B/en
Publication of CN111641781A publication Critical patent/CN111641781A/en
Application granted granted Critical
Publication of CN111641781B publication Critical patent/CN111641781B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • 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
    • 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

Landscapes

  • Engineering & Computer Science (AREA)
  • Multimedia (AREA)
  • Signal Processing (AREA)
  • Automatic Focus Adjustment (AREA)
  • Studio Devices (AREA)

Abstract

The application relates to an automatic focusing method, an automatic focusing device and an electronic device, wherein the automatic focusing method comprises the following steps: compared with the related art, the method for automatic focusing provided by the embodiment of the application calculates the first definition evaluation value of the main focusing area and the second definition evaluation value of the auxiliary focusing area by acquiring the main focusing area and the auxiliary focusing area of the video image; searching a first main focusing peak value and an auxiliary focusing peak value, calculating a deviation value of the auxiliary focusing peak value compared with the first main focusing peak value, increasing a weight coefficient of an auxiliary focusing area, calculating a third definition evaluation value and searching a second main focusing peak value, and taking a focusing point corresponding to the second main focusing peak value as a focusing point of a video image, so that the problems that the definition of the auxiliary focusing area does not reach the standard by taking the position with the maximum definition evaluation value of an area with higher attention as the position of the clearest point of the image are solved, and the focusing of the auxiliary focusing area is clear while the focusing of the main focusing area is clear are realized.

Description

Automatic focusing method and device and electronic equipment
Technical Field
The present application relates to the field of image processing, and in particular, to an auto-focusing method and apparatus, and an electronic device.
Background
Autofocus is divided into two categories: (1) active mode: an infrared ray generator and an ultrasonic generator on the camera emit infrared light or ultrasonic waves to a shot object, and a receiver on the camera receives the emitted infrared light or ultrasonic waves to carry out focusing active focusing. The mode is difficult to focus on objects with inclined planes, smooth surfaces, light absorption or waves, and difficult to focus on objects with high brightness and long distance; (2) the passive type: the method is a mode of directly receiving and analyzing the reflected light from the scenery to carry out automatic focusing, and does not need a transmitting system, so that the method has the advantages of low energy consumption, miniaturization benefiting, cost saving, ideal automatic focusing for a shot object with certain brightness, and realization of remote focusing, and therefore, the passive focusing technology is a mainstream automatic focusing mode at present. With the popularization of auto focus cameras, the requirements for performance such as focus accuracy and focus speed are also increasing.
In the related art, the automatic focusing technology is to determine a definition evaluation value before focusing is started, generally select a region with higher attention in an image to calculate the definition evaluation value, then drive a focusing motor to move to a position with the maximum definition evaluation value, wherein the position is the clearest point, and the automatic focusing is completed.
At present, an effective solution is not provided aiming at the problem that the definition of an auxiliary focusing area does not reach the standard in the related technology that the position with the maximum definition evaluation value of an area with higher attention is used as the position of the clearest point of an image.
Disclosure of Invention
The embodiment of the application provides an automatic focusing method, an automatic focusing device and electronic equipment, and aims to at least solve the problem that the definition of an auxiliary focusing area does not reach the standard by taking the position with the highest definition evaluation value of an area with higher attention as the position of the clearest point of an image in the related art.
In a first aspect, an embodiment of the present application provides an auto-focusing method, where the method includes:
acquiring a main focusing area and an auxiliary focusing area of a video image, and respectively calculating a first definition evaluation value of the main focusing area and a second definition evaluation value of the auxiliary focusing area according to a definition evaluation value algorithm;
searching a first main focusing peak value according to the first definition evaluation value, searching an auxiliary focusing peak value according to the second definition evaluation value, and calculating a deviation value of the auxiliary focusing peak value compared with the first main focusing peak value;
and under the condition that the deviation value is not within a preset range, increasing a weight coefficient of the auxiliary focusing area according to a weight calculation algorithm, calculating a third definition evaluation value of the main focusing area according to the weight coefficient, searching a second main focusing peak value, and taking a focusing point corresponding to the second main focusing peak value as a focusing point of the video image.
In some of these embodiments, the calculating a deviation value of the secondary focus peak from the first primary focus peak comprises:
obtaining coordinates (x) of the first primary focus peak1、y1) And the coordinates (x) of the auxiliary focus peak2、y2) Wherein x isnTo focus the number of steps of the motor, ynThe definition evaluation value is obtained;
and calculating the difference of the step numbers of the focusing motors under the first main focusing peak value and the auxiliary focusing peak value, wherein the difference of the step numbers of the focusing motors indicates the deviation value.
In some of these embodiments, the calculating a deviation value of the secondary focus peak from the first primary focus peak comprises:
acquiring a focusing curve X for searching the first main focusing peak and a focusing curve Y for searching the auxiliary focusing peak, wherein the coordinate of the first main focusing peak is marked as (X)1、y1) The coordinate of the auxiliary focusing peak is (x)2、y2) Wherein x isnTo focus the number of steps of the motor, ynThe definition evaluation value is obtained;
acquiring a definition evaluation value M of a main focusing area corresponding to the intersection point of the focusing curve X and the focusing curve Y;
and judging the ratio of the definition evaluation value M to the auxiliary focusing peak value, wherein the ratio indicates the deviation value.
In some embodiments, the focus point corresponding to the second primary focus peak is before the focus point of the video image, and the method further comprises:
obtaining coordinates (x) of the second main focus peak3、y3);
Determining the coordinates (x) of the second main focus peak3、y3) In x3Whether or not it is located at x1And x2In the above-mentioned manner,
at x3Is not in x1And x2In the case in between, after a preset number of cycles, x3Still not at x1And x2In the meantime, the focus point corresponding to the first primary focus peak is taken as the focus point of the video image, and the preset loop is operated to calculate the second sharpness evaluation value of the primary focus area according to the weight coefficient and search for a primary focus peak coordinate (x)3、y3);
At x3At x1And x2In the above case, the focus point corresponding to the second main focus peak is the focus point of the video image.
In some of these embodiments, the weight calculation algorithm comprises:
obtaining coordinates (x) of the first primary focus peak1、y1) And seating of said secondary focusing peakLabel (x)2、y2) Wherein x isnTo focus the number of steps of the motor, ynThe definition evaluation value is obtained;
calculating the deviation steps of the first main focusing peak value and the focusing motor under the auxiliary focusing peak value;
and generating the weight calculation algorithm according to the deviation steps and the deviation coefficient.
In some embodiments, the auxiliary focus area is located in a corner area of the video image, and the main focus area is the entire video image area.
In a second aspect, an embodiment of the present application provides an apparatus for automatic focusing, the apparatus including: an acquisition module and a focusing module;
the device comprises an acquisition module, a display module and a display module, wherein the acquisition module is used for acquiring a main focusing area and an auxiliary focusing area of a video image, and respectively calculating a first definition evaluation value of the main focusing area and a second definition evaluation value of the auxiliary focusing area according to a definition evaluation value algorithm;
the focusing module is used for searching a first main focusing peak value according to the first definition evaluation value, searching an auxiliary focusing peak value according to the second definition evaluation value and calculating a deviation value of the auxiliary focusing peak value relative to the first main focusing peak value;
the obtaining module is further configured to, when the deviation value is not within a preset range, increase a weight coefficient of the auxiliary focusing area according to a weight calculation algorithm, calculate a third sharpness evaluation value of the primary focusing area according to the weight coefficient, and search for a second primary focusing peak value, where a focusing point corresponding to the second primary focusing peak value is a focusing point of the video image.
In some of these embodiments, the obtaining module is further configured to obtain a coordinate (x) of the first main focus peak1、y1) And the coordinates (x) of the auxiliary focus peak2、y2) Wherein x isnTo focus the number of steps of the motor, ynThe definition evaluation value is obtained;
the focusing module is further configured to calculate a focusing motor step difference between the first main focusing peak value and the auxiliary focusing peak value, and the focusing motor step difference indicates the deviation value.
In a third aspect, an embodiment of the present application provides an electronic device, which includes a memory, a processor, and a computer program stored on the memory and executable on the processor, and when the processor executes the computer program, the method of autofocus described in the first aspect is implemented.
In a fourth aspect, embodiments of the present application provide a computer-readable storage medium, on which a computer program is stored, which when executed by a processor, implements the method for autofocusing as described in the second aspect above.
Compared with the related art, the method for automatic focusing provided by the embodiment of the application respectively calculates the first definition evaluation value of the main focusing area and the second definition evaluation value of the auxiliary focusing area according to the definition evaluation value algorithm by acquiring the main focusing area and the auxiliary focusing area of the video image; searching a first main focusing peak value according to the first definition evaluation value, searching an auxiliary focusing peak value according to the second definition evaluation value, and calculating a deviation value of the auxiliary focusing peak value relative to the first main focusing peak value; under the condition that the deviation value is not within the preset range, the weight coefficient of the auxiliary focusing area is increased according to the weight calculation algorithm, the third definition evaluation value of the main focusing area is calculated according to the weight coefficient, the second main focusing peak value is searched, the focusing point corresponding to the second main focusing peak value is taken as the focusing point of the video image, the problem that the definition of the auxiliary focusing area does not reach the standard when the position with the maximum definition evaluation value of the area with higher attention is taken as the position of the clearest point of the image is solved, and the focusing of the auxiliary focusing area is clear while the focusing of the main focusing area is clear is achieved.
Drawings
The accompanying drawings, which are included to provide a further understanding of the application and are incorporated in and constitute a part of this application, illustrate embodiment(s) of the application and together with the description serve to explain the application and not to limit the application. In the drawings:
FIG. 1 is a flow chart of a method of autofocusing according to an embodiment of the application;
FIG. 2 is a flow chart of a method of calculating a deviation value according to an embodiment of the present application;
FIG. 3 is a flow chart of another method of calculating a deviation value according to an embodiment of the present application;
FIG. 4 is a flow chart of another method of autofocusing according to an embodiment of the application;
FIG. 5 is a flow chart of a method of a weight calculation algorithm according to an embodiment of the present application;
FIG. 6 is a schematic diagram of one of the divisions of a main focusing area and a plurality of auxiliary focusing areas corresponding to a video image according to an embodiment of the present application;
FIG. 7 is a schematic diagram of one of various focus curves for region A, B, C, D, E, according to an embodiment of the application;
FIG. 8 is a block diagram of an apparatus for auto-focusing according to an embodiment of the present application;
fig. 9 is an internal structural diagram of an electronic device according to an embodiment of the present application.
Detailed Description
In order to make the objects, technical solutions and advantages of the present application more apparent, the present application will be described and illustrated below with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative of the present application and are not intended to limit the present application. All other embodiments obtained by a person of ordinary skill in the art based on the embodiments provided in the present application without any inventive step are within the scope of protection of the present application.
It is obvious that the drawings in the following description are only examples or embodiments of the present application, and that it is also possible for a person skilled in the art to apply the present application to other similar contexts on the basis of these drawings without inventive effort. Moreover, it should be appreciated that in the development of any such actual implementation, as in any engineering or design project, numerous implementation-specific decisions must be made to achieve the developers' specific goals, such as compliance with system-related and business-related constraints, which may vary from one implementation to another.
Reference in the specification to "an embodiment" means that a particular feature, structure, or characteristic described in connection with the embodiment can be included in at least one embodiment of the specification. The appearances of the phrase in various places in the specification are not necessarily all referring to the same embodiment, nor are separate or alternative embodiments mutually exclusive of other embodiments. Those of ordinary skill in the art will explicitly and implicitly appreciate that the embodiments described herein may be combined with other embodiments without conflict.
Unless defined otherwise, technical or scientific terms referred to herein shall have the ordinary meaning as understood by those of ordinary skill in the art to which this application belongs. Reference to "a," "an," "the," and similar words throughout this application are not to be construed as limiting in number, and may refer to the singular or the plural. The present application is directed to the use of the terms "including," "comprising," "having," and any variations thereof, which are intended to cover non-exclusive inclusions; for example, a process, method, system, article, or apparatus that comprises a list of steps or modules (elements) is not limited to the listed steps or elements, but may include other steps or elements not expressly listed or inherent to such process, method, article, or apparatus. Reference to "connected," "coupled," and the like in this application is not intended to be limited to physical or mechanical connections, but may include electrical connections, whether direct or indirect. Reference herein to the terms "first," "second," "third," and the like, are merely to distinguish similar objects and do not denote a particular ordering for the objects.
The method for automatically focusing can be applied to a camera, the light reflected by an object is received by a sensor on the camera in the automatic focusing process, the optimal position is selected through computer processing, then the focusing motor is driven to move to the optimal position for automatically focusing, and the focusing of the auxiliary focusing area can be considered to be clear under the condition that the focusing of the main focusing area is clear. The camera obtains a main focusing area and an auxiliary focusing area of a video image, respectively calculates a first definition evaluation value of the main focusing area and a second definition evaluation value of the auxiliary focusing area according to a definition evaluation value algorithm, searches for a first main focusing peak value according to the first definition evaluation value, searches for an auxiliary focusing peak value according to the second definition evaluation value, calculates a deviation value of the auxiliary focusing peak value compared with the first main focusing peak value, increases a weight coefficient of the auxiliary focusing area under the condition that the deviation value is not within a preset range, calculates a third definition evaluation value of the main focusing area according to the weight coefficient, searches for a second main focusing peak value, and takes a focusing point corresponding to the second main focusing peak value as a focusing point of the video image. Note that the video image in the present application includes a still picture and a moving image.
The present embodiment provides a method of autofocusing. Fig. 1 is a flowchart of a method of autofocusing according to an embodiment of the application, as shown in fig. 1, the flowchart including the steps of:
step S101, acquiring a main focusing area and an auxiliary focusing area of a video image, and respectively calculating a first definition evaluation value of the main focusing area and a second definition evaluation value of the auxiliary focusing area according to a definition evaluation value algorithm;
the main focus area and the auxiliary focus area of the video image may be arbitrarily set, and the algorithm for calculating the first sharpness evaluation value of the main focus area and the second sharpness evaluation value of the auxiliary focus area includes, but is not limited to, the following calculation methods: a spatial domain evaluation function, a frequency domain evaluation function and a Laplacian gradient function.
Step S102, searching a first main focusing peak value according to the first definition evaluation value, searching an auxiliary focusing peak value according to the second definition evaluation value, and calculating a deviation value of the auxiliary focusing peak value relative to the first main focusing peak value;
after the camera automatic focusing process is started, the focusing motor drives the lens to move, in the moving process, the first definition evaluation value is obtained according to the step in the step S102, and the hill climbing algorithm is utilized to judge whether the focusing curve is in an uphill state or a downhill state at the moment according to the variation.
Step S103, under the condition that the deviation value is not within the preset range, increasing the weight coefficient of the auxiliary focusing area according to a weight calculation algorithm, calculating a third definition evaluation value of the main focusing area according to the weight coefficient, searching a second main focusing peak value, and taking a focusing point corresponding to the second main focusing peak value as a focusing point of the video image;
under the condition that the deviation value is not in the preset range, the fact that the auxiliary focusing peak point of the auxiliary focusing area is not close to the main focusing peak point is indicated, so that if the peak point of the whole video image is taken as the optimal focusing point of the video image at the moment, focusing blurring of the auxiliary focusing area occurs, and the definition of the auxiliary focusing area does not reach the standard. In order to improve the focusing definition of the auxiliary focusing area, the weight coefficient of the auxiliary focusing area is increased, a third definition evaluation value of the video image is calculated according to the weight coefficient by adopting a calculation method which is not limited to a spatial domain evaluation function, a frequency domain evaluation function and a Laplacian gradient function, a second main focusing peak value is searched, and a focusing point corresponding to the second main focusing peak value is taken as a focusing point of the video image. It should be noted that the preset range may be modified according to the actual debugging situation.
Through the steps S101 to S103, the method divides the automatic focusing into two stages, firstly, a first definition evaluation value of a main focusing area and a second definition evaluation value of an auxiliary focusing area are respectively calculated, under the condition that the main focusing area is focused to be clearest, whether the definition of the current auxiliary focusing area reaches the standard or not is deduced by judging the deviation value of an auxiliary focusing peak value compared with the main focusing peak value, and if the definition reaches the standard, the peak value point of the main focusing area is used as the focusing point of a video image; if the definition of the auxiliary focusing area does not reach the standard, the second stage can be started, the weight coefficient of the auxiliary focusing area is increased, the third definition evaluation value of the main focusing area is calculated according to the weight coefficient, then a second main focusing peak value is searched according to the third definition evaluation value, the focusing point corresponding to the second main focusing peak value is the focusing point of the video image, the problem that the definition of the auxiliary focusing area does not reach the standard when the position with the maximum definition evaluation value of the area with higher attention is used as the position of the clearest point of the image is solved, the focusing of the main focusing area is clear while the focusing of the auxiliary focusing area is clear, and the problem that the definition of the individual area does not reach the standard due to the slight inclination of a lens and a sensor surface of an automatic focusing camera product is solved.
In some embodiments, fig. 2 is a flowchart of a method for calculating a deviation value according to an embodiment of the present application, as shown in fig. 2, the method including the steps of:
step S201, obtaining the coordinate (x) of the first main focus peak1、y1) And coordinates (x) of the auxiliary focus peak2、y2) Wherein x isnTo focus the number of steps of the motor, ynThe definition evaluation value is obtained;
it should be noted that, in order to more clearly understand the first main focus peak point and the auxiliary focus peak point, the coordinate (x) of the first main focus peak may be obtained1、y1) And coordinates (x) of the auxiliary focus peak2、y2) And acquiring the number of steps of the focusing motor corresponding to the first main focusing peak value and the number of steps of the focusing motor corresponding to the auxiliary focusing peak value.
Step S202, calculating a focusing motor step difference under a first main focusing peak value and an auxiliary focusing peak value, wherein the focusing motor step difference indicates a deviation value;
by judging the difference between the focusing motor steps under the first main focusing peak value and the auxiliary focusing peak value, whether the auxiliary focusing peak value is positioned near the first main focusing peak value can be easily known.
Through the steps S201 to S202, the number of steps of the focus motor corresponding to the first main focus peak value and the number of steps of the focus motor corresponding to the auxiliary focus peak value are obtained, and by determining the difference between the number of steps of the focus motor at the first main focus peak value and the number of steps of the focus motor at the auxiliary focus peak value, whether the auxiliary focus peak value is located near the first main focus peak value can be easily known, so that whether the definition of the current auxiliary focus area reaches the standard can be quickly determined.
In some embodiments, fig. 3 is a flow chart of another method for calculating a bias value according to embodiments of the present application, as shown in fig. 3, the method comprising the steps of:
step S301, obtaining a focusing curve X for searching a first main focusing peak value and a focusing curve Y for searching an auxiliary focusing peak value, wherein the coordinate of the first main focusing peak value is recorded as (X)1、y1) The coordinate of the auxiliary focus peak is noted as (x)2、y2) Wherein x isnTo focus the number of steps of the motor, ynIs a sharpness evaluation value.
Step S302, acquiring a definition evaluation value M of a main focusing area corresponding to the intersection point of the focusing curve X and the focusing curve Y;
the intersection point of the focus curve X and the focus curve Y refers to an intersection point in a coordinate system with an abscissa as the number of steps of the focus motor and an ordinate as the sharpness evaluation value.
Step S303, judging the ratio of the definition evaluation value M to the auxiliary focusing peak value, wherein the ratio indicates a deviation value;
the ratio of the sharpness evaluation value M to the auxiliary focus peak is a deviation ratio of the auxiliary focus peak of the auxiliary focus area, and optionally, the preset range in step S103 may be that the ratio of the sharpness evaluation value M to the auxiliary focus peak is greater than or less than 90%, and if the ratio of the sharpness evaluation value M to the auxiliary focus peak is less than 90%, the sharpness evaluation value M is not within the preset range.
Through the steps S301 to S303, the ratio of the sharpness evaluation value M to the auxiliary focus peak value is calculated, so that the deviation rate of the auxiliary focus peak value of the auxiliary focus area can be obtained, that is, the accurate deviation rate of the auxiliary focus peak value under the condition that the first main focus peak value is taken as the focus point, and whether the sharpness of the current auxiliary focus area reaches the standard can be accurately determined.
In some embodiments, fig. 4 is a flowchart of another method for automatic focusing according to an embodiment of the present application, where, as shown in fig. 4, the focus point corresponding to the second primary focus peak is before the focus point of the video image, the method further includes the following steps:
step S401, obtaining the coordinate (x) of the second main focusing peak value3、y3);
Coordinate (x) of the second main focus peak3、y3) In, x3To focus the number of steps of the motor, y3Is a sharpness evaluation value.
Step S402, judging the coordinate (x) of the second main focusing peak value3、y3) In x3Whether or not it is located at x1And x2In the meantime.
Step S403, at x3Is not in x1And x2In the case in between, after a preset number of cycles, x3Still not at x1And x2In the meantime, the focusing point corresponding to the first primary focusing peak is taken as the focusing point of the video image, and the preset loop operation is to calculate the second sharpness evaluation value of the primary focusing area according to the weight coefficient and search for the coordinates (x) of the primary focusing peak3、y3);
Specifically, in the case where x3 is not between x1 and x2, it indicates that the sharpness of the auxiliary focus area after the second focusing is not improved compared with the first focusing, so the sharpness evaluation value of the entire video image area can be calculated twice according to the weighting factor of the current auxiliary focus area and the main focus peak coordinates (x3, y3) are searched, and if x3 is still not between x1 and x2, it indicates that the focus is disturbed and the focus sharpness of the auxiliary focus area cannot be achieved, and at this time, the focus point corresponding to the first main focus peak is taken as the focus point of the video image.
Step S404, at x3At x1And x2Under the condition of the second main focusing peak value, the focusing point corresponding to the second main focusing peak value is the focusing point of the video image;
x3at x1And x2Meanwhile, the situation that the focus blur of the auxiliary focus area is improved by the current focus is explained, and then the focus point corresponding to the second main focus peak value is taken as the focus point of the video image.
Through steps S401 to S403, before the focus point corresponding to the second main focus peak is set as the focus point of the video image, it is determined again whether the resolution of the auxiliary focus area is improved, so as to avoid the problem that the video image fails to be focused due to external interference.
In some embodiments, fig. 5 is a flowchart of a method of a weight calculation algorithm according to an embodiment of the present application, as shown in fig. 5, the method including the steps of:
step S501, obtaining the coordinate (x) of the first main focusing peak value1、y1) And coordinates (x) of the auxiliary focus peak2、y2) Wherein x isnTo focus the number of steps of the motor, ynIs a sharpness evaluation value.
Step S502, calculating the deviation steps of the focusing motor under the first main focusing peak value and the auxiliary focusing peak value;
wherein, the deviation step number of the focusing motor under the first main focusing peak value and the auxiliary focusing peak value is also x1And x2The absolute value of the difference.
Step S503, combining the deviation coefficient according to the deviation step number to generate a weight calculation algorithm.
The expression for the weight calculation algorithm generated from the number of deviation steps in combination with the deviation coefficients may be | x1-x2The method comprises the steps of obtaining a new weight coefficient of an auxiliary focusing area through a weight calculation algorithm, wherein the new weight coefficient of the auxiliary focusing area is increased along with the increase of deviation steps, namely when the deviation steps of a focusing motor under a first main focusing peak value and an auxiliary focusing peak value are larger, the auxiliary focusing peak value point is farther away from the first main focusing peak value point, the focusing of the auxiliary focusing area is more fuzzy, the weight coefficient of the auxiliary focusing area is further required to be increased, it needs to be noted that the deviation coefficient x is calibrated according to an actual test verification result, and the use environments of cameras are different in deviationThe difference coefficient x is adjustable accordingly.
Through the steps S501 to S503, the weight calculation algorithm is linked to the deviation step number of the focus motor, and further, under the condition that the auxiliary focus peak point is farther from the first main focus peak point, the weight coefficient of the auxiliary focus increased by the weight calculation algorithm is larger, and the weight coefficients corresponding to the auxiliary focus area under different fuzzy degrees can be accurately calculated.
In some embodiments, optionally, the auxiliary focus area is located in a corner area of the video image, and the main focus area is an entire video image area, so that the entire video image is in focus balance and is considered for each area of the video image.
Fig. 6 is a schematic diagram of one of the divisions of a main focus area and a plurality of auxiliary focus areas corresponding to a video image according to an embodiment of the present application, in fig. 6, a global area E is the main focus area, and four corner areas A, B, C, D are the auxiliary focus areas. It is convenient to understand the method for auto-focusing in the present application, and in particular, the following describes the focusing process for the video image in fig. 6 in conjunction with the method steps for auto-focusing in some embodiments of the present application. First, the sharpness evaluation values of the regions A, B, C, D, E are calculated, and the focus curve of the region A, B, C, D, E can be obtained by performing a search focus using the hill-climbing algorithm.
Fig. 7 is a schematic diagram of various focus curves for region A, B, C, D, E according to an embodiment of the application. As shown in fig. 7, the abscissa is the number of steps taken by the autofocus motor, the ordinate is the sharpness evaluation value, and Fa-Fe is the number of steps taken by the focus motor at the peak point corresponding to the region A, B, C, D, E in fig. 6. In general, the peak points Fa, Fb, Fc, Fd are substantially the same as Fe, and the definition of the region A, B, C, D is up to standard, at which time the focusing is directly completed. However, as shown in fig. 7, the difference between the peak points Fb, Fd and Fe is large, which indicates that the definition of the area B, D on the video image does not reach the standard, which may be caused by the unevenness of the lens and the sensor surface, and the like, at this time, the weight coefficient of the B, D area is added to calculate the new definition evaluation value of the area E, and the calculation method of the weight coefficient may be: the absolute value of the deviation step number | Fe- (Fb + Fd)/2| X according to the region B, D, E, where X is a deviation coefficient. And then focusing the area E again according to the new definition evaluation value, and if a new peak value point after focusing is located between Fe and Fb as the position of Fn in the graph of FIG. 7, the new focusing result improves B, D the area focus fuzzy problem, and the focusing is finished.
The present embodiment further provides an auto-focusing apparatus, which is used to implement the foregoing embodiments and preferred embodiments, and the description of the apparatus is omitted for brevity. As used hereinafter, the terms "module," "unit," "subunit," and the like may implement a combination of software and/or hardware for a predetermined function. Although the means described in the embodiments below are preferably implemented in software, an implementation in hardware, or a combination of software and hardware is also possible and contemplated.
In some embodiments, fig. 8 is a block diagram of an apparatus for auto-focusing according to an embodiment of the present application, as shown in fig. 8, the apparatus including: an acquisition module 81 and a focusing module 82.
The obtaining module 81 is configured to obtain a main focus area and an auxiliary focus area of a video image, and respectively calculate a first sharpness evaluation value of the main focus area and a second sharpness evaluation value of the auxiliary focus area according to a sharpness evaluation value algorithm.
The focusing module 82 searches for a first main focusing peak value according to the first sharpness evaluation value, searches for an auxiliary focusing peak value according to the second sharpness evaluation value, and calculates a deviation value of the auxiliary focusing peak value relative to the first main focusing peak value.
The obtaining module 81 is further configured to, when the deviation value is not within the preset range, increase the weight of the auxiliary focus area according to a weight calculation algorithm, calculate a third sharpness evaluation value of the main focus area according to the weight, and search for a second main focus peak value, where a focus point corresponding to the second main focus peak value is a focus point of the video image.
Through the automatic focusing device, the focusing module 82 divides the automatic focusing into two stages, firstly, the acquisition module 81 respectively calculates a first definition evaluation value of a main focusing area and a second definition evaluation value of an auxiliary focusing area, under the condition that the main focusing area is focused to the clearest, whether the definition of the current auxiliary focusing area reaches the standard is deduced by judging the deviation value of the auxiliary focusing peak value compared with the main focusing peak value, if the definition reaches the standard, the peak value point of the main focusing area is taken as the focusing point of the video image, if the definition does not reach the standard, the second stage can be carried out, the weight coefficient of the auxiliary focusing area is increased, a new definition evaluation value of the main focusing area is calculated according to the weight coefficient, then the automatic focusing device is refocused according to the new definition evaluation value, the focusing point corresponding to the second main focusing peak value is the focusing point of the video image, and the problem that the position with the maximum definition evaluation value of the area with higher attention is taken as the clearest point position of the image is solved, the definition of the auxiliary focusing area does not reach the standard, so that the main focusing area can focus clearly while the auxiliary focusing area can focus clearly.
In some embodiments, the obtaining module 81 is further configured to obtain the coordinate (x) of the first main focus peak1、y1) And coordinates (x) of the auxiliary focus peak2、y2) Wherein x isnTo focus the number of steps of the motor, ynThe definition evaluation value is obtained; the focus module 82 is further configured to calculate a focus motor step difference at the first primary focus peak and the secondary focus peak, the focus motor step difference indicating a deviation value of the secondary focus peak from the first primary focus peak. In this embodiment, the obtaining module 81 obtains the number of steps of the focusing motor corresponding to the first main focusing peak value and the number of steps of the focusing motor corresponding to the auxiliary focusing peak value, and the focusing module 82 can easily know whether the auxiliary focusing peak value is located near the first main focusing peak value by determining the difference between the number of steps of the focusing motor at the first main focusing peak value and the number of steps of the focusing motor at the auxiliary focusing peak value, so as to quickly determine whether the definition of the current auxiliary focusing area reaches the standard.
In some embodiments, the obtaining module 81 and the focusing module 82 are further configured to implement steps in the methods for automatically focusing provided in the foregoing embodiments, and are not described herein again.
The above modules may be functional modules or program modules, and may be implemented by software or hardware. For a module implemented by hardware, the modules may be located in the same processor; or the modules can be respectively positioned in different processors in any combination.
In one embodiment, an electronic device is provided, which may be a terminal. The electronic device comprises a processor, a memory, a network interface, a display screen and an input device which are connected through a system bus. Wherein the processor of the electronic device is configured to provide computing and control capabilities. The memory of the electronic equipment comprises a nonvolatile storage medium and an internal memory. The non-volatile storage medium stores an operating system and a computer program. The internal memory provides an environment for the operation of an operating system and computer programs in the non-volatile storage medium. The network interface of the electronic device is used for connecting and communicating with an external terminal through a network. The computer program is executed by a processor to implement a method of auto-focusing. The display screen of the electronic equipment can be a liquid crystal display screen or an electronic ink display screen, and the input device of the electronic equipment can be a touch layer covered on the display screen, a key, a track ball or a touch pad arranged on the shell of the electronic equipment, an external keyboard, a touch pad or a mouse and the like.
In an embodiment, fig. 9 is a schematic internal structure diagram of an electronic device according to an embodiment of the present application, and as shown in fig. 9, there is provided an electronic device, which may be a server, and its internal structure diagram may be as shown in fig. 9. The electronic device includes a processor, a memory, a network interface, and a database connected by a system bus. Wherein the processor of the electronic device is configured to provide computing and control capabilities. The memory of the electronic equipment comprises a nonvolatile storage medium and an internal memory. The non-volatile storage medium stores an operating system, a computer program, and a database. The internal memory provides an environment for the operation of an operating system and computer programs in the non-volatile storage medium. The database of the electronic device is used for storing data. The network interface of the electronic device is used for connecting and communicating with an external terminal through a network. The computer program is executed by a processor to implement a method of auto-focusing.
Those skilled in the art will appreciate that the configuration shown in fig. 9 is a block diagram of only a portion of the configuration relevant to the present application, and does not constitute a limitation on the electronic device to which the present application is applied, and a particular electronic device may include more or less components than those shown in the drawings, or combine certain components, or have a different arrangement of components.
In one embodiment, an electronic device is provided, which includes a memory, a processor, and a computer program stored on the memory and executable on the processor, and the processor executes the computer program to implement the steps of the method for auto-focusing provided by the above embodiments.
In one embodiment, a computer-readable storage medium is provided, on which a computer program is stored, which, when being executed by a processor, carries out the steps of the method of autofocusing as provided by the various embodiments described above.
It will be understood by those skilled in the art that all or part of the processes of the methods of the embodiments described above can be implemented by hardware instructions of a computer program, which can be stored in a non-volatile computer-readable storage medium, and when executed, can include the processes of the embodiments of the methods described above. Any reference to memory, storage, database, or other medium used in the embodiments provided herein may include non-volatile and/or volatile memory, among others. Non-volatile memory can include read-only memory (ROM), Programmable ROM (PROM), Electrically Programmable ROM (EPROM), Electrically Erasable Programmable ROM (EEPROM), or flash memory. Volatile memory can include Random Access Memory (RAM) or external cache memory. By way of illustration and not limitation, RAM is available in a variety of forms such as Static RAM (SRAM), Dynamic RAM (DRAM), Synchronous DRAM (SDRAM), Double Data Rate SDRAM (DDRSDRAM), Enhanced SDRAM (ESDRAM), Synchronous Link DRAM (SLDRAM), Rambus Direct RAM (RDRAM), direct bus dynamic RAM (DRDRAM), and memory bus dynamic RAM (RDRAM).
The technical features of the above embodiments can be arbitrarily combined, and for the sake of brevity, all possible combinations of the technical features in the above embodiments are not described, but should be considered as the scope of the present specification as long as there is no contradiction between the combinations of the technical features.
The above examples only express several embodiments of the present application, and the description thereof is more specific and detailed, but not construed as limiting the scope of the invention. It should be noted that, for a person skilled in the art, several variations and modifications can be made without departing from the concept of the present application, which falls within the scope of protection of the present application. Therefore, the protection scope of the present patent shall be subject to the appended claims.

Claims (9)

1. A method of auto-focusing, the method comprising:
acquiring a main focusing area and an auxiliary focusing area of a video image, and respectively calculating a first definition evaluation value of the main focusing area and a second definition evaluation value of the auxiliary focusing area according to a definition evaluation value algorithm;
searching a first main focusing peak value according to the first definition evaluation value, searching an auxiliary focusing peak value according to the second definition evaluation value, and calculating a deviation value of the auxiliary focusing peak value compared with the first main focusing peak value;
and under the condition that the deviation value is not within a preset range, increasing a weight coefficient of the auxiliary focusing area according to a weight calculation algorithm, calculating a third definition evaluation value of the main focusing area according to the weight coefficient, searching a second main focusing peak value, and setting a focusing point corresponding to the second main focusing peak value as a focusing point of the video image, wherein the main focusing area is the whole video image area, and the auxiliary focusing area is positioned in a corner area of the video image.
2. The method of claim 1, wherein calculating the deviation value of the secondary focus peak from the first primary focus peak comprises:
obtaining coordinates (x) of the first primary focus peak1、y1) And the coordinates (x) of the auxiliary focus peak2、y2) Wherein x isnTo focus the number of steps of the motor, ynThe definition evaluation value is obtained;
and calculating the difference of the step numbers of the focusing motors under the first main focusing peak value and the auxiliary focusing peak value, wherein the difference of the step numbers of the focusing motors indicates the deviation value.
3. The method of claim 1, wherein calculating the deviation value of the secondary focus peak from the first primary focus peak comprises:
acquiring a focusing curve X for searching the first main focusing peak and a focusing curve Y for searching the auxiliary focusing peak, wherein the coordinate of the first main focusing peak is marked as (X)1、y1) The coordinate of the auxiliary focusing peak is (x)2、y2) Wherein x isnTo focus the number of steps of the motor, ynThe definition evaluation value is obtained;
acquiring a definition evaluation value M of a main focusing area corresponding to the intersection point of the focusing curve X and the focusing curve Y;
and judging the ratio of the definition evaluation value M to the auxiliary focusing peak value, wherein the ratio indicates the deviation value.
4. The method of claim 2 or 3, wherein the focus point corresponding to the second primary focus peak is before the focus point of the video image, the method further comprising:
obtaining coordinates (x) of the second main focus peak3、y3);
Determining the coordinates (x) of the second main focus peak3、y3) In x3Whether or not it is located at x1And x2In the above-mentioned manner,
at x3Is not in x1And x2In the case in between, after a preset number of cycles, x3Still not at x1And x2In the meantime, the focus point corresponding to the first primary focus peak is taken as the focus point of the video image, and the preset loop is operated to calculate the second sharpness evaluation value of the primary focus area according to the weight coefficient and search for a primary focus peak coordinate (x)3、y3);
At x3At x1And x2In the above case, the focus point corresponding to the second main focus peak is the focus point of the video image.
5. The method of claim 1, wherein the weight calculation algorithm comprises:
obtaining coordinates (x) of the first primary focus peak1、y1) And the coordinates (x) of the auxiliary focus peak2、y2) Wherein x isnTo focus the number of steps of the motor, ynThe definition evaluation value is obtained;
calculating the deviation steps of the first main focusing peak value and the focusing motor under the auxiliary focusing peak value;
and generating the weight calculation algorithm according to the deviation steps and the deviation coefficient.
6. An apparatus for auto-focusing, the apparatus comprising: an acquisition module and a focusing module;
the device comprises an acquisition module, a display module and a display module, wherein the acquisition module is used for acquiring a main focusing area and an auxiliary focusing area of a video image, and respectively calculating a first definition evaluation value of the main focusing area and a second definition evaluation value of the auxiliary focusing area according to a definition evaluation value algorithm;
the focusing module is used for searching a first main focusing peak value according to the first definition evaluation value, searching an auxiliary focusing peak value according to the second definition evaluation value and calculating a deviation value of the auxiliary focusing peak value relative to the first main focusing peak value;
the obtaining module is further configured to, when the deviation value is not within a preset range, increase a weight of the auxiliary focus area according to a weight calculation algorithm, calculate a third sharpness evaluation value of the primary focus area according to the weight, and search for a second primary focus peak, where a focus point corresponding to the second primary focus peak is a focus point of the video image, where the primary focus area is the entire video image area, and the auxiliary focus area is located in an angular area of the video image.
7. The apparatus of claim 6, wherein the obtaining module is further configured to obtain coordinates (x) of the first primary focus peak1、y1) And the coordinates (x) of the auxiliary focus peak2、y2) Wherein x isnTo focus the number of steps of the motor, ynThe definition evaluation value is obtained;
the focusing module is further configured to calculate a focusing motor step difference between the first primary focusing peak value and the auxiliary focusing peak value, where the focusing motor step difference indicates a deviation value of the auxiliary focusing peak value from the first primary focusing peak value.
8. An electronic device comprising a memory, a processor, and a computer program stored on the memory and executable on the processor, wherein the processor, when executing the computer program, implements the method of auto-focusing according to any one of claims 1 to 5.
9. A computer-readable storage medium, on which a computer program is stored which, when being executed by a processor, carries out the method of autofocus according to any one of claims 1 to 5.
CN202010449914.1A 2020-05-25 2020-05-25 Automatic focusing method and device and electronic equipment Active CN111641781B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202010449914.1A CN111641781B (en) 2020-05-25 2020-05-25 Automatic focusing method and device and electronic equipment

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202010449914.1A CN111641781B (en) 2020-05-25 2020-05-25 Automatic focusing method and device and electronic equipment

Publications (2)

Publication Number Publication Date
CN111641781A CN111641781A (en) 2020-09-08
CN111641781B true CN111641781B (en) 2021-12-14

Family

ID=72331312

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202010449914.1A Active CN111641781B (en) 2020-05-25 2020-05-25 Automatic focusing method and device and electronic equipment

Country Status (1)

Country Link
CN (1) CN111641781B (en)

Families Citing this family (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113163114B (en) * 2021-03-29 2023-07-04 无锡闻泰信息技术有限公司 Image focusing method, device, equipment and medium

Family Cites Families (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102087458B (en) * 2009-12-04 2012-11-07 豪威科技有限公司 System and method for realizing automatic focusing function in imaging system with lens located by actuator
JP5484631B2 (en) * 2011-03-31 2014-05-07 富士フイルム株式会社 Imaging apparatus, imaging method, program, and program storage medium
KR101773168B1 (en) * 2011-07-21 2017-09-12 삼성전자주식회사 Apparatus and method for controlling focus by image sensor for outputting phase difference signal
US9742980B2 (en) * 2013-11-01 2017-08-22 Canon Kabushiki Kaisha Focus control apparatus and control method therefor
JP2019128548A (en) * 2018-01-26 2019-08-01 キヤノン株式会社 Focus detector and optical apparatus equipped with focus detector
CN109085695B (en) * 2018-08-08 2021-06-18 杭州上池科技有限公司 Method for quickly focusing and photographing plane sample
CN110581953A (en) * 2019-09-27 2019-12-17 畅索软件科技(上海)有限公司 Method and device for improving definition of still-shot picture of camera and electronic equipment

Also Published As

Publication number Publication date
CN111641781A (en) 2020-09-08

Similar Documents

Publication Publication Date Title
CN105659580B (en) A kind of Atomatic focusing method, device and electronic equipment
JP6091228B2 (en) Image processing apparatus and imaging apparatus
JP6663040B2 (en) Depth information acquisition method and apparatus, and image acquisition device
KR102138845B1 (en) Device, system and method for providing auto-focus function based on object distance information
CN108401457A (en) A kind of control method of exposure, device and unmanned plane
KR20190104216A (en) Focus method, terminal and computer readable storage media
US8698945B2 (en) Autofocus apparatus and method
US9508153B2 (en) Distance measurement apparatus, imaging apparatus, distance measurement method, and program
CN107787463B (en) The capture of optimization focusing storehouse
JP2014168227A (en) Image processing apparatus, imaging apparatus, and image processing method
US20140307054A1 (en) Auto focus method and auto focus apparatus
CA2832074A1 (en) Multi-resolution depth-from-defocus-based autofocus
CN111641781B (en) Automatic focusing method and device and electronic equipment
CN114390201A (en) Focusing method and device thereof
CN113438409B (en) Delay calibration method, delay calibration device, computer equipment and storage medium
JP6564284B2 (en) Image processing apparatus and image processing method
KR102226256B1 (en) Electro-optical tracking apparatus capable of automatic viewing angle correction and method thereof
JP6485116B2 (en) Focus position detection device, focus position detection method, and computer program for focus position detection
CN113747067A (en) Photographing method and device, electronic equipment and storage medium
KR101783990B1 (en) Digital image processing apparatus and, method for estimating global motion of image
JP6645711B2 (en) Image processing apparatus, image processing method, and program
US9883105B2 (en) Image processing apparatus and control method thereof
CN106470309A (en) The method and apparatus obtaining the focal length of double shootings
CN109211185A (en) A kind of flight equipment, the method and device for obtaining location information
CN110839126B (en) Zoom tracking method and device and zoom camera

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant