Focusing method and imaging device
Through image registration and calculation of preset focus position, the problem of autofocus speed and accuracy of telephoto cameras is solved, fast and accurate focus is achieved, and image quality is maintained.
Patent Information
- Application Number
- CN202411828689.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-12
- Publication Date
- 2025-03-14
AI Technical Summary
The existing focusing methods have shortcomings in speed, quality, accuracy, distance and application range, and are difficult to meet the autofocus needs of telephoto cameras.
By acquiring the pixel position of the target image from the first shooting module, acquiring an image covering the first image field of view using the second shooting module for image registration, a preset focus position of the target image scene is calculated, and the focus position of the first shooting module is adjusted.
Fast and accurate autofocus is achieved, avoiding the calculation of image contrast or sharpness values of multiple positions in traditional methods, maintaining image resolution and dynamic range, and is suitable for close and long-distance scene focus.
Smart Images

Figure CN119629475A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of photographic technology, and in particular to a focusing method and an imaging device. Background Art
[0002] Existing focusing methods mainly include traditional camera focusing methods and lidar autofocus methods. Traditional camera focusing methods mainly include contrast detection autofocus and phase detection autofocus. Contrast detection autofocus has high accuracy, but it needs to obtain image clarity at multiple positions of the target to determine the focus position of the target, and the focusing speed is slow, resulting in poor focusing experience and difficulty in autofocusing fast-moving targets. There are two main phase detection autofocus methods, both of which can achieve fast focusing; but one of the phase detection autofocus methods requires dedicated focus pixels on the sensor to obtain the phase information of the target to achieve focusing, which will lose the output image resolution; the other method to achieve phase detection autofocus is based on a dual-pixel sensor, which does not require reserved dedicated pixels for focusing, but this method requires splitting a single pixel into two to obtain the phase information of the target, which will lose the dynamic range of the sensor. The LiDAR autofocus method measures the time it takes for a laser pulse to reflect from a target back to the sensor to determine the distance from the target to the sensor, thereby achieving focus. However, it is an active focus method with the following limitations: 1. Laser signals are likely to be crosstalked in the air, causing confusion in the received signal and affecting focus accuracy. 2. Long-distance transmission of laser signals will cause signal attenuation, limiting the focus distance of the technology (usually within 20 meters). 3. The emission of laser signals will expose the location of the device, limiting its application in some scenarios (such as the military). Summary of the invention
[0003] In order to solve the above problems, an embodiment of the present application provides a focusing method and an imaging device.
[0004] In a first aspect, the present application provides a focusing method, comprising the following steps: S1: Acquire a first image from a first shooting module, acquire a target image from the first image, and acquire a first pixel position of the target image in the first image, wherein the target image is the first image or a partial image in the first image; S2: Acquire a second image from a second shooting module that is a first preset length away from the first shooting module, wherein the field of view of the second image covers the field of view of the first image; S3: Matching the target image with the second image through image registration to obtain a matching area in the target image that matches the second image, and obtaining a second pixel position of the matching area in the second image; S4: Calculating a third pixel position of the first image in the second image according to the first pixel position and the second pixel position; S5: Obtain a mapping relationship between a focus position of the first shooting module and a third pixel position, and calculate and obtain a first preset focus position corresponding to the target image scene according to the mapping relationship and the third pixel position; S6: adjusting the focus position of the first shooting module according to a first preset focus position corresponding to the target image scene.
[0005] Preferably, an optical axis of the first shooting module when shooting the first image is arranged in parallel with an optical axis of the second shooting module when shooting the second image.
[0006] Preferably, the optical axis of the first shooting module and the optical axis of the second shooting module are both fixed; or at least one of the optical axis of the first shooting module and the optical axis of the second shooting module is rotatable.
[0007] Preferably, before matching the target image with the second image by image registration, step S3 includes: performing distortion correction on at least one of the first image and the second image.
[0008] Preferably, step S3 specifically includes: S31: performing image transformation on the target image through an image transformation matrix to obtain a target transformed image, so that the target transformed image and the overlapping field of view of the target image and the second image have the same image resolution; S32: Matching the target transformed image with the second image through image registration to obtain a matching area in the target transformed image that matches the second image, and obtaining a second pixel position of the matching area in the second image.
[0009] Preferably, step S4 specifically includes: S41: Obtaining a first pixel coordinate (x1, y1) of a first preset pixel point at a first preset position in the matching area in the first image; S42: Obtain a second pixel coordinate (x2, y2) of the first preset pixel point in the second image; S43: performing image transformation on the first image by using an image transformation matrix to obtain a first transformed image, and obtaining a third pixel coordinate (x1′, y1′) of the first preset pixel point in the first transformed image; S44: Calculate and obtain the fourth pixel coordinate (x3, y3) of the third pixel position according to the second pixel coordinate (x2, y2) and the third pixel coordinate (x1', y1'), where x3=x2-x1', y3=y2-y1'.
[0010] Preferably, the image transformation matrix is a linear scaling matrix A, , wherein r1 represents the linear scaling ratio of the first image or the second image in the x direction, r2 represents the linear scaling ratio of the first image or the second image in the y direction, the third pixel coordinate (x1', y1') in step S43 satisfies: x1'=r1*x1, y1'=r2*y1, and the fourth pixel coordinate (x3, y3) in step S44 satisfies: x3=x2- x1'=x2- r1*x1, y3=y2- y1'=y2- r2*y1.
[0011] Preferably, the image registration algorithm is a template matching algorithm or a feature point matching algorithm.
[0012] Preferably, the template matching algorithm uses normalized cross-correlation or normalized square difference as a matching similarity criterion.
[0013] Preferably, the feature point matching algorithm is one of a feature point matching algorithm based on SIFT feature points, a feature point matching algorithm based on SURF feature points, or a feature point matching algorithm based on ORB feature points.
[0014] Preferably, obtaining the first pixel position of the target image in the first image in step S1 specifically includes: obtaining the first pixel position by detecting through a target detection algorithm or receiving the first pixel position sent by an input module.
[0015] Preferably, the target detection algorithm is one of a deep learning target detection algorithm based on the YOLO series, a deep learning target detection algorithm based on the R-CNN series, a deep learning target detection algorithm based on the Transformer, a traditional target detection algorithm based on the Haar cascade classifier, or a traditional target detection algorithm based on the DPM.
[0016] Preferably, the target image is a rectangular image, the first pixel position of the target image in the first image is the pixel coordinate of the upper left corner vertex of the matching area in the first image, and the second pixel position of the matching area in the second image is the pixel coordinate of the upper left corner vertex of the matching area in the second image.
[0017] Preferably, step S6 specifically includes: S61: Acquire the current focus position of the first shooting module; S62: Calculating and acquiring the number of steps and the moving direction required for the first shooting module to move from the current focusing position to the first preset focusing position according to the first preset focusing position and the current focusing position; S63: adjusting the focus position of the first shooting module according to the moving step number and the moving direction to match a first preset focus position corresponding to the target image scene.
[0018] Preferably, after step S63, the following steps are further included: S64: respectively calculating and acquiring a plurality of image contrast or image clarity information at a plurality of positions adjacent to the first preset focus position; S65: Obtaining a maximum value of image contrast or image clarity information from multiple pieces of image contrast or image clarity information, and obtaining a focus position corresponding to the maximum value of the image contrast or image clarity information; S66: moving the focus position of the first shooting module to a focus adjustment position.
[0019] In a second aspect, an embodiment of the present application provides an imaging device, including a first shooting module, a second shooting module, a first image acquisition module, a second image acquisition module, a first matching module, a first storage module, a first calculation module, a second calculation module, and a first adjustment module, wherein the distance between the second shooting module and the first shooting module is a first preset length; The first shooting module and the second shooting module are used to shoot images respectively; The first image acquisition module is used to acquire a first image from the first shooting module, acquire a target image from the first image, and acquire a first pixel position of the target image in the first image, wherein the target image is the first image or a partial image in the first image; The second image acquisition module is used to acquire a second image from the second shooting module, and the field of view of the second image covers the field of view of the first image; The first matching module is used to match the target image with the second image through image registration to obtain a matching area in the target image that matches the second image, and to obtain a second pixel position of the matching area in the second image; The first calculation module is used to calculate a third pixel position of the first image in the second image according to the first pixel position and the second pixel position; The first storage module is used to store a mapping relationship between the third pixel position and the focus position of the first shooting module; The second calculation module is used to obtain a mapping relationship between a focus position of the first shooting module and a third pixel position from the first storage module, and calculate and obtain a first preset focus position corresponding to the target image scene according to the mapping relationship and the third pixel position; The first adjustment module is used to adjust the focus position of the first shooting module according to a first preset focus position corresponding to the target image scene.
[0020] Preferably, an optical axis of the first shooting module when shooting the first image and an optical axis of the second shooting module when shooting the second image are arranged in parallel.
[0021] Preferably, the optical axis of the first shooting module and the optical axis of the second shooting module are both fixed; or at least one of the optical axis of the first shooting module and the optical axis of the second shooting module is rotatable.
[0022] Preferably, the first matching module includes a first image transformation unit, which is used to perform image transformation on the target image through an image transformation matrix to obtain a target transformed image, so that the target transformed image and the overlapping field of view of the target image and the second image have the same image resolution; The first image matching unit is used to match the target transformed image with the second image through image registration to obtain a matching area in the target transformed image that matches the second image, and to obtain a second pixel position of the matching area in the second image.
[0023] Preferably, the first calculation module includes a first coordinate acquisition unit, which is used to acquire a first pixel coordinate (x1, y1) of a first preset pixel point at a first preset position in the matching area in the first image; A second coordinate acquisition unit, used for acquiring a second pixel coordinate (x2, y2) of the first preset pixel point in the second image; A third coordinate acquisition unit, used for performing image transformation on the first image through an image transformation matrix to obtain a first transformed image, and obtaining a third pixel coordinate (x1', y1') of the first preset pixel point in the first transformed image; The fourth coordinate acquisition unit is used to calculate and acquire the fourth pixel coordinate (x3, y3) of the third pixel position according to the second pixel coordinate (x2, y2) and the third pixel coordinate (x1', y1'), where x3=x2-x1', y3=y2-y1'.
[0024] Preferably, the image transformation matrix is a linear scaling matrix A, , wherein r1 represents the linear scaling ratio of the first image or the second image in the x direction, r2 represents the linear scaling ratio of the first image or the second image in the y direction, the third pixel coordinate (x1', y1') satisfies: x1'=r1*x1, y1'=r2*y1, and the fourth pixel coordinate (x3, y3) satisfies: x3=x2- x1'=x2- r1*x1, y3=y2- y1'=y2- r2*y1.
[0025] Preferably, the image registration algorithm is a template matching algorithm or a feature point matching algorithm.
[0026] Preferably, the template matching algorithm uses normalized cross-correlation or normalized square difference as a matching similarity criterion.
[0027] Preferably, the feature point matching algorithm is one of a feature point matching algorithm based on SIFT feature points, a feature point matching algorithm based on SURF feature points, or a feature point matching algorithm based on ORB feature points.
[0028] Preferably, it also includes an input module; the first image acquisition module is used to detect and acquire the first pixel position through a target detection algorithm or receive the first pixel position sent by the input module.
[0029] Preferably, the target detection algorithm is one of a deep learning target detection algorithm based on the YOLO series, a deep learning target detection algorithm based on the R-CNN series, a deep learning target detection algorithm based on Transformer, a traditional target detection algorithm based on Haar cascade classifier, or a traditional target detection algorithm based on DPM.
[0030] Preferably, the target image is a rectangular image, the first pixel position of the target image in the first image is the pixel coordinate of the upper left corner vertex of the matching area in the first image, and the second pixel position of the matching area in the second image is the pixel coordinate of the upper left corner vertex of the matching area in the second image.
[0031] Preferably, the first adjustment module includes a first position acquisition unit, which is used to acquire the current focus position of the first shooting module; A movement calculation unit, used for calculating the number of movement steps and the movement direction required for the first shooting module to move from the current focus position to the first preset focus position according to the first preset focus position and the current focus position; The focusing unit is used to adjust the focusing position of the first shooting module to match a first preset focusing position corresponding to a target image scene according to the moving steps and the moving direction.
[0032] Preferably, after the focusing unit adjusts the focusing position of the first shooting module according to the moving step number and the moving direction to match the first preset focusing position corresponding to the target image scene, the focusing unit also includes: respectively calculating and obtaining multiple image contrasts or image clarity information at multiple positions adjacent to the first preset focusing position; obtaining the maximum value of the image contrast or image clarity information from the multiple image contrasts or image clarity information, and obtaining the focusing position corresponding to the maximum value of the image contrast or image clarity information; and moving the focusing position of the first shooting module to the focusing position.
[0033] Preferably, it further comprises a display module, and the display module can display the first image and / or the second image.
[0034] Preferably, the display module is a touch display module capable of displaying at least the first image; the touch display module can sense a click or touch position on the first image and generate a target image position.
[0035] In a third aspect, an embodiment of the present application provides an electronic device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the computer program, the steps of the method provided in the first aspect or any possible implementation of the first aspect are implemented.
[0036] In a fourth aspect, an embodiment of the present application provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the steps of the method provided in the first aspect or any possible implementation of the first aspect.
[0037] The beneficial effects of the present invention are: 1. Obtain a first pixel position of the target image in the first image and a second pixel position of the matching area in the second image respectively, calculate and obtain a first preset focus position corresponding to the target image scene according to a mapping relationship between the third pixel position and the focus position of the first shooting module and the third pixel position, and adjust the focus position of the first shooting module according to the first preset focus position corresponding to the target image scene. Compared with the traditional contrast focusing method, the scene focus position can be determined by the first image and the second image in the present application, avoiding the calculation of the contrast or clarity values of multiple position images, and realizing fast focusing, and can realize real-time focus of the scene or tracking focus of the target; 2. Compared with the phase focusing method, this application does not need to reserve pixels on the sensor specifically for focusing or use a special dual-pixel sensor to achieve focusing. Therefore, this application does not need to lose image resolution or image dynamic range to achieve focusing. In addition, compared with the phase focusing method, this application has no strict requirements on the sensor model; 3. Compared with the laser radar focusing method, this application can achieve both close-range and long-range scene focusing; 4. Compared with the conventional dual-camera focusing method, the present application can complete the focusing based on the images captured by the first shooting module and the second shooting module, without the need to calibrate the camera intrinsic parameters (left and right camera baselines and camera focal length); 5. This application uses a wide-angle camera to assist the telephoto camera in focusing, which can achieve better telephoto focusing accuracy. BRIEF DESCRIPTION OF THE DRAWINGS
[0038] In order to more clearly illustrate the technical solutions in 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 work.
[0039] Figure 1 A flowchart of a focusing method provided in an embodiment of the present application; Figure 2 A schematic diagram of the structure of an imaging device provided in an embodiment of the present application; Figure 3 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application; Figure 4 A schematic diagram of a first image and a target image position in the first image provided in an embodiment of the present application; Figure 5 A schematic diagram of the positions of the second image, the first image and the target image provided in an embodiment of the present application; Figure 6 A schematic diagram of the positions of a linearly scaled first image and a target image in the linearly scaled first image provided by an embodiment of the present application; Figure 7 A schematic diagram of a curve showing the relationship between the focus position of the first shooting module and the contrast of the target image provided in an embodiment of the present application; Figure 8 A schematic diagram of an interface of a touch display unit in an imaging device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0040] The technical solutions in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application.
[0041] In the following introduction, the terms "first" and "second" are used for descriptive purposes only and should not be understood as indicating or implying relative importance. The following introduction provides multiple embodiments of the present application, and different embodiments can be replaced or combined, so the present application can also be considered to include all possible combinations of the same and / or different embodiments recorded. Therefore, if one embodiment includes features A, B, and C, and another embodiment includes features B and D, then the present application should also be considered to include embodiments containing one or more of all other possible combinations of A, B, C, and D, although the embodiment may not be clearly recorded in the following text.
[0042] The following description provides examples and does not limit the scope, applicability or examples set forth in the claims. Changes may be made to the functions and arrangements of the elements described without departing from the scope of the present application. Various processes or components may be appropriately omitted, substituted or added to each example. For example, the described method may be performed in an order different from the order described, and various steps may be added, omitted or combined. In addition, features described in some examples may be combined in other examples.
[0043] See also Figure 1 , 4 -7. Figure 1 is a flowchart of a focusing method provided in an embodiment of the present application, Figure 4 A schematic diagram of a first image and a target image position in the first image provided in an embodiment of the present application, Figure 5 A schematic diagram of the positions of the second image, the first image and the target image provided in the embodiment of the present application, Figure 6 A schematic diagram of the positions of a linearly scaled first image and a target image in the linearly scaled first image provided in an embodiment of the present application, Figure 7 A schematic diagram of a curve showing the relationship between the focus position of the first camera module and the contrast of the target image provided in an embodiment of the present application. In an embodiment of the present application, the method comprises the following steps: S1: Acquire a first image from a first shooting module, acquire a target image from the first image, and acquire a first pixel position of the target image in the first image, wherein the target image is the first image or a partial image in the first image; S2: Acquire a second image from a second shooting module that is a first preset length away from the first shooting module, wherein the field of view of the second image covers the field of view of the first image; S3: Matching the target image with the second image through image registration to obtain a matching area in the target image that matches the second image, and obtaining a pixel position of the matching area in the second image, where the pixel position is a second pixel position; S4: Calculate a pixel position of the first image in the second image according to the first pixel position and the second pixel position, where the pixel position is a third pixel position; S5: Acquire a mapping relationship between the third pixel position and the focus position of the first shooting module, and calculate and acquire a first preset focus position corresponding to the target image scene according to the mapping relationship and the third pixel position; S6: adjusting the focus position of the first shooting module according to the first preset focus position corresponding to the target image scene.
[0044] In the embodiments of the present application, the present application aims to solve the problem of autofocus of a telephoto camera. According to the background technology, the focusing method in the prior art cannot take into account the focusing speed, image quality, focusing accuracy, focusing distance and scope of application of the method, and is difficult to be satisfactory. In addition, the telephoto camera itself has a shallow depth of field, which will also bring additional difficulties to focusing. In order to solve the above problems, the present application proposes a focusing method that can achieve fast and accurate autofocus; and because the present application has no special requirements for the sensor and the present application is a passive focusing method, it does not have the limitations of the above-mentioned phase focusing and lidar focusing (loss of imaging quality, short focusing distance and exposure of the device position).
[0045] In the embodiment of the present application, the mapping relationship between the third pixel position and the focus position of the first shooting module can be preset by the user, and the mapping relationship between the third pixel position and the focus position of the first shooting module can be pre-stored in the storage module.
[0046] In one possible implementation, the optical axis of the first shooting module when shooting the first image and the optical axis of the second shooting module when shooting the second image are arranged in parallel.
[0047] In the embodiment of the present application, the first shooting module may be a first camera, and the second shooting module may be a second camera. The first shooting module may be a telephoto camera, and the second shooting module may be a wide-angle camera.
[0048] In the embodiment of the present application, the first camera module and the second camera module are integrated in the same product, and the second camera module assists the first camera module in focusing. The product may be a telescope with dual cameras, etc. The method is executed by the first camera module and the second camera module, or may also be executed by a control unit in the product.
[0049] In one possible implementation, the optical axis of the first shooting module and the optical axis of the second shooting module are both fixed; or at least one of the optical axis of the first shooting module and the optical axis of the second shooting module is rotatable.
[0050] In the embodiment of the present application, the optical axis of the first camera module and the optical axis of the second camera module can be fixed, and the optical axis of the first camera module and the optical axis of the second camera module can be arranged in parallel. At least one of the optical axis of the first camera module and the optical axis of the second camera module can be rotated, and the optical axis of the first camera module and the optical axis of the second camera module can be adjusted to be arranged in parallel when the first camera module shoots the first image and the second camera module shoots the second image.
[0051] In one possible implementation, before matching the target image with the second image through image registration in step S3, the step includes: performing distortion correction on at least one of the first image and the second image.
[0052] In an embodiment of the present application, before matching the target image with the second image, distortion correction is performed on one or both of the target image and the second image, thereby improving matching accuracy and further improving focusing efficiency.
[0053] In one possible implementation, step S3 specifically includes: S31: performing image transformation on the target image through an image transformation matrix to obtain a target transformed image, so that the target transformed image and an overlapping field of view area of the target image and the second image have the same image resolution; S32: Matching the target transformed image with the second image through image registration to obtain a matching area in the target transformed image that matches the second image, and obtaining a second pixel position of the matching area in the second image.
[0054] In the embodiment of the present application, having the same image resolution means that the target image and the second image have the same pixel dimension, and the object field of view corresponding to the target image is consistent with the object field of view corresponding to the overlapping field of view area of the target image and the second image.
[0055] In one possible implementation, step S4 specifically includes: S41: Obtaining a first pixel coordinate (x1, y1) of a first preset pixel point at a first preset position in the matching area in the first image; S42: Obtain a second pixel coordinate (x2, y2) of the first preset pixel point in the second image; S43: performing image transformation on the first image by using an image transformation matrix to obtain a first transformed image, and obtaining a third pixel coordinate (x1′, y1′) of the first preset pixel point in the first transformed image; S44: Calculate and obtain the fourth pixel coordinate (x3, y3) of the third pixel position according to the second pixel coordinate (x2, y2) and the third pixel coordinate (x1', y1'), where x3=x2-x1', y3=y2-y1'.
[0056] In one possible implementation, the target image is an image with a rectangular outline, the matching area is an area with a rectangular outline, and the first preset pixel point at the first preset position in the matching area can be any vertex of the rectangular outline of the matching area.
[0057] In one possible implementation, the image transformation matrix is a linear scaling matrix A, , wherein r1 represents the linear scaling ratio of the first image or the second image in the x direction, r2 represents the linear scaling ratio of the first image or the second image in the y direction, the third pixel coordinate (x1', y1') in step S43 satisfies: x1'=r1*x1, y1'=r2*y1, and the fourth pixel coordinate (x3, y3) in step S44 satisfies: x3=x2- x1'=x2- r1*x1, y3=y2- y1'=y2- r2*y1.
[0058] In one possible implementation, the image registration algorithm is a template matching algorithm or a feature point matching algorithm.
[0059] In one possible implementation, the template matching algorithm uses normalized cross-correlation or normalized square difference as a matching similarity criterion.
[0060] In one possible implementation, the feature point matching algorithm is one of a feature point matching algorithm based on SIFT feature points, a feature point matching algorithm based on SURF feature points, or a feature point matching algorithm based on ORB feature points.
[0061] In one possible implementation manner, obtaining the first pixel position of the target image in the first image in step S1 specifically includes: obtaining the first pixel position through detection by a target detection algorithm or receiving the first pixel position sent by an input module.
[0062] In one possible implementation, the target detection algorithm is a deep learning target detection algorithm based on the YOLO series, a deep learning target detection algorithm based on the R-CNN series, a deep learning target detection algorithm based on Transformer, a traditional target detection algorithm based on Haar cascade classifier, or a traditional target detection algorithm based on DPM.
[0063] In one possible implementation, the target image is a rectangular image, the first pixel position of the target image in the first image is the pixel coordinate of the upper left corner vertex of the matching area in the first image, and the second pixel position of the matching area in the second image is the pixel coordinate of the upper left corner vertex of the matching area in the second image.
[0064] In an embodiment of the present application, the first pixel position may be the pixel coordinates of the upper left corner vertex of the matching area in the first image, the third pixel position may be the pixel coordinates of the upper left corner vertex of the first image in the second image, and the mapping relationship may be the relationship between the third pixel position and the focusing position of the first shooting module. The mapping relationship may also be the relationship between the focusing position of the first shooting module and the pixel coordinates of the upper left corner vertex of the first image in the second image.
[0065] In one possible implementation, step S6 specifically includes: S61: Acquire the current focus position of the first shooting module; S62: Calculating and acquiring the number of steps and the moving direction required for the first shooting module to move from the current focusing position to the first preset focusing position according to the first preset focusing position and the current focusing position; S63: adjusting the focus position of the first shooting module according to the moving step number and the moving direction to match a first preset focus position corresponding to the target image scene.
[0066] In an embodiment of the present application, the number of moving steps and the moving direction required for the first shooting module to move from the current focusing position to the first preset focusing position corresponding to the target image scene are calculated according to the focusing position corresponding to the target image scene, and the focusing position of the first camera is adjusted according to the obtained number of moving steps and the moving direction to be consistent with the first preset focusing position corresponding to the target image scene, so as to complete the focusing of the first shooting module, thereby realizing the first adjustment of the first shooting module.
[0067] In one possible implementation, step S63 further includes: S64: respectively calculating and acquiring a plurality of image contrast or image clarity information at a plurality of positions adjacent to the first preset focus position; S65: Obtaining a maximum value of image contrast or image clarity information from multiple pieces of image contrast or image clarity information, and obtaining a focus position corresponding to the maximum value of the image contrast or image clarity information; S66: moving the focus position of the first shooting module to a focus adjustment position.
[0068] In an embodiment of the present application, after adjusting the focus position of the first shooting module according to the acquired number of moving steps and moving direction to make it consistent with the first preset focus position corresponding to the target image scene, it also includes: obtaining image contrast or image clarity information at multiple adjacent positions of the focus position corresponding to the target image scene, and moving the focus position of the first shooting module to a focusing position corresponding to the maximum value of the image contrast or image clarity at multiple positions, thereby achieving fine-tuning of the first shooting module.
[0069] The method of the present application may also include three embodiments: First embodiment The present invention provides a focusing method, comprising the following steps: S110: Acquire a first image from a first camera and use it as a target image; S120: Acquire a second image from a second camera that is a distance away from the first camera, where the field of view of the second image covers the field of view of the first image; The optical axes of the first camera and the second camera are parallel; S130: Match the first image and the second image using image registration, and obtain the pixel coordinate position of the upper left corner vertex of the first image in the second image; The image registration algorithm is an image registration algorithm based on SIFT feature points; S140: Calculate a focus position corresponding to the first image scene by using a mapping relationship between a focus position of the first camera and a pixel coordinate position of an upper left corner vertex of the first image in the second image stored in the memory; S150: Calculating the number of steps and the moving direction required for the first camera to move from the current focus position to the focus position corresponding to the first image scene according to the focus position corresponding to the first image scene acquired in step S140; S160: adjusting the focus position of the first camera according to the acquired moving step number and moving direction so as to make it consistent with the focus position corresponding to the first image scene and complete focusing.
[0070] Second embodiment The present invention provides a focusing method. Figure 4-6 , the second embodiment comprises the following steps: S210: Acquire a partial image of a rectangular outline in the first image 211 from the first camera as the target image 213; The image coordinates of the upper left corner vertex 201 of the target image 213 in the first image 211 may be first pixel coordinates, that is, (x1, y1); S220: Acquire a second image 215 from a second camera that is a distance away from the first camera, where the field of view of the second image 215 covers the field of view of the first image 211; The optical axes of the first camera and the second camera are parallel; S230: applying an image transformation matrix to the target image 213, so that the transformed target image 223 and the overlapping field of view area 219 of the target image 213 and the second image 215 have the same image resolution; The image transformation matrix is a linear scaling matrix A, which satisfies: , wherein r1 represents the linear scaling ratio of the first image 211 or the second image 215 in the x direction, and r2 represents the linear scaling ratio of the first image 211 or the second image 215 in the y direction; The same image resolution means that the transformed target image 223, the overlapping field of view area 219 of the target image 213 and the second image 215 have the same image dimension, and the object field of view corresponding to the overlapping field of view area 219 of the transformed target image 223, the target image 213 and the second image 215 is consistent; S240: Match the transformed target image 223 after linear scaling with the second image 215 by using image registration, and obtain the pixel position of the upper left corner vertex 205 of the overlapping field of view area 219 in the second image 215, which may be a second pixel coordinate, i.e. (x2, y2); The image registration algorithm may be a template matching algorithm that uses a normalized correlation coefficient as a matching similarity criterion; S250: Perform image transformation on the first image 211 using the linear scaling matrix A, and obtain the pixel coordinates of the upper left corner vertex 207 of the transformed target image 223 in the transformed first image 221 after linear scaling, the pixel coordinates may be third pixel coordinates, i.e. (x1', y1'), and the third pixel coordinates (x1', y1') satisfy: x1'=r1*x1, y1'=r2*y1; S260: Calculate the pixel coordinates of the upper left corner vertex 207 of the transformed target image 223 in the transformed first image 221 and the pixel coordinates of the upper left corner vertex 205 of the overlapping field of view area 219 in the second image 215, and the pixel coordinates of the upper left corner vertex 203 of the first image 217 in the second image 215 in the second image 215. The pixel coordinates may be fourth pixel coordinates, i.e. (x3, y3). The fourth pixel coordinates (x3, y3) satisfy: x3=x2- x1'=x2- r1*x1, y3=y2- y1'=y2- r2*y1; S270: Calculate the focus position corresponding to the target image scene by using the mapping relationship between the focus position of the first camera stored in the memory and the pixel coordinates of the upper left corner vertex 203 of the first image 217 in the second image 215; S280: adjusting the focus position of the first camera according to the acquired focus position corresponding to the target image scene; The method for adjusting the focus position of the first camera includes two steps: a. calculating the number of moving steps and the moving direction required to adjust the focus position of the first camera according to the difference between the current focus position of the first camera and the focus position of the scene contained in the target image; b. adjusting the focus position of the first camera according to the number of moving steps and the moving direction so that it is consistent with the focus position corresponding to the target image scene and completes the focusing.
[0071] Third embodiment In this embodiment, the first several steps are consistent with S210 to S270 in the second embodiment, and the specific method of adjusting the focus position of the first camera according to the acquired focus position corresponding to the target image scene in step S280 includes the following steps: a. calculating the number of moving steps and the moving direction required to adjust the focus position of the first camera according to the difference between the current focus position of the first camera and the focus position corresponding to the target image scene; b. adjusting the focus position of the first camera to be consistent with the focus position corresponding to the target image scene in step S270 according to the number of moving steps and the moving method; c. continuing to obtain the image contrast at multiple adjacent positions of the focus position corresponding to the target image scene, and adjusting the focus position of the first camera to the position corresponding to the maximum value of the image contrast at the multiple positions; The step c specifically comprises continuing to move the first camera according to the moving method in the step a, and obtaining the contrast of the target image during the moving process. Figure 7 The diagram shows the relationship between the focus position of the first camera module and the contrast of the target image. If the moving direction of the first camera determined in step a is the positive direction of the x-axis, there are two situations: In case 1, the focus position of the target image acquired in steps S210 to S270 is on the left side of the actual focus position of the target image. Figure 7 In 301, the actual focus position of the target image is 303, the focus position of the acquired target image is 301, and the moving direction is rightward. At this time, if the first shooting module is continued to be adjusted in the moving direction, the image contrast value during the movement will first increase and then decrease; when it is detected that the image contrast value first increases and then decreases, it is necessary to stop moving the first shooting module in the direction and calculate the focus position of the first shooting module corresponding to the maximum image contrast value 303 during the movement, and then adjust the focus position of the first shooting module to the focus position of the first shooting module corresponding to 303 to complete the focusing; In case 2, the focus position of the target image obtained in steps S210 to S270 is on the right side of the actual focus position of the target image. Figure 7In 305, the actual focus position of the target image is 303, and the focus position of the acquired target image is 305. At this time, if the first shooting module is continued to be adjusted in the moving direction, the image contrast value during the movement will continue to decrease; when it is detected that the image contrast value continues to decrease, it is necessary to adjust the moving direction of the first shooting module and continue to move the first camera, and record the image contrast during the movement; when it is detected that the image contrast value has experienced a process of first rising and then falling, it is necessary to stop moving the first shooting module in the current direction and calculate the focus position of the first shooting module corresponding to the maximum image contrast 303 during the movement after the first shooting module turns, and then adjust the focus position of the first shooting module to the focus position of the first shooting module corresponding to 303 to complete the focusing; in this embodiment, the image contrast refers to the Sobel response of the image. Specifically, if the input image is recorded as , the image contrast C satisfies: In this embodiment, the focus position of the target image acquired in steps S210 to S270 is already close to the actual focus position of the target image, so it is only necessary to move the first shooting module a small number of steps near the focus position corresponding to the target image scene in step S270 to determine the actual focus position corresponding to the target image scene, thereby achieving fast focusing.
[0072] The following will be combined with the attached Figure 2 , an imaging device provided in an embodiment of the present application is described in detail. It should be noted that the attached Figure 2 An imaging device shown is used to execute the present application Figure 1 For the convenience of explanation, only the part related to the embodiment of the present application is shown. For the specific technical details not disclosed, please refer to the present application. Figure 1 The embodiment shown.
[0073] See also Figure 2 , 4 -8, Figure 2 is a schematic structural diagram of an imaging device provided in an embodiment of the present application, Figure 4 A schematic diagram of a first image and a target image position in the first image provided in an embodiment of the present application, Figure 5 A schematic diagram of the positions of the second image, the first image and the target image provided in the embodiment of the present application, Figure 6 A schematic diagram of the positions of a linearly scaled first image and a target image in the linearly scaled first image provided in an embodiment of the present application, Figure 7 This is a schematic diagram of a curve showing the relationship between the focus position of the first shooting module and the contrast of the target image provided in an embodiment of the present application. Figure 8 This is a schematic diagram of an interface of a touch display unit in an imaging device provided in an embodiment of the present application. Figure 2 ,4 -8, the device includes a first shooting module 401, a second shooting module 402, a first image acquisition module 403, a second image acquisition module 404, a first matching module 405, a first storage module 406, a first calculation module 407, a second calculation module 408, and a first adjustment module 409, and the distance between the second shooting module 402 and the first shooting module 401 is a first preset length; The first shooting module 401 and the second shooting module 402 are used to shoot images respectively; The first image acquisition module 403 is used to acquire a first image from the first shooting module, acquire a target image from the first image, and acquire a first pixel position of the target image in the first image, wherein the target image is the first image or a partial image in the first image; The second image acquisition module 404 is used to acquire a second image from the second shooting module, and the field of view of the second image covers the field of view of the first image; The first matching module 405 is used to match the target image with the second image through image registration to obtain a matching area in the target image that matches the second image, and obtain a pixel position of the matching area in the second image, which pixel position is a second pixel position; The first calculation module 407 is used to calculate the pixel position of the first image in the second image according to the first pixel position and the second pixel position, and the pixel position is the third pixel position; The first storage module 406 is used to store a mapping relationship between the third pixel position and the focus position of the first shooting module; The second calculation module 408 is used to obtain a mapping relationship between a focus position of the first shooting module and a third pixel position from the first storage module, and calculate and obtain a first preset focus position corresponding to the target image scene according to the mapping relationship and the third pixel position; The first adjustment module 409 is used to adjust the focus position of the first shooting module according to the first preset focus position corresponding to the target image scene.
[0074] In the embodiment of the present application, both the first shooting module 401 and the second shooting module 402 can be cameras.
[0075] In one possible implementation, the optical axis of the first shooting module 401 when shooting the first image and the optical axis of the second shooting module 402 when shooting the second image are arranged in parallel.
[0076] In one possible implementation, the optical axis of the first shooting module 401 and the optical axis of the second shooting module 402 are both fixed; or at least one of the optical axis of the first shooting module 401 and the optical axis of the second shooting module 402 is rotatable.
[0077] In the embodiment of the present application, the optical axis of the first shooting module 401 and the optical axis of the second shooting module 402 can be fixed, and the optical axis of the first shooting module 401 and the optical axis of the second shooting module 402 are ensured to be arranged in parallel. At least one of the optical axis of the first shooting module 401 and the optical axis of the second shooting module 402 can be rotated, and the optical axis of the first shooting module 401 and the optical axis of the second shooting module 402 can be adjusted to be arranged in parallel when the first shooting module 401 shoots the first image and the second shooting module 402 shoots the second image.
[0078] In the embodiment of the present application, the image resolution of the first image and the second image are both 1920 x 1080.
[0079] In one possible implementation, the first matching module 405 includes a first image transformation unit, which is used to perform image transformation on the target image through an image transformation matrix to obtain a target transformed image, so that the target transformed image and the overlapping field of view of the target image and the second image have the same image resolution; The first image matching unit is used to match the target transformed image with the second image through image registration to obtain a matching area in the target transformed image that matches the second image, and to obtain a second pixel position of the matching area in the second image.
[0080] In an embodiment of the present application, the first image transformation unit linearly scales the target image so that the target image and the overlapping field of view area between the target image and the second image have the same image pixel dimension, and the target image and the overlapping field of view area between the target image and the second image correspond to the same object field of view; the first image matching unit uses a template matching algorithm to match the linearly scaled target image with the second image.
[0081] In one possible implementation, the first calculation module 407 includes A first coordinate acquisition unit, used for acquiring a first pixel coordinate (x1, y1) of a first preset pixel point at a first preset position in the matching area in the first image; A second coordinate acquisition unit, used for acquiring a second pixel coordinate (x2, y2) of the first preset pixel point in the second image; A third coordinate acquisition unit, used for performing image transformation on the first image through an image transformation matrix to obtain a first transformed image, and obtaining a third pixel coordinate (x1', y1') of the first preset pixel point in the first transformed image; The fourth coordinate acquisition unit is used to calculate and acquire the fourth pixel coordinate (x3, y3) of the third pixel position according to the second pixel coordinate (x2, y2) and the third pixel coordinate (x1', y1'), where x3=x2-x1', y3=y2-y1'.
[0082] In one possible implementation, the image transformation matrix is a linear scaling matrix A, , wherein r1 represents the linear scaling ratio of the first image or the second image in the x direction, r2 represents the linear scaling ratio of the first image or the second image in the y direction, the third pixel coordinate (x1', y1') satisfies: x1'=r1*x1, y1'=r2*y1, and the fourth pixel coordinate (x3, y3) satisfies: x3=x2- x1'=x2- r1*x1, y3=y2- y1'=y2- r2*y1.
[0083] In the embodiment of the present application, the first coordinate acquisition unit obtains the coordinates of the upper left corner vertex in the first image, that is, the first pixel coordinates (x1, y1); the second coordinate acquisition unit obtains the pixel coordinates of the upper left corner vertex 205 of the target image after linear scaling in the second image, that is, the second pixel coordinates (x2, y2); the third coordinate acquisition unit calculates the pixel coordinates of the upper left corner vertex 207 of the target image in the first image after linear scaling, that is, the third pixel coordinates (x1', y1'); the fourth coordinate acquisition unit calculates the pixel coordinates of the upper left corner vertex of the first image in the second image, that is, the fourth pixel coordinates (x3, y3), according to the coordinates of the upper left corner vertex of the target image in the first image (x1, y1), the pixel coordinates of the upper left corner vertex of the target image in the second image (x2, y2), and the pixel coordinates of the upper left corner vertex of the target image in the first image after linear scaling (x1', y1'), x3=x2-x1', y3=y2-y1'. The second calculation module obtains the mapping relationship between the focus position of the first shooting module and the third pixel position from the first storage module, and obtains the first preset focus position corresponding to the target image scene according to the mapping relationship and the third pixel position. The movement calculation unit in the first adjustment module calculates the number of movement steps and the movement direction of the first shooting module from the current focus position to the first preset focus position corresponding to the target image scene according to the current focus position of the first shooting module and the focus position corresponding to the target image scene; the focus unit in the first adjustment module calculates the image contrast or clarity information at multiple adjacent positions corresponding to the focus position of the target image scene respectively, the focus unit obtains the maximum value of the image contrast or image clarity information from the multiple image contrast or image clarity information, obtains the focus position corresponding to the maximum value of the image contrast or image clarity information, and the focus unit moves the focus position of the first shooting module to the focus position to complete the focus.
[0084] In one possible implementation, the image registration algorithm is a template matching algorithm or a feature point matching algorithm.
[0085] In one possible implementation, the template matching algorithm uses normalized cross-correlation or normalized square difference as a matching similarity criterion.
[0086] In one possible implementation, the feature point matching algorithm is one of a feature point matching algorithm based on SIFT feature points, a feature point matching algorithm based on SURF feature points, or a feature point matching algorithm based on ORB feature points.
[0087] In one possible implementation, it further includes an input module; the first image acquisition module is used to detect and acquire the first pixel position through a target detection algorithm or receive the first pixel position sent by the input module.
[0088] In one possible implementation, the target detection algorithm is a deep learning target detection algorithm based on the YOLO series, a deep learning target detection algorithm based on the R-CNN series, a deep learning target detection algorithm based on Transformer, a traditional target detection algorithm based on Haar cascade classifier, or a traditional target detection algorithm based on DPM.
[0089] In one possible implementation, the target image is a rectangular image, the first pixel position of the target image in the first image is the pixel coordinate of the upper left corner vertex of the matching area in the first image, and the second pixel position of the matching area in the second image is the pixel coordinate of the upper left corner vertex of the matching area in the second image.
[0090] In one possible implementation, the first adjustment module 409 includes a first position acquisition unit, which is used to acquire the current focus position of the first shooting module; A movement calculation unit, used for calculating the number of movement steps and the movement direction required for the first shooting module to move from the current focus position to the first preset focus position according to the first preset focus position and the current focus position; The focusing unit is used to adjust the focusing position of the first shooting module to match a first preset focusing position corresponding to a target image scene according to the moving steps and the moving direction.
[0091] In one possible implementation, after the focusing unit adjusts the focus position of the first shooting module according to the moving steps and the moving direction to match the first preset focus position corresponding to the target image scene, it also includes: respectively calculating and obtaining multiple image contrasts or image clarity information at multiple positions adjacent to the first preset focus position; obtaining the maximum value of the image contrast or image clarity information from the multiple image contrasts or image clarity information, and obtaining the focusing position corresponding to the maximum value of the image contrast or image clarity information; and moving the focus position of the first shooting module to the focusing position.
[0092] In one possible implementation, the device further includes a display module, and the display module can display the first image and / or the second image.
[0093] In one possible implementation, the display module is a touch display module that can display at least the first image; the touch display module can sense a click or touch position on the first image and generate a target image position.
[0094] In the examples of this application, see Figure 8 The touch display module is used to display the first image 501 and the second image 503, and can sense the image pixel coordinates corresponding to the click position 507 of the user on the displayed first image. The imaging device can obtain the image pixel coordinates corresponding to the click position of the user on the first image displayed on the touch display unit, and use them as the coordinates of the upper left corner vertex of the target image in the first image, that is, the first pixel coordinates (x1, y1); in the embodiment of the present application, the target image 505 has a square outline with a side length of 400 x 400.
[0095] Those skilled in the art can clearly understand that the technical solutions of the embodiments of the present application can be implemented with the help of software and / or hardware. The "unit", "module" and "part" in this specification refer to software and / or hardware that can independently complete or cooperate with other components to complete specific functions, where the hardware can be, for example, a field programmable gate array (FPGA), an integrated circuit (IC), etc.
[0096] Each processing unit and / or module of the embodiments of the present application may be implemented by an analog circuit that implements the functions described in the embodiments of the present application, or may be implemented by software that executes the functions described in the embodiments of the present application.
[0097] See also Figure 3 , which shows a schematic diagram of the structure of an electronic device involved in an embodiment of the present application, the electronic device can be used to implement Figure 1 The method in the embodiment shown. Figure 3As shown, the electronic device 600 may include: at least one central processor 601 , at least one network interface 604 , a user interface 603 , a memory 605 , and at least one communication bus 602 .
[0098] The communication bus 602 is used to realize the connection and communication between these components.
[0099] The user interface 603 may include a display screen (Display) and a camera (Camera). The optional user interface 603 may also include a standard wired interface and a wireless interface.
[0100] The network interface 604 may optionally include a standard wired interface or a wireless interface (such as a WI-FI interface).
[0101] Among them, the central processing unit 601 may include one or more processing cores. The central processing unit 601 uses various interfaces and lines to connect various parts of the entire electronic device 600, and executes various functions and processes data of the terminal 600 by running or executing instructions, programs, code sets or instruction sets stored in the memory 605, and calling data stored in the memory 605. Optionally, the central processing unit 601 can be implemented in at least one hardware form of digital signal processing (Digital Signal Processing, DSP), field programmable gate array (Field-Programmable Gate Array, FPGA), and programmable logic array (Programmable Logic Array, PLA). The central processing unit 601 can integrate one or a combination of a central processing unit (Central Processing Unit, CPU), a graphics processing unit (Graphics Processing Unit, GPU) and a modem. Among them, the CPU mainly processes the operating system, user interface and application programs; the GPU is responsible for rendering and drawing the content to be displayed on the display screen; and the modem is used to process wireless communications. It can be understood that the above-mentioned modem may not be integrated into the central processing unit 601, and can be implemented separately through a chip.
[0102] Among them, the memory 605 may include a random access memory (Random Access Memory, RAM) and may also include a read-only memory (Read-Only Memory). Optionally, the memory 605 includes a non-transitory computer-readable storage medium. The memory 605 can be used to store instructions, programs, codes, code sets or instruction sets. The memory 605 may include a program storage area and a data storage area, wherein the program storage area may store instructions for implementing an operating system, instructions for at least one function (such as a touch function, a sound playback function, an image playback function, etc.), instructions for implementing the above-mentioned various method embodiments, etc.; the data storage area may store data involved in the above-mentioned various method embodiments, etc. The memory 605 may optionally be at least one storage device located away from the aforementioned central processor 601. As Figure 3 As shown, the memory 605 as a computer storage medium may include an operating system, a network communication module, a user interface module, and program instructions.
[0103] exist Figure 3 In the electronic device 600 shown, the user interface 603 is mainly used to provide an input interface for the user and obtain data input by the user; and the central processor 601 can be used to call an application of a focusing method stored in the memory 605, and specifically perform the following operations: S1: Acquire a first image from a first shooting module, acquire a target image from the first image, and acquire a first pixel position of the target image in the first image, wherein the target image is the first image or a partial image in the first image; S2: Acquire a second image from a second shooting module that is a first preset length away from the first shooting module, wherein the field of view of the second image covers the field of view of the first image; S3: Matching the target image with the second image through image registration to obtain a matching area in the target image that matches the second image, and obtaining a second pixel position of the matching area in the second image; S4: Calculating a third pixel position of the first image in the second image according to the first pixel position and the second pixel position; S5: Acquire a mapping relationship between the third pixel position and the focus position of the first shooting module, and calculate and acquire a first preset focus position corresponding to the target image scene according to the mapping relationship and the third pixel position; S6: adjusting the focus position of the first shooting module according to a first preset focus position corresponding to the target image scene.
[0104] The present application also provides a computer-readable storage medium on which a computer program is stored, and when the program is executed by a processor, the steps of the above method are implemented. The computer-readable storage medium may include, but is not limited to, any type of disk, including a floppy disk, an optical disk, a DVD, a CD-ROM, a micro drive, and a magneto-optical disk, a ROM, a RAM, an EPROM, an EEPROM, a DRAM, a VRAM, a flash memory device, a magnetic card or an optical card, a nanosystem (including a molecular memory IC), or any type of medium or device suitable for storing instructions and / or data.
[0105] It should be noted that, for the aforementioned method embodiments, for the sake of simplicity, they are all expressed as a series of action combinations, but those skilled in the art should be aware that the present application is not limited by the described order of actions, because according to the present application, certain steps can be performed in other orders or simultaneously. Secondly, those skilled in the art should also be aware that the embodiments described in the specification are all preferred embodiments, and the actions and modules involved are not necessarily required by the present application.
[0106] In the above embodiments, the description of each embodiment has its own emphasis. For parts that are not described in detail in a certain embodiment, reference can be made to the relevant descriptions of other embodiments.
[0107] In the several embodiments provided in the present application, it should be understood that the disclosed devices can be implemented in other ways. For example, the device embodiments described above are only schematic, such as the division of the modules or units, which is only a logical function division. There may be other division methods in actual implementation, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some service interfaces, and the indirect coupling or communication connection of the devices or units can be electrical or other forms.
[0108] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0109] In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of software functional units.
[0110] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable memory. Based on this understanding, the technical solution of the present application, or the part that contributes to the prior art, or all or part of the technical solution can be embodied in the form of a software product. The computer software product is stored in a memory, including a number of instructions to enable a computer device (which can be a personal computer, server or network device, etc.) to execute all or part of the steps of the method described in each embodiment of the present application. The aforementioned memory includes: U disk, read-only memory (ROM), random access memory (RAM), mobile hard disk, disk or optical disk and other media that can store program codes.
[0111] A person skilled in the art may understand that all or part of the steps in the various methods of the above embodiments may be completed by entering a program to instruct related hardware. The program may be stored in a computer-readable memory, and the memory may include: a flash drive, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk, etc.
[0112] The above is only an exemplary embodiment of the present disclosure, and the scope of the present disclosure cannot be limited thereto. That is, any equivalent changes and modifications made according to the teachings of the present disclosure are still within the scope of the present disclosure. After considering the specification and practicing the disclosure here, those skilled in the art will easily think of the implementation scheme of the present disclosure. This application is intended to cover any modification, use or adaptation of the present disclosure, which follows the general principles of the present disclosure and includes common knowledge or customary technical means in the technical field not recorded in the present disclosure. The description and examples are regarded as exemplary only, and the scope and spirit of the present disclosure are defined by the claims.
Claims
1. A focusing method, characterized in that: The steps include: S1: Acquire a first image from a first shooting module, acquire a target image from the first image, and acquire a first pixel position of the target image in the first image, wherein the target image is the first image or a partial image in the first image; S2: Acquire a second image from a second shooting module that is a first preset length away from the first shooting module, wherein the field of view of the second image covers the field of view of the first image; S3: Matching the target image with the second image through image registration to obtain a matching area in the target image that matches the second image, and obtaining a second pixel position of the matching area in the second image; S4: Calculating a third pixel position of the first image in the second image according to the first pixel position and the second pixel position; S5: Acquire a mapping relationship between the third pixel position and the focus position of the first shooting module, and calculate and acquire a first preset focus position corresponding to the target image scene according to the mapping relationship and the third pixel position; S6: adjusting the focus position of the first shooting module according to a first preset focus position corresponding to the target image scene.
2. A focusing method according to claim 1, characterized in that: The optical axis of the first shooting module when shooting the first image is parallel to the optical axis of the second shooting module when shooting the second image.
3. A focusing method as claimed in claim 2, characterized in that: The optical axis of the first shooting module and the optical axis of the second shooting module are both fixed; or at least one of the optical axis of the first shooting module and the optical axis of the second shooting module is rotatable.
4. A focusing method as claimed in claim 1, 2 or 3, characterized in that: Before matching the target image with the second image through image registration, step S3 includes: performing distortion correction on at least one of the first image and the second image.
5. A focusing method as claimed in claim 1, 2 or 3, characterized in that: Step S3 specifically includes: S31: performing image transformation on the target image through an image transformation matrix to obtain a target transformed image, so that the target transformed image and the overlapping field of view of the target image and the second image have the same image resolution; S32: Matching the target transformed image with the second image through image registration to obtain a matching area in the target transformed image that matches the second image, and obtaining a second pixel position of the matching area in the second image.
6. A focusing method as claimed in claim 5, characterized in that: Step S4 specifically includes: S41: Obtaining a first pixel coordinate (x1, y1) of a first preset pixel point at a first preset position in the matching area in the first image; S42: Obtain a second pixel coordinate (x2, y2) of the first preset pixel point in the second image; S43: performing image transformation on the first image by using an image transformation matrix to obtain a first transformed image, and obtaining a third pixel coordinate (x1′, y1′) of the first preset pixel point in the first transformed image; S44: Calculate and obtain the fourth pixel coordinate (x3, y3) of the third pixel position according to the second pixel coordinate (x2, y2) and the third pixel coordinate (x1', y1'), where x3=x2-x1', y3=y2-y1'.
7. A focusing method according to claim 6, characterized in that: The image transformation matrix is a linear scaling matrix A, , wherein r1 represents the linear scaling ratio of the first image or the second image in the x direction, r2 represents the linear scaling ratio of the first image or the second image in the y direction, the third pixel coordinate (x1', y1') in step S43 satisfies: x1'=r1*x1, y1'=r2*y1, and the fourth pixel coordinate (x3, y3) in step S44 satisfies: x3=x2- x1'=x2- r1*x1, y3=y2- y1'=y2- r2*y1.
8. A focusing method as claimed in claim 1, 2 or 3, characterized in that: The image registration algorithm is a template matching algorithm or a feature point matching algorithm.
9. A focusing method as claimed in claim 8, characterized in that: The template matching algorithm uses normalized cross-correlation or normalized square difference as a matching similarity criterion.
10. A focusing method according to claim 8, characterized in that: The feature point matching algorithm is one of a feature point matching algorithm based on SIFT feature points, a feature point matching algorithm based on SURF feature points, or a feature point matching algorithm based on ORB feature points.
11. A focusing method according to claim 1, 2 or 3, characterized in that: Acquiring the first pixel position of the target image in the first image in step S1 specifically includes: acquiring the first pixel position through detection by a target detection algorithm or receiving the first pixel position sent by an input module.
12. A focusing method according to claim 11, characterized in that: The target detection algorithm is one of a deep learning target detection algorithm based on the YOLO series, a deep learning target detection algorithm based on the R-CNN series, a deep learning target detection algorithm based on the Transformer, a traditional target detection algorithm based on the Haar cascade classifier, or a traditional target detection algorithm based on the DPM.
13. A focusing method according to claim 1, 2 or 3, characterized in that: The target image is a rectangular image, the first pixel position of the target image in the first image is the pixel coordinate of the upper left corner vertex of the matching area in the first image, and the second pixel position of the matching area in the second image is the pixel coordinate of the upper left corner vertex of the matching area in the second image.
14. A focusing method according to claim 1, 2 or 3, characterized in that: Step S6 specifically includes: S61: Acquire the current focus position of the first shooting module; S62: Calculating and acquiring the number of steps and the moving direction required for the first shooting module to move from the current focusing position to the first preset focusing position according to the first preset focusing position and the current focusing position; S63: adjusting the focus position of the first shooting module according to the moving step number and the moving direction to match a first preset focus position corresponding to the target image scene.
15. A focusing method according to claim 14, characterized in that: After step S63, the following steps are also included: S64: respectively calculating and acquiring a plurality of image contrast or image clarity information at a plurality of positions adjacent to the first preset focus position; S65: Obtaining a maximum value of image contrast or image clarity information from multiple pieces of image contrast or image clarity information, and obtaining a focus position corresponding to the maximum value of the image contrast or image clarity information; S66: moving the focus position of the first shooting module to a focus adjustment position.
16. An imaging device, characterized in that: It includes a first shooting module, a second shooting module, a first image acquisition module, a second image acquisition module, a first matching module, a first storage module, a first calculation module, a second calculation module, and a first adjustment module, wherein the distance between the second shooting module and the first shooting module is a first preset length; The first shooting module and the second shooting module are used to shoot images respectively; The first image acquisition module is used to acquire a first image from the first shooting module, acquire a target image from the first image, and acquire a first pixel position of the target image in the first image, wherein the target image is the first image or a partial image in the first image; The second image acquisition module is used to acquire a second image from the second shooting module, and the field of view of the second image covers the field of view of the first image; The first matching module is used to match the target image with the second image through image registration to obtain a matching area in the target image that matches the second image, and to obtain a second pixel position of the matching area in the second image; The first calculation module is used to calculate a third pixel position of the first image in the second image according to the first pixel position and the second pixel position; The first storage module is used to store a mapping relationship between the third pixel position and the focus position of the first shooting module; The second calculation module is used to obtain a mapping relationship between a focus position of the first shooting module and a third pixel position from the first storage module, and calculate and obtain a first preset focus position corresponding to the target image scene according to the mapping relationship and the third pixel position; The first adjustment module is used to adjust the focus position of the first shooting module according to a first preset focus position corresponding to the target image scene.
17. An imaging device as claimed in claim 16, characterized in that: The optical axis of the first shooting module when shooting the first image is parallel to the optical axis of the second shooting module when shooting the second image.
18. An imaging device as claimed in claim 17, characterized in that: The optical axis of the first shooting module and the optical axis of the second shooting module are both fixed; or at least one of the optical axis of the first shooting module and the optical axis of the second shooting module is rotatable.
19. An imaging device as claimed in claim 16, 17 or 18, characterized in that: The first matching module includes a first image transformation unit, which is used to perform image transformation on the target image through an image transformation matrix to obtain a target transformed image, so that the target transformed image and the overlapping field of view of the target image and the second image have the same image resolution; The first image matching unit is used to match the target transformed image with the second image through image registration to obtain a matching area in the target transformed image that matches the second image, and to obtain a second pixel position of the matching area in the second image.
20. An imaging device as claimed in claim 19, characterized in that: The first calculation module includes A first coordinate acquisition unit, used for acquiring a first pixel coordinate (x1, y1) of a first preset pixel point at a first preset position in the matching area in the first image; A second coordinate acquisition unit, used for acquiring a second pixel coordinate (x2, y2) of the first preset pixel point in the second image; A third coordinate acquisition unit, used for performing image transformation on the first image through an image transformation matrix to obtain a first transformed image, and obtaining a third pixel coordinate (x1', y1') of the first preset pixel point in the first transformed image; The fourth coordinate acquisition unit is used to calculate and acquire the fourth pixel coordinate (x3, y3) of the third pixel position according to the second pixel coordinate (x2, y2) and the third pixel coordinate (x1', y1'), where x3=x2-x1', y3=y2-y1'.
21. An imaging device as claimed in claim 20, characterized in that: The image transformation matrix is a linear scaling matrix A, , wherein r1 represents the linear scaling ratio of the first image or the second image in the x direction, r2 represents the linear scaling ratio of the first image or the second image in the y direction, the third pixel coordinate (x1', y1') satisfies: x1'=r1*x1, y1'=r2*y1, and the fourth pixel coordinate (x3, y3) satisfies: x3=x2- x1'=x2- r1*x1, y3=y2- y1'=y2- r2*y1.
22. An imaging device as claimed in claim 16, 17 or 18, characterized in that: The image registration algorithm is a template matching algorithm or a feature point matching algorithm.
23. An imaging device as claimed in claim 22, characterized in that: The template matching algorithm uses normalized cross-correlation or normalized square difference as a matching similarity criterion.
24. An imaging device as claimed in claim 22, characterized in that: The feature point matching algorithm is one of a feature point matching algorithm based on SIFT feature points, a feature point matching algorithm based on SURF feature points, or a feature point matching algorithm based on ORB feature points.
25. An imaging device according to claim 16, 17 or 18, characterized in that: It also includes an input module; the first image acquisition module is used to detect and acquire the first pixel position through a target detection algorithm or receive the first pixel position sent by the input module.
26. An imaging device as claimed in claim 25, characterized in that: The target detection algorithm is one of a deep learning target detection algorithm based on the YOLO series, a deep learning target detection algorithm based on the R-CNN series, a deep learning target detection algorithm based on the Transformer, a traditional target detection algorithm based on the Haar cascade classifier, or a traditional target detection algorithm based on the DPM.
27. An imaging device according to claim 16, 17 or 18, characterized in that: The target image is a rectangular image, the first pixel position of the target image in the first image is the pixel coordinate of the upper left corner vertex of the matching area in the first image, and the second pixel position of the matching area in the second image is the pixel coordinate of the upper left corner vertex of the matching area in the second image.
28. An imaging device as claimed in claim 16, 17 or 18, characterized in that: The first adjustment module includes a first position acquisition unit, which is used to acquire the current focus position of the first shooting module; A movement calculation unit, used for calculating the number of movement steps and the movement direction required for the first shooting module to move from the current focus position to the first preset focus position according to the first preset focus position and the current focus position; The focusing unit is used to adjust the focusing position of the first shooting module to match a first preset focusing position corresponding to a target image scene according to the moving steps and the moving direction.
29. An imaging device as claimed in claim 28, characterized in that: After the focusing unit adjusts the focus position of the first shooting module to match the first preset focus position corresponding to the target image scene according to the moving steps and the moving direction, the method further includes: respectively calculating and obtaining multiple image contrasts or image clarity information at multiple positions adjacent to the first preset focus position; obtaining the maximum value of the image contrast or image clarity information from the multiple image contrasts or image clarity information, and obtaining the focus position corresponding to the maximum value of the image contrast or image clarity information; and moving the focus position of the first shooting module to the focus position.
30. An imaging device according to claim 16, 17 or 18, characterized in that: A display module is also included, and the display module can display the first image and / or the second image.
31. An imaging device as claimed in claim 30, characterized in that: The display module is a touch display module that can display at least a first image; the touch display module can sense a click or touch position on the first image and generate a target image position.
32. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the computer program, the steps of the method according to any one of claims 1 to 15 are implemented.
33. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 15 are implemented.
Citation Information
Patent Citations
Focusing method and device of camera module
CN115734076A
Focusing method and electronic equipment
CN117135450A
Camera focusing method and device, electronic equipment and computer readable storage medium
CN117156269A
Imaging device and focus control program
CN117546475A
Automatic focusing method and system based on binocular parallax approximate matching
CN118338123A
Cited By
Focusing method and imaging device
WO2026124471A1