Auxiliary automatic focusing method, device and equipment

By using the attitude sensor data of electronic devices to correct image frames, the problem of interference from external factors during the autofocus process is solved, the accuracy of focus quality and image sharpness measurement is improved, and a more efficient autofocus effect is achieved.

CN118741307APending Publication Date: 2024-10-01SPREADTRUM COMMUNICATION (SHANGHAI) CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411008830.9
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-07-25
Publication Date
2024-10-01

AI Technical Summary

Technical Problem

During the autofocus process, external factors such as hand shake cause changes in image clarity and affect focus quality. It is difficult to effectively reduce or eliminate these interferences with existing technology.

Method used

By obtaining the posture sensor data of the electronic device, the transformation matrix of the image frame is calculated, and the image frame is corrected to the device posture of the reference frame, thereby reducing image content distortion and improving focus quality.

Benefits of technology

Without increasing hardware costs, it improves the accuracy of image sharpness measurement, enhances the focus effect, and reduces the impact of external factors on autofocus.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118741307A_ABST
    Figure CN118741307A_ABST
Patent Text Reader

Abstract

The embodiment of the invention provides an auxiliary automatic focusing method, device and equipment. The method comprises the following steps: acquiring equipment attitude data acquired by an attitude sensor in the electronic equipment; determining a transformation matrix of a current image frame relative to a reference frame according to the equipment attitude data; according to the transformation matrix, correcting the current image frame to an equipment posture where a reference frame is located, and obtaining a corrected image frame of the current image frame; and focusing according to the corrected image frame. According to the embodiment of the invention, in combination with the equipment attitude data, the to-be-focused image frame (corresponding to the current image frame) is re-corrected to the equipment attitude where the reference frame is located, so that image distortion caused by equipment attitude change can be corrected, for example, image distortion caused by hand shaking can be corrected; therefore, the accuracy of representing the image definition metric value FV can be improved, and the focusing speed and quality are improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of autofocus technology, and in particular to an auxiliary autofocus method, device and equipment. Background Art

[0002] Auto Focus, Auto Exposure and Auto White Balance are three algorithms that automatically adjust the parameters of electronic device cameras, also known as 3A algorithms. The 3A algorithm is an important part of the electronic device imaging system and largely determines the imaging quality and effect of the electronic device. In the 3A algorithm, the autofocus technology adjusts the distance between the lens and the photosensitive sensor to ensure that the focused subject presents a clear image on the imaging plane. In the autofocus process, the lens position when the image clarity is the highest can be considered as the focus position, and the measurement of image clarity determines the focusing speed and quality. However, in addition to the focus position, there are many external factors that can cause the image captured by the camera to present distortion of the image content in addition to the normal clarity change, and finally lead to inaccurate or failed focusing. Therefore, in the autofocus process, how to minimize or eliminate the impact of external factors on image clarity and improve the focus quality has become a technical problem that needs to be solved. Summary of the invention

[0003] In view of this, the present application provides an auxiliary autofocus method, device and equipment to minimize or eliminate the impact of external factors on image clarity evaluation during the autofocus process and improve the focusing quality.

[0004] In a first aspect, an embodiment of the present invention provides an automatic focusing method, comprising:

[0005] Acquire device posture data collected by a posture sensor in the electronic device;

[0006] Determining a transformation matrix of a current image frame relative to a reference frame according to the device posture data;

[0007] According to the transformation matrix, the current image frame is corrected to the device posture of the reference frame to obtain a corrected image frame of the current image frame;

[0008] Wherein, the corrected image frame is used for focusing.

[0009] Wherein, determining the transformation matrix of the current image frame relative to the reference frame according to the device posture data includes:

[0010] Determining a relative rotation angle of the current image frame relative to the reference frame according to the device posture data;

[0011] Determine the rotation matrix in the camera extrinsic parameters according to the relative rotation angle;

[0012] The transformation matrix of the current image frame relative to the reference frame is determined according to the rotation matrix in the camera extrinsic parameters and the camera intrinsic parameter matrix.

[0013] Wherein, the device posture data includes: angular velocity data and data acquisition timestamp;

[0014] Determining the relative rotation angle of the current image frame with respect to the reference frame according to the device posture data includes:

[0015] According to the exposure time of the current image frame and the exposure time of the reference frame, the angular velocity data at the corresponding data acquisition timestamp is integrated to obtain the relative rotation angle of the current image frame with respect to the reference frame.

[0016] Wherein, determining the transformation matrix of the current image frame relative to the reference frame according to the device posture data includes:

[0017] According to the device posture data corresponding to each n rows of the current image frame, calculating a transformation matrix for each n rows of the current image frame, where n is greater than or equal to 2;

[0018] The transformation matrix corresponding to each n rows is used to correct the image of the corresponding n rows.

[0019] The step of calculating a transformation matrix for each n rows of the current image frame according to the device posture data corresponding to each n rows of the current image frame includes:

[0020] Determine the first row exposure timestamp of the current image frame;

[0021] Determine a row offset of one of every n rows of the current image frame relative to the first row of the current image frame;

[0022] Determine the exposure time of every n rows of the current image frame according to the first row exposure timestamp of the current image frame, the row offset of one of every n rows, the total number of rows of the current image frame, and the full-image exposure time of the current image frame;

[0023] According to the exposure time of every n lines of the current image frame, the exposure time of the reference frame and the device posture data of the corresponding time period, the content of the current image frame is corrected once every n lines.

[0024] The step of correcting the current image frame to the device posture of the reference frame according to the transformation matrix to obtain a corrected image frame of the current image frame includes:

[0025] According to the transformation matrix, the pixel coordinates of the corrected image frame are mapped to the pixel coordinates of the current image frame, and the pixel values ​​of the pixel coordinates of the corrected image frame are determined according to the mapped pixels of the current image frame, wherein if the pixel coordinates of the corrected image frame mapped to the current image frame are out of bounds, the corresponding pixels of the corrected image frame are set to 0.

[0026] Before determining the transformation matrix of the current image frame relative to the reference frame according to the device posture data, the method further includes:

[0027] Determine whether a focus subject included in the current image frame undergoes non-planar motion, and / or whether a voice coil motor (VCM) oscillation occurs during the process of capturing the current image frame;

[0028] If the judgment result of any item is yes, discard the current image frame;

[0029] Otherwise, a transformation matrix of the current image frame relative to the reference frame is calculated.

[0030] Before determining the transformation matrix of the current image frame relative to the reference frame according to the device posture data, the method further includes:

[0031] Performing blur kernel estimation on the current image frame to determine a scaling factor of the current image frame relative to the reference frame;

[0032] The current image frame is scaled according to the scaling factor so that a focus region of interest ROI of the current image frame is aligned with a focus ROI of the reference frame.

[0033] Before the corrected image frame is used for focusing, the method further includes:

[0034] determining a global offset of the rectified image frame relative to the reference frame;

[0035] Aligning the corrected image frame with the reference frame according to the global offset to obtain an aligned image frame;

[0036] Cropping a focus ROI from the aligned image frame;

[0037] Using the historical image frame before the current image frame to fill the out-of-bounds black edge of the focus ROI with pixels of the historical frame;

[0038] The focus ROI after pixel filling is used to calculate the focus value FV and focus.

[0039] Among them, the current image frame is collected by the photosensor of the electronic device and stored in the image memory. When the autofocus algorithm is executed, the current image frame is read out from the image memory, and enters the Pipeline pipeline process of the image signal processor ISP after executing the autofocus algorithm.

[0040] In a second aspect, an embodiment of the present invention provides an automatic focusing device, comprising:

[0041] An acquisition module, used to acquire device posture data collected by a posture sensor in the electronic device;

[0042] a dedistortion module, for determining a transformation matrix of a current image frame relative to a reference frame according to the device posture data; and for correcting the current image frame to the device posture of the reference frame according to the transformation matrix to obtain a corrected image frame of the current image frame;

[0043] A focusing module is used to focus according to the corrected image frame.

[0044] In a third aspect, an embodiment of the present invention provides an electronic device, including:

[0045] A posture sensor, used to collect device posture data of electronic equipment;

[0046] A photosensitive sensor for collecting image frames through photoelectric conversion;

[0047] Image signal processor ISP, used to pre-process image frames collected by the photosensitive sensor;

[0048] A memory for storing computer program instructions and a main processor for executing the program instructions, wherein when the computer program instructions are executed by the main processor, the electronic device executes the method described in the first aspect or any one of the first aspects.

[0049] In a fourth aspect, an embodiment of the present invention provides a computer-readable storage medium, wherein the computer-readable storage medium includes a stored program, wherein when the program is running, the device where the computer-readable storage medium is located is controlled to execute the method described in the first aspect or any one of the first aspects.

[0050] The embodiment of the present invention integrates the device posture data into the autofocus algorithm, and transforms the image frame to be focused (such as the current image frame) back to the device posture of the reference frame according to the device posture data, thereby correcting the image content distortion caused by the change of the electronic device posture, for example, the image content distortion caused by hand shaking can be corrected. It can be seen that the autofocus solution of the embodiment of the present invention can improve the accuracy of image clarity measurement without increasing hardware costs, thereby improving the focusing effect. BRIEF DESCRIPTION OF THE DRAWINGS

[0051] In order to more clearly illustrate the technical solutions of the embodiments of the present application, the drawings required for use in the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative labor.

[0052] Figure 1 A flowchart of an auxiliary auto-focusing method provided by an embodiment of the present invention;

[0053] Figure 2 A detailed flow chart of an auxiliary auto-focusing method provided by an embodiment of the present invention;

[0054] Figure 3 A schematic diagram of dewarp distortion correction provided by an embodiment of the present invention;

[0055] Figure 4 A schematic diagram of the correction effect provided by an embodiment of the present invention;

[0056] Figure 5 A schematic diagram of a focusing effect provided by an embodiment of the present invention;

[0057] Figure 6 A schematic diagram of the structure of an auxiliary auto-focusing device provided in an embodiment of the present application;

[0058] Figure 7 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION

[0059] In order to better understand the technical solution of the present application, the embodiments of the present application are described in detail below with reference to the accompanying drawings.

[0060] It should be clear that the described embodiments are only part of the embodiments of the present application, rather than all the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in the field without creative work are within the scope of protection of the present application.

[0061] The terms used in the embodiments of the present application are only for the purpose of describing specific embodiments, and are not intended to limit the present application. The singular forms "a", "said" and "the" used in the embodiments of the present application and the appended claims are also intended to include plural forms, unless the context clearly indicates other meanings.

[0062] It should be understood that the term "and / or" used in this article is only a description of the association relationship of associated objects, indicating that there can be three relationships. For example, A and / or B can represent: A exists alone, A and B exist at the same time, and B exists alone. In addition, the character " / " in this article generally indicates that the associated objects before and after are in an "or" relationship.

[0063] The following first explains some technical terms involved in the embodiments of the present invention.

[0064] Auto Focus (AF) is an autonomous focusing function of electronic device cameras. During the AF process, the user does not need to manually adjust the focus. AF mainly includes three aspects: the first is the selection of the region of interest (ROI), including the default center focus, face focus, and manual selection of the focus area; the second is the image clarity measurement of the focus ROI; and the third is the travel control of the voice coil motor (VCM).

[0065] Focus Value (FV) is used to measure the clarity of the image.

[0066] Contrast AF (CAF) is a type of AF algorithm. CAF pushes the VCM to multiple positions within a certain range, counts the image FV value at each position, and finds the lens position corresponding to the maximum FV value for focusing.

[0067] When an electronic device is automatically focusing, if the shooting scene is stable, such as the ambient brightness remains unchanged, the electronic device and the focus subject are fixed, etc., the clarity of the image is mainly affected by the focus position. In actual focusing, there will inevitably be some external factors in the shooting scene that affect the focusing effect, such as hand shaking. Hand shaking can cause the electronic device to shake, and the shaking of the electronic device can cause distortion of the image content. The distortion of the image content can affect the measurement of the image clarity, and then affect the focusing effect. In order to reduce or eliminate the influence of external factors such as hand shaking on the autofocus effect, an embodiment of the present invention provides an autofocus method. The autofocus method introduces device posture data collected by an external sensor, and corrects the image content distortion caused by the shaking of the electronic device according to the device posture data, so that the result of the image clarity measurement is more accurate and the focusing effect is improved.

[0068] The design idea of ​​using device posture data to correct image content distortion in the embodiment of the present invention is that the shaking of the electronic device can be regarded as a change in the posture of the electronic device. The posture sensor in the electronic device can capture the posture change of the electronic device and generate device posture data. According to the device posture data, the current image frame can be corrected to the device posture of the reference frame, thereby reducing or eliminating the image content distortion caused by the change in the posture of the electronic device, improving the accuracy of image clarity measurement, and improving the focusing effect.

[0069] See also Figure 1 , is a flow chart of an automatic focusing method provided by an embodiment of the present invention. The method of the embodiment of the present invention can be applied to an electronic device with a camera function. Figure 1 As shown, the processing steps of the method include:

[0070] 101, obtaining device posture data collected by a posture sensor in the electronic device. The posture sensor may be, for example, a gyroscope (Gyro) sensor and / or an accelerometer (ACC) sensor, etc. The collected device posture data may include, for example, angular velocity data, acceleration and other measurement data.

[0071] 102. Determine a transformation matrix of the current image frame relative to the reference frame according to the device posture data. The current image frame may be any image frame captured by the electronic device. Optionally, the current image frame may be an image frame to be focused. For example, the current image frame may be a current preview frame captured by the electronic device in an autofocus scene. Optionally, the transformation matrix is ​​determined according to the device posture data, and the transformation matrix is ​​used to transform the current image frame to the device posture of the reference frame.

[0072] 103 , according to the transformation matrix, correct the current image frame to the device posture of the reference frame to obtain a corrected image frame of the current image frame.

[0073] 104, focusing is performed according to the corrected image frame.

[0074] The embodiment of the present invention integrates the device posture data into the auto-focus algorithm, and transforms the image frame to be focused (such as the current image frame) back to the device posture of the reference frame according to the device posture data, thereby correcting the image content distortion caused by the change of the electronic device posture, for example, the image content distortion caused by hand shaking can be corrected. It can be seen that the embodiment of the present invention integrates the posture sensor of the electronic device itself for focusing, which can improve the focusing algorithm without increasing the hardware cost, improve the accuracy of image clarity measurement, and improve the focusing effect.

[0075] In an embodiment of the present invention, the method of determining the reference frame may include: calculating the FV of multiple frames to be focused that have been acquired by the electronic device, selecting a frame with the highest FV value and relatively stable device posture data as the reference frame, and subsequently acquiring frames to be focused by Figure 1 The method shown performs auto focus.

[0076] See also Figure 2 , is a detailed flow chart of an auxiliary auto-focusing method provided by an embodiment of the present invention. Figure 2 As shown, the processing steps performed by the electronic device after turning on the auto focus include:

[0077] 200, initialization. The initialization of the electronic device after the automatic focus is turned on may include:

[0078] Configure calibration parameters, which may include t s / t d / ωd / f, etc. Among them, t s is the full image exposure time of the preview frame. d It is the clock delay between the device attitude sensor (such as Gyro sensor) and the electronic device camera. ωd is the zero drift and temperature drift calibration value of the gyroscope sensor. f is the focal length of the image sensor, etc.

[0079] Configure the image information of the original Raw image, such as image width and height, bit width, Bayer Mode, frame rate, ROI size and coordinates, etc.

[0080] 201, read device posture data. Optionally, the posture sensor may be a Gyro sensor and / or an Acc sensor, and the device posture data may be angular velocity data and / or acceleration data, etc. After reading the device posture sensor, the device posture data may be preprocessed, such as filtering out clutter, screening valid data, etc.

[0081] The posture sensor in the electronic device is usually a public sensor, and the device posture data collected by the posture sensor can be provided to various software algorithms in the electronic device. The automatic focusing method of the embodiment of the present invention can register the posture sensor monitoring service to the electronic device sensor channel to obtain the device posture data collected by the posture sensor after starting the focusing algorithm.

[0082] 202, store the frame in DDR.

[0083] In the related art, the autofocus method is usually online focus, that is, the Raw frames collected by the photosensitive sensor are exposed line by line and enter the Pipeline process of the ISP. The autofocus method of the embodiment of the present invention modifies the online focus to offline focus, that is, the Raw frames collected by the photosensitive sensor do not directly enter the Pipeline process of the ISP, but the Raw frames collected by the photosensitive sensor are first simply processed by the ISP Pipeline and then cached to the DDR and then re-injected into the Pipeline front-end process of the ISP after passing through the autofocus algorithm of the embodiment of the present invention. Optionally, the Raw frames collected by the photosensitive sensor can be downsampled and stored in the DDR.

[0084] 203, determine the reference frame.

[0085] After the autofocus algorithm is started, if there is no reference frame yet, it is necessary to determine the reference frame from the frames to be focused that have been stored in the DDR. Among them, the method of determining the reference frame includes: calculating the FV values ​​of multiple frames to be focused by AFM, and selecting the frame to be focused with the maximum FV value as the reference frame. Optionally, when determining the reference frame, the device posture data can also be combined, that is, the frame with the largest FV value and relatively stable device posture data can be selected as the reference frame. The frames to be focused that are subsequently stored in the DDR are aligned with the reference frame. After the reference frame is determined, there is no need to execute step 203 after the frame to be focused is subsequently acquired.

[0086] 204, fetch a frame from DDR. For the convenience of description, the frame to be focused currently fetched from DDR is referred to as the current image frame.

[0087] 205 , calculating the device posture data corresponding to the current image frame through an interpolation algorithm.

[0088] In some embodiments, the sampling frequency of the attitude sensor can reach 100Hz or even 200Hz, the frame rate of the preview frame is 25-30Hz, and the sampling rate of the attitude sensor can meet the Nyquist sampling theorem. During the autofocus process, since the X / Y / Z three-axis rotation angle of the electronic device is relatively small, the problem of universal joint deadlock almost does not occur. Therefore, the embodiment of the present invention can use Euler angle interpolation and Gaussian motion smoothing algorithm to interpolate the device attitude data of the current image frame. After the device attitude data of the current image frame is interpolated, the current image frame is associated with the current device attitude.

[0089] 206, whether the focus subject has non-planar motion. If non-planar motion has occurred, the current image frame is discarded and the process goes to step 204. If non-planar motion has not occurred, the process continues to go to step 207.

[0090] The focus subject is the ROI part of the photographed object that needs to be focused, such as faces, trees, flowers, etc. When focusing, the movement of the focus subject, especially the non-planar movement of the focus subject, will also cause blurring of the image content. Therefore, the embodiment of the present invention will discard the current frame image when non-planar movement of the focus subject is detected to avoid image content distortion caused by the non-planar movement of the focus subject, affecting the focusing effect. Optionally, the above-mentioned non-planar movement may refer to a movement with a rotation angle in three-dimensional space. Among them, it can be determined by an image feature detection algorithm or the like whether the focus subject of the current image frame undergoes planar motion. Alternatively, it is also possible to estimate whether the focus subject undergoes planar motion by a motion vector. Specifically, the motion vector can be estimated by the image frame before the current image frame. One feasible way is that the image frame before the current image frame will calculate the motion vector when the global alignment is performed in step 211, and the motion vector calculated in step 211 is used to estimate whether the focus subject of the current image frame undergoes non-planar motion. This method is simple to implement and avoids repeated calculations.

[0091] 207 , whether there is VCM oscillation. If there is VCM oscillation, the current image frame is discarded and the process goes to step 204 ; if there is no VCM oscillation, the process goes to step 208 .

[0092] Step 207 is used to detect whether there is VCM oscillation in the process of shooting the current image frame. If there is VCM oscillation in the process of shooting the current image frame, for example, there is an action of pushing the VCM in the process of shooting the first image, the current image frame is an unreliable image frame and is not suitable as a basis for focusing, so it will also be discarded. Among them, the method of judging whether there is VCM oscillation can be: after pushing the VCM, the VCM stabilizes within a preset time, if the exposure time of the current image frame is within the preset time after pushing the VCM, it is determined that there is VCM oscillation in the current image frame; if the exposure time of the current image frame is outside the preset time after pushing the VCM, it is determined that there is no VCM oscillation in the current image frame.

[0093] 208,Blur Kernel Estimation and Image Scaling.

[0094] The out-of-focus image will have a certain out-of-focus zoom ratio relative to the in-focus clear image. In this step, the zoom factor of the current image frame relative to the clear image can be estimated by estimating the blur kernel. The current image frame is scaled according to the zoom factor. After scaling, the focus subject in the current image frame is more consistent in size with the focus subject in the reference frame, which is beneficial to the subsequent focusing step.

[0095] 209, calculate the transformation matrix.

[0096] The specific steps of calculating the transformation matrix may include: determining the relative rotation angle of the current image frame relative to the reference frame according to the device posture data, and determining the rotation matrix in the camera extrinsic parameters according to the relative rotation angle. The camera intrinsic parameters are parameters that describe the internal properties of the camera, including focal length, optical center coordinates, etc. When the current image frame is determined, the intrinsic parameter matrix corresponding to the current image frame is a known quantity. According to the rotation matrix in the camera extrinsic parameters and the camera intrinsic parameter matrix, the transformation matrix of the current image frame relative to the reference frame is determined. In this step, the transformation matrix is ​​determined according to the device posture data, and the current image frame can be transformed to the device posture of the reference frame according to the transformation matrix.

[0097] In some embodiments, the device posture data includes angular velocity data and data collection time collected by the Gyro sensor. Calculating the relative rotation angle of the current image frame relative to the reference frame based on the device posture data includes: integrating the angular velocity data at the corresponding data collection timestamp according to the exposure time of the current image frame and the exposure time of the reference frame to obtain the relative rotation angle of the current image frame relative to the reference frame.

[0098] In some embodiments, after determining the exposure time of the current image frame and the exposure time of the reference frame, t d The exposure time parameters of the current image frame are corrected by using ωd, and the relative rotation angle of the current image frame relative to the reference frame is calculated using the corrected exposure time. d It is the clock delay between the device attitude sensor (such as Gyro sensor) and the electronic device camera. ωd is the angular velocity calibration value of the Gyro sensor zero drift and temperature drift.

[0099] In some embodiments, due to the rolling shutter effect when the full image is exposed, each row of each frame theoretically has a different rotation angle relative to the reference frame, so if the full image uses a dewarp transformation matrix, the image cannot be corrected back. Based on the balance between computational efficiency and correction effect, n rows can be merged into one block for correction based on the idea of ​​row-by-row correction. That is, every n rows of the current image frame corresponds to a transformation matrix, and every n rows are corrected according to the corresponding transformation matrix. In actual engineering, a balance should be struck between accuracy and efficiency, and n can take a typical value of 20.

[0100] 210, Dewarp transformation.

[0101] Performing a Dewarp transformation on the current image frame includes: mapping the pixel coordinates of the corrected image frame to the current image frame, and the pixel values ​​of each pixel coordinate of the corrected image frame are determined according to the mapped pixels of the current image frame, wherein if the pixel coordinates of the corrected image frame mapped to the current image frame are out of bounds, the corresponding pixels are set to 0. Figure 3As shown in the figure, image a is the current image frame, and image b is the corrected image frame of the current image frame. Based on the Dewarp transformation, the x in image b j Coordinates are mapped to x in image a i Coordinate, x j The pixel value of the coordinate is based on the x in image a. i If the coordinates of image b mapped to image a are out of bounds, the pixels of the corresponding coordinates in image b are set to 0. j The coordinates of the image a are transformed by Dewarp. i If the coordinates are negative, the pixel coordinates of the corrected image frame are considered to be out of bounds, and the corresponding pixel value is set to 0. Through this step, the current image frame is transformed to the device posture of the reference frame, thereby reducing or eliminating the image content distortion caused by the rotation of the electronic device driven by hand shaking.

[0102] 211, global alignment.

[0103] In step 210, the current image frame is subjected to a Dewarp transformation to obtain a corrected image frame. In step 210, the Dewarp transformation can reduce or eliminate the image content distortion caused by the rotation of the electronic device. In this step, the second image frame is further globally aligned with the reference frame to eliminate the translation bias in the second image frame.

[0104] Specifically, the global alignment between the corrected image frame and the reference frame includes: determining the global offset of the corrected image frame relative to the reference frame. Aligning the corrected image frame with the reference frame according to the global offset to obtain an aligned image frame. Optionally, determining the global offset of the corrected image frame with respect to the reference frame includes: projecting the corrected image frame and the reference frame in the X / Y direction respectively, calculating the Sum of Absolute Difference (SAD) between the corrected image frame and the reference frame in the X / Y direction, and moving one pixel left / right / up / down in the X / Y direction respectively, and then calculating the SAD value in the X / Y direction, and so on, moving and calculating the SAD value within a certain range, finding the minimum difference between the corrected image frame and the reference frame in the X / Y direction among these SAD values, as the motion vector of the corrected image frame relative to the reference frame, and the motion vector is used as the global offset of the corrected image frame relative to the reference frame. Aligning the corrected image frame with the reference frame according to the global offset.

[0105] 212, crop the focus ROI and fill in the black border.

[0106] In step 212, the focus ROI is cropped from the aligned image frame. In step 211, when the corrected image frame is globally aligned with the reference frame, the corrected image frame is mainly translated and aligned. For example, the focus subject in the corrected image frame and the reference frame is a face. If the global offset of the corrected image frame relative to the reference frame is translated to the left by 5 pixels, then the corrected image frame needs to be translated to the right by 5 pixels during the global alignment in step 211. In addition, the cropped focus ROI may have out-of-bounds black edges, such as the out-of-bounds coordinates set to 0 as described in step 210. In this step, the out-of-bounds black edges of the focus ROI can be filled with historical frame pixels using the historical image frames before the current image frame. Among them, when the ROI is filled with black edges, if the previous frame of the current image frame fails to fill the black edges completely, the ROI is filled with black edges using the previous frame of the current image frame, that is, the ROI is filled with black edges using a frame-by-frame complementation method.

[0107] See also Figure 4 , based on the method of the embodiment of the present invention, after transforming each image frame to the reference frame device posture and performing global alignment, the focus subject in the cropped focus ROI (white frame) can be kept consistent. When the focus subject in the focus ROI is consistent, each frame of the image can accurately reflect the clarity of the VCM / lens focus, providing a strong guarantee for the subsequent determination of the focus position.

[0108] 213, sending the focus ROI cut out in step 212 to the AFM module, so as to calculate the FV value of the focus ROI through the AFM module.

[0109] 214, the FV value and device posture data of the focus ROI are sent to AF Lib (autofocus algorithm library) for focusing. AF Lib is an autofocus algorithm module, which can control the motor to push the Lens stroke to focus according to the FV value and device posture data. For example, AF Lib can determine whether the currently incoming device posture data is credible. If it is credible, the currently incoming FV value is compared with the previously acquired FV values. If the currently incoming FV value is less than the FV value of the previous frame image, it means that the FV value of the previous frame image is the maximum value, then the FV value of the previous frame image can be used to calculate the focus position, and the VCM is pushed to the focus position and the method ends. If the currently incoming FV value is greater than the FV value of the previous frame image, but it is impossible to determine whether the currently incoming FV value is the maximum value, it is necessary to push the VCM and obtain the FV value of the next frame image.

[0110] 215, determine whether the focusing method is finished. If not finished, jump to step 204.

[0111] The method of the embodiment of the present invention can transform the frame to be focused to the device posture of the reference frame, and can globally align the reference frame, thereby reducing or eliminating the image content distortion caused by the change of the device posture, and the embodiment of the present invention discards the frame to be focused in which the focus subject undergoes non-planar motion and the frame to be focused in which VCM oscillation occurs, thereby avoiding the image content distortion caused by the focus subject motion and VCM oscillation. It can be seen that the method of the embodiment of the present invention can utilize the existing hardware of the electronic device without increasing the hardware cost, and can reduce or eliminate the influence of external factors such as hand shaking, focus subject motion, VCM oscillation, etc. on the AF effect by improving the AF algorithm, thereby improving the AF effect.

[0112] The embodiment of the present invention also provides a method for calculating a transformation matrix. Specifically, the dewarp transformation mainly considers rotation transformation. Among them, the relationship between pixel coordinates and world coordinates can be obtained by the camera rotation through formulas (1), (2), and (3):

[0113] X=KR(t)x R(t) ∈ SO(3) Formula (1)

[0114] Δθ(t)=(ω(t+td)+ωd)*Δt Formula (2)

[0115] t(i,y)=t i +t s *y / h Formula (3)

[0116] Among them, X is the coordinate of the world coordinate system, and x is the coordinate of the pixel coordinate system. K is the camera intrinsic parameter matrix that needs to be calibrated in advance, R is the rotation matrix in the camera extrinsic parameter, and the rotation angle θ is a function of the timestamp t, which can be calculated based on the Gyro angle integral. td is the clock delay between Gyro and the camera, ωd is the Gyro zero drift and temperature drift calibration value that needs to be calibrated in advance, t i is the current frame timestamp, t s is the exposure time of the whole image, y is the offset of the current row exposed, and h is the number of rows in the whole image.

[0117] In the above formulas (1), (2), and (3), the transformation matrix only includes the rotation component. It is assumed that the world coordinates coincide with the origin of the camera coordinates, and there is no scaling and translation component. The rotation matrix is ​​calculated by R in the previous formula. For the same physical point X in the world coordinate system, xj is the mapping point of a coordinate point on frame m after being rotated by an angle θ on frame n. According to formula (1), they can be expressed as:

[0118] X=KR(t) xi Formula (4)

[0119] X=KR(t) xj Formula (5)

[0120] By making formula (4) and formula (5) equal, we can determine formula (6).

[0121] x j =W(t(j,y j ),t(i,y i ))x i Formula (6)

[0122] in:

[0123]

[0124] W(t1, t2) in formula (7) is the transformation matrix of the embodiment of the present invention. R in formula (7) can be determined according to formulas (1), (2) and (3).

[0125] In one example, the current image frame calculates a transformation matrix relative to the reference frame, and the transformation matrix is ​​calculated according to formula (7) and (1)-(3) including:

[0126] The exposure time of the current image frame is determined according to formula (3). Optionally, the timestamp of the current image frame can be used as the exposure time of the current image frame, and similarly, the timestamp of the reference frame can be used as the exposure time of the reference frame.

[0127] Substitute the exposure time of the current image frame and the exposure time of the reference frame in formula (3) into formula (2) to integrate the angular velocity of Gyro to obtain the rotation angle Δθ(t), and determine the rotation matrix R of the camera extrinsic parameter according to the rotation angle Δθ(t). Substitute the calculated R into formula (7) to obtain the transformation matrix W(t1, t2).

[0128] In another example, due to the rolling shutter effect when the preview frame is fully exposed, theoretically each row of each frame has a different rotation angle relative to the reference frame, so if a Dewarp transformation matrix is ​​used for the entire image, the image cannot be corrected back. Based on the balance between computational efficiency and correction effect, n rows can be merged into one block for correction based on the idea of ​​row-by-row correction. Specifically, the transformation matrix can be calculated once for every n rows of the current image frame based on the device posture data corresponding to each n rows of the current image frame, where n is greater than or equal to 2; wherein the transformation matrix corresponding to each n rows is used to correct the image of the corresponding n rows.

[0129] Calculating the transformation matrix once for every n rows of the current image frame includes: determining the exposure time of the first row of the current image frame, where the exposure time of the first row can be the timestamp t of the current image frame. i Determine the row offset y of one of every n rows of the current image frame relative to the first row of the current image frame. According to the exposure time t of the first row of the current image frame i, the row offset y of one of the n rows, the total number of rows in the current image frame h, and the full image exposure time t of the current image frame s , determine the exposure time of each n lines of the current image frame, for example, t i ,t s Substituting , y and h into formula (3) can obtain the exposure time t(i,y) of each n rows of the current image frame. Similarly, the exposure time of the corresponding n rows of the reference frame can be obtained. According to the exposure time of each n rows of the current image frame, the exposure time of the corresponding n rows of the reference frame and the device posture data of the corresponding time period, the transformation matrix is ​​calculated once for each n rows of the current image frame. Specifically, the exposure time of each n rows of the current image frame and the exposure time of the corresponding n rows of the reference frame can be used to integrate the angular velocity of Gyro, that is, the rotation angle of each n rows of the current image frame relative to the reference frame can be calculated using formula (2). The camera extrinsic rotation matrix R is calculated based on the rotation angle Δθ(t). Then, the rotation matrix corresponding to each n rows of the current image frame is calculated according to formula (7).

[0130] like Figure 5 As shown in the curve graph in the upper left corner, when Gyro collects angular velocity data of the X / Y / Z axes of the electronic device, the method of the embodiment of the present invention can also correct the image content distortion to achieve efficient focusing.

[0131] See also Figure 6 , is a schematic diagram of the structure of an auxiliary auto-focusing device provided by an embodiment of the present invention. Figure 6 As shown, the device comprises:

[0132] An acquisition module 310 is used to acquire device posture data collected by a posture sensor in the electronic device;

[0133] The dedistortion module 320 is used to determine the transformation matrix of the current image frame relative to the reference frame according to the device posture data; and to convert the current image frame to the device posture of the reference frame according to the transformation matrix to obtain a corrected image frame of the current image frame;

[0134] The focusing module 330 is used to perform focusing according to the corrected image frame.

[0135] For the specific process, please refer to the description in the above method flowchart.

[0136] See also Figure 7 , is a schematic diagram of the structure of an electronic device provided by an embodiment of the present invention. Figure 7As shown, the device includes: a lens module, a posture sensor, a memory and a processing unit. Among them, the lens module includes: an optical device Lens, a VCM and a photosensitive sensor. The processing unit includes an ISP and a main processor. The main processor can be a CPU, a GPU or other possible processors. The ISP and the main processor can be integrated or independently set. Figure 7 The electronic device shown executes the method of the embodiment of the present invention including:

[0137] exist Figure 7 In the electronic device shown, the light signal is transmitted to the photosensitive sensor through the lens, and the photosensitive sensor is used to convert the light signal into an electrical signal and transmit it to the ISP. The ISP is used to pre-process the image frame collected by the photosensitive sensor and store the pre-processed image frame in the memory. The main processor obtains the device posture data collected by the posture sensor and reads the image frame to be focused from the memory and performs the focusing operation according to the posture sensor. Figure 1 and Figure 2 The method shown extracts the focus ROI from the image frame. The main processor sends the focus ROI to the ISP to calculate the FV value through the AFM in the ISP and perform the focus action through the AF lib. Figure 7 The automatic focusing method executed by the main processor of the electronic device shown can be referred to Figure 1 and Figure 2 The description is not repeated here.

[0138] It should be noted that Figure 7 The various components of the electronic device shown can communicate with each other through one or more buses. Those skilled in the art can understand that the structure of the electronic device shown in the figure does not constitute a limitation on the embodiments of the present application. It can be a bus structure or a star structure, and can also include more or fewer components than shown in the figure, or combine certain components, or arrange the components differently.

[0139] Things that need to be explained, Figure 7 The memory in the electronic device shown may include DDR, and the DDR is used to cache image frames captured by the image sensor. Figure 7 The memory in the electronic device shown can also store execution instructions of the main processor. When the execution instructions in the memory are executed by the main processor, the electronic device can execute Figure 1 or Figure 2 Some or all of the steps in the illustrated embodiments.

[0140] In a specific implementation, the present application further provides a computer storage medium, wherein the computer storage medium may store a program, and when the program is executed, the program may include some or all of the steps in each embodiment of the vehicle control signal processing method provided in the present application. The storage medium may be a magnetic disk, an optical disk, a read-only memory (ROM) or a random access memory (RAM), etc.

[0141] In a specific implementation, the present application also provides a computer program product, wherein the computer program product includes executable instructions, and when the executable instructions are executed on a computer, the computer executes part or all of the steps in each embodiment of the autofocus method provided in the present application.

[0142] The embodiment of the present application also provides a non-transitory computer-readable storage medium, which stores computer instructions, and the computer instructions enable the computer to execute the automatic focusing method provided by the embodiment of the present application.

[0143] The above-mentioned non-temporary computer-readable storage medium can adopt any combination of one or more computer-readable media. The computer-readable medium can be a computer-readable signal medium or a computer-readable storage medium. The computer-readable storage medium can be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or device, or any combination of the above. More specific examples (non-exhaustive list) of computer-readable storage media include: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (Read Only Memory; hereinafter referred to as: ROM), an erasable programmable read-only memory (ErasableProgrammable Read Only Memory; hereinafter referred to as: EPROM) or flash memory, optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In this document, a computer-readable storage medium can be any tangible medium containing or storing a program, which can be used by an instruction execution system, device or device or used in combination with it.

[0144] Computer-readable signal media may include a data signal propagated in baseband or as part of a carrier wave, which carries a computer-readable program code. Such propagated data signals may take a variety of forms, including, but not limited to, electromagnetic signals, optical signals, or any suitable combination of the above. Computer-readable signal media may also be any computer-readable medium other than a computer-readable storage medium, which may send, propagate, or transmit a program for use by or in conjunction with an instruction execution system, apparatus, or device.

[0145] Program code embodied on a computer readable medium may be transmitted using any appropriate medium, including but not limited to wireless, wireline, optical fiber cable, RF, etc., or any suitable combination of the foregoing.

[0146] Those skilled in the art can clearly understand that the technology in the embodiments of the present application can be implemented by means of software plus a necessary general hardware platform. Based on this understanding, the technical solution in the embodiments of the present application is essentially or the part that contributes to the prior art can be embodied in the form of a software product, which can be stored in a storage medium such as ROM / RAM, a disk, an optical disk, etc., including several instructions for enabling a computer device (which can be a personal computer, a server, or a network device, etc.) to execute the methods described in each embodiment of the present application or some parts of the embodiments.

[0147] In this specification, the same or similar parts between the various embodiments can be referred to each other. In particular, for the device embodiment and the terminal embodiment, since they are basically similar to the method embodiment, the description is relatively simple, and the relevant parts can be referred to the description in the method embodiment.

Claims

1. An auxiliary auto-focusing method, characterized in that: include: Acquire device posture data collected by a posture sensor in the electronic device; Determining a transformation matrix of a current image frame relative to a reference frame according to the device posture data; According to the transformation matrix, the current image frame is corrected to the device posture of the reference frame to obtain a corrected image frame of the current image frame; Wherein, the corrected image frame is used for focusing.

2. The method according to claim 1, characterized in that Determining the transformation matrix of the current image frame relative to the reference frame according to the device posture data includes: Determining a relative rotation angle of the current image frame relative to the reference frame according to the device posture data; Determine the rotation matrix in the camera extrinsic parameters according to the relative rotation angle; The transformation matrix of the current image frame relative to the reference frame is determined according to the rotation matrix in the camera extrinsic parameters and the camera intrinsic parameter matrix.

3. The method according to claim 2, characterized in that The device posture data includes: angular velocity data and data acquisition timestamp; Determining the relative rotation angle of the current image frame with respect to the reference frame according to the device posture data includes: According to the exposure time of the current image frame and the exposure time of the reference frame, the angular velocity data at the corresponding data acquisition timestamp is integrated to obtain the relative rotation angle of the current image frame with respect to the reference frame.

4. The method according to claim 1, characterized in that: Determining the transformation matrix of the current image frame relative to the reference frame according to the device posture data includes: According to the device posture data corresponding to each n rows of the current image frame, calculating a transformation matrix for each n rows of the current image frame, where n is greater than or equal to 2; The transformation matrix corresponding to each n rows is used to correct the image of the corresponding n rows.

5. The method according to claim 4, characterized in that The step of calculating a transformation matrix for each n rows of the current image frame according to the device posture data corresponding to each n rows of the current image frame includes: Determine the first row exposure timestamp of the current image frame; Determine a row offset of one of every n rows of the current image frame relative to the first row of the current image frame; Determine the exposure time of every n rows of the current image frame according to the first row exposure timestamp of the current image frame, the row offset of one of every n rows, the total number of rows of the current image frame, and the full-image exposure time of the current image frame; According to the exposure time of every n lines of the current image frame, the exposure time of the reference frame and the device posture data of the corresponding time period, the content of the current image frame is corrected once every n lines.

6. The method according to claim 1, characterized in that The step of correcting the current image frame to the device posture of the reference frame according to the transformation matrix to obtain a corrected image frame of the current image frame includes: According to the transformation matrix, the pixel coordinates of the corrected image frame are mapped to the pixel coordinates of the current image frame, and the pixel values ​​of the pixel coordinates of the corrected image frame are determined according to the mapped pixels of the current image frame, wherein if the pixel coordinates of the corrected image frame mapped to the current image frame are out of bounds, the corresponding pixels of the corrected image frame are set to 0.

7. The method according to claim 1, characterized in that Before determining the transformation matrix of the current image frame relative to the reference frame according to the device posture data, the method further includes: Determine whether a focus subject included in the current image frame undergoes non-planar motion, and / or whether a voice coil motor (VCM) oscillation occurs during the process of capturing the current image frame; If the judgment result of any item is yes, discard the current image frame; Otherwise, a transformation matrix of the current image frame relative to the reference frame is calculated.

8. The method according to claim 1, characterized in that Before determining the transformation matrix of the current image frame relative to the reference frame according to the device posture data, the method further includes: Performing blur kernel estimation on the current image frame to determine a scaling factor of the current image frame relative to the reference frame; The current image frame is scaled according to the scaling factor so that a focus region of interest ROI of the current image frame is aligned with a focus ROI of a reference frame.

9. The method according to claim 1, characterized in that: Before the corrected image frame is used for focusing, the method further includes: determining a global offset of the rectified image frame relative to the reference frame; Aligning the corrected image frame with the reference frame according to the global offset to obtain an aligned image frame; Cropping a focus ROI from the aligned image frame; Using the historical image frame before the current image frame to fill the out-of-bounds black edge of the focus ROI with pixels of the historical frame; The focus ROI after pixel filling is used to calculate the focus value FV and focus.

10. The method according to claim 1, characterized in that The current image frame is collected by the photosensor of the electronic device and stored in the image memory. When the autofocus algorithm is executed, the current image frame is read out from the image memory and enters the Pipeline process of the image signal processor ISP after executing the autofocus algorithm.

11. An auxiliary automatic focusing device, characterized in that: include: An acquisition module, used to acquire device posture data collected by a posture sensor in the electronic device; A dedistortion module, used to determine a transformation matrix of a current image frame relative to a reference frame according to the device posture data; and for correcting the current image frame to the device posture of the reference frame according to the transformation matrix to obtain a corrected image frame of the current image frame; A focusing module is used to focus according to the corrected image frame.

12. An electronic device, characterized in that: include: A posture sensor, used to collect device posture data of electronic equipment; A photosensitive sensor for collecting image frames through photoelectric conversion; Image signal processor ISP, used to pre-process image frames collected by the photosensitive sensor; A memory for storing computer program instructions and a main processor for executing the program instructions, wherein when the computer program instructions are executed by the main processor, the electronic device executes the method according to any one of claims 1 to 10.

13. A computer-readable storage medium, characterized in that: The computer-readable storage medium includes a stored program, wherein when the program is executed, the device where the computer-readable storage medium is located is controlled to execute the method according to any one of claims 1 to 10.