Image measurement method and device, equipment and storage medium
By employing a dual-canvas component architecture and an improved Bressenham line algorithm, automated and precise line measurement of images is achieved, solving the problems of low measurement accuracy and poor interactivity in existing technologies, and improving measurement efficiency and user experience.
Patent Information
- Application Number
- CN202511055713.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-07-30
- Publication Date
- 2025-10-31
AI Technical Summary
Existing image measurement solutions have shortcomings in terms of accuracy, efficiency, and user experience. The single Canvas architecture is susceptible to noise, resulting in low measurement accuracy, low computational efficiency, poor interactivity, and complex user operation.
It adopts a dual-canvas component architecture, with the display canvas component used for image display and the data canvas component used for image data processing. Combined with the improved Bressenham line algorithm and pixel coordinate conversion scale, it realizes interactive line drawing and automated measurement.
It improves the accuracy, efficiency, and adaptability of image straight line measurement, solves the problem of measurement accuracy distortion under the influence of noise, and simplifies the user operation process.
Smart Images

Figure CN120876576A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of image processing technology, and in particular to an image measurement method, apparatus, device, and storage medium. Background Technology
[0002] Currently, existing image measurement solutions have some shortcomings in terms of accuracy, efficiency, and user experience. The single Canvas architecture used in these solutions limits measurement accuracy, making them susceptible to noise in the image (such as defect box colors), leading to deviations in the measured physical dimensions. At the algorithm level, the linear measurement implementation used in these solutions is computationally inefficient and struggles to achieve real-time acquisition of continuous pixel data. Furthermore, the measurement process requires users to manually convert physical dimensions and pixel coordinates, resulting in low efficiency and inaccurate results. The complex user interface further degrades the user experience. Summary of the Invention
[0003] In view of this, the purpose of this invention is to provide an image measurement method, apparatus, device, and storage medium that can effectively solve the problems of measurement accuracy distortion caused by noise in the image recognition of the single Canvas architecture in existing solutions, as well as the poor interactivity in existing solutions. It automatically realizes the accurate measurement of the physical dimensions of straight lines in an image, thereby improving the efficiency, accuracy, and adaptability of image straight line measurement. The specific solution is as follows: In a first aspect, this application provides an image measurement method applied to an image line measurement system, comprising: In the human-computer interaction interface, the preset dual canvas component in the image straight line measurement system is initialized, and the image to be measured is loaded based on the preset dual canvas component; wherein, the preset dual canvas component includes a display canvas component and a data canvas component, the display canvas component is used for image display, and the data canvas component is used for image data processing; When the display canvas component detects a mouse event corresponding to the image under test, a line drawing operation corresponding to the image under test is triggered in the display canvas based on the mouse event to determine the drawn target line and the corresponding line drawing information; the mouse event includes mouse press event, mouse move event and mouse release event. Using the data canvas component, and based on the line drawing information, the preset dynamic line measurement strategy, and the pixel coordinate conversion scale, a line measurement is performed to determine the target line measurement result corresponding to the target line; the target line measurement result includes physical dimension information.
[0004] Optionally, loading the image to be tested based on the preset dual-canvas component includes: The display canvas component loads and displays the recognition image corresponding to the image under test; the recognition image is the image under test with defect annotation boxes. The original image corresponding to the image to be tested is loaded based on the data canvas component; the original image is the image to be tested without defect annotation boxes.
[0005] Optionally, before performing line measurement using the data canvas component and based on the line drawing information, a preset dynamic line measurement strategy, and a pixel coordinate conversion scale, the method further includes: Based on the element property get function corresponding to the DOM element, determine the corresponding first width value and first height value; The second width and second height values corresponding to the DOM element are determined based on the display canvas component; Determine the width conversion scale based on the first width value and the second width value; Determine the height conversion scale based on the first height value and the second height value; Based on the width conversion scale and the height conversion scale, the pixel coordinate conversion scale is determined.
[0006] Optionally, triggering the line drawing operation corresponding to the image under test based on the mouse event in the display canvas includes: When the display canvas component detects a mouse press event corresponding to the image under test, a line drawing operation corresponding to the image under test is triggered in the display canvas, and the first pixel coordinates corresponding to the initial point of the line are recorded. Based on the mouse movement event corresponding to the mouse press event, a straight line is drawn, and the second pixel coordinates of the points through which the line passes are recorded. Based on the mouse release event corresponding to the mouse press event, the line drawing is terminated, the drawn target line is determined, and the third pixel coordinates corresponding to the end point of the line are recorded. Based on the first pixel coordinates, the second pixel coordinates, and the third pixel coordinates, the line drawing information corresponding to the target line is determined.
[0007] Optionally, the step of performing line measurement through the data canvas component and based on the line drawing information, a preset dynamic line measurement strategy, and a pixel coordinate conversion scale includes: The data canvas component is used to initialize the measurement parameters and the current measurement point based on the line drawing information and the preset dynamic line measurement strategy, so as to determine the initial pixel coordinates corresponding to the initial parameters and the initial measurement point. Based on the first pixel coordinates and the third pixel coordinates in the line drawing information, and the pixel coordinate conversion scale, determine the physical dimension information corresponding to the target line; Acquire and store the pixel data corresponding to the initial measurement point; Determine the first step direction corresponding to the initial measurement point based on the initial parameters; Based on the first step forward direction, update the initial measurement point and the initial parameters to determine the updated current parameters, the current measurement point, and the current pixel coordinates corresponding to the current measurement point; Acquire and store the target pixel data corresponding to the current measurement point, and determine and store the current measurement result array based on the target pixel data; the current measurement result array includes the target pixel data and the corresponding current cumulative measurement length of the straight line; Based on the current pixel coordinates, determine whether the end point of the line has been reached, and if the corresponding first determination result is negative, determine the second step direction corresponding to the current measurement point based on the current parameters; Based on the second stepping direction, update the current measurement point and the current parameters to determine the updated current parameters, the current measurement point, and the current pixel coordinates corresponding to the current measurement point; The process jumps back to the step of acquiring and storing the target pixel data corresponding to the current measurement point until the first judgment result is yes. Based on the current measurement result array and the physical size information, the target line measurement result corresponding to the target line is determined.
[0008] Optionally, the initialization operation of measurement parameters and the current measurement point based on the line drawing information and the preset dynamic line measurement strategy includes: The measurement point is initialized based on the first pixel coordinates corresponding to the initial point of the line, so as to determine the initial measurement point and the initial pixel coordinates corresponding to the initial measurement point. The basic parameters and step increment are initialized based on the first pixel coordinate and the third pixel coordinate to determine the initial horizontal basic parameters, the initial vertical basic parameters, the horizontal step increment, and the vertical step increment. Initialize the cumulative measurement length of the straight line to determine the initial cumulative measurement length of the straight line; The first error term is determined based on the initial lateral foundation parameters and the initial longitudinal foundation parameters; The second error term is determined based on the first error term; Accordingly, determining the first step direction corresponding to the initial measurement point based on the initial parameters includes: The initial lateral foundation parameters and the initial longitudinal foundation parameters are compared with the second error term, and the first step direction corresponding to the initial measurement point is determined based on the comparison results.
[0009] Optionally, updating the initial measurement point and the initial parameters based on the first step direction includes: If the first step direction is a lateral step, then the first error is updated based on the initial longitudinal basic parameters to determine the updated current first error; The initial measurement point is updated based on the horizontal step increment to determine the updated current measurement point and the current pixel coordinates corresponding to the current measurement point; Based on the current pixel coordinates, the initial pixel coordinates, and the pixel coordinate conversion scale, the corresponding physical distance is determined, and it is determined whether the physical distance is greater than the preset sampling distance to determine the second judgment result. If the judgment result is greater than, then the initial cumulative measurement length of the straight line is updated to determine the current cumulative measurement length of the straight line.
[0010] Secondly, this application provides an image measurement device applied to an image line measurement system, comprising: An image loading module is used to initialize a preset dual-canvas component in the image straight-line measurement system at the human-computer interaction interface, and load the image to be measured based on the preset dual-canvas component; wherein, the preset dual-canvas component includes a display canvas component and a data canvas component, the display canvas component is used for image display, and the data canvas component is used for image data processing; The line drawing module is used to trigger a line drawing operation on the image under test in the display canvas based on the mouse event detected by the display canvas component, so as to determine the drawn target line and the corresponding line drawing information; the mouse event includes mouse press event, mouse move event and mouse release event. The straight line measurement module is used to perform straight line measurement through the data canvas component and based on the straight line drawing information, the preset dynamic straight line measurement strategy and the pixel coordinate conversion scale, so as to determine the target straight line measurement result corresponding to the target straight line; the target straight line measurement result includes physical dimension information.
[0011] Thirdly, this application provides an electronic device, comprising: Memory, used to store computer programs; A processor is used to execute the computer program to implement the steps of the aforementioned image measurement method.
[0012] Fourthly, this application provides a computer-readable storage medium for storing a computer program that, when executed by a processor, implements the steps of the aforementioned image measurement method.
[0013] As can be seen, in this application, applied to an image straight line measurement system, a preset dual-canvas component in the image straight line measurement system is initialized at the human-computer interaction interface, and the image to be measured is loaded based on the preset dual-canvas component. The preset dual-canvas component includes a display canvas component and a data canvas component. The display canvas component is used for image display, and the data canvas component is used for image data processing. When a mouse event corresponding to the image to be measured is detected based on the display canvas component, a straight line drawing operation corresponding to the image to be measured is triggered in the display canvas based on the mouse event to determine the drawn target straight line and its corresponding drawing information. The mouse events include mouse press events, mouse move events, and mouse release events. Through the data canvas component, and based on the straight line drawing information, a preset dynamic straight line measurement strategy, and a pixel coordinate conversion scale, a straight line measurement is performed to determine the target straight line measurement result corresponding to the target straight line. The target straight line measurement result includes physical dimension information. In other words, in this application, a preset dual-canvas component is first initialized in the human-computer interaction interface of the image line measurement system. The image to be measured is then loaded based on the initialized display canvas component and data canvas component. Subsequently, when the display canvas component detects a mouse event corresponding to the image to be measured, a line drawing operation is triggered to determine the target line and line drawing information. Line measurement is then performed using the data canvas component, the line drawing information, a preset dynamic line measurement strategy, and a pixel coordinate conversion scale to determine the target line measurement result. This effectively solves the problem of measurement accuracy distortion caused by noise in the image recognition of the single-Canvas architecture in existing solutions, as well as the problem of poor interactivity in existing solutions. It automatically achieves accurate measurement of the physical dimensions of image lines, thereby improving the efficiency, accuracy, and adaptability of image line measurement. Attached Figure Description
[0014] To more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on the provided drawings without creative effort.
[0015] Figure 1 A flowchart of an image measurement method provided in this application; Figure 2 A system architecture diagram for image measurement is provided in this application; Figure 3 This application provides a schematic diagram of a specific image measurement process; Figure 4 An example diagram of an identification image provided in this application; Figure 5 An example diagram of an original drawing provided for this application; Figure 6 A schematic diagram of an image measurement device provided in this application; Figure 7 This application provides a structural diagram of an electronic device. Detailed Implementation
[0016] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0017] Existing image measurement solutions have shortcomings in terms of accuracy, efficiency, and user experience. The single-Canvas architecture used in these solutions limits measurement accuracy, making them susceptible to noise in the image (such as defect box colors), leading to deviations in the measured physical dimensions. At the algorithm level, the linear measurement implementation used in these solutions is computationally inefficient and struggles to achieve real-time acquisition of continuous pixel data. Furthermore, the measurement process requires users to manually convert physical dimensions and pixel coordinates, resulting in low efficiency and inaccurate results. The complex user interface further degrades the user experience.
[0018] To address this, this application provides an image measurement scheme that effectively solves the problem of measurement accuracy distortion caused by noise in the image due to the single Canvas architecture in existing schemes, as well as the problem of poor interactivity in existing schemes. It automatically realizes the accurate measurement of the physical dimensions of straight lines in the image, thereby improving the efficiency, accuracy, and adaptability of image straight line measurement.
[0019] See Figure 1 As shown, this embodiment of the invention discloses an image measurement method applied to an image line measurement system, comprising:
[0020] Step S11: In the human-computer interaction interface, initialize the preset dual canvas component in the image straight line measurement system, and load the image to be measured based on the preset dual canvas component; wherein, the preset dual canvas component includes a display canvas component and a data canvas component, the display canvas component is used for image display, and the data canvas component is used for image data processing.
[0021] Combination Figure 2 As shown, in this embodiment, the architecture of the image straight line measurement system includes a user interface (human-computer interaction interface) providing an interactive entry point, a display Canvas (display canvas component) responsible for image rendering and user interaction, a data Canvas (data canvas component) responsible for storing raw image data to achieve accurate measurement, an interactive control module responsible for handling user mouse events, a coordinate transformation module responsible for automatically converting pixel coordinates to physical dimensions, and a measurement engine responsible for executing the improved Bressenham line algorithm to realize physical distance calculation. In other words, this embodiment achieves image display and data separation processing by constructing a dual-Canvas architecture, fundamentally solving the accuracy distortion problem caused by noise (defect box colors, etc.) in the image recognition of the traditional single-Canvas architecture. Furthermore, it uses the improved Bressenham line algorithm to accurately acquire straight line pixel data, supports interactive straight line drawing, real-time acquisition of RGB (Red, Green, Blue) values, and achieves accurate measurement of physical dimensions through automatic proportional conversion of pixel coordinates.
[0022] Combination Figure 3 As shown, after initializing the dual Canvas, the image to be tested is loaded through the human-computer interaction interface. Specifically, the recognition image corresponding to the image to be tested is loaded and displayed based on the display canvas component; the recognition image is the image to be tested with defect annotation boxes. The original image corresponding to the image to be tested is loaded based on the data canvas component; the original image is the image to be tested without defect annotation boxes. It can be understood that for the same image, the two canvas components load different versions of the image, and the display canvas component loads the recognition image (with defect annotation boxes), as shown below. Figure 4 As shown, the data canvas component loads the original image (without defect annotation boxes), as follows. Figure 5 As shown.
[0023] Specifically, the image to be measured can be from medical imaging, industrial inspection, or similar fields. For example, if an X-ray image needs to be measured, it can be used as the image to be measured. Before loading, defects are identified and annotated. Then, the display canvas component and the data canvas component display the original X-ray image and the X-ray image with defects annotated, respectively, and proceed with the subsequent measurement process. If an image of an industrial object (semiconductor, casting, etc.) needs to be measured, it can be used as the image to be measured. Before loading, defects are identified and annotated. Then, the display canvas component and the data canvas component display the original image and the image with defects annotated, respectively, and proceed with the subsequent measurement process.
[0024] Step S12: When the display canvas component detects a mouse event corresponding to the image under test, a line drawing operation corresponding to the image under test is triggered in the display canvas based on the mouse event to determine the drawn target line and the corresponding line drawing information; the mouse event includes mouse press event, mouse move event and mouse release event.
[0025] In this embodiment, when the display canvas component detects a mouse event, it can trigger interactive line drawing. Specifically, when the display canvas component detects a mouse down event (mouse down event, where the mouse is pressed within an element (DOM element (Document Object Model)) corresponding to the image under test), a line drawing operation corresponding to the image under test is triggered on the display canvas, and the first pixel coordinates of the initial point of the line are recorded (i.e., startPoint={x0,y0}, where x0 is the horizontal coordinate and y0 is the vertical coordinate). Based on the detected mouse move event (mouse move event) corresponding to the mouse down event, the pixel coordinates of the points the mouse has passed through are obtained. A line is drawn based on the starting point and the currently passed points. The width and color of the line can be customized, and the second pixel coordinates of the points the line has passed through are recorded. Based on the detected mouse release event (mouse release event) corresponding to the mouse down event... The up event terminates the line drawing, determines the drawn target line, and records the third pixel coordinates corresponding to the end point of the line (i.e., endPoint={x1,y1}, where x1 is the horizontal coordinate and y1 is the vertical coordinate); based on the first pixel coordinate, the second pixel coordinate, and the third pixel coordinate, the line drawing information corresponding to the target line is determined.
[0026] Step S13: Using the data canvas component, and based on the line drawing information, the preset dynamic line measurement strategy, and the pixel coordinate conversion scale, perform line measurement to determine the target line measurement result corresponding to the target line; the target line measurement result includes physical dimension information.
[0027] In this embodiment, the line drawing status in the display canvas component is synchronously displayed in the data canvas component. Without further operation, the data canvas component can directly perform line measurement. That is, through the data canvas component, and based on the line drawing information and a preset dynamic line measurement strategy, the measurement parameters and the current measurement point are initialized to determine the initial parameters and the initial pixel coordinates corresponding to the initial measurement point. Based on the first and third pixel coordinates in the line drawing information, and a pixel coordinate conversion scale, the physical dimension information corresponding to the target line is determined. Pixel data corresponding to the initial measurement point is acquired and stored. The first step direction corresponding to the initial measurement point is determined based on the initial parameters. The initial measurement point and the initial parameters are updated based on the first step direction to determine the updated current parameters, the current measurement point, and the parameters corresponding to the current measurement point. The process involves: determining the current pixel coordinates; acquiring and storing the target pixel data corresponding to the current measurement point, and determining and storing the current measurement result array based on the target pixel data; the current measurement result array including the target pixel data and the corresponding current cumulative measurement length of the straight line; determining whether the end point of the straight line has been reached based on the current pixel coordinates, and when the corresponding first determination result is negative, determining the second stepping direction corresponding to the current measurement point based on the current parameters; updating the current measurement point and current parameters based on the second stepping direction to determine the updated current parameters, the current measurement point, and the current pixel coordinates corresponding to the current measurement point; and returning to the step of acquiring and storing the target pixel data corresponding to the current measurement point until the first determination result is positive, and determining the target straight line measurement result corresponding to the target straight line based on the current measurement result array and the physical size information.
[0028] Furthermore, during initialization, the measurement point is first initialized based on the first pixel coordinates corresponding to the initial point of the straight line to determine the initial measurement point and the initial pixel coordinates corresponding to the initial measurement point; then, the basic parameters and step increment are initialized based on the first pixel coordinates and the third pixel coordinates to determine the initial horizontal basic parameters, the initial vertical basic parameters, the horizontal step increment, and the vertical step increment; the cumulative measurement length of the straight line is initialized to determine the initial cumulative measurement length of the straight line; a first error term is determined based on the initial horizontal basic parameters and the initial vertical basic parameters; a second error term is determined based on the first error term; correspondingly, determining the first step direction corresponding to the initial measurement point based on the initial parameters includes: comparing the initial horizontal basic parameters and the initial vertical basic parameters with the second error term respectively, and determining the first step direction corresponding to the initial measurement point based on the corresponding comparison results.
[0029] And, after taking a further step, update the relevant parameters. That is, if the first step direction is a horizontal step, update the first error based on the initial vertical basic parameter to determine the updated current first error; update the initial measurement point based on the horizontal step increment to determine the updated current measurement point and the corresponding current pixel coordinates; determine the corresponding physical distance based on the current pixel coordinates, the initial pixel coordinates, and the pixel coordinate conversion scale ratio, and judge whether the physical distance is greater than the preset sampling distance to determine the second judgment result; when the judgment result indicates greater, update the initial cumulative measurement length of the straight line to determine the current cumulative measurement length of the straight line.
[0030] It should be understood that when dynamically measuring a straight line drawn in a待测图像 (to-be-measured image) based on the improved Bresenham straight line algorithm process, the following steps may be specifically included: (1) Initialization stage, calculate the basic parameters (dx, dy), step direction, that is, the step increment (sx, sy), which are defined as: .
[0031] Among them, when x0 < x1, the step sx = 1, otherwise, sx = -1. Similarly, when y0 < y1, the step sy = 1, otherwise sy = -1. And initialize the error term (err, that is, the first error term), define err = dx - dy; initialize the cumulative distance accumulatedDistance = 0; initialize the array points = [] corresponding to the distance and pixel data; initialize the error term (e2, that is, the second error term), define e2 = 2 * err; initialize the coordinates of the current point based on the initial point of the straight line.
[0032] (2) Preprocessing data stage, according to the starting point coordinates, ending point coordinates of the straight line, and the pixel coordinate conversion scale ratio (width conversion scale ratio width Scale, height conversion scale ratio height Scale), calculate the physical distance of the straight line in combination with the Pythagorean theorem. Obtain the pixel data of the starting point according to the getImageData algorithm, then the starting point data information is obtained, and the distance at this time is still 0. Store the distance accumulated Distance and the pixel value of the starting point in the array points in the form of a data pair.
[0033] It should be noted that "待测图像" is a literal translation and may need to be adjusted according to the specific context to a more appropriate term like "to-be-measured image" or "image to be measured". Also, for the tags like , they are kept as they are as required.(3) In the main loop logic and data acquisition stage, the error term e2 is used to determine the step direction (horizontal step or vertical step) to ensure that the step is only in one direction each time, which is the characteristic of a straight line. The rules are as follows: when the error term e2 is greater than -dy, horizontal step is used, and the first error term err is updated to err-dy, and the horizontal coordinate x0 of the point is updated to x0+sx; when the error term e2 is less than dx, vertical step is used, and the first error term err is updated to err+dx, and the vertical coordinate y0 of the point is updated to y0+sy.
[0034] Next, the distance between the updated point and the previous point is calculated. Similarly, pixel coordinate conversion and the Pythagorean theorem are used to calculate the physical distance of the line. Adaptive sampling is supported; a distance is considered valid only if it is greater than a user-defined sampling distance (min Distance). In this embodiment, min Distance is defined as 0. When the calculated distance is greater than the sampling distance, the accumulated distance is updated. The pixel data of the updated point is obtained using the getImageData algorithm, and the current accumulated distance and the current pixel value are stored as data pairs in the points array.
[0035] (4) Termination Processing Stage: The loop ends when the absolute value of the difference between the corresponding horizontal and vertical coordinates of the starting point and the ending point is less than or equal to 1. In this embodiment, to ensure that the ending point is included, after the loop ends, step (3) continues, calculating the physical distance between the ending point and the previous update point. If the distance is greater than the sampling distance, the accumulated distance is updated to the total straight-line distance. Furthermore, the pixel data of the ending point is obtained according to the getImageData algorithm, and the distance and pixel value are stored in the points array. At this point, the array corresponding to the distance and pixel data is complete.
[0036] Furthermore, regarding the pixel coordinate conversion scale, in this embodiment, the first width and first height values are determined based on the element attribute acquisition function corresponding to the DOM element; the second width and second height values corresponding to the DOM element are determined based on the display canvas component; a width conversion scale is determined based on the first width and second width values; a height conversion scale is determined based on the first height and second height values; and a pixel coordinate conversion scale is determined based on the width conversion scale and the height conversion scale. Taking heightScale as an example, the specific process is as follows: (1) Use the getBoundingClientRect algorithm of the DOM element to get the size of the element and its position relative to the viewport. Here, the height property is used and defined as rectHeight. (2) Get the height value of the display Canvas, i.e., the height property, and define it as canvasHeight; (3) Based on the formula for the dynamic height scaling scale obtained above, the definition is as follows: .
[0037] In summary, this embodiment not only realizes interactive line drawing, but also acquires pixel data (i.e., RGB values and pixel coordinates) in real time when dynamically measuring lines, thereby enabling dynamic determination of coordinates in conjunction with the scale, which improves measurement efficiency.
[0038] Therefore, in this application, a preset dual-canvas component is first initialized in the human-computer interaction interface of the image line measurement system. The image to be measured is then loaded based on the initialized display canvas component and data canvas component. Subsequently, when the display canvas component detects a mouse event corresponding to the image to be measured, a line drawing operation is triggered to determine the target line and line drawing information. Line measurement is then performed using the data canvas component, the line drawing information, a preset dynamic line measurement strategy, and a pixel coordinate conversion scale to determine the target line measurement result. This effectively solves the problem of measurement accuracy distortion caused by noise in the image recognition of the single-Canvas architecture in existing solutions, as well as the problem of poor interactivity in existing solutions. It automatically achieves accurate measurement of the physical dimensions of image lines, thereby improving the efficiency, accuracy, and adaptability of image line measurement.
[0039] See Figure 6 As shown, this application also discloses an image measurement device applied to an image line measurement system, comprising: The image loading module 11 is used to initialize the preset dual canvas component in the image straight line measurement system in the human-computer interaction interface, and load the image to be measured based on the preset dual canvas component; wherein, the preset dual canvas component includes a display canvas component and a data canvas component, the display canvas component is used for image display, and the data canvas component is used for image data processing; The line drawing module 12 is used to trigger a line drawing operation corresponding to the image under test in the display canvas based on the mouse event detected by the display canvas component, so as to determine the drawn target line and the corresponding line drawing information; the mouse event includes mouse press event, mouse move event and mouse release event. The straight line measurement module 13 is used to perform straight line measurement through the data canvas component and based on the straight line drawing information, the preset dynamic straight line measurement strategy and the pixel coordinate conversion scale, so as to determine the target straight line measurement result corresponding to the target straight line; the target straight line measurement result includes physical dimension information.
[0040] Therefore, in this application, a preset dual-canvas component is first initialized in the human-computer interaction interface of the image line measurement system. The image to be measured is then loaded based on the initialized display canvas component and data canvas component. Subsequently, when the display canvas component detects a mouse event corresponding to the image to be measured, a line drawing operation is triggered to determine the target line and line drawing information. Line measurement is then performed using the data canvas component, the line drawing information, a preset dynamic line measurement strategy, and a pixel coordinate conversion scale to determine the target line measurement result. This effectively solves the problem of measurement accuracy distortion caused by noise in the image recognition of the single-Canvas architecture in existing solutions, as well as the problem of poor interactivity in existing solutions. It automatically achieves accurate measurement of the physical dimensions of image lines, thereby improving the efficiency, accuracy, and adaptability of image line measurement.
[0041] In some specific embodiments, the image loading module 11 can be used to: load and display the recognition image corresponding to the image to be tested based on the display canvas component; the recognition image is the image to be tested with defect annotation boxes; load the original image corresponding to the image to be tested based on the data canvas component; the original image is the image to be tested without defect annotation boxes.
[0042] In some specific embodiments, the image measurement device can also be used to: determine a first width value and a first height value based on the element attribute acquisition function corresponding to the DOM element; determine a second width value and a second height value corresponding to the DOM element based on the display canvas component; determine a width conversion scale based on the first width value and the second width value; determine a height conversion scale based on the first height value and the second height value; and determine a pixel coordinate conversion scale based on the width conversion scale and the height conversion scale.
[0043] In some specific embodiments, the line drawing module 12 can be used to: when the display canvas component detects a mouse press event corresponding to the image under test, trigger a line drawing operation corresponding to the image under test in the display canvas, and record the first pixel coordinates corresponding to the initial point of the line; draw a line based on the mouse movement event corresponding to the mouse press event, and record the second pixel coordinates corresponding to the points through which the line passes; terminate the line drawing based on the mouse release event corresponding to the mouse press event, determine the drawn target line, and record the third pixel coordinates corresponding to the end point of the line; and determine the line drawing information corresponding to the target line based on the first pixel coordinates, the second pixel coordinates, and the third pixel coordinates.
[0044] In some specific embodiments, the straight line measurement module 13 may specifically include: An initialization unit is used to perform initialization operations on measurement parameters and the current measurement point through the data canvas component and based on the line drawing information and a preset dynamic line measurement strategy, so as to determine the initial pixel coordinates corresponding to the initial parameters and the initial measurement point. The physical dimension information determination unit is used to determine the physical dimension information corresponding to the target line based on the first pixel coordinates and the third pixel coordinates in the line drawing information and the pixel coordinate conversion scale. The first data acquisition unit is used to acquire and store the pixel data corresponding to the initial measurement point; The first step direction determination unit is used to determine the first step direction corresponding to the initial measurement point based on the initial parameters; The first stepping unit is used to update the initial measurement point and the initial parameters based on the first stepping direction, so as to determine the updated current parameters, the current measurement point, and the current pixel coordinates corresponding to the current measurement point; The second data acquisition unit is used to acquire and store the target pixel data corresponding to the current measurement point, and to determine and store the current measurement result array based on the target pixel data; the current measurement result array includes the target pixel data and the corresponding current cumulative measurement length of the straight line; The endpoint determination unit is used to determine whether the current pixel coordinates have reached the endpoint of the line, and when the corresponding first determination result is negative, to determine the second step direction corresponding to the current measurement point based on the current parameters. The second stepping unit is used to update the current measurement point and the current parameters based on the second stepping direction, so as to determine the updated current parameters, the current measurement point, and the current pixel coordinates corresponding to the current measurement point; The step jump unit is used to jump back to the step of acquiring and storing the target pixel data corresponding to the current measurement point until the first judgment result is yes, and then determine the target line measurement result corresponding to the target line based on the current measurement result array and the physical size information.
[0045] In some specific embodiments, the initialization unit may be used to: initialize a measurement point based on the first pixel coordinates corresponding to the initial point of the straight line, to determine the initial measurement point and the initial pixel coordinates corresponding to the initial measurement point; initialize basic parameters and step increments based on the first pixel coordinates and the third pixel coordinates, to determine the initial horizontal basic parameters, the initial vertical basic parameters, the horizontal step increment, and the vertical step increment; initialize the cumulative measurement length of the straight line, to determine the initial cumulative measurement length of the straight line; determine a first error term based on the initial horizontal basic parameters and the initial vertical basic parameters; and determine a second error term based on the first error term. Accordingly, the first step direction determination unit can be used to: compare the initial lateral foundation parameters and the initial longitudinal foundation parameters with the second error term, and determine the first step direction corresponding to the initial measurement point based on the comparison results.
[0046] In some specific embodiments, the first stepping unit can be used to: if the first stepping direction is a lateral step, update the first error based on the initial longitudinal basic parameters to determine the updated current first error; update the initial measurement point based on the lateral stepping increment to determine the updated current measurement point and the current pixel coordinates corresponding to the current measurement point; determine the corresponding physical distance based on the current pixel coordinates, the initial pixel coordinates, and the pixel coordinate conversion scale, and determine whether the physical distance is greater than a preset sampling distance to determine a second judgment result; when the judgment result indicates that it is greater than the preset sampling distance, update the initial cumulative straight line measurement length to determine the current cumulative straight line measurement length.
[0047] Furthermore, embodiments of this application also disclose an electronic device, Figure 7 This is a structural diagram of an electronic device 20 according to an exemplary embodiment. The content of the diagram should not be construed as limiting the scope of this application.
[0048] Figure 7This is a schematic diagram of the structure of an electronic device 20 provided in an embodiment of this application. Specifically, the electronic device 20 may include: at least one processor 21, at least one memory 22, a power supply 23, a communication interface 24, an input / output interface 25, and a communication bus 26. The memory 22 stores a computer program, which is loaded and executed by the processor 21 to implement the relevant steps in the image measurement method disclosed in any of the foregoing embodiments. Furthermore, the electronic device 20 in this embodiment may specifically be an electronic computer.
[0049] In this embodiment, the power supply 23 is used to provide operating voltage for each hardware device on the electronic device 20; the communication interface 24 can create a data transmission channel between the electronic device 20 and external devices, and the communication protocol it follows can be any communication protocol applicable to the technical solution of this application, and is not specifically limited here; the input / output interface 25 is used to acquire external input data or output data to the outside world, and its specific interface type can be selected according to specific application needs, and is not specifically limited here.
[0050] In addition, the memory 22, as a carrier for resource storage, can be a read-only memory, random access memory, disk or optical disk, etc. The resources stored thereon can include operating system 221, computer program 222, etc., and the storage method can be temporary storage or permanent storage.
[0051] The operating system 221 is used to manage and control the various hardware devices on the electronic device 20 and the computer program 222, which may be Windows Server, Netware, Unix, Linux, etc. In addition to including a computer program capable of performing the image measurement method executed by the electronic device 20 as disclosed in any of the foregoing embodiments, the computer program 222 may further include a computer program capable of performing other specific tasks.
[0052] Furthermore, this application also discloses a computer-readable storage medium for storing a computer program; wherein, when the computer program is executed by a processor, it implements the aforementioned disclosed image measurement method. Specific steps of this method can be found in the corresponding content disclosed in the foregoing embodiments, and will not be repeated here.
[0053] The various embodiments in this specification are described in a progressive manner, with each embodiment focusing on its differences from other embodiments. Similar or identical parts between embodiments can be referred to interchangeably. For the apparatus disclosed in the embodiments, since it corresponds to the method disclosed in the embodiments, the description is relatively simple; relevant parts can be referred to in the method section.
[0054] Those skilled in the art will further recognize that the units and algorithm steps of the various examples described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of both. To clearly illustrate the interchangeability of hardware and software, the components and steps of the various examples have been generally described in terms of functionality in the foregoing description. Whether these functions are implemented in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of this application.
[0055] The steps of the methods or algorithms described in conjunction with the embodiments disclosed herein can be implemented directly by hardware, a software module executed by a processor, or a combination of both. The software module can be located in random access memory (RAM), main memory, read-only memory (ROM), electrically programmable ROM, electrically erasable programmable ROM, registers, hard disk, removable disk, CD-ROM, or any other form of storage medium known in the art.
[0056] Finally, it should be noted that in this document, relational terms such as "first" and "second" are used only to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Furthermore, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitations, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes said element.
[0057] The technical solutions provided in this application have been described in detail above. Specific examples have been used to illustrate the principles and implementation methods of this application. The descriptions of the above embodiments are only for the purpose of helping to understand the methods and core ideas of this application. At the same time, for those skilled in the art, there will be changes in the specific implementation methods and application scope based on the ideas of this application. Therefore, the content of this specification should not be construed as a limitation of this application.
Claims
1. An image measurement method, characterized in that, Applications include image line measurement systems, including: In the human-computer interaction interface, the preset dual canvas component in the image straight line measurement system is initialized, and the image to be measured is loaded based on the preset dual canvas component; wherein, the preset dual canvas component includes a display canvas component and a data canvas component, the display canvas component is used for image display, and the data canvas component is used for image data processing; When the display canvas component detects a mouse event corresponding to the image under test, a line drawing operation corresponding to the image under test is triggered in the display canvas based on the mouse event to determine the drawn target line and the corresponding line drawing information; the mouse event includes mouse press event, mouse move event and mouse release event. Using the data canvas component, and based on the line drawing information, the preset dynamic line measurement strategy, and the pixel coordinate conversion scale, a line measurement is performed to determine the target line measurement result corresponding to the target line; the target line measurement result includes physical dimension information.
2. The image measurement method according to claim 1, characterized in that, The loading of the image to be tested based on the preset dual-canvas component includes: The display canvas component loads and displays the recognition image corresponding to the image under test; the recognition image is the image under test with defect annotation boxes. The original image corresponding to the image to be tested is loaded based on the data canvas component; the original image is the image to be tested without defect annotation boxes.
3. The image measurement method according to claim 1, characterized in that, Before performing line measurement using the data canvas component and based on the line drawing information, the preset dynamic line measurement strategy, and the pixel coordinate conversion scale, the method further includes: Based on the element property get function corresponding to the DOM element, determine the corresponding first width value and first height value; The second width and second height values corresponding to the DOM element are determined based on the display canvas component; Determine the width conversion scale based on the first width value and the second width value; Determine the height conversion scale based on the first height value and the second height value; Based on the width conversion scale and the height conversion scale, the pixel coordinate conversion scale is determined.
4. The image measurement method according to any one of claims 1 to 3, characterized in that, The step of triggering a line drawing operation corresponding to the image under test based on the mouse event in the display canvas includes: When the display canvas component detects a mouse press event corresponding to the image under test, a line drawing operation corresponding to the image under test is triggered in the display canvas, and the first pixel coordinates corresponding to the initial point of the line are recorded. Based on the mouse movement event corresponding to the mouse press event, a straight line is drawn, and the second pixel coordinates of the points through which the line passes are recorded. Based on the mouse release event corresponding to the mouse press event, the line drawing is terminated, the drawn target line is determined, and the third pixel coordinates corresponding to the end point of the line are recorded. Based on the first pixel coordinates, the second pixel coordinates, and the third pixel coordinates, the line drawing information corresponding to the target line is determined.
5. The image measurement method according to claim 4, characterized in that, The step of measuring a straight line using the data canvas component and based on the straight line drawing information, a preset dynamic straight line measurement strategy, and a pixel coordinate conversion scale includes: The data canvas component is used to initialize the measurement parameters and the current measurement point based on the line drawing information and the preset dynamic line measurement strategy, so as to determine the initial pixel coordinates corresponding to the initial parameters and the initial measurement point. Based on the first pixel coordinates and the third pixel coordinates in the line drawing information, and the pixel coordinate conversion scale, determine the physical dimension information corresponding to the target line; Acquire and store the pixel data corresponding to the initial measurement point; Determine the first step direction corresponding to the initial measurement point based on the initial parameters; Based on the first step forward direction, update the initial measurement point and the initial parameters to determine the updated current parameters, the current measurement point, and the current pixel coordinates corresponding to the current measurement point; Acquire and store the target pixel data corresponding to the current measurement point, and determine and store the current measurement result array based on the target pixel data; the current measurement result array includes the target pixel data and the corresponding current cumulative measurement length of the straight line; Based on the current pixel coordinates, determine whether the end point of the line has been reached, and if the corresponding first determination result is negative, determine the second step direction corresponding to the current measurement point based on the current parameters; Based on the second stepping direction, update the current measurement point and the current parameters to determine the updated current parameters, the current measurement point, and the current pixel coordinates corresponding to the current measurement point; The process jumps back to the step of acquiring and storing the target pixel data corresponding to the current measurement point until the first judgment result is yes. Based on the current measurement result array and the physical size information, the target line measurement result corresponding to the target line is determined.
6. The image measurement method according to claim 5, characterized in that, The initialization operation of measurement parameters and the current measurement point based on the line drawing information and the preset dynamic line measurement strategy includes: The measurement point is initialized based on the first pixel coordinates corresponding to the initial point of the line, so as to determine the initial measurement point and the initial pixel coordinates corresponding to the initial measurement point. The basic parameters and step increment are initialized based on the first pixel coordinate and the third pixel coordinate to determine the initial horizontal basic parameters, the initial vertical basic parameters, the horizontal step increment, and the vertical step increment. Initialize the cumulative measurement length of the straight line to determine the initial cumulative measurement length of the straight line; The first error term is determined based on the initial lateral foundation parameters and the initial longitudinal foundation parameters; The second error term is determined based on the first error term; Accordingly, determining the first step direction corresponding to the initial measurement point based on the initial parameters includes: The initial lateral foundation parameters and the initial longitudinal foundation parameters are compared with the second error term, and the first step direction corresponding to the initial measurement point is determined based on the comparison results.
7. The image measurement method according to claim 6, characterized in that, The step of updating the initial measurement point and the initial parameters based on the first step direction includes: If the first step direction is a lateral step, then the first error is updated based on the initial longitudinal basic parameters to determine the updated current first error; The initial measurement point is updated based on the horizontal step increment to determine the updated current measurement point and the current pixel coordinates corresponding to the current measurement point; Based on the current pixel coordinates, the initial pixel coordinates, and the pixel coordinate conversion scale, the corresponding physical distance is determined, and it is determined whether the physical distance is greater than the preset sampling distance to determine the second judgment result. If the judgment result is greater than, then the initial cumulative measurement length of the straight line is updated to determine the current cumulative measurement length of the straight line.
8. An image measurement method apparatus, characterized in that, Applications include image line measurement systems, including: An image loading module is used to initialize a preset dual-canvas component in the image straight-line measurement system at the human-computer interaction interface, and load the image to be measured based on the preset dual-canvas component; wherein, the preset dual-canvas component includes a display canvas component and a data canvas component, the display canvas component is used for image display, and the data canvas component is used for image data processing; The line drawing module is used to trigger a line drawing operation on the image under test in the display canvas based on the mouse event detected by the display canvas component, so as to determine the drawn target line and the corresponding line drawing information; the mouse event includes mouse press event, mouse move event and mouse release event. The straight line measurement module is used to perform straight line measurement through the data canvas component and based on the straight line drawing information, the preset dynamic straight line measurement strategy and the pixel coordinate conversion scale, so as to determine the target straight line measurement result corresponding to the target straight line; the target straight line measurement result includes physical dimension information.
9. An electronic device, characterized in that, include: Memory, used to store computer programs; A processor for executing the computer program to implement the image measurement method as described in any one of claims 1 to 7.
10. A computer-readable storage medium, characterized in that, Used to store a computer program, which, when executed by a processor, implements the image measurement method as described in any one of claims 1 to 7.