Automatic focusing method of imaging device and exterior mirror system
The distance detection module determines the focus search range and acquisition step length of the imaging device, and searches the focus position within this range, solving the problem of focus failure or inefficiency in the prior art, and achieving efficient and accurate automatic focus.
Patent Information
- Application Number
- CN202411928876.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-25
- Publication Date
- 2025-03-18
AI Technical Summary
In the prior art, imaging devices are prone to failure in focus or low focus efficiency, especially when the depth of field is small or the image contrast curve is high.
The distance detection module obtains the working distance between the zoom lens and the imaging target, determines the focus search range and image acquisition step, and searches for the focus position within the focus search range. The specific steps include: initially locking the focus search range, adjusting the endpoint of the lens to the search range, traversing the search range in one direction, collecting images and calculating clarity, and updating the acquisition step size according to the clarity changes until the focus position is found.
Improves focus efficiency and accuracy, and reduces the possibility of focus failure, especially when the depth of field is shallow or the image contrast curve is high.
Smart Images

Figure CN119644540A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of medical devices, and in particular to an automatic focusing method of an imaging device and an external mirror system. Background Art
[0002] Focusing refers to the process of adjusting the lens so that the image can be clearly formed on the image receiving surface (such as the camera's photosensitive surface). The autofocus in the prior art usually controls the movement of the lens in a certain step length and gradually collects images, and then calculates the image contrast or contrast to measure the image clarity. The greater the clarity, the clearer the image. The lens position with the clearest image corresponds to the focus position.
[0003] The defects of this method are: 1. A lot of time is wasted in the process of locking the "peak area". Since the "clarity-focal length" curve is not an ideal bell-shaped curve, there may be noise data in the calculation of clarity, and the focusing process may also fall into a local optimum in the "peak bottom area"; 2. In some usage scenarios, the depth of field is small (for example, when the magnification is large and the working distance is close), and the "clarity-focal length" curve of the image has a high kurtosis, that is, there is a sharp peak. During the objective lens adjustment process, the focal length can easily "cross" the peak, resulting in focusing failure, or the objective lens needs to be repeatedly adjusted to search for the clearest position of the image. The focusing process is inefficient.
[0004] In view of the defects of the imaging device in the prior art that it is easy to fail to focus or the focusing efficiency is low, the present invention provides an automatic focusing method for an imaging device and an exterior mirror system. Summary of the invention
[0005] The present invention provides an automatic focusing method for an imaging device and an external mirror system, which are used to solve or at least partially solve the defects of easy focusing failure or low focusing efficiency in the prior art, and realize efficient and accurate focusing.
[0006] The present invention provides an automatic focusing method for an imaging device, comprising:
[0007] The working distance between the variable focus lens and the imaging target is obtained through the distance detection module;
[0008] Determining a focus search range of the variable focus lens according to the working distance, and determining an image acquisition step length according to the working distance and a current focus clarity;
[0009] The variable focus lens is adjusted according to the image acquisition step length, and a focus position is searched within the focus search range.
[0010] According to an automatic focusing method for an imaging device provided by the present invention, the focusing search range of the variable focus lens according to the working distance includes:
[0011] Taking the working distance as the center, determining the distance range of the target object according to the detection error of the distance detection module;
[0012] The focus search range that the focus of the variable-focus lens needs to traverse is determined according to the distance range of the target object.
[0013] According to an automatic focusing method for an imaging device provided by the present invention, the distance range of the target object is:
[0014] L-δ~L+δ; where L is the measured working distance and δ is the detection error.
[0015] According to an automatic focusing method for an imaging device provided by the present invention, before adjusting the variable focus lens according to the image acquisition step length and searching for a focus position within the focus search range, the method further includes:
[0016] The focus of the variable-focus lens is adjusted to one of the two end points of the focus search range that is closer to the initial focus position of the variable-focus lens, so as to traverse the focus search range in one direction.
[0017] According to an automatic focusing method of an imaging device provided by the present invention, in the process of unidirectional traversal of the focus search range, an image is first acquired with the image acquisition step length and a first clarity is calculated; if a change value of the first clarity of a current frame image relative to a previous frame image exceeds a preset threshold, the image acquisition step length is updated, and an image is acquired with the updated acquisition step length; a second clarity is calculated for all images acquired with the updated image acquisition step length, and a focus position is determined according to the second clarity of each image.
[0018] According to an automatic focusing method for an imaging device provided by the present invention, the updating of the image acquisition step size comprises:
[0019] Based on the image acquisition step size, it is reset according to a preset ratio; wherein the preset ratio is less than 1.
[0020] According to an autofocus method for an imaging device provided by the present invention, the first clarity is obtained by calculating the entire captured image, and the second clarity is obtained by: extracting the target object in the image or extracting the area containing the target object; calculating the second clarity of the target object in the image or the area containing the target object.
[0021] According to an automatic focusing method for an imaging device provided by the present invention, searching for a focus position within the focus search range comprises:
[0022] In the process of focusing within the focus search range, capturing images according to the image capture step length and calculating a first clarity;
[0023] According to the first clarity of the current frame image and the first m frames of images before it, the third clarity of the current frame image is obtained by averaging; wherein m≥2;
[0024] Determine whether the focus position has been passed according to the first definition and the third definition of each image, and / or determine whether the focus direction needs to be changed.
[0025] According to an automatic focusing method of an imaging device provided by the present invention, the determining whether the focusing position has been passed according to the first clarity and the third clarity of each image, and / or determining whether the focusing direction needs to be changed includes:
[0026] If the third definition of the current frame image is greater than or equal to the third definition of the previous frame image, continue to focus along the current direction;
[0027] If the third definition of the current frame image is smaller than the third definition of the previous frame image, the current focus direction is changed until the third definition of the image no longer increases.
[0028] According to an automatic focusing method of an imaging device provided by the present invention, determining whether a focus position has been passed according to a first definition and a third definition of each image, and / or determining whether a focus direction needs to be changed, comprises:
[0029] If the third definition of the n consecutive frames of images increases first and then decreases, the position with the maximum first definition in the n consecutive frames of images is used as the focus position; wherein n≥3;
[0030] If the third definition of the consecutive n frames of images increases, continue to focus along the current direction;
[0031] If the third definition of the consecutive n frames of images decreases, the current direction focus is continuously changed.
[0032] According to an automatic focusing method of an imaging device provided by the present invention, determining whether a focus position has been passed according to a first definition and a second definition of each image, and / or determining whether a focus direction needs to be changed, comprises:
[0033] If the ratio of the variance to the average value of the third definition of the n consecutive frames of images is less than a set threshold, it is determined that the n frames of images have passed the focus position, and the position with the largest first definition in the n frames of images is used as the focus position; wherein n≥3;
[0034] If the ratio of the variance to the average value of the third clarity of n consecutive frames of images is greater than or equal to a set threshold, further judgment is made: if the third clarity of n consecutive frames of images decreases, or the focus position is not found after reaching the boundary of the focus search range, the focus direction is changed; otherwise, the current focus direction is maintained.
[0035] According to an automatic focusing method for an imaging device provided by the present invention, during focusing within the focus search range, the initialization focus direction is to focus toward the center of the focus search range.
[0036] According to an automatic focusing method for an imaging device provided by the present invention, the first definition is obtained by the following formula:
[0037]
[0038] Among them, M is the number of pixels in the x-coordinate direction of the image, N is the number of coordinates in the y-coordinate direction, and G x (x,y),G y (x, y) are the gradients of the pixel in the x and y directions respectively.
[0039] According to an automatic focusing method for an imaging device provided by the present invention, the first clarity is calculated according to the following formula:
[0040]
[0041] Among them, Pi is the probability of occurrence of a pixel with gray value i in the image, and L is the total number of gray levels.
[0042] According to an automatic focusing method for an imaging device provided by the present invention, the first clarity is calculated for a region of interest in a captured image.
[0043] The present invention also provides an imaging device, comprising:
[0044] An imaging module, wherein the imaging module comprises a variable-focus lens;
[0045] A distance detection module, used to detect the distance between the variable focus lens and the imaging target;
[0046] A processing module, wherein the processing module is used to execute any of the above-mentioned automatic focusing methods for an imaging device and adjust the variable focus lens.
[0047] According to an imaging device provided by the present invention, the variable focus lens comprises a fixed front objective lens and an adjustable zoom objective lens group;
[0048] The distance between the front objective lens and the imaging target is the working distance;
[0049] The zoom objective lens group includes at least two lens components.
[0050] According to an imaging device provided by the present invention, the imaging device further includes an adjusting component, and the processing module controls the movement of the lens component through the adjusting component.
[0051] According to an imaging device provided by the present invention, the distance detection module is selected from at least one of a laser distance measuring unit, an ultrasonic distance measuring unit, and an infrared distance measuring unit.
[0052] The present invention also provides an exterior mirror system, comprising any of the aforementioned imaging devices and a lighting module, a display module, and a mechanical arm or a balancing arm.
[0053] The automatic focusing method of an imaging device and an exterior mirror system provided by the present invention have at least the following beneficial effects:
[0054] 1. The distance detection module measures the working distance between the zoom lens and the imaging target, preliminarily locks the focus search range, reduces the time spent on focusing outside the focus search range, and improves the focus efficiency;
[0055] 2. According to the measured working distance and the current focus clarity, the appropriate focus step size is set, so that the focus process can cover the "peak position" of the image clarity, avoiding the step size being too large and directly crossing the "peak", improving the focus success rate and focus accuracy in situations such as shallow depth of field and high peak of image contrast curve, and avoiding limiting the autofocus efficiency due to too small step size;
[0056] 3. The zoom lens includes a zoom objective lens, which includes a fixed lens and a moving lens. During the focusing process, the working distance can be kept constant. The zoom objective lens can be adjusted by adjusting the components to achieve higher focusing accuracy.
[0057] 4. The clarity status of a single frame image is obtained by calculating the first clarity of the image collected within the focus search range. The second clarity is calculated to more accurately reflect the clarity change trend during the focusing process. In combination with specific focusing strategies, more accurate and efficient autofocus is achieved.
[0058] 5. Based on the second clarity of n consecutive frames of images, the peak position is accurately identified by calculating the variance and average value, avoiding the interference of "pseudo peak" and improving the focusing accuracy. BRIEF DESCRIPTION OF THE DRAWINGS
[0059] In order to more clearly illustrate the technical solutions in the present invention or the prior art, the following briefly introduces the drawings required for use in the embodiments or the description of the prior art. Obviously, the drawings described below are some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0060] Figure 1 The present invention is a flowchart of an automatic focusing method for an imaging device provided by the present invention. DETAILED DESCRIPTION
[0061] In order to make the purpose, technical solution and advantages of the present invention clearer, the technical solution of the present invention will be clearly and completely described below in conjunction with the drawings of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0062] like Figure 1 As shown, the present invention provides an automatic focusing method for an imaging device, comprising:
[0063] S11, obtaining a working distance between the zoom lens and the imaging target through a distance detection module;
[0064] S12, determining a focus search range of the variable focus lens according to the working distance, and determining an image acquisition step length according to the working distance and a current focus clarity;
[0065] S13, adjusting the variable focus lens according to the focusing step length, and searching for a focus position within the focusing search range.
[0066] Specifically, the imaging device is such as an external mirror, a microscope, etc., and the imaging device is equipped with a distance detection module for measuring and calculating the working distance between the zoom lens (front end) and the imaging target. The distance detection module is such as an ultrasonic distance detection module, an infrared distance detection module, a laser distance detection module, etc. In the optical field, the working distance refers to the distance between the front end face of the imaging device lens and the imaging target. The front end of the conventional imaging device is an object lens, and the working distance is the distance between the object lens and the imaging target. Of course, a window can also be set in front of the object lens. At this time, the working distance is the distance between the window and the imaging target. It is understandable that when the distance detection module is flush with the front end face of the lens, the distance measured by the distance detection module is the working distance. When the distance detection module is not flush with the front end face of the lens, it is also necessary to convert and calculate the working distance based on the measured distance in combination with the positional relationship between the distance detection module and the front end face of the lens.
[0067] The working distance can be used to determine the object distance (u), and combined with the internal parameters of the imaging device, the possible range of focus in the case of clear imaging (i.e., the focus search range of the zoom lens) can be determined. It can be understood that when the focus is within this range, the collected image has a certain clarity basis, and the focusing process only needs to find the clearest position of the image within this range.
[0068] The measured working distance is also used to determine the appropriate image acquisition step length. Specifically, the size of the working distance will indirectly affect the size of the depth of field, and the size of the depth of field will in turn affect the selection of the image acquisition step length. Specifically, the smaller the working distance, the smaller the depth of field, the more sensitive the clarity is to the change of the focal length, and the smaller the image acquisition step length is required to avoid missing the focus position. The current focus clarity also affects the selection of the image acquisition step length. For example, if the current focus clarity is higher, the closer to the focus position, the smaller the image acquisition step length is required. Of course, the focusing sensitivity is also related to the current magnification and aperture size of the imaging device, and the image acquisition step length can be further combined with these parameters to set the image acquisition step length. The relationship between the working distance and the image acquisition step length can be pre-calibrated. After the calibration is completed, the image acquisition step length can be quickly determined according to the calibration relationship during the actual autofocus process. During the focusing process, parameters such as the magnification and aperture size can be fixed or adjustable, that is, after these parameters are adjusted, a new stage of focusing is entered. After determining the focus search range according to the working distance and determining the image acquisition step length in combination with the current focus clarity, the lens can be adjusted to search for the focus position with the highest clarity within the focus search range. In addition, the image acquisition step length can be adjusted by adjusting the moving speed of the objective lens (or zoom objective lens) and / or the image sampling frequency, which together determine the image acquisition step length.
[0069] The present invention measures the working distance between the lens and the imaging target through a distance detection module, preliminarily locks the focus search range, avoids invalid focusing outside the focus search range, and improves the focus efficiency; the working distance is also used to set a suitable image acquisition step length in combination with the current focus clarity, so that the focusing process can cover the "peak position" of the image clarity, avoids directly crossing the "peak" due to a large step length, improves the focus success rate for situations such as a shallow depth of field and a high peak of the image contrast curve, and avoids limiting the automatic focusing efficiency due to a small step length.
[0070] Based on any embodiment, in one embodiment, determining the focus search range of the variable focus lens according to the working distance includes:
[0071] Taking the working distance as the center, determining the distance range of the target object according to the detection error of the distance detection module;
[0072] The focus search range that the focus of the variable-focus lens needs to traverse is determined according to the distance range of the target object.
[0073] Specifically, the distance detection module measures the physical distance between the lens (front end) and the target object. Combined with the detection error of the distance detection module, the target object's location can be initially locked to avoid the distance measurement error causing an incomplete search range, resulting in a focus failure. Further, the focus search range of the lens can be determined in combination with the correspondence between the position of the target object and the quasi-focus focal length. The imaging device also determines the image acquisition step length based on the working distance. For example, the correspondence between the working distance and the image acquisition step length is pre-calibrated. After the calibration is completed, the image acquisition step length can be quickly determined based on the calibration relationship during the actual autofocus process.
[0074] Based on any embodiment, in one embodiment, the distance range of the target object is:
[0075] L-δ~L+δ; where L is the measured working distance and δ is the detection error.
[0076] Specifically, based on the measured working distance, the range of the target object is preliminarily locked according to the detection error of the distance detection module to avoid the incomplete search range caused by the ranging error, resulting in focusing failure.
[0077] Based on any one of the embodiments, in one embodiment, determining the focus search range required to traverse the focus of the lens according to the distance range of the target object includes:
[0078] An extended depth of field range is obtained based on the distance range of the target object;
[0079] According to the extended depth of field range, a focus search range that the focus of the lens needs to traverse is determined.
[0080] Specifically, the measured working distance is L, the measurement error of the distance detection module is δ, and the distance range of the target object is L±δ. When the clear imaging position falls on L-δ, its depth of field range is DOF(L-δ), and when the clear imaging position falls on L+δ, its depth of field is DOF(L+δ). A certain depth of field range is expanded on the basis of the distance range of the target object. For example, the expanded depth of field range is: L-δ-1 / 2DOF(L-δ)~L+δ+1 / 2DOF(L+δ). By adjusting the focus so that the clear imaging position falls within the expanded depth of field range, the location of the target object can be accurately covered, and the process of the target object's clarity change can be fully observed.
[0081] Based on any of the embodiments, in one embodiment, before adjusting the variable focus lens according to the image acquisition step length and searching for a focus position within a focus search range, the method further includes:
[0082] The focus of the variable-focus lens is adjusted to one of the two end points of the focus search range that is closer to the initial focus position of the variable-focus lens, so as to traverse the focus search range in one direction.
[0083] Specifically, since the focus search range is locked by the distance detection module, the variable focus lens can be quickly adjusted so that its focus reaches the end point position of the focus search range, and there is no need to waste time on "invalid focus" outside the focus search range. It can be understood that in the process of adjusting the focus to reach the end point of the focus search range close to the initial focus position, the adjustment speed of the variable focus lens can be faster, and there is no need to capture images during this adjustment process to improve the efficiency of autofocus. After the adjustment reaches the end point position, a one-way traversal is performed from the end point to the other end of the focus search range, and the variable focus lens is adjusted according to the aforementioned image capture step size and the image is captured to search for the focus position, so as to avoid repeatedly adjusting the focus direction within the focus search range. The autofocus process is concise and accurate.
[0084] Based on the previous embodiment, in the process of traversing the focus search range in one direction, the focus position is searched by comparing the clarity frame by frame. It can be understood that if the image clarity increases during the search process, the focus is continued in the current direction to search for the focus position; if the image clarity decreases, it means that the focus position has been passed, and the position with the largest image clarity in the previous focusing process is used as the focus position.
[0085] Of course, the image acquisition step size can also be gradually reduced to repeatedly search for the focus position. Specifically, when the image clarity decreases, the current focus direction can be changed, and the image acquisition step size can be reduced to search for the focus position again, and the above process can be repeated until the focus position is found. The termination conditions of the above repeated search process include, for example, the image clarity exceeds a set threshold, the number of times the current focus direction has been changed has reached a set number, and the image clarity no longer increases.
[0086] Based on any embodiment, in one embodiment, in the process of unidirectional traversal of the focus search range, an image is first acquired with the image acquisition step and a first clarity is calculated. If a change in the first clarity of a current frame image relative to a previous frame image exceeds a preset threshold, the image acquisition step is updated, and a second clarity is calculated for the image acquired with the updated image acquisition step, and the focus position is determined based on the second clarity.
[0087] Specifically, the first clarity is the clarity calculated for the entire captured image. When the change in image clarity is greater than a preset threshold, it means that the focus position is approaching, and the target object can be roughly observed in the image. The image acquisition step can be updated. For example, the step can be reset at a preset ratio based on the original image acquisition step, such as 80%, 60%, 50%, 40% of the original image acquisition step, etc., to acquire images more "densely" to improve autofocus accuracy. The image with the second largest clarity among the images captured at this stage corresponds to the focus position.
[0088] Based on the previous embodiment, in one embodiment, the second clarity is obtained by: extracting the target object in the image or extracting the area containing the target object; and calculating the second clarity for the target object in the image or the area containing the target object.
[0089] Specifically, the images acquired with the updated image acquisition step size all have a certain clarity, on this basis, the target object or the area containing the target object in the extracted image can be accurately identified, and the second clarity is calculated only for this area. The second clarity can make the final focus position more accurate, and can achieve "targeted" focus on the target object with corresponding attributes in a specific scene. In addition, this process also reduces the calculation amount of the second clarity.
[0090] After determining the focus search range, this embodiment quickly adjusts the focus to a relatively close end within the focus search range, and traverses from this position to the other end in a one-way direction, thereby avoiding invalid focus outside the focus search range and eliminating the need to repeatedly search for the focus position within the focus search range, thereby improving the focus efficiency.
[0091] Based on any one of the embodiments, in one embodiment, searching for a focus position within the focus search range includes:
[0092] In the process of focusing within the focus search range, continuously capturing images according to the image capture step length and calculating a first clarity;
[0093] According to the first clarity of the current frame image and the first m frames of images before it, the third clarity of the current frame image is obtained by averaging; wherein m≥2;
[0094] Determine whether the focus position has been passed according to the first definition and the third definition of each image, and / or determine whether the focus direction needs to be changed.
[0095] Specifically, the calculation method of the above-mentioned first definition can be flexibly selected, such as the Brenner gradient method, the Tenegrad gradient method, the Laplace method, etc. The first definition can be the definition calculated for the entire image, or the definition calculated for a partial area. For example, a window (such as a central window) is set in the image, and the first definition is only calculated for the window area. For example, the target object is identified by a deep learning model or a target detection algorithm, and the first definition is only calculated for the target object area. The first definition can reflect the definition of a single frame image. On the basis of the first definition, the third definition is obtained by averaging the current frame image and its previous m frames. It can be understood that the average here can be a normal average or a weighted average. For example, the weight of the current frame image is 2, the weight of the previous frame image is 1.5, and the weight of the previous 2 frames is 1. The average can more accurately reflect the overall change trend of the definition, avoid the local fluctuation of the definition misleading the focusing process, causing the focus to fail or reduce the focusing efficiency. The value of m can be 2, 3, 4, 5, etc. Preferably, m is 3. It can be understood that, in this embodiment, the search may be started from a certain end point in the focus search range, or may be started from any position in the focus search range.
[0096] Based on any of the embodiments, in one embodiment, determining whether the focus position has been passed according to the first clarity and the third clarity of each image, and / or determining whether the focus direction needs to be changed, includes:
[0097] If the third definition of the n consecutive frames of images increases first and then decreases, the position with the maximum first definition in the n consecutive frames of images is used as the focus position;
[0098] If the third definition of the consecutive n frames of images increases, continue to focus along the current direction;
[0099] If the third definition of the consecutive n frames of images decreases, the current direction focus is continuously changed.
[0100] Specifically, the third definition can more accurately reflect the definition change trend between images. If the third definition of n consecutive frames of images increases first and then decreases, it means that the focus position has been passed, and the position with the largest first definition of n frames of images is used as the focus position. If the third definition of n consecutive frames of images increases, it means that the focus position is approaching, and the focus can continue to be adjusted in the current direction; if the third definition of n consecutive frames of images decreases, it means that the focus position is moving away, and the focus direction needs to be changed.
[0101] In another embodiment, the third clarity of two adjacent frames of images may be directly compared to determine whether the focus direction needs to be changed and whether the focus state is currently reached.
[0102] Specifically, if the third definition of the current frame image is greater than or equal to the third definition of the previous frame image, the current focus direction is maintained; if the third definition of the current frame image is less than the third definition of the previous frame image, the current focus direction is switched until the third definition of the image no longer increases. In this embodiment, the focus position is searched concisely and accurately according to the third definition.
[0103] Based on any of the embodiments, in one embodiment, determining whether the focus position has been passed according to the first clarity and the third clarity of each image, and / or determining whether the focus direction needs to be changed, includes:
[0104] If the ratio of the variance of the third definition of the continuous n frames of images to the average value is less than a set threshold, it is determined that the n frames of images have passed the focus position, and the position with the largest first definition in the n frames of images is used as the focus position; n≥3;
[0105] If the ratio of the variance to the average value of the third clarity of n consecutive frames of images is greater than or equal to a set threshold, further judgment is made: if the third clarity of n consecutive frames of images decreases, or the focus position is not found after reaching the boundary of the focus search range, the focus direction is changed; otherwise, the current focus direction is maintained.
[0106] Specifically, if multiple frames of images are located near the target focus position, the third clarity of each frame of image has a certain variance, and the average value of the third clarity of each image is relatively large. By comparing the ratio of the variance to the average value of the third clarity of consecutive n frames of image with the set threshold, it is possible to accurately determine whether the n frames of image contain the focus position, eliminating the interference of "pseudo peaks". If the focus position is not included, the trend of the third clarity can be further judged to decide whether to change the focusing direction. If the third clarity decreases continuously, it means that the current focusing direction is moving away from the focus position, or the focus position is not found after the focus reaches the boundary of the aforementioned focus search range, then the focusing direction needs to be changed to search the focus position again. For other situations, for example, if the third clarity increases continuously or the third clarity fluctuates, the focus can continue to be adjusted along the current direction so that further images can be collected to determine whether the focus position has been passed.
[0107] This embodiment reasonably guides the focusing process by judging the ratio of the variance to the average value of the third clarity of n consecutive frames of images, accurately identifies the focus position, and avoids the interference of pseudo peaks.
[0108] Based on any one of the embodiments, in one embodiment, during focusing within the focus search range, the initialization focus direction is focusing toward the center of the focus search range.
[0109] Specifically, in the present embodiment, it is not necessary to adjust the focus to one end of the focus search range and then traverse the focus search range. The present embodiment can start focusing from any position within the focus search range, initialize the focus direction to focus toward the center of the focus search range, and then determine whether to change the focus direction in combination with the judgment of the first clarity and the second clarity.
[0110] In this embodiment, the initial focus direction is to focus toward the center of the target focus range, and then the subsequent focus strategy is combined to determine whether to change the focus direction, so that the focus process does not need to traverse the focus search range, further improving the focus efficiency.
[0111] Based on any embodiment, in one embodiment, the first definition is obtained by the following formula:
[0112]
[0113] Among them, M is the number of pixels in the x-coordinate direction of the image, N is the number of coordinates in the y-coordinate direction, and G x (x,y),G y (x, y) are the gradients of the pixel in the x and y directions respectively.
[0114] This embodiment uses a function based on the gradient at each pixel point to accurately evaluate the clarity of the image.
[0115] Based on any embodiment, in one embodiment, the first definition is obtained by the following formula:
[0116]
[0117] Among them, P i is the probability of a pixel with gray value i appearing in the image, and L is the total number of gray levels.
[0118] Based on any one of the embodiments, in one embodiment, the first clarity is calculated for a region of interest in the acquired image.
[0119] Specifically, the region of interest can be the central area of the image, for example, a rectangular, circular or other shaped frame is set in the center of the image, and the area within the frame is the region of interest. The region of interest can also be an identified area, such as blood vessels, cerebral cortex and other tissues observed in an exoscopic scene. The area is identified by an algorithm or a deep learning model, and then the first clarity of the area is calculated.
[0120] The present invention improves the evaluation effect of image clarity and reduces the amount of data processing by calculating the first clarity of the region of interest.
[0121] Based on any embodiment, in one embodiment, the first definition is obtained by:
[0122] Extract the central area of the image;
[0123] Performing a convolution operation on the central area to output a new grayscale image;
[0124] The first definition is obtained by taking the square average of the new grayscale image.
[0125] Specifically, the central region is a range of a rectangular, circular or other shaped frame at the center of the image, and the area of the central region does not exceed 60% of the image area, for example, it is set to 20%, 30%, 40%, etc. After extracting the central region image, a convolution operation is performed on the central region, for example, a Sobel operator or a Roberts operator is used to perform a convolution operation to obtain a new grayscale image, and the square mean of the new grayscale image is taken as the first clarity.
[0126] An imaging device provided by the present invention is described below. The imaging device described below and the automatic focusing method described above can be referred to each other.
[0127] The imaging device provided by the present invention comprises:
[0128] An imaging module, wherein the imaging module comprises a variable-focus lens;
[0129] A distance detection module, used to detect the distance between the variable focus lens and the imaging target;
[0130] The processing module is used to execute any of the aforementioned automatic focusing methods for an imaging device and adjust the objective lens.
[0131] Specifically, the imaging device is such as a camera, a microscope, an endoscope, etc., and the imaging device is equipped with a distance detection module for measuring the working distance between the lens (front end) and the imaging target. In the field of optics, the working distance refers to the distance between the front end face of the imaging device lens and the imaging target. The front end of the conventional imaging device is an object lens, and the working distance is the distance between the object lens and the imaging target. Of course, a window can also be set in front of the object lens. At this time, the working distance is the distance between the window and the imaging target. It can be understood that when the distance detection module is flush with the front end face of the lens, the distance measured by the distance detection module is the working distance. When the distance detection module is not flush with the front end face of the lens, it is also necessary to convert and calculate the working distance based on the measured distance in combination with the positional relationship between the distance detection module and the front end face of the lens. The distance detection module is such as an ultrasonic distance detection module, an infrared distance detection module, a laser distance detection module, etc. The processing module determines the focusing search range and the image acquisition step according to the measured working distance, and controls the object lens to search for the focus position within the focusing search range according to the image acquisition step. In addition, the image acquisition step length can be adjusted by adjusting the moving speed of the objective lens (or zoom objective lens) or the image sampling frequency, and the two together determine the image acquisition step length.
[0132] The present invention measures the working distance between the lens and the imaging target through the distance detection module, preliminarily locks the focus search range, avoids invalid focus outside the focus search range, and improves the focus efficiency; the working distance is also used to set a suitable image acquisition step length in combination with the current focus clarity, so that the focusing process can cover the "peak position" of the image clarity, avoids directly crossing the "peak" due to a large step length, improves the focus success rate for situations such as shallow depth of field and high peak of image contrast curve, and avoids limiting the automatic focusing efficiency due to too small a step length.
[0133] Based on the previous embodiment, in one embodiment, the variable focus lens includes a variable focus objective lens, and the variable focus objective lens includes a fixed lens and a moving lens.
[0134] Specifically, the variable focus objective lens includes multiple lens assemblies, which can expand the focusing range. In addition, multiple lens assemblies also help to eliminate dispersion and improve imaging quality. The multiple lens assemblies include a fixed lens with a fixed position and a movable mirror. The fixed lens is preferably arranged at the front end of the lens so that the working distance is fixed during the focusing process.
[0135] Based on any one of the embodiments, in one embodiment, the imaging module further includes an adjusting component, and the processing module controls the movement of the lens component through the adjusting component.
[0136] Specifically, the adjustment component is, for example, a stepper motor, a servo motor, etc. Preferably, a stepper motor is used, which has better linearity in displacement control. The processing module controls the adjustment component to achieve continuous adjustment of the objective lens.
[0137] Based on any one of the embodiments, in one embodiment, the distance detection module is selected from at least one of a laser ranging unit, an ultrasonic ranging unit, and an infrared ranging unit.
[0138] An imaging device provided by the present invention is described below. The imaging device described below and the automatic focusing method described above can be referred to each other.
[0139] The exterior mirror system includes any of the aforementioned imaging devices as well as a lighting module, a display module, and a mechanical arm or a support arm.
[0140] Specifically, the imaging device is set at the end of the robotic arm / support arm, and the doctor can adjust the position and angle of the imaging device by inputting instructions or dragging the robotic arm / support arm. The lighting module can emit light to illuminate the surgical area or imaging area to improve the imaging quality. The lighting module can be integrated into the imaging device or set independently. The display module is used to receive and display the images collected by the imaging device.
[0141] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit it. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present invention.
Claims
1. An automatic focusing method for an imaging device, characterized in that: include: The working distance between the variable focus lens and the imaging target is obtained through the distance detection module; Determining a focus search range of the variable focus lens according to the working distance, and determining an image acquisition step length according to the working distance and a current focus clarity; The variable focus lens is adjusted according to the image acquisition step length, and a focus position is searched within the focus search range.
2. The automatic focusing method of an imaging device according to claim 1, characterized in that: The step of determining the focus search range of the variable focus lens according to the working distance comprises: Taking the working distance as the center, determining the distance range of the target object according to the detection error of the distance detection module; The focus search range that the focus of the variable-focus lens needs to traverse is determined according to the distance range of the target object.
3. The automatic focusing method of an imaging device according to claim 2, characterized in that: The distance range of the target object is: L-δ~L+δ; where L is the measured working distance and δ is the measurement error.
4. The automatic focusing method of an imaging device according to claim 1, characterized in that: Before adjusting the variable focus lens according to the image acquisition step length and searching for a focus position within the focus search range, the method further includes: The focus of the variable-focus lens is adjusted to one of the two end points of the focus search range that is closer to the initial focus position of the variable-focus lens, so as to traverse the focus search range in one direction.
5. The automatic focusing method of an imaging device according to claim 4, characterized in that: In the process of unidirectional traversal of the focus search range, an image is first acquired with the image acquisition step and a first clarity is calculated. If a change in the first clarity of a current frame image relative to a previous frame image exceeds a preset threshold, the image acquisition step is updated, and an image is acquired with the updated acquisition step. A second clarity is calculated for all images acquired with the updated image acquisition step, and a focus position is determined based on the second clarity of each image.
6. The automatic focusing method of an imaging device according to claim 5, characterized in that: The updating of the image acquisition step size comprises: Based on the image acquisition step size, it is reset according to a preset ratio; wherein the preset ratio is less than 1.
7. The automatic focusing method of an imaging device according to claim 5, characterized in that: The first clarity is calculated based on the entire captured image, and the second clarity is obtained by: extracting the target object in the image or extracting the area containing the target object; and calculating the second clarity based on the target object in the image or the area containing the target object.
8. The automatic focusing method of an imaging device according to claim 1, characterized in that: The searching for the focus position within the focus search range comprises: In the process of focusing within the focus search range, capturing images according to the image capture step length and calculating a first clarity; According to the first clarity of the current frame image and the first m frames of images before it, the third clarity of the current frame image is obtained by averaging; wherein m≥2; Determine whether the focus position has been passed according to the first definition and the third definition of each image, and / or determine whether the focus direction needs to be changed.
9. The automatic focusing method of an imaging device according to claim 8, characterized in that: The determining whether the focus position has been passed according to the first definition and the third definition of each image, and / or determining whether the focus direction needs to be changed includes: If the third definition of the current frame image is greater than or equal to the third definition of the previous frame image, continue to focus along the current direction; If the third definition of the current frame image is smaller than the third definition of the previous frame image, the current focus direction is changed until the third definition of the image no longer increases.
10. The automatic focusing method of an imaging device according to claim 8, characterized in that: The determining whether the focus position has been passed according to the first definition and the third definition of each image, and / or determining whether the focus direction needs to be changed, includes: If the third definition of the n consecutive frames of images increases first and then decreases, the position with the maximum first definition in the n consecutive frames of images is used as the focus position; wherein n≥3; If the third definition of the consecutive n frames of images increases, continue to focus along the current direction; If the third definition of the consecutive n frames of images decreases, the current direction focus is continuously changed.
11. The automatic focusing method of an imaging device according to claim 8, characterized in that: The determining whether the focus position has been passed according to the first definition and the third definition of each image, and / or determining whether the focus direction needs to be changed, includes: If the ratio of the variance to the average value of the third definition of the n consecutive frames of images is less than a set threshold, it is determined that the n frames of images have passed the focus position, and the position with the largest first definition in the n frames of images is used as the focus position; wherein n≥3; If the ratio of the variance to the average value of the third clarity of n consecutive frames of images is greater than or equal to a set threshold, further judgment is made: if the third clarity of n consecutive frames of images decreases, or the focus position is not found after reaching the boundary of the focus search range, the focus direction is changed; otherwise, the current focus direction is maintained.
12. The automatic focusing method of an imaging device according to claim 8, characterized in that: During the process of focusing within the focus search range, the initialization focus direction is focusing toward the center of the focus search range.
13. An imaging device, characterized in that: include: An imaging module, wherein the imaging module comprises a variable-focus lens; A distance detection module, used to detect the distance between the variable focus lens and the imaging target; A processing module, wherein the processing module is used to execute the automatic focusing method of the imaging device according to any one of claims 1 to 12, and adjust the variable focus lens.
14. The imaging device according to claim 13, characterized in that The variable-focus lens comprises a variable-focus objective lens, and the variable-focus objective lens comprises a fixed lens and a moving lens.
15. The imaging device according to claim 13, characterized in that The imaging device further comprises a control component, and the processing module controls the movement of the moving mirror through the control component.
16. The imaging device according to claim 13, characterized in that The distance detection module is selected from at least one of a laser distance measurement unit, an ultrasonic distance measurement unit, and an infrared distance measurement unit.
17. An exterior mirror system, characterized in that: It comprises the imaging device as described in any one of claims 13 to 16, as well as a lighting module, a display module, and a mechanical arm or a supporting arm.
Citation Information
Cited By
Automatic focusing method and device, equipment and storage medium
CN121792851A