Method and device for determining optimal shooting distance of fixed depth-of-field camera
By keeping the content of the region of interest unchanged and dynamically adjusting the parameters during the camera advance, combined with the multi-scale gradient fusion method, the problem of determining the optimal shooting distance of a fixed depth of field camera is solved, and accurate evaluation of image clarity and determination of the optimal shooting distance are achieved.
Patent Information
- Application Number
- CN202510776741.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-06-11
- Publication Date
- 2025-09-09
- Estimated Expiration
- 2045-06-11
AI Technical Summary
When shooting with a fixed depth of field camera, it is impossible to accurately find the optimal shooting distance, resulting in inaccurate image clarity assessment and failure to reflect the objective relationship between shooting distance and image quality.
By keeping the content of the region of interest unchanged during the camera advancement, dynamically adjusting the regional parameters, and using a multi-scale gradient fusion method to evaluate image clarity, the correspondence between clarity and shooting distance is recorded, and the distance with the highest clarity is selected as the optimal shooting distance.
Accurately determine the optimal shooting distance of the fixed depth-of-field camera to ensure consistent content in the region of interest, and use multi-scale gradient fusion to comprehensively evaluate image clarity, avoiding regional inconsistency problems caused by changes in imaging size and providing reliable clarity assessment results.
Smart Images

Figure CN120302155B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of data processing technology, and in particular to a method and device for determining an optimal shooting distance for a fixed depth-of-field camera. Background Art
[0002] When photographing an object with a fixed depth of field camera, finding the optimal distance between the camera and the captured area is crucial for obtaining clear images. Traditional methods determine this optimal distance by comparing the clarity of images taken from different camera positions. However, when adjusting the shooting distance, the size of the object image changes due to the distance between the camera and the object.
[0003] If a fixed region of interest (ROI) is used, the portion of the object selected by the ROI will vary significantly at different shooting distances. For example, when the camera moves closer to the object, the image becomes larger, and the original fixed ROI may only select local details of the object, missing key overall features. When the camera moves away from the object, the image becomes smaller, and a large amount of background content may be mixed into the ROI, reducing the proportion of effective object information.
[0004] When ROI content isn't consistent across different shooting distances, image clarity calculated based on a fixed ROI will be affected by these differences. This interference causes image clarity to fail to truly reflect the objective relationship between shooting distance and image quality. This can lead to overestimation of clarity due to sharp details at close range, and underestimation of clarity due to background clutter at long range. This inability to accurately determine clarity means there's no reliable standard for measuring image quality at different shooting distances. Consequently, comparing image clarity from different locations will make it impossible to pinpoint the shooting distance that optimizes the overall image quality of the entire object. Summary of the Invention
[0005] The present application provides a method and apparatus for determining the optimal shooting distance of a fixed depth-of-field camera to solve the problem of being unable to accurately find the optimal shooting distance.
[0006] In a first aspect, the present application provides a method for determining an optimal shooting distance of a fixed depth-of-field camera, the method comprising:
[0007] Determining an initial region of interest focused on by a camera with a fixed depth of field, and determining first region parameters of the initial region of interest, wherein the camera captures an image each time it advances a fixed distance toward the subject;
[0008] determining, based on an initial shooting distance between the camera and the photographed object before the camera is advanced and a current shooting distance between the camera and the photographed object after the camera is advanced, a zoom ratio of an image generated before and after the camera is advanced;
[0009] Adjusting the first region parameter according to the image scaling ratio to obtain the second region parameter after the camera is advanced, and determining a current region of interest corresponding to the second region parameter, wherein the captured content of the region of interest is scaled in the same ratio during the advancement of the camera;
[0010] Obtaining image clarity by fusing multi-scale gradients of the image captured in the current region of interest, and recording a corresponding relationship between the clarity and the current shooting distance;
[0011] After the camera advance is completed, the shooting distance with the highest definition is selected as the optimal shooting distance according to the corresponding relationship.
[0012] Optionally, the first region parameters include a first horizontal coordinate, a first vertical coordinate, a first width, and a first height of a corner point of the initial region of interest, and adjusting the first region parameters according to the image scaling ratio to obtain the second region parameters after the camera advances includes:
[0013] Determining a central abscissa and a central ordinate of a center point of an overall image, wherein the overall image is the entire image captured by the camera;
[0014] determining a second abscissa according to the central abscissa, the image scaling ratio, and the first abscissa;
[0015] determining a second vertical coordinate according to the central vertical coordinate, the image scaling ratio, and the first vertical coordinate;
[0016] determining a second width according to the first width and the image scaling ratio;
[0017] determining a second height according to the first height and the image scaling ratio;
[0018] The second area parameter is constructed according to the second horizontal coordinate, the second vertical coordinate, the second width, and the second height.
[0019] Optionally, obtaining image clarity by fusing multi-scale gradients of the captured image in the current region of interest includes:
[0020] Generate a multi-scale image by downsampling the captured image in the current region of interest;
[0021] By dynamically assigning weights to images of each scale and fusing multi-scale gradients, a target image with an initial clarity score is generated;
[0022] Selecting blurred sub-blocks from a plurality of candidate sub-blocks according to a gradient mean value of each candidate sub-block in the target image, wherein the local image region corresponding to the blurred sub-block has image blur;
[0023] The clarity of the captured image is obtained by deducting the blur region score corresponding to the blur sub-block from the initial clarity score.
[0024] Optionally, generating a target image with an initial clarity score by dynamically assigning weights to images of each scale and fusing multi-scale gradients includes:
[0025] Determining a gradient magnitude of each pixel in each scale image, and determining a gradient magnitude variance and a gradient magnitude mean of the scale image based on the gradient magnitudes of the plurality of pixels, wherein the gradient magnitude variance is used to indicate a texture density of the scale image;
[0026] Assigning a weight to the corresponding scale image according to the texture density of each scale image, wherein the weight is positively correlated with the richness of the texture density;
[0027] According to the weighted sum of the gradient amplitude mean and weight of each scale image, the target image with an initial clarity score is obtained.
[0028] Optionally, selecting a blurred sub-block from the plurality of candidate sub-blocks according to the gradient mean of each candidate sub-block in the target image includes:
[0029] Dividing the target image into a plurality of candidate sub-blocks, and determining a gradient mean value of each candidate sub-block;
[0030] Determining a scoring threshold based on a preset threshold coefficient and the initial clarity score;
[0031] If the absolute value of the difference between the gradient mean of the candidate sub-block and the initial clarity score exceeds the score threshold, the candidate sub-block is determined to be a blurred sub-block.
[0032] Optionally, obtaining the clarity of the captured image by deducting the blur region score corresponding to the blur sub-block from the initial clarity score includes:
[0033] Determining a blur region score according to the number of blur sub-blocks, the number of candidate sub-blocks, and a preset penalty coefficient, wherein the preset penalty coefficient is used to indicate the degree of influence of local blur on the overall clarity of the image;
[0034] A final clarity score is obtained according to a difference between the initial clarity score and the blurred area score, and the final clarity score is used as the clarity of the captured image.
[0035] Optionally, the fixed distance of camera advancement is determined based on a first advancement step length and a preset number of advancement steps. After determining the optimal shooting distance, the method further includes:
[0036] determining a shooting distance range according to the optimal shooting distance and the difference and the sum of the first advancing step length, and using the shooting distance range as an initial shooting distance between the camera and the shooting object;
[0037] re-determining the advancing distance of the camera each time according to a second advancing step length and the preset advancing step number, wherein the second advancing step length is smaller than the first advancing step length;
[0038] The step of re-determining the current shooting distance according to the updated initial shooting distance and the updated advancing distance, and selecting the shooting distance with the highest definition as the optimal shooting distance after executing multiple advancements.
[0039] In a second aspect, the present application provides a device for determining an optimal shooting distance of a fixed depth-of-field camera, the device comprising:
[0040] a first determining module, configured to determine an initial region of interest focused on by a camera with a fixed depth of field, and determine first region parameters of the initial region of interest, wherein the camera captures an image each time it advances a fixed distance toward a photographed object;
[0041] a second determining module, configured to determine the image scaling ratios before and after the camera is advanced, based on an initial shooting distance between the camera and the subject before the camera is advanced and a current shooting distance between the camera and the subject after the camera is advanced;
[0042] an adjustment module, configured to adjust the first region parameter according to the image scaling ratio, obtain the second region parameter after the camera advances, and determine a current region of interest corresponding to the second region parameter, wherein the captured content of the region of interest is scaled in the same ratio during the advancement of the camera;
[0043] a third determining module, configured to obtain image clarity by fusing multi-scale gradients of the image captured in the current region of interest, and record a corresponding relationship between the clarity and the current shooting distance;
[0044] The selection module is used to select the shooting distance with the highest definition as the optimal shooting distance according to the corresponding relationship after the camera is moved forward.
[0045] In a third aspect, the present application provides an electronic device comprising: at least one communication interface; at least one bus connected to the at least one communication interface; at least one processor connected to the at least one bus; and at least one memory connected to the at least one bus.
[0046] In a fourth aspect, the present application further provides a computer storage medium storing computer executable instructions, wherein the computer executable instructions are used to execute the method for determining the optimal shooting distance of a fixed depth-of-field camera as described in any one of the above items of the present application.
[0047] The above technical solution provided by the embodiment of the present application has the following advantages over the prior art: the camera captures an image each time it advances a fixed distance. During the advancement process, the image scaling ratios before and after advancement are determined based on the change in shooting distance. The regional parameters of the region of interest are then dynamically adjusted based on the image scaling ratio to ensure that the region of interest is always scaled at the same ratio. Regardless of how the shooting distance changes, the content of the captured object remains the same. A multi-scale gradient fusion method is then used to determine the clarity of the image in the region of interest. The image details and edge information are comprehensively evaluated from multiple scales to accurately reflect the image clarity. The corresponding relationship between each shooting distance and image clarity is recorded. After the camera completes all advancements, the optimal shooting distance that makes the fixed depth of field camera capture the clearest image is found. This application accurately determines the optimal shooting distance of the camera through a dynamic region of interest. BRIEF DESCRIPTION OF THE DRAWINGS
[0048] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present application and, together with the description, serve to explain the principles of the present application.
[0049] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the following briefly introduces the drawings required for use in the embodiments or the description of the prior art. Obviously, for ordinary technicians in this field, other drawings can be obtained based on these drawings without any creative work.
[0050] One or more embodiments are exemplarily illustrated by pictures in the corresponding drawings. These exemplifications do not constitute limitations on the embodiments. Elements with the same reference numerals in the drawings are represented as similar elements. Unless otherwise stated, the figures in the drawings do not constitute proportional limitations.
[0051] Figure 1 A flow chart of a method for determining the optimal shooting distance of a fixed depth-of-field camera provided in an embodiment of the present application;
[0052] Figure 2 A schematic diagram of the overall process of determining the optimal shooting distance of a fixed depth-of-field camera provided in an embodiment of the present application;
[0053] Figure 3 A schematic diagram of the structure of a device for determining the optimal shooting distance of a fixed depth-of-field camera provided in an embodiment of the present application;
[0054] Figure 4 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0055] To make the purpose, technical solutions, and advantages of the embodiments of this application more clear, the technical solutions in the embodiments of this application will be clearly and completely described below in conjunction with the drawings in the embodiments of this application. Obviously, the described embodiments are part of the embodiments of this application, not all of the embodiments. Based on the embodiments in this application, all other embodiments obtained by ordinary technicians in this field without making creative efforts are within the scope of protection of this application.
[0056] The disclosure below provides many different embodiments or examples for implementing different structures of the present application. In order to simplify the disclosure of the present application, the components and settings of specific examples are described below. Of course, these are merely examples and are not intended to limit the present application. In addition, the present application may repeat reference numbers and / or letters in different examples. Such repetition is for the purpose of simplicity and clarity and does not in itself indicate the relationship between the various embodiments and / or settings discussed.
[0057] In order to solve the problem mentioned in the background technology that the optimal shooting distance of the camera cannot be accurately determined, the embodiment of the present application establishes accurate clarity by keeping the content of the object being photographed in the area of interest unchanged during the camera advancement process, thereby providing an accurate basis for determining the optimal shooting distance.
[0058] The embodiments of the present application are applied to the field of camera shooting, and specific application scenarios include but are not limited to: monitoring industrial production, intelligent monitoring, pathological section diagnosis or cell growth recording.
[0059] The following will describe in detail a method for determining the optimal shooting distance of a fixed depth of field camera provided by an embodiment of the present application in conjunction with specific implementation methods, taking a camera with a fixed depth of field as an example. Figure 1 The specific steps are as follows:
[0060] Step 101: determining an initial region of interest focused on by a camera with a fixed depth of field, and determining first region parameters of the initial region of interest, wherein the camera captures an image each time it advances a fixed distance toward the subject;
[0061] Step 102: Determine the image scaling ratios before and after the camera is advanced based on the initial shooting distance between the camera and the object before the camera is advanced and the current shooting distance between the camera and the object after the camera is advanced.
[0062] Step 103: adjusting the first region parameters according to the image scaling ratio to obtain the second region parameters after the camera is advanced, and determining the current region of interest corresponding to the second region parameters, wherein the captured content of the region of interest is scaled in the same ratio during the advancement of the camera;
[0063] Step 104: Obtain image clarity by fusing multi-scale gradients of the captured image in the current region of interest, and record the corresponding relationship between the clarity and the current shooting distance;
[0064] Step 105: After the camera advance is completed, the shooting distance with the highest definition is selected as the optimal shooting distance according to the corresponding relationship.
[0065] First, the terms used in the embodiments of the present application are explained, including the following content.
[0066] Fixed depth of field camera: The camera has a fixed depth of field range. Objects within a certain distance range are clearly imaged, but beyond this range they will be blurred. It is necessary to find a suitable shooting distance to ensure a clear target.
[0067] Initial region of interest: A specific area in an image that is selected manually or algorithmically before recording begins. This area contains the object that you want to focus on or analyze.
[0068] First region parameters: Parameters used to describe the characteristics of the initial region of interest, including the coordinates of a corner point of the region, the width and height of the region, etc., to determine the position and size of the region in the image.
[0069] Image zoom ratio: As the camera moves forward or backward, the size of objects in the image will change due to changes in shooting distance. The image zoom ratio reflects the degree of this size change.
[0070] Second region parameters: Parameters obtained by adjusting the first region parameters according to the image scaling ratio, used to determine the new region of interest after the camera advances.
[0071] Multi-scale gradient fusion: This technology comprehensively processes the gradient information of an image at different scales (e.g., reduced to 1 / 2 or 1 / 4 of the original image). By fusing this information, the image clarity is evaluated, which can more comprehensively reflect the image details and quality.
[0072] In step 101, before officially shooting, the first task is to identify the core target of the shot and use this as a basis for selecting a region of interest (ROI). This selection process can be implemented in a variety of ways. The operator can manually select an area containing key objects or details in the camera's viewfinder based on the shooting requirements. Alternatively, image recognition algorithms can automatically detect the target object and accurately define the area. For example, when photographing precision mechanical parts, the algorithm can quickly identify the part's outline and set it as the ROI.
[0073] The initial region of interest (ROI) mentioned in the embodiments of this application is the region of interest before each camera advance. After determining the initial ROI, the system obtains its first region parameters, which include the precise coordinates of the region's corner points, as well as the width and height of the region itself. These parameters can be used to determine the specific location and size of the ROI within the entire image.
[0074] In addition, you need to set a fixed distance for the camera to advance toward the subject each time. This distance determines the pace at which the camera gradually approaches the subject. The camera will subsequently approach the subject at this predetermined distance, and each time it completes an advance, it triggers the capture function and records an image of the current position. The distance of each advance is determined by the product of the first advance step length S and the preset number of advance steps i.
[0075] In step 102, when the camera performs a push operation, the change in shooting distance before and after each push will directly lead to a change in the size of the object in the image. Therefore, before each push, the camera records the initial shooting distance D between the camera and the object at that time; when the camera completes a push, it records the current shooting distance between the camera and the object again. By comparing these two distance values, we can determine the scale ratio of the image before and after the camera is moved forward. The image scale ratio reflects the extent to which the size of the object in the image changes due to the change in shooting distance.
[0076] The image scaling ratio is calculated as: , where R is the image scaling ratio, D is the initial shooting distance, i is the preset number of advancement steps, and S is the first advancement step length. is the current shooting distance.
[0077] In step 103, after obtaining the image scaling ratio, the camera will accurately adjust the parameters of the first area according to this ratio. Specifically, the camera will calculate the parameters such as the corner coordinates, width and height of the initial area of interest with the scaling ratio according to established rules and algorithms. Through such calculations, the adjusted second area parameters are obtained. These new parameters redefine the position and size of the area of interest. Based on the second area parameters, the camera can accurately determine the current area of interest. In this way, as the camera continues to move forward, the area of interest will be scaled accordingly as the image size of the object changes. Regardless of how the distance between the camera and the subject changes, it can ensure that the content captured in the area of interest always maintains the same proportional change, so that each shot is aimed at the same part of the subject, avoiding the problem of inconsistent analysis areas due to changes in image size.
[0078] In step 104, the camera employs a multi-scale gradient fusion method to comprehensively and accurately assess the clarity of the captured image within the current region of interest. First, the captured image is processed at multiple scales, generating multiple images of varying sizes through technical means. For example, these images are reduced to 1 / 2 or 1 / 4 of the original image. At different scales, the details and features presented in the images vary; small-scale images can reveal overall contours, while large-scale images retain more local details. Next, the camera calculates gradient information for each scale. This gradient information reflects the magnitude of pixel changes within the image, with areas of significant pixel change often corresponding to edges and details. This gradient information from different scales is then organically fused, analyzed, and processed to ultimately produce a single value that comprehensively represents the image's clarity. This value is not a one-sided assessment at a single scale, but rather a comprehensive result that integrates information from multiple scales. Finally, the camera associates this clarity value with the current shooting distance, forming a set of corresponding relationship data.
[0079] In step 105, after the camera completes all advance operations according to the pre-set advance distance, it has accumulated multiple sets of different shooting distances and their corresponding image clarity data. This data constitutes a complete dataset reflecting the image quality at different shooting distances. The camera compares each clarity value one by one to find the one with the highest clarity. The shooting distance corresponding to this highest clarity value is the optimal shooting distance that enables the fixed depth of field camera to capture the clearest image during this shooting process.
[0080] For example, a fixed-depth-of-field camera was used to photograph an irregularly shaped antique ornament. Before filming began, the operator manually selected the antique ornament as a region of interest (ROI) using the camera interface. The coordinates of the upper-left corner of the region were obtained as (100, 100) in the image, with a width of 200 pixels and a height of 150 pixels. The camera was set to advance 2 cm toward the ornament at a time, capturing one image with each advance. The camera began advancing from 30 cm away from the ornament. After the first advance, the current shooting distance became 28 cm. The image zoom ratio was determined by comparing the initial shooting distance with the current shooting distance. The initial ROI parameters were adjusted based on the zoom ratio to obtain a new ROI, ensuring that the antique ornament remained completely within the ROI. Multi-scale gradient fusion processing was performed on each captured ROI image to obtain an image clarity value, and the corresponding relationship between this value and the current shooting distance was recorded. All advances were completed when the camera reached 20 cm from the ornament. Finally, by comparing all recorded shooting distances and clarity values, it was found that the clarity of the image was highest when the distance was 24 cm from the ornament, so 24 cm was determined to be the optimal shooting distance for this shooting.
[0081] In this application, the camera captures an image each time it advances a fixed distance. During the advancement process, the image scaling ratios before and after advancement are determined based on the change in shooting distance. Then, the regional parameters of the region of interest are dynamically adjusted based on the image scaling ratio to ensure that the region of interest is always scaled at the same ratio. Regardless of how the shooting distance changes, the content of the photographed object remains the same. A multi-scale gradient fusion method is then used to determine the clarity of the image in the region of interest. The image details and edge information are comprehensively evaluated from multiple scales to accurately reflect the image clarity. The corresponding relationship between each shooting distance and image clarity is recorded. After the camera completes all advancements, the optimal shooting distance that makes the fixed depth of field camera capture the clearest image is found. This application accurately determines the optimal shooting distance of the camera through a dynamic region of interest.
[0082] As an optional implementation, in step 103, adjusting the first region parameters according to the image scaling ratio to obtain the second region parameters after the camera is advanced includes the following.
[0083] Step S11: determining the central abscissa and central ordinate of the center point of the overall image, wherein the overall image is the entire image captured by the camera;
[0084] Step S12: determining a second horizontal coordinate according to the central horizontal coordinate, the image scaling ratio, and the first horizontal coordinate;
[0085] Step S13: determining the second vertical coordinate according to the center vertical coordinate, the image scaling ratio, and the first vertical coordinate;
[0086] Step S14: determining a second width according to the first width and the image scaling ratio;
[0087] Step S15: determining a second height according to the first height and the image scaling ratio;
[0088] Step S16: constructing a second area parameter according to the second horizontal coordinate, the second vertical coordinate, the second width, and the second height.
[0089] The first region parameters include the first horizontal coordinate and the first vertical coordinate (X, Y), the first width Width and the first height Height of the corner point of the initial region of interest. The coordinates of the center point of the entire image are , It is a fixed value.
[0090] The calculation formula for the second area parameter is as follows.
[0091]
[0092] in, are the coordinates of the corner points of the current region of interest, is the second width of the current region of interest, is the second height of the current area of interest.
[0093] As an optional implementation, in step 104, obtaining image clarity by fusing multi-scale gradients of the captured image in the current region of interest includes the following.
[0094] Step S21: generating a multi-scale image by downsampling the captured image in the current region of interest;
[0095] Step S22: Generate a target image with an initial clarity score by dynamically assigning weights to each scale image and fusing multi-scale gradients;
[0096] Step S23: selecting a blurred sub-block from the plurality of candidate sub-blocks according to the gradient mean of each candidate sub-block in the target image, wherein the local image region corresponding to the blurred sub-block has image blur;
[0097] Step S24: The clarity of the captured image is obtained by deducting the blurry area score corresponding to the blurry sub-block from the initial clarity score.
[0098] In step S21, the camera processes the captured image within the current region of interest by downsampling it to generate image versions of different scales, such as 1 / 2 or 1 / 4 of the original image, thereby constructing a multi-scale image structure. Images of different scales carry differentiated characteristic information about an object. Large-scale images focus on preserving object details and edges, capturing subtle textures and local variations; small-scale images focus on the object's overall outline and macroscopic form, revealing its structural layout. By integrating these different levels of features, multi-scale analysis can overcome the limitations of information at a single scale and conduct a comprehensive, multi-layered analysis of image content.
[0099] In step S22, for each scale image generated, its gradient amplitude is first extracted. This amplitude reflects the severity of the image pixel changes. The areas where the pixels change drastically correspond to the edges and detail information of the image, and are key factors in measuring image clarity. Since images of different scales differ in texture richness, in order to more accurately evaluate image clarity, weights are dynamically assigned based on the texture density of each scale image. Texture-rich areas have a greater impact on the image clarity perceived by the human eye, so the denser the texture, the higher the weight assigned to the scale image. By weighted summing the gradient means of each scale image according to the assigned weights, the information of different scales is fused, and finally a score that can comprehensively reflect the overall clarity of the image is obtained, generating a target image containing the initial clarity score. This method integrates multi-scale information to make the initial clarity score more accurate.
[0100] In step S23, the camera segments the target image, including the initial sharpness score, into multiple, independent candidate sub-blocks of uniform size. The camera then calculates the mean gradient of the pixels within each candidate sub-block, which reflects the richness of image detail and edges within the candidate sub-block. In clear image areas, the mean gradient of the sub-block is typically close to the initial sharpness score of the overall image. However, the mean gradient of blurry sub-blocks is significantly lower than the overall score. Based on this characteristic, by comparing the mean gradient of each candidate sub-block with the overall initial sharpness score, it is possible to accurately identify blurry local areas in the image, namely blurry sub-blocks, laying the foundation for subsequent correction of the initial sharpness score.
[0101] In step S24, the camera comprehensively assesses the impact of the detected multiple blurred sub-blocks on the overall image quality and calculates a corresponding blurred area score. Because localized blur can reduce the subjective perception of overall image clarity, the blurred area score is deducted from the previously obtained initial overall image clarity score to correct the initial clarity score. This approach eliminates the influence of localized blur on the overall score, ensuring that the final initial image clarity score more accurately reflects the perceived clarity of the image to the human eye, improving the accuracy and reliability of clarity assessment.
[0102] In this application, we first perform multi-scale downsampling on the image of the region of interest, capturing image features in multiple dimensions from global contours to local details, breaking through the limitations of single-scale analysis. Secondly, we dynamically assign weights based on texture density and fuse multi-scale gradient information to simulate the human eye's sensitivity to texture-rich areas, making the initial clarity score more accurate. Then, we accurately locate the blurred areas through the sub-block gradient mean to avoid local blur from interfering with the overall evaluation. Finally, we deduct the blurred area score to correct the image clarity and ensure that the score truly reflects the image quality. By comprehensively analyzing image features and accurately eliminating interference factors, we ultimately provide a more reliable clarity assessment result for fixed depth of field cameras, thereby accurately finding the optimal shooting distance.
[0103] As an optional implementation, in step S22, dynamically assigning weights to images of each scale and fusing multi-scale gradients to generate a target image with an initial clarity score includes the following.
[0104] Step S221: determining the gradient magnitude of each pixel in each scaled image, and determining the gradient magnitude variance and the gradient magnitude mean of the scaled image based on the gradient magnitudes of the multiple pixels, wherein the gradient magnitude variance is used to indicate the texture density of the scaled image;
[0105] Step S222: assigning weights to the corresponding scale images according to the texture density of each scale image, wherein the weights are positively correlated with the richness of the texture density;
[0106] Step S223: Obtain a target image with an initial clarity score based on the weighted addition of the gradient amplitude mean and weight of each scale image.
[0107] In step S221, after the multi-scale image is generated, the camera uses a gradient operator (such as the Scharr operator or the Sobel operator) to calculate the gradient magnitude of each pixel in each scale image. The gradient magnitude indicates the degree of grayscale variation in the horizontal and vertical directions of the pixel in the scale image. Regions with more pronounced grayscale variation (such as object edges and texture details) have larger gradient magnitudes.
[0108] The calculation formula of the pixel gradient amplitude is:
[0109] ,in, is the gradient magnitude of the pixel, I represents the scale image, represents the convolution operation, represents the convolution kernel in the horizontal direction, Represents the convolution kernel in the vertical direction, .
[0110] For example, .
[0111] After calculating the gradient magnitudes for all pixels, the camera performs a statistical analysis of the gradient magnitudes for all pixels in the image at that scale, yielding two key metrics: the mean gradient magnitude and the variance. The mean gradient magnitude reflects the overall grayscale variation of the image at that scale, while the variance measures the dispersion of pixel gradient magnitudes within the image. A larger variance indicates more dramatic grayscale variation within the image, indicating richer texture. This variance serves as an important indicator for determining image texture density.
[0112] In step S222, the camera assigns weights to each scale image based on its gradient amplitude variance (i.e., a measure of texture density). Because the human eye is more sensitive to the sharpness of texture-rich areas within an image, a weighting strategy is adopted that is positively correlated with the richness of the texture density. Specifically, scale images with high texture density (larger gradient amplitude variance) are assigned higher weights, meaning they carry a greater weight in the final sharpness assessment; scale images with lower texture density are assigned lower weights. By linking weights to image texture density, the impact of texture-rich areas on the sharpness assessment is prioritized, ensuring that the initial sharpness score generated by the algorithm is highly consistent with the human eye's subjective perception of image sharpness.
[0113] This dynamic weight allocation mechanism enables the algorithm to automatically adjust the weights of images at different scales based on differences in image content. The algorithm can adaptively determine the importance of each scale layer, thereby adaptively adjusting the contribution of each scale image to the clarity assessment and improving the accuracy of clarity assessment.
[0114] The weight calculation formula is:
[0115] ,in, is the weight of the i-th scale image, n is the total number of scales, j is the j-th scale, is the gradient amplitude variance of the i-th scale image, is the gradient magnitude variance of the j-th scale image.
[0116] In step S223, after determining the weights for each scale image, the camera performs a weighted calculation on the mean gradient amplitude of each scale image and the corresponding weight. Specifically, the mean gradient amplitude of each scale image is multiplied by the corresponding weight, and the weighted results across all scale layers are summed to obtain a composite value, which serves as the initial sharpness score for the target image. This initial sharpness score incorporates information from images at different scales and is weighted based on the importance of texture at each scale, comprehensively and accurately reflecting the overall sharpness of the image.
[0117] The initial clarity score is calculated as:
[0118] ,in, is the initial clarity score of the target image, n is the total number of scales, i is the i-th scale, is the mean gradient amplitude of the i-th scale image, is the weight of the i-th scale image.
[0119] This embodiment of the application fully utilizes the information contained in images at different scales by weighted fusion of images at each scale. The large-scale layer captures image details and edges, while the small-scale layer reveals the overall image structure. This avoids the potential loss of information or misjudgment caused by relying solely on a single-scale image for clarity assessment, resulting in a more comprehensive and accurate initial clarity score, providing a more reliable basis for determining the optimal shooting distance.
[0120] This application achieves accurate quantitative evaluation of image clarity through gradient feature analysis, adaptive weight allocation and multi-scale fusion. First, by calculating the pixel gradient amplitude, variance and mean of images at each scale, the image texture features are converted into measurable numerical indicators; then, according to the texture density, weights are dynamically assigned to each scale layer, so that areas with rich textures and greater impact on the human eye's clarity perception have higher weights in the evaluation, which is in line with human visual characteristics; finally, by weighted fusion of the gradient mean of each scale layer, image information at different resolutions is integrated to avoid the limitations of single-scale analysis. This process solves the problems of traditional methods such as the inconsistency between clarity evaluation and human eye perception and the inability to adapt to complex scenes, and improves the accuracy and reliability of the initial clarity score, thereby determining the optimal shooting distance.
[0121] As an optional implementation, in step S23, selecting a blurred sub-block from a plurality of candidate sub-blocks according to the gradient mean of each candidate sub-block in the target image includes the following contents.
[0122] Step S231: dividing the target image into multiple candidate sub-blocks, and determining the gradient mean of each candidate sub-block;
[0123] Step S232: determining a scoring threshold according to a preset threshold coefficient and an initial clarity score;
[0124] Step S233: If the absolute value of the difference between the gradient mean of the candidate sub-block and the initial clarity score exceeds the score threshold, the candidate sub-block is determined to be a blurred sub-block.
[0125] In step S231, the camera segments the target image, obtained through multi-scale gradient fusion, into multiple, uniformly sized, non-overlapping candidate sub-blocks according to preset rules. These sub-blocks serve as the fundamental building blocks of the image and collectively form the units for refined analysis of local image features. After segmentation, the gradient amplitude of all pixels within each candidate sub-block is calculated. The gradient amplitude reflects the severity of pixel grayscale changes and represents the richness of image edges and details. Subsequently, the gradient amplitudes of all pixels within the candidate sub-block are arithmetic averaged to obtain the gradient mean for that candidate sub-block. This mean serves as a quantitative indicator of sub-block clarity. A higher value indicates richer image details and sharper edges within the sub-block; a lower value indicates potential blurriness within the sub-block. By segmenting the target image into sub-blocks and analyzing each one individually, it is possible to precisely locate specific areas of image blur. This allows for rapid identification of blurred sub-blocks within the background, preventing misjudgments of overall image quality due to local blur.
[0126] In step S232, the camera calculates a scoring threshold based on a pre-set threshold coefficient and the initial sharpness score of the target image. The threshold coefficient can be a manually set adjustment parameter, reflecting the algorithm's strictness in determining blurred areas. The threshold coefficient can also be dynamically adjusted based on the image's own sharpness level. Multiplying the threshold coefficient by the initial sharpness score yields the specific scoring threshold. This scoring threshold serves as a yardstick for determining whether a sub-block is blurred. It comprehensively considers the overall image sharpness level and provides a unified quantitative standard for subsequent screening of blurred sub-blocks.
[0127] By combining the initial overall image clarity score with a dynamically calculated scoring threshold, the algorithm adaptively adapts to the image characteristics of different scenarios. Whether it's an image with complex textures (such as richly textured fabrics) or a relatively smooth image (such as a portrait against a solid background), the algorithm sets a reasonable judgment threshold based on the image's clarity level, effectively avoiding misjudgments caused by fixed thresholds and improving the reliability of the evaluation results.
[0128] In step S233, the camera compares the mean gradient of each candidate sub-block with the initial sharpness score of the target image and calculates the absolute value of the difference between the two. If this absolute value exceeds the score threshold determined in step S232, it indicates that the sharpness of the candidate sub-block is lower than that of the overall image, and the sub-block is therefore determined to be blurred.
[0129] The calculation formula for fuzzy sub-block judgment is:
[0130] ,in, is the gradient mean of the candidate sub-block, Score the initial clarity. is the threshold coefficient.
[0131] After the camera identifies and marks blurred sub-blocks, it can subsequently correct the overall initial sharpness score by subtracting their impact, making the score more consistent with the human eye's subjective perception. For example, in a landscape photo with some areas blurred due to shaking, the algorithm first locates the blurred sub-blocks and then subtracts their negative impact from the initial sharpness score. The resulting score truly reflects the quality of the sharp areas of the image, providing a more reliable basis for determining the optimal shooting distance.
[0132] As an optional implementation, in step S24, by deducting the blur region score corresponding to the blur sub-block from the initial clarity score, the clarity of the captured image is obtained, including the following content.
[0133] Step S241: determining a blur region score based on the number of blur sub-blocks, the number of candidate sub-blocks, and a preset penalty coefficient, wherein the preset penalty coefficient is used to indicate the degree of influence of local blur on the overall clarity of the image;
[0134] Step S242: Obtain a final clarity score based on the difference between the initial clarity score and the blurred area score, and use the final clarity score as the clarity of the captured image.
[0135] First, the camera counts the number M of all blurred sub-blocks and the total number of candidate sub-blocks , and then by the ratio Determine the proportion of the blurred area in the entire image, which reflects the coverage of the blurred phenomenon, and then preset the penalty coefficient As an adjustment factor, its value depends on the sensitivity of the application scene to local blur. Finally, the blur ratio and penalty coefficient Multiply to get the fuzzy area score ,The blur area score quantifies the extent to which local blur weakens the overall clarity.
[0136] Based on initial clarity rating and fuzzy area scoring The final image clarity score is obtained through subtraction operation. The final clarity score is the clarity of the captured image. This subtraction operation is essentially to deduct the quality loss caused by local blur from the initial clarity score, so that the final score is closer to the human eye's subjective perception of image clarity.
[0137] The final clarity score is calculated as:
[0138] ,in, Score the final clarity.
[0139] As an optional implementation, the fixed distance of camera advancement is determined based on the first advancement step length and a preset number of advancement steps. After determining the optimal shooting distance, the method further includes:
[0140] Determine a shooting distance range according to the optimal shooting distance, the difference between the first advancing step length, and the sum thereof, and use the shooting distance range as an initial shooting distance between the camera and the object;
[0141] re-determining the camera's advancing distance each time according to the second advancing step length and the preset advancing step number, wherein the second advancing step length is smaller than the first advancing step length;
[0142] The step of re-determining the current shooting distance according to the updated initial shooting distance and the updated advancing distance, and selecting the shooting distance with the highest definition as the optimal shooting distance after executing multiple advancements.
[0143] Preferably, this application uses a hierarchical search strategy, using a coarse-first-then-fine search strategy. A larger first step size is used to quickly determine the approximate optimal shooting distance range, significantly reducing search time and improving search efficiency. A smaller second step size is then used to carefully search within the precise range, improving the accuracy of determining the optimal shooting distance. The steps of the coarse search stage and the fine search stage are shown below.
[0144] Coarse search phase.
[0145] First, a large initial step size (e.g., 5 cm) is set, and the total number of camera advances is determined. The camera then moves from its initial position toward the subject, each time with the first step size, capturing an image. During this process, a sharpness score is calculated for each captured image using methods such as multi-scale gradient fusion and correction of blurred areas. Finally, the sharpness scores corresponding to all shooting distances are compared to determine an initial optimal shooting distance H. This large step size rapidly narrows the range for finding the optimal shooting distance.
[0146] Precision search stage.
[0147] First, based on the optimal shooting distance H and the first advance step S determined in the previous step, a new shooting distance range [HS, H + S] is defined. This range will serve as the starting interval for the next round of shooting. This range will serve as the initial shooting distance between the camera and the subject for the next round of shooting. Compared with the shooting in the coarse search stage, this range is closer to the actual optimal distance, effectively narrowing the search space.
[0148] Next, a second advance step size is set that is significantly smaller than the first, such as 1 cm. The camera then advances again within the new distance range using the second advance step size, continuing to calculate image clarity after each advance. By using a smaller step size for fine search with the same advance step number, and fine-tuning within the range determined by the coarse search, the accuracy of the optimal shooting distance is improved, avoiding missing the true optimal distance due to excessive step sizes.
[0149] Finally, the camera advances multiple times according to the new settings, capturing an image after each advance. The image clarity is calculated to establish a correspondence between clarity and the current shooting distance. After all advances are completed, the shooting distance with the highest clarity is selected from the correspondence and used as the final shooting distance, achieving fine-tuning of the shooting distance.
[0150] In this application, the final shooting distance is determined by a coarse-first, then fine search method, ensuring optimal image clarity. Coarse search reduces unnecessary shots and calculations, while fine search focuses on a smaller area, reducing the number of camera movements and image calculations overall. This reduces mechanical wear and tear on the camera during long shooting missions, conserving computing resources, extending the life of the equipment, and lowering operating costs.
[0151] This application provides a schematic diagram of the overall process of determining the optimal shooting distance of a fixed depth of field camera, such as Figure 2 As shown, the following steps are included.
[0152] Step 1: Initial parameter setting.
[0153] Step 1.1: Set the camera's first step size, S, to a relatively large distance value, such as 5 cm, to quickly search for the approximate range of the optimal shooting distance. Also set the camera's preset step size, i.
[0154] Step 1.2: Set the initial region parameters of the region of interest, such as corner coordinates (X, Y), width, and height.
[0155] Step 1.3: Determine the total number of camera advances, which will be used in the subsequent coarse search and fine search stages.
[0156] Step 1.4: Set the initial position of the camera and use this position as the starting point for the shooting distance.
[0157] Step 2: Coarse search phase (rapid positioning over a large area).
[0158] Step 2.1: Starting from the initial position, the camera moves toward the subject according to the first advance step, capturing an image each time it moves. This process is repeated until the preset total number of advances is reached.
[0159] Step 2.2: During the advancement process, the image zoom ratio is determined based on the ratio of the shooting distance before and after each advancement.
[0160] Step 2.3: Use the image scaling ratio to process the region parameters of the region of interest before advancing, obtain the region parameters after advancing, and determine the corresponding region of interest. The content captured in the region of interest is scaled in the same proportion during the camera advancing process.
[0161] Step 2.4: Determine the captured image in the region of interest after the camera is advanced.
[0162] Step 2.5: Downsample the captured image to generate images of different scales, such as 1 / 2 or 1 / 4 the size of the original image.
[0163] Step 2.6: Calculate the gradient magnitude, gradient magnitude variance, and gradient magnitude mean of each scale image.
[0164] Step 2.7: Assign weights to each scale image based on the gradient magnitude variance. The gradient magnitude variance reflects the texture density of the image. Weights are assigned to each scale image based on the texture density, with regions with richer texture receiving higher weights.
[0165] Step 2.8: Fuse the mean gradient amplitudes of images of different scales, comprehensively consider the weights of each region, generate an initial clarity score, and obtain the target image.
[0166] Step 2.9: Divide the target image into multiple small sub-blocks and calculate the mean gradient of each sub-block. Identify blurry sub-blocks by comparing the sub-block gradient mean with the initial clarity score of the overall image.
[0167] Step 2.10: Deduct the blur area score of the blur sub-block from the initial clarity score to obtain the clarity of the captured image.
[0168] Step 2.11: Compare the sharpness scores of all shooting distances and find the shooting distance with the highest sharpness score as the optimal shooting distance H.
[0169] Step 3: Fine search phase (fine adjustment in a small range).
[0170] Step 3.1: Based on the initial optimal shooting distance H and the first advancement step S, determine a new shooting distance range [HS, H+S].
[0171] Step 3.2: Set a second advancement step size, which should be significantly smaller than the first advancement step size, such as 1 cm, for performing a more detailed search within the newly determined small range.
[0172] Step 3.3: The camera moves toward the subject within the new shooting distance range, starting from the minimum value of the shooting distance range, according to the second advance step length, capturing one image each time it moves, and repeating the process until the preset total number of advances is reached.
[0173] Step 3.4: Repeat the image processing steps 2.2-2.10 for each image captured during the fine search phase to calculate the corrected sharpness score for each shooting distance.
[0174] Step 4: Determine the final result.
[0175] Step 4.1: From all the clarity scores obtained in the fine search phase, select the shooting distance with the highest score and use it as the final optimal shooting distance.
[0176] Step 4.2: The camera moves to the optimal shooting distance position determined finally and takes the actual shot to obtain the image with the best clarity.
[0177] Based on the same technical concept, the present application provides a device for determining the optimal shooting distance of a fixed depth-of-field camera, such as Figure 3 As shown, the device includes:
[0178] A first determining module 301 is configured to determine an initial region of interest focused on by a camera with a fixed depth of field, and determine first region parameters of the initial region of interest, wherein the camera captures an image each time it advances a fixed distance toward the subject;
[0179] A second determining module 302 is configured to determine the image scaling ratios before and after the camera is advanced, based on the initial shooting distance between the camera and the subject before the camera is advanced and the current shooting distance between the camera and the subject after the camera is advanced;
[0180] An adjustment module 303 is configured to adjust the first region parameters according to the image scaling ratio to obtain the second region parameters after the camera advances, and determine the current region of interest corresponding to the second region parameters, wherein the captured content of the region of interest is scaled in the same ratio during the camera advance process;
[0181] The third determination module 304 is configured to obtain image clarity by fusing multi-scale gradients of the image captured in the current region of interest, and record a corresponding relationship between the clarity and the current shooting distance;
[0182] The selection module 305 is used to select the shooting distance with the highest definition as the optimal shooting distance according to the corresponding relationship after the camera advance is completed.
[0183] Optionally, the first region parameter includes a first abscissa, a first ordinate, a first width, and a first height of a corner point of the initial region of interest, and the adjustment module 303 is configured to:
[0184] Determine the central abscissa and central ordinate of the center point of the overall image, wherein the overall image is the entire image captured by the camera;
[0185] Determine a second abscissa according to the central abscissa, the image scaling ratio, and the first abscissa;
[0186] Determine a second ordinate according to the central ordinate, the image scaling ratio, and the first ordinate;
[0187] Determine a second width based on the first width and the image scaling ratio;
[0188] Determine a second height based on the first height and the image scaling ratio;
[0189] A second area parameter is constructed according to the second abscissa, the second ordinate, the second width, and the second height.
[0190] Optionally, the third determining module 304 is configured to:
[0191] Generate a multi-scale image by downsampling the captured image in the current region of interest;
[0192] By dynamically assigning weights to images of each scale and fusing multi-scale gradients, a target image with an initial clarity score is generated;
[0193] Selecting a blurred sub-block from the plurality of candidate sub-blocks according to the gradient mean of each candidate sub-block in the target image, wherein the local image region corresponding to the blurred sub-block has image blur;
[0194] The clarity of the captured image is obtained by deducting the blurry area score corresponding to the blurry sub-block from the initial clarity score.
[0195] Optionally, the third determining module 304 is specifically configured to:
[0196] Determining the gradient magnitude of each pixel in each scale image, and determining the gradient magnitude variance and the gradient magnitude mean of the scale image based on the gradient magnitudes of the multiple pixels, wherein the gradient magnitude variance is used to indicate the texture density of the scale image;
[0197] Assign weights to the corresponding scale images according to the texture density of each scale image, where the weight is positively correlated with the richness of the texture density;
[0198] According to the weighted sum of the gradient amplitude mean and weight of each scale image, the target image with an initial clarity score is obtained.
[0199] Optionally, the third determining module 304 is specifically configured to:
[0200] Divide the target image into multiple candidate sub-blocks and determine the gradient mean of each candidate sub-block;
[0201] Determining a scoring threshold based on a preset threshold coefficient and an initial clarity score;
[0202] If the absolute value of the difference between the gradient mean of the candidate sub-block and the initial clarity score exceeds the score threshold, the candidate sub-block is determined to be a blurred sub-block.
[0203] Optionally, the third determining module 304 is specifically configured to:
[0204] Determining a blur region score based on the number of blur sub-blocks, the number of candidate sub-blocks, and a preset penalty coefficient, wherein the preset penalty coefficient is used to indicate the degree of influence of local blur on the overall clarity of the image;
[0205] The final clarity score is obtained based on the difference between the initial clarity score and the blurred area score, and the final clarity score is used as the clarity of the captured image.
[0206] Optionally, the device is further used to:
[0207] Determine a shooting distance range according to the optimal shooting distance, the difference between the first advancing step length, and the sum thereof, and use the shooting distance range as an initial shooting distance between the camera and the object;
[0208] re-determining the camera's advancing distance each time according to the second advancing step length and the preset advancing step number, wherein the second advancing step length is smaller than the first advancing step length;
[0209] The step of re-determining the current shooting distance according to the updated initial shooting distance and the updated advancing distance, and selecting the shooting distance with the highest definition as the optimal shooting distance after executing multiple advancements.
[0210] like Figure 4 As shown, an embodiment of the present application provides an electronic device, including a processor 401, a communication interface 402, a memory 403 and a communication bus 404, wherein the processor 401, the communication interface 402, and the memory 403 communicate with each other through the communication bus 404.
[0211] The memory 403 is used to store computer programs.
[0212] In one embodiment of the present application, the processor 401 is configured to implement the method for determining the optimal shooting distance of a fixed depth-of-field camera provided by any one of the aforementioned method embodiments when executing the program stored in the memory 403 .
[0213] An embodiment of the present application further provides a computer-readable storage medium having a computer program stored thereon. When the computer program is executed by a processor, the steps of the method for determining the optimal shooting distance of a fixed depth-of-field camera provided in any of the aforementioned method embodiments are implemented.
[0214] The device embodiments described above are merely illustrative. The units described as separate components may or may not be physically separate, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed across multiple network units. Some or all of the modules may be selected based on actual needs to achieve the objectives of this embodiment.
[0215] Through the description of the above embodiments, those skilled in the art will clearly understand that each embodiment can be implemented using software plus a general-purpose hardware platform, or of course, hardware. Based on this understanding, the essence of the above technical solution, or the portion that contributes to the relevant technology, can be embodied in the form of a software product. This computer software product can be stored in a computer-readable storage medium, such as ROM / RAM, a magnetic disk, or an optical disk, and includes a number of instructions for causing a computer device (such as a personal computer, server, or network device) to execute the methods of each embodiment or certain portions of the embodiments.
[0216] It should be understood that the terms used herein are for the purpose of describing specific example embodiments only and are not intended to be limiting. Unless the context clearly indicates otherwise, the singular forms "one", "an" and "said" as used herein may also be meant to include plural forms. The terms "comprise", "include", "contain" and "have" are inclusive and therefore specify the presence of stated features, steps, operations, elements and / or parts, but do not exclude the presence or addition of one or more other features, steps, operations, elements, parts, and / or combinations thereof. The method steps, processes, and operations described herein are not to be construed as necessarily requiring them to be performed in the specific order described or illustrated, unless the order of execution is clearly indicated. It should also be understood that additional or alternative steps may be used.
[0217] The foregoing is merely a list of specific embodiments of the present application, intended to enable those skilled in the art to understand or implement the present application. Various modifications to these embodiments will be readily apparent to those skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of the present application. Therefore, the present application is not limited to the embodiments shown herein, but is intended to conform to the broadest scope consistent with the principles and novel features of the present application.
Claims
1. A method for determining the optimal shooting distance of a fixed depth-of-field camera, characterized in that: The method comprises: Determining an initial region of interest focused on by a camera with a fixed depth of field, and determining first region parameters of the initial region of interest, wherein the camera captures an image each time it advances a fixed distance toward the subject; determining, based on an initial shooting distance between the camera and the photographed object before the camera is advanced and a current shooting distance between the camera and the photographed object after the camera is advanced, a zoom ratio of an image generated before and after the camera is advanced; Adjusting the first region parameter according to the image scaling ratio to obtain the second region parameter after the camera advances, and determining a current region of interest corresponding to the second region parameter, wherein the captured content of the region of interest is scaled in the same ratio during the advancement of the camera; Obtaining image clarity by fusing multi-scale gradients of the image captured in the current region of interest, and recording a corresponding relationship between the clarity and the current shooting distance; After the camera advance is completed, the shooting distance with the highest definition is selected as the optimal shooting distance according to the corresponding relationship.
2. The method according to claim 1, characterized in that The first region parameters include a first horizontal coordinate, a first vertical coordinate, a first width, and a first height of a corner point of the initial region of interest. The first region parameters are adjusted according to the image scaling ratio to obtain the second region parameters after the camera is advanced. Determining a central abscissa and a central ordinate of a center point of an overall image, wherein the overall image is the entire image captured by the camera; determining a second abscissa according to the central abscissa, the image scaling ratio, and the first abscissa; determining a second vertical coordinate according to the central vertical coordinate, the image scaling ratio, and the first vertical coordinate; determining a second width according to the first width and the image scaling ratio; determining a second height according to the first height and the image scaling ratio; The second area parameter is constructed according to the second horizontal coordinate, the second vertical coordinate, the second width, and the second height.
3. The method according to claim 1, characterized in that The image clarity is obtained by fusing the multi-scale gradients of the captured image in the current region of interest, including: Generate a multi-scale image by downsampling the captured image in the current region of interest; By dynamically assigning weights to images of each scale and fusing multi-scale gradients, a target image with an initial clarity score is generated; Selecting blurred sub-blocks from a plurality of candidate sub-blocks according to a gradient mean value of each candidate sub-block in the target image, wherein the local image region corresponding to the blurred sub-block has image blur; The clarity of the captured image is obtained by deducting the blur region score corresponding to the blur sub-block from the initial clarity score.
4. The method according to claim 3, characterized in that By dynamically assigning weights to images of each scale and fusing multi-scale gradients, the target image with an initial clarity score is generated, including: Determining a gradient magnitude of each pixel in each scale image, and determining a gradient magnitude variance and a gradient magnitude mean of the scale image based on the gradient magnitudes of the plurality of pixels, wherein the gradient magnitude variance is used to indicate a texture density of the scale image; Assigning a weight to the corresponding scale image according to the texture density of each scale image, wherein the weight is positively correlated with the richness of the texture density; According to the weighted sum of the gradient amplitude mean and weight of each scale image, the target image with an initial clarity score is obtained.
5. The method according to claim 3, characterized in that Selecting blurred sub-blocks from a plurality of candidate sub-blocks according to the gradient mean of each candidate sub-block in the target image includes: Dividing the target image into a plurality of candidate sub-blocks, and determining a gradient mean value of each candidate sub-block; Determining a scoring threshold based on a preset threshold coefficient and the initial clarity score; If the absolute value of the difference between the gradient mean of the candidate sub-block and the initial clarity score exceeds the score threshold, the candidate sub-block is determined to be a blurred sub-block.
6. The method according to claim 3, characterized in that Obtaining the clarity of the captured image by deducting the blur region score corresponding to the blur sub-block from the initial clarity score includes: Determining a blur region score according to the number of blur sub-blocks, the number of candidate sub-blocks, and a preset penalty coefficient, wherein the preset penalty coefficient is used to indicate the degree of influence of local blur on the overall clarity of the image; A final clarity score is obtained according to a difference between the initial clarity score and the blurred area score, and the final clarity score is used as the clarity of the captured image.
7. The method according to claim 1, characterized in that The fixed distance of camera advancement is determined based on the first advancement step length and a preset number of advancement steps. After determining the optimal shooting distance, the method further includes: determining a new shooting distance range according to the optimal shooting distance and the difference and the sum of the first advancing step length, and using the minimum value of the new shooting distance range as the updated initial shooting distance between the camera and the shooting object; re-determining the advancing distance of the camera each time according to a second advancing step length and the preset advancing step number, wherein the second advancing step length is smaller than the first advancing step length; The step of re-determining the current shooting distance according to the updated initial shooting distance and the updated advancing distance, and selecting the shooting distance with the highest definition as the optimal shooting distance after executing multiple advancements.
8. A device for determining the optimal shooting distance of a fixed depth-of-field camera, characterized in that: The device comprises: a first determining module, configured to determine an initial region of interest focused on by a camera with a fixed depth of field, and determine first region parameters of the initial region of interest, wherein the camera captures an image each time it advances a fixed distance toward a photographed object; a second determining module, configured to determine the image scaling ratios before and after the camera is advanced, based on an initial shooting distance between the camera and the subject before the camera is advanced and a current shooting distance between the camera and the subject after the camera is advanced; an adjustment module, configured to adjust the first region parameter according to the image scaling ratio, obtain the second region parameter after the camera advances, and determine a current region of interest corresponding to the second region parameter, wherein the captured content of the region of interest is scaled in the same ratio during the advancement of the camera; a third determining module, configured to obtain image clarity by fusing multi-scale gradients of the image captured in the current region of interest, and record a corresponding relationship between the clarity and the current shooting distance; The selection module is used to select the shooting distance with the highest definition as the optimal shooting distance according to the corresponding relationship after the camera is moved forward.
9. An electronic device, characterized in that: It includes a processor, a communication interface, a memory and a communication bus, wherein the processor, the communication interface and the memory communicate with each other via the communication bus; Memory for storing computer programs; A processor, configured to implement the method according to any one of claims 1 to 7 when executing a program stored in a memory.
10. A computer-readable storage medium, characterized in that The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the method according to any one of claims 1 to 7 is implemented.
Citation Information
Patent Citations
Image photographing method and equipment and computer readable storage medium
CN108171743A
Automatic focusing method, system and equipment for medium-format inspection camera and storage medium
CN117939293A