Spacing measurement method, spacing measurement device and computer equipment
By performing noise cancellation and edge contrast calculation on the image, the gap spacing is directly measured, which solves the problem of high resource consumption in the prior art, and realizes accurate measurement in resource-constrained environments.
Patent Information
- Application Number
- CN202411033426.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-30
- Publication Date
- 2024-11-22
AI Technical Summary
The existing spacing measurement methods rely on deep learning models, resulting in the need of a large number of computing resources for model training and operation, and cannot be implemented in resource-constrained environments.
By performing noise cancellation and image enhancement on the original image, the pixel points with the highest and lowest edge contrast within the region of interest are determined, and the distance between these points is calculated to measure the spacing of the gap to be measured.
It realizes that the spacing of the gap to be measured is accurately measured without model training and large amounts of computing resources, reducing costs and resource requirements.
Smart Images

Figure CN119006566A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer vision image technology, and in particular to a distance measurement method, a distance measurement device and a computer device. Background Art
[0002] In computer vision and image processing, the application of measuring the distance between objects is very extensive. By measuring the distance between objects, it can help locate and track the position of the target object, thereby realizing automated control or monitoring tasks. Measuring the distance between objects can be used for dimensional analysis, such as checking whether the product size meets the standard, or detecting the degree of deformation of the object. By measuring the distance between objects, it can help estimate the posture and relative position of the object, such as determining the position and direction of the grasped object in robot operation.
[0003] Existing distance measurement methods mainly use deep learning technology to train models to identify and measure the distance between objects in images, such as using neural networks for target detection and distance measurement. The model training and operation of the above distance measurement methods require a lot of computing resources, including high-performance hardware such as GPUs, resulting in high measurement costs and cannot be implemented in resource-constrained environments. Summary of the invention
[0004] The present application provides a distance measurement method, a distance measurement device and a computer device, which can realize the distance measurement without model training and consuming less computing resources.
[0005] The first aspect of the present application provides a distance measurement method, comprising: Performing noise elimination and image enhancement on the original image to obtain a target image, wherein the original image is a grayscale image including a target gap; Determine N regions of interest ROIs corresponding to the target image, where N is an integer greater than or equal to 1; Calculate the edge contrast of each pixel in a target ROI, where the target ROI is any one of the N ROIs; Determine a first pixel and a second pixel according to the edge contrast of each pixel in the target ROI, wherein the first pixel is a pixel with the highest edge contrast in the target ROI, and the second pixel is a pixel with the lowest edge contrast in the target ROI; Calculating a target distance between the first pixel point and the second pixel point; The spacing of the gap to be measured is determined according to the target distance.
[0006] By adopting the above technical solution, the original grayscale image is subjected to noise elimination and image enhancement processing to obtain a target image, and N regions of interest ROIs are determined in the processed image, and the edge contrast of each pixel in each ROI is calculated, and the pixel point with the highest edge contrast and the pixel point with the lowest edge contrast in each ROI are determined, and the spacing of the gap to be measured is determined according to the distance between the pixel point with the highest edge contrast and the pixel point with the lowest edge contrast in the N ROIs. Thus, by calculating the average value of the distance between the pixel point with the highest edge contrast and the pixel point with the lowest edge contrast in the N ROIs as the spacing of the gap to be measured, the spacing of the gap to be measured can be accurately measured in the scenario where no model training is performed and there are no large amounts of computing resources.
[0007] Optionally, determining N regions of interest ROIs corresponding to the target image includes: determining a first line segment on the target image according to a first operation instruction of a user, wherein the first line segment corresponds to the target gap setting; Divide the first line segment into equal parts to obtain N second line segments; The N ROIs are determined according to a target line segment and a grayscale value corresponding to the target gap, wherein the target line segment is any one of the N second line segments.
[0008] By adopting the above technical solution, a first operation instruction from a user is received, the position of a first line segment on a target image is determined, and the first line segment is set, and then the first line segment is equally divided to obtain N second line segments, and N ROIs corresponding to the N second line segments are determined according to the gray value of the target image. Thus, the position of the gap to be measured on the target image is accurately located through the operation instruction of the user, and the first line segment is set at the position, so that the N ROIs can be accurately set on the gap to be measured.
[0009] Optionally, determining the N ROIs according to the grayscale values corresponding to the target line segments and the target gaps includes: receiving a second operation instruction from the user; determining a target height according to the second operation instruction; The N ROIs are determined according to the target height and the length of the target line segment.
[0010] By adopting the above technical solution, the second operation instruction of the user is received, the target height is determined according to the second operation instruction, and the ROI is determined according to the target height and the target line segment. Thus, through the user's operation instruction, it is ensured that the target ROI can cover the gap to be measured.
[0011] Optionally, determining the N ROIs according to the grayscale values corresponding to the target line segments and the target gaps includes: The target line segment is translated on the target image in a direction perpendicular to the target line segment to obtain an initial ROI; and the grayscale value of each pixel in the initial ROI is determined; A target ROI is determined from the initial ROI according to the grayscale value of each pixel in the initial ROI, and the target ROI is an ROI corresponding to the target line segment among the N ROIs.
[0012] By adopting the above technical solution, the target line segment is translated in a direction perpendicular to the target line segment to obtain an initial ROI, and the grayscale value of each pixel in the initial ROI is obtained. According to the grayscale value of each pixel in the initial ROI, the target ROI is determined in the initial ROI, thereby achieving coverage of the target ROI on the gap to be measured without the need for user operation instructions.
[0013] Optionally, determining the target ROI from the initial ROI according to the grayscale value of each pixel in the initial ROI includes: Setting M auxiliary lines parallel to the target line segment in the initial ROI at preset intervals, wherein M is an integer greater than or equal to 2; Determine a target difference between the grayscale values of any two auxiliary lines among the M auxiliary lines; Determine two pairs of auxiliary lines from the M auxiliary lines whose target difference is greater than a preset threshold; Determining two target auxiliary lines from the M auxiliary lines according to the two pairs of auxiliary lines; The target ROI is determined according to the two target auxiliary lines.
[0014] By adopting the above technical solution, M auxiliary lines with equal spacing are set in the initial ROI, the grayscale value of each auxiliary line is obtained, and the difference in grayscale values between any two auxiliary lines is calculated, and two pairs of auxiliary lines whose difference exceeds a preset threshold are obtained. Two target auxiliary lines are determined from the M auxiliary lines according to the two pairs of auxiliary lines, and the target ROI is determined according to the two target auxiliary lines. Thus, it is judged whether the difference in grayscale values between any two auxiliary lines in the M auxiliary lines exceeds the preset threshold, so as to achieve that the target ROI between the two target auxiliary lines can cover the target gap.
[0015] Optionally, determining the N ROIs according to the grayscale values corresponding to the target line segments and the target gaps includes: Calculate the average gray value of the target line segment pixels to obtain a first average gray value; Translating the first auxiliary line on the target image along a first direction perpendicular to the target line segment; translating the second auxiliary line on the target image along a second direction in which the first auxiliary line is translated, wherein the second direction is opposite to the first direction; Calculating an average grayscale value of pixels between the first auxiliary line and the target line segment to obtain a second average grayscale value; If the difference between the first average grayscale value and the second average grayscale value is greater than a preset threshold, stopping translating the first auxiliary line; Calculating an average grayscale value of pixels between the second auxiliary line and the target line segment to obtain a third average grayscale value; If the difference between the first average grayscale value and the third average grayscale value is greater than a preset threshold, stop translating the second auxiliary line; A target ROI is determined according to the first auxiliary line and the second auxiliary line, where the target ROI is an ROI corresponding to the target line segment among the N ROIs.
[0016] By adopting the above technical solution, the average grayscale value of the pixels on the target line segment is first calculated to obtain the first average grayscale value, the first auxiliary line is gradually translated in a direction perpendicular to the target line segment, the second auxiliary line is gradually translated in a direction opposite to the translation of the first auxiliary line, and the average grayscale value of the pixels on the first auxiliary line and the second auxiliary line is calculated. When the difference between the average grayscale value of the first auxiliary line or the second auxiliary line and the first average grayscale value exceeds a preset threshold, the translation of the corresponding auxiliary line is stopped. When both auxiliary lines stop translating, the target ROI is determined based on the two auxiliary lines. Thus, the two auxiliary lines are gradually translated to expand the distance between the auxiliary lines until it is detected that the difference between the average grayscale value of the two auxiliary lines and the first average grayscale value exceeds the preset threshold, then the translation is stopped to ensure that the target ROI between the two auxiliary lines can cover the target gap.
[0017] Optionally, performing noise elimination and image enhancement on the original image to obtain the target image includes: determining a target pixel point, where the target pixel point is any pixel point of the original image; Determine a neighborhood matrix of the target pixel point, wherein the neighborhood matrix includes N pixels in addition to the target pixel point; Calculating weighted values of N pixels in the neighborhood matrix; Calculating a normalization factor according to the N weighted values; Calculate the target grayscale value of the neighborhood matrix according to the Gaussian filter formula, and replace the grayscale value of the target pixel with the target grayscale value; The grayscale value of each pixel in the original image is replaced with the corresponding target grayscale value to obtain a noise-eliminated image; and the contrast of the noise-eliminated image is enhanced according to a contrast enhancement formula to obtain a target image.
[0018] By adopting the above technical solution, the original image is processed using Gaussian filtering and contrast enhancement formulas to obtain a target image with noise eliminated and contrast enhanced. Thus, the original image is processed to obtain a target image, and the target image is used as an image for calculating the gap spacing to be measured, which can reduce the calculation errors caused by image noise and unclear gap edges.
[0019] Optionally, calculating the edge contrast of each pixel in the target ROI includes: Determine the grayscale value of a target pixel in the target ROI and the grayscale values of N surrounding pixels, wherein the target pixel is any pixel in the target ROI; Calculate the average grayscale value of the surrounding N pixels; The difference between the grayscale value of the target pixel and the average grayscale value is calculated to obtain the edge contrast corresponding to the target pixel.
[0020] By adopting the above technical solution, the difference between the grayscale value of any pixel in the target ROI and the average grayscale value of the surrounding N pixels is calculated to obtain the edge contrast of the corresponding pixel. Thus, the edge contrast of the pixel can be obtained, which is convenient for the subsequent calculation of the spacing of the gap to be measured.
[0021] The second aspect of the present application provides a distance measurement device, which adopts the following technical solution: A spacing measurement device, comprising: A processing module is used to remove noise from the original image and enhance the image to obtain a target image; A drawing module, used to determine N regions of interest ROI corresponding to the target image; A calculation module is used to calculate the edge contrast of each pixel in the target ROI; The determination module is used to determine the first pixel point and the second pixel point according to the edge contrast of each pixel point in the target ROI and to determine the spacing of the gap to be measured according to the target distance.
[0022] A third aspect of the present application provides a computer device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the steps of the distance measurement method described in the first aspect when executing the computer program.
[0023] A fourth aspect of the present application provides a computer storage medium, which includes instructions, and when the instructions are executed on a computer, the computer executes the steps of the distance measurement method described in any of the above aspects.
[0024] In summary, it can be seen that in the embodiments provided by the present application, the target image is obtained by performing noise elimination and contrast enhancement on the original image, and the position of the gap to be measured on the target image is determined through user operation. At this position, N ROIs can be determined by user operation or by identifying the grayscale value of the target image, and the distance between the two points with the highest edge contrast and the lowest edge contrast in each ROI is calculated. Finally, the average value of the distance is calculated as the spacing of the gap to be measured, thereby eliminating the need for model training and a large amount of computing resources, and achieving accurate measurement of the spacing of the gap to be measured in a resource-constrained environment. BRIEF DESCRIPTION OF THE DRAWINGS
[0025] Figure 1 is a flow chart of a distance measurement method provided in an embodiment of the present application; Figure 2 is a virtual structural diagram of a spacing measurement device provided in an embodiment of the present application; Figure 3 It is a schematic diagram of the hardware structure of a computer device provided in an embodiment of the present application; Figure 4 is a schematic diagram of determining a target ROI based on an initial ROI provided in an embodiment of the present application; Figure 5 It is a schematic diagram of determining ROI by translating auxiliary lines provided in an embodiment of the present application. DETAILED DESCRIPTION
[0026] The technical solutions in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, rather than all of the embodiments.
[0027] For ease of understanding, some terms provided in the embodiments of the present application are explained below, specifically as follows: ROI refers to "Region of Interest" in the field of image recognition. When processing images, ROI technology allows us to focus on specific parts of the image that may contain important features or information, while ignoring other irrelevant areas.
[0028] Gaussian filtering is a linear smoothing filtering technology that is widely used in image processing and computer vision, especially for eliminating Gaussian noise.
[0029] Combined with reference Figure 1 , Figure 1 A flow chart of a distance measurement method provided in an embodiment of the present application includes: 101, performing noise elimination and image enhancement on an original image to obtain a target image.
[0030] In this embodiment, the spacing measurement device can obtain the original image. The original image can be obtained by the spacing measurement device selecting a black and white camera with appropriate pixels according to the size of the product, taking a photo to obtain the original image. For example, if the size of the product is 4mm, it is necessary to select a 5-megapixel black and white camera for shooting. The specific parameters of the camera are 2592*1944pix, so the obtained pixel accuracy is 0.0154m / pix, or the user transfers the original image to the spacing measurement device through a mobile storage device, such as a USB flash drive, a memory card, etc., without specific limitation.
[0031] Afterwards, the distance measurement device uses a Gaussian filtering formula to remove noise from the original image to obtain a noise-removed image, and uses a contrast enhancement formula to enhance the contrast of the noise-removed image to obtain a target image.
[0032] In one embodiment, performing noise elimination and image enhancement on the original image to obtain the target image includes: Determine the target pixel point, where the target pixel point is any pixel point in the original image; Determine a neighborhood matrix of the target pixel, where the neighborhood matrix contains N pixels in addition to the target pixel; Calculate the weighted values of N pixels in the neighborhood matrix; Calculating a normalization factor based on the N weighted values; The target grayscale value of the neighborhood matrix is calculated according to the Gaussian filter formula, and the target grayscale value is used to replace the grayscale value of the target pixel; the grayscale value of each pixel in the original image is replaced with the corresponding target grayscale value to obtain a noise-eliminated image; The contrast of the noise-eliminated image is enhanced according to the contrast enhancement formula to obtain the target image.
[0033] In this embodiment, the distance measurement device first determines the target pixel point and the neighborhood matrix of the target pixel point, and calculates the weighted values of the N pixel points in the neighborhood matrix.
[0034] Specifically, the distance measurement device can calculate the weighted values of N pixels using the following formula: Among them, k(i,j) is the weighted value of the pixel at position (i,j) in the neighborhood matrix, e is a natural constant, i is the horizontal coordinate of the pixel, j is the vertical coordinate of the pixel, and σ is the standard deviation of the Gaussian distribution.
[0035] Afterwards, the spacing measurement device calculates a normalization factor based on the N weighted values; Specifically, the spacing measurement device can calculate the normalization factor by the following formula: Among them, K is the normalization factor, and s×t is the neighborhood matrix of the target pixel.
[0036] Finally, the distance measurement device calculates the target grayscale value of the neighborhood matrix according to the Gaussian filtering formula, and replaces the grayscale value of the target pixel with the target grayscale value.
[0037] Specifically, the distance measurement device can calculate the target grayscale value of the neighborhood matrix by the following formula: Among them, f(x,y) is the weighted average of the target pixel, (x,y) is the target pixel, and z(i,j) is the pixel value at the (i,j) position in the neighborhood matrix.
[0038] The spacing measurement device replaces the grayscale value of each pixel in the original image with the corresponding target grayscale value to obtain a noise-eliminated image, and performs contrast enhancement on the noise-eliminated image according to a contrast enhancement formula to obtain a target image.
[0039] Specifically, the spacing measurement device can perform contrast enhancement by the following formula: Where res is the second target image, orig is the grayscale value of the original image, u is the grayscale value of the first target image, v is the image of the standard deviation of each pixel value of the original image, and Factor is a scalar that controls contrast enhancement.
[0040] 102. Determine N regions of interest ROIs corresponding to the target image.
[0041] In this embodiment, the spacing measurement device determines N regions of interest ROIs of the target image. The determination method may be that the user determines the positions and sizes of the N ROIs through the touch screen of the spacing measurement device, or the spacing measurement device automatically identifies the position of the gap to be measured and determines the positions and sizes of the N ROIs. There is no specific limitation.
[0042] In one embodiment, determining N regions of interest ROIs corresponding to the target image includes: determining a first line segment on the target image according to a first operation instruction of the user, the first line segment corresponding to the target gap setting; Divide the first line segment into equal parts to obtain N second line segments; N ROIs are determined according to the grayscale values corresponding to the target line segment and the target gap, and the target line segment is any line segment among the N second line segments.
[0043] In this embodiment, the spacing measurement device receives a first operation instruction from the user, and sets a first line segment on the target image according to the first operation instruction. The first line segment can be set by the user directly drawing the first line segment on the touch screen of the spacing measurement device, or by the spacing measurement device establishing a coordinate system and setting the first line segment according to the coordinates entered by the user on the keyboard. There is no specific limitation. The first line segment is set inside the target gap and parallel to the target gap.
[0044] Afterwards, the spacing measurement device divides the first line segment into N second line segments according to a preset value, and determines N ROIs according to the grayscale values corresponding to the N second line segments and the target gap. The preset value can be stored in the spacing measurement device in advance or input by the user on site, and is not specifically limited.
[0045] In one embodiment, determining N ROIs according to grayscale values corresponding to target line segments and target gaps includes: receiving a second operation instruction from the user; determining a target height according to a second operation instruction; N ROIs are determined according to the target height and the length of the target line segment.
[0046] In this embodiment, the distance measuring device receives a second operation instruction from the user. The second operation instruction may be received by the user rotating a knob of the distance measuring device or by inputting the second operation instruction through a button on the distance measuring device. Of course, the second operation instruction may also be obtained in other ways, such as the user directly dragging the target line segment on the touch screen. There is no specific limitation on this.
[0047] Afterwards, the spacing measurement device converts the received second operation instruction into a target height, and sets the ROI according to the target height and the length of the target line segment.
[0048] In one embodiment, determining N ROIs according to the grayscale values corresponding to the target line segment and the target gap includes: translating the target line segment on the target image in a direction perpendicular to the target line segment to obtain an initial ROI; Determine the grayscale value of each pixel in the initial ROI; The target ROI is determined from the initial ROI according to the gray value of each pixel in the initial ROI, and the target ROI is the ROI corresponding to the target line segment among the N ROIs.
[0049] In this embodiment, the spacing measurement device translates the target line segment in a direction perpendicular to the target line segment, and determines an initial ROI according to the target line segment after the target line segment translates a preset distance, and the preset distance needs to be greater than the spacing of the gap to be measured.
[0050] Afterwards, the distance measurement device obtains the grayscale value of each pixel in the initial ROI, and determines the position of the target ROI from the initial ROI according to the grayscale value of each pixel in the initial ROI.
[0051] The following is a specific example to illustrate how to determine the initial ROI. Figure 4 , Figure 4 It is a schematic diagram of determining ROI from a target image provided in an embodiment of the present application. The target line segment 405 is one of the N second line segments. The spacing measurement device translates the target line segment 405 in a direction 404 perpendicular to the target line segment 405 to obtain line segment 401 and line segment 480. The rectangle 409 obtained by connecting the line segment 401 and the line segment 480 is the initial ROI.
[0052] In one embodiment, determining the target ROI from the initial ROI according to the gray value of each pixel in the initial ROI includes: Setting M auxiliary lines parallel to the target line segment in the initial ROI at preset intervals, where M is an integer greater than or equal to 2; Determine a target difference between the grayscale values of any two auxiliary lines among the M auxiliary lines; Determine two pairs of auxiliary lines from the M auxiliary lines whose target difference is greater than a preset threshold; Determine two target auxiliary lines from the M auxiliary lines according to the two pairs of auxiliary lines; Determine the target ROI based on the two target auxiliary lines.
[0053] In this embodiment, the distance measurement device sets M auxiliary lines parallel to the target line segment in the initial ROI according to a preset interval, and calculates the target difference between the grayscale values of any two auxiliary lines among the M auxiliary lines.
[0054] Afterwards, the distance measuring device determines two pairs of auxiliary lines from the M auxiliary lines whose target difference is greater than a preset threshold, and determines two target auxiliary lines from the M auxiliary lines based on the two pairs of auxiliary lines. The target auxiliary line can be an auxiliary line in each pair of auxiliary lines that is farther away from the target line segment, or it can be an auxiliary line outside each pair of auxiliary lines and farther away from the target line segment. There is no specific limitation.
[0055] Finally, the distance measurement device determines the target ROI based on the two target auxiliary lines.
[0056] The following is a specific example to illustrate how to determine the target ROI. Figure 4 , Figure 4It is a schematic diagram of determining ROI of a target image provided by an embodiment of the present application. The spacing measurement device sets M auxiliary lines parallel to the target line segment in the initial ROI, determines the target difference between the grayscale values of any two auxiliary lines among the M auxiliary lines, and determines two pairs of auxiliary lines whose target difference is greater than a preset threshold from the M auxiliary lines. The first pair of auxiliary lines is line segment 402 and line segment 403, and the second pair of auxiliary lines is line segment 406 and line segment 407. Two target auxiliary lines are determined from the M auxiliary lines based on the two pairs of auxiliary lines. The target auxiliary lines can be auxiliary lines in each pair of auxiliary lines that are farther from line segment 405, such as line segment 402 and line segment 407, or auxiliary lines outside each pair of auxiliary lines and farther from the target line segment 405, such as line segment 410 and line segment 411, line segment 402 and line segment 407, and the specific details are not limited. Finally, the target auxiliary lines are connected to obtain the target ROI. For example, the rectangle obtained by connecting line segment 402 and line segment 407 is the target ROI.
[0057] In one embodiment, determining N ROIs according to grayscale values corresponding to target line segments and target gaps includes: Calculate the average gray value of the target line segment pixels to obtain a first average gray value; Translating the first auxiliary line on the target image along a first direction perpendicular to the target line segment; The second auxiliary line is translated on the target image along a second direction of the translation of the first auxiliary line, the second direction being opposite to the first direction; the average gray value of the pixels between the first auxiliary line and the target line segment is calculated to obtain a second average gray value; If the difference between the first average grayscale value and the second average grayscale value is greater than a preset threshold, then stop translating the first auxiliary line; Calculating an average grayscale value of pixels between the second auxiliary line and the target line segment to obtain a third average grayscale value; If the difference between the first average grayscale value and the third average grayscale value is greater than a preset threshold, then stop translating the second auxiliary line; A target ROI is determined according to the first auxiliary line and the second auxiliary line, where the target ROI is an ROI corresponding to the target line segment among the N ROIs.
[0058] In this embodiment, the spacing measurement device calculates the average grayscale value of the target line segment pixels to obtain a first grayscale value, and sets two auxiliary lines. The first auxiliary line is translated on the target image along a first direction perpendicular to the target line segment, and the second auxiliary line is translated in a direction opposite to the translation direction of the first auxiliary line. In the process of translating the auxiliary lines, the average grayscale value of each auxiliary line is calculated. When the difference between the average grayscale value of the auxiliary line and the first grayscale value is greater than a preset threshold, the translation of the auxiliary line is stopped. When both auxiliary lines stop translating, the target ROI is determined based on the two auxiliary lines.
[0059] The following is a specific example to illustrate how to determine the target ROI. Figure 5 , Figure 5 : It is a schematic diagram of determining ROI by translating auxiliary lines provided in an embodiment of the present application. The spacing measurement device calculates the average grayscale value of the target line segment 504 pixels to obtain a first grayscale value, and sets two auxiliary lines, line segment 503 and line segment 505. Line segment 503 is translated on the target image along a first direction 502 perpendicular to the target line segment, and line segment 505 is translated along a direction 506 opposite to the translation direction of line segment 503. In the process of translating the auxiliary lines, the average grayscale value of each auxiliary line is calculated. When the difference between the average grayscale value of the auxiliary line and the first grayscale value is greater than a preset threshold, the translation of the auxiliary line is stopped. For example, after translating line segment 503, line segment 501 is obtained, and after translating line segment 505, line segment 507 is obtained. Finally, the rectangle obtained by connecting line segment 505 and line segment 507 is the target ROI.
[0060] 103. Calculate the edge contrast of each pixel in the target ROI.
[0061] In this embodiment, the spacing measurement device calculates the edge contrast based on the grayscale value of the target pixel and the grayscale values of the pixels around the target pixel. The surrounding pixels can be pixels adjacent to the target pixel or pixels within a preset range near the target pixel, without specific limitation.
[0062] In one embodiment, calculating the edge contrast of each pixel in the target ROI includes: Determine the grayscale value of the target pixel in the target ROI and the grayscale values of the surrounding N pixels, where the target pixel is any pixel in the target ROI; Calculate the average gray value of the surrounding N pixels; The difference between the grayscale value of the target pixel and the average grayscale value is calculated to obtain the edge contrast corresponding to the target pixel.
[0063] In this embodiment, the spacing measurement device first selects any pixel point from the target ROI as the target pixel point, and then determines the grayscale value of the target pixel point through xxx method, and determines the grayscale value of each pixel point in the N pixels in the preset area around the target pixel point (the surrounding preset area can be a circular area with the target pixel point as the center and the preset distance as the radius, or it can be a square with the target pixel point as the center and the preset distance as the side length, and there is no specific limitation), and calculates the grayscale value of each pixel point in the N pixels to obtain the average grayscale value of the N pixels, and calculates the difference between the average grayscale value and the grayscale value of the target pixel point, and the difference is the edge contrast of the target pixel point.
[0064] 104. Determine a first pixel and a second pixel according to an edge contrast of each pixel in the target ROI.
[0065] In this embodiment, the distance measurement device will compare the edge contrast of the pixels in the target ROI one by one, and record the pixels with the highest edge contrast and the pixels with the lowest edge contrast, so as to calculate the distance between the first pixel and the second pixel in step 105, wherein the first pixel is the pixel with the highest edge contrast in the ROI, and the second pixel is the pixel with the lowest edge contrast in the target ROI.
[0066] 105. Calculate a target distance between the first pixel point and the second pixel point.
[0067] In this embodiment, the distance measurement device will establish a coordinate system, determine the coordinates of the first pixel point and the second pixel point in each ROI, and calculate the distance between the N first pixel points and the second pixel point by using a distance formula.
[0068] Specifically, the distance measuring device can calculate the distance between the first pixel and the second pixel by the following formula: |AB|=√(x1-x2) 2 +(y1-y2) 2 ; Wherein, |AB| is the distance between the first pixel and the second pixel, (x1, y1) is the coordinate of the first pixel, and (x2, y2) is the coordinate of the second pixel.
[0069] 106. Determine the spacing of the gap to be measured according to the target distance.
[0070] In this embodiment, after calculating the target distance corresponding to each ROI in the N ROIs, the spacing measurement device calculates an average value of the N target distances, and the average value is the spacing of the gap to be measured.
[0071] In summary, it can be seen that in the embodiment provided by the present application, the spacing measurement device processes the original image through the Gaussian filtering formula and the contrast enhancement formula to obtain the target image, determines the size and position of N ROIs by receiving user operations or the spacing measurement device determines the size and position of N ROIs according to the grayscale value of the target image, calculates the edge contrast of each pixel in the N ROIs, determines the pixel with the highest edge contrast and the pixel with the lowest edge contrast in each ROI, and calculates the distance between the pixel with the highest edge contrast and the pixel with the lowest edge contrast, removes outliers in the N distances, and calculates the average distance, which is the spacing of the gap to be measured. Therefore, there is no need for model training and a large amount of computing resources, and accurate measurement of the spacing of the gap to be measured can be achieved under resource-constrained conditions.
[0072] See also Figure 2 , Figure 2 This is a virtual structural diagram of a distance measurement device of the present application. The distance measurement device 200 includes: The processing module 201 is used to remove noise and enhance the original image to obtain a target image; A drawing module 202 is used to determine N regions of interest ROIs corresponding to the target image; A calculation module 203 is used to calculate the edge contrast of each pixel in the target ROI; The determination module 204 is used to determine the first pixel point and the second pixel point according to the edge contrast of each pixel point in the target ROI and to determine the spacing of the gap to be measured according to the target distance.
[0073] See also Figure 3 , Figure 3 A schematic diagram of the structure of a computer device provided in an embodiment of the present application, the computer device 300 includes: At least one processor 301, at least one communication bus 302, at least one memory 306, a power supply 307, a camera 309, and a user interface 308. The user interface 308 of the terminal device 300 includes a display, a knob, a keyboard, or a click device. The memory 306 may include a high-speed RAM memory, or may include a non-volatile memory (non-volatile memory), such as at least one disk memory. The memory 306 stores one or more computer programs 303 or data 305. When the terminal device 300 is running, the processor 301 communicates with the memory 306, and the processor 301 calls the instructions stored in the memory 306 to execute the above Figure 1 The operating system 304 includes various programs for implementing various basic services and processing tasks based on hardware.
[0074] In one embodiment, the present application provides a computer device, which may be a server, and its internal structure diagram may be as follows: Figure 3 As shown. The computer device includes a processor, a memory and a network interface connected through a system bus. Among them, the processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system, a computer program and a database. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The database of the computer device is used to store data. The network interface of the computer device is used to communicate with an external terminal through a network connection. When the computer program is executed by the processor, a method for measuring a distance is implemented.
[0075] Those skilled in the art will understand that Figure 3 The structure shown in the figure is only a block diagram of a part of the structure related to the solution of the present application, and does not constitute a limitation on the computer device to which the solution of the present application is applied. The specific computer device may include more or fewer components than those shown in the figure, or combine certain components, or have a different arrangement of components.
[0076] In one embodiment, a computer device is further provided, including a memory and a processor, wherein a computer program is stored in the memory, and the processor implements the steps in the above method embodiments when executing the computer program.
[0077] Those of ordinary skill in the art can understand that all or part of the processes in the above-mentioned embodiment methods can be completed by instructing the relevant hardware through a computer program, and the above-mentioned computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to memory, storage, database or other media used in the embodiments provided in this application can include at least one of non-volatile and volatile memory. Non-volatile memory can include read-only memory (ROM), magnetic tape, floppy disk, flash memory or optical memory, etc. Volatile memory can include random access memory (RAM) or external cache memory. As an illustration and not limitation, RAM can be in various forms, such as static random access memory (SRAM) or dynamic random access memory (DRAM).
[0078] The above are all preferred embodiments of the present application, and the protection scope of the present application is not limited thereto. Therefore, any equivalent changes made according to the structure, shape, and principle of the present application should be included in the protection scope of the present application.
Claims
1. A method for measuring a spacing, characterized in that: include: Performing noise elimination and image enhancement on the original image to obtain a target image, wherein the original image is a grayscale image including a target gap; Determine N regions of interest ROIs corresponding to the target image, where N is an integer greater than or equal to 1; Calculate the edge contrast of each pixel in a target ROI, where the target ROI is any one of the N ROIs; Determine a first pixel and a second pixel according to the edge contrast of each pixel in the target ROI, wherein the first pixel is a pixel with the highest edge contrast in the target ROI, and the second pixel is a pixel with the lowest edge contrast in the target ROI; Calculating a target distance between the first pixel point and the second pixel point; The spacing of the gap to be measured is determined according to the target distance.
2. The method according to claim 1, characterized in that: The determining of N regions of interest ROIs corresponding to the target image comprises: determining a first line segment on the target image according to a first operation instruction of a user, wherein the first line segment corresponds to the target gap setting; Divide the first line segment into equal parts to obtain N second line segments; The N ROIs are determined according to a target line segment and a grayscale value corresponding to the target gap, wherein the target line segment is any one of the N second line segments.
3. The method according to claim 2, characterized in that: The determining the N ROIs according to the grayscale values corresponding to the target line segments and the target gaps comprises: receiving a second operation instruction from the user; determining a target height according to the second operation instruction; The N ROIs are determined according to the target height and the length of the target line segment.
4. The method according to claim 2, characterized in that: The determining the N ROIs according to the grayscale values corresponding to the target line segments and the target gaps comprises: Translating the target line segment on the target image in a direction perpendicular to the target line segment to obtain an initial ROI; Determine the grayscale value of each pixel in the initial ROI; A target ROI is determined from the initial ROI according to the grayscale value of each pixel in the initial ROI, and the target ROI is an ROI corresponding to the target line segment among the N ROIs.
5. The method according to claim 4, characterized in that: Determining the target ROI from the initial ROI according to the grayscale value of each pixel in the initial ROI includes: Setting M auxiliary lines parallel to the target line segment in the initial ROI at preset intervals, wherein M is an integer greater than or equal to 2; Determine a target difference between the grayscale values of any two auxiliary lines among the M auxiliary lines; Determine two pairs of auxiliary lines from the M auxiliary lines whose target difference is greater than a preset threshold; Determining two target auxiliary lines from the M auxiliary lines according to the two pairs of auxiliary lines; The target ROI is determined according to the two target auxiliary lines.
6. The method according to claim 2, characterized in that: The determining the N ROIs according to the grayscale values corresponding to the target line segments and the target gaps comprises: Calculate the average gray value of the target line segment pixels to obtain a first average gray value; Translating the first auxiliary line on the target image along a first direction perpendicular to the target line segment; translating the second auxiliary line on the target image along a second direction in which the first auxiliary line is translated, wherein the second direction is opposite to the first direction; Calculating an average grayscale value of pixels between the first auxiliary line and the target line segment to obtain a second average grayscale value; If the difference between the first average grayscale value and the second average grayscale value is greater than a preset threshold, stopping translating the first auxiliary line; Calculating an average grayscale value of pixels between the second auxiliary line and the target line segment to obtain a third average grayscale value; If the difference between the first average grayscale value and the third average grayscale value is greater than a preset threshold, stop translating the second auxiliary line; A target ROI is determined according to the first auxiliary line and the second auxiliary line, where the target ROI is an ROI corresponding to the target line segment among the N ROIs.
7. The method according to claim 1, characterized in that: The process of removing noise from the original image and enhancing the image to obtain the target image includes: Determine a target pixel point, where the target pixel point is any pixel point of the original image; Determine a neighborhood matrix of the target pixel point, wherein the neighborhood matrix includes N pixels in addition to the target pixel point; Calculating weighted values of N pixels in the neighborhood matrix; Calculating a normalization factor according to the N weighted values; Calculate the target grayscale value of the neighborhood matrix according to the Gaussian filter formula, and replace the grayscale value of the target pixel with the target grayscale value; The grayscale value of each pixel in the original image is replaced with the corresponding target grayscale value to obtain a noise-removed image; The contrast of the noise-eliminated image is enhanced according to a contrast enhancement formula to obtain a target image.
8. The method according to claim 1, characterized in that: Calculating the edge contrast of each pixel in the target ROI includes: Determine the grayscale value of a target pixel in the target ROI and the grayscale values of N surrounding pixels, wherein the target pixel is any pixel in the target ROI; Calculate the average grayscale value of the surrounding N pixels; The difference between the grayscale value of the target pixel and the average grayscale value is calculated to obtain the edge contrast corresponding to the target pixel.
9. A device for measuring a distance, characterized in that: include: A processing module is used to remove noise from the original image and enhance the image to obtain a target image; A drawing module, used to determine N regions of interest ROI corresponding to the target image; A calculation module is used to calculate the edge contrast of each pixel in the target ROI; The determination module is used to determine the first pixel point and the second pixel point according to the edge contrast of each pixel point in the target ROI and to determine the spacing of the gap to be measured according to the target distance.
10. A computer device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the computer program, the steps of the distance measurement method according to any one of claims 1 to 8 are implemented.
