Visual measurement method, device and equipment of workpiece and storage medium
By using machine vision technology to perform grayscale conversion and edge detection on workpiece images, and combining directional gradient histogram and image moment matching to fit edge lines, the inefficiency and subjectivity of traditional workpiece rotation angle measurement methods are solved, realizing non-contact, fast, and accurate rotation angle measurement.
Patent Information
- Application Number
- CN202411295971.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-14
- Publication Date
- 2025-11-25
- Estimated Expiration
- 2044-09-14
AI Technical Summary
Traditional methods for measuring workpiece rotation angles are cumbersome, inefficient, and subjective, failing to meet the needs of non-contact measurement, and resulting in inaccurate measurement results, especially in mass production.
Machine vision technology is used to acquire workpiece images, perform grayscale processing and edge detection, obtain directional gradient histograms and contour information, match image moments and contour information, fit edge lines to determine rotation angles, and combine pyramid algorithm and random sample consensus algorithm to improve measurement accuracy and efficiency.
It enables non-contact, rapid, and accurate measurement of workpiece rotation angle, reduces labor costs, improves the automation and intelligence level of measurement, and adapts to the needs of mass production.
Smart Images

Figure CN119130999B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of machine vision measurement, and in particular to a workpiece visual measurement method, device, equipment and storage medium. BACKGROUND
[0002] With the progress and development requirements of modern manufacturing, the accuracy and speed requirements of measuring the key position size of finished products or semi-finished products are higher and higher. The traditional measurement method of the rotation angle of a workpiece is to use a vernier caliper or a plug gauge and the like to obtain the rotation angle and other information of the workpiece in the machining process. The traditional measurement method can meet the detection accuracy requirement to a great extent, but it needs to be operated manually, the operation process is relatively cumbersome, the work efficiency is not high in mass production, and there are certain defects. In addition, manual operation has certain subjectivity, and it is difficult to achieve unity in the grasping degree of the measurement standard, thereby causing the inaccuracy of the measurement result. In addition, some workpieces are not suitable for contact measurement due to some objective conditions. SUMMARY
[0003] Therefore, the embodiments of the present application provide a workpiece visual measurement method, device, equipment and storage medium, which can perform non-contact and accurate measurement on a workpiece to be measured, and is simple to operate and saves labor cost.
[0004] In a first aspect, the embodiments of the present application provide a workpiece visual measurement method, comprising:
[0005] An original image containing a workpiece to be measured is collected, the original image is subjected to grayscale processing to obtain a grayscale image, and edge detection processing is performed based on the grayscale image to obtain a workpiece image, wherein the workpiece image includes edge information of the workpiece to be measured;
[0006] A direction gradient histogram of the workpiece image is obtained based on the edge information, and contour information of the workpiece to be measured is extracted according to the direction gradient histogram;
[0007] An image moment of the workpiece to be measured is determined according to the grayscale image, and the workpiece to be measured is matched with a template workpiece according to the image moment and the contour information to determine whether the workpiece to be measured has rotated;
[0008] If the workpiece to be measured has rotated, an edge straight line of the workpiece to be measured is fitted according to the edge information of the workpiece to be measured;
[0009] A rotation angle of the workpiece to be measured relative to the placement state of the template workpiece is determined according to the edge straight line of the workpiece to be measured.
[0010] In combination with the first aspect, the embodiments of the present application provide a first possible implementation manner of the first aspect, wherein the method further comprises:
[0011] According to the contour information of the template workpiece, a local coordinate system is established in the workpiece image, with the center position of the template workpiece as an origin, with a center axis of the template workpiece as a longitudinal axis, and with a straight line perpendicular to the center axis as a transverse axis.
[0012] With reference to the first aspect, a second possible implementation of the first aspect is provided in the embodiments of the present application, and the method comprises the following steps.
[0013] In the local coordinate system, each edge straight line of the workpiece to be measured is extended to the origin, so as to obtain an angle bisector of the included angle of the edge straight line passing through the origin.
[0014] The angle between the angle bisector and the longitudinal axis of the local coordinate system is determined as the rotation angle of the workpiece to be measured relative to the placement state of the template workpiece.
[0015] With reference to the first aspect, a third possible implementation of the first aspect is provided in the embodiments of the present application, and the method comprises the following steps.
[0016] The workpiece image is up-sampled by a pyramid algorithm, so that the workpiece image is matched with the template workpiece in the same size as the template workpiece.
[0017] With reference to the first aspect, a fourth possible implementation of the first aspect is provided in the embodiments of the present application, and the method comprises the following steps.
[0018] The gradient and the gradient direction of the gradient of each pixel point in the workpiece image are calculated, and the gradient exceeding a preset threshold is retained.
[0019] The gradient directions in a preset neighborhood are counted, the gradients with the same gradient direction and exceeding a preset number are retained, and the direction gradient histogram is obtained according to the retained gradients.
[0020] With reference to the first aspect, a fifth possible implementation of the first aspect is provided in the embodiments of the present application, and the method comprises the following steps.
[0021] The edge straight line of the workpiece to be measured is fitted by a random sample consensus algorithm, so as to eliminate the edge abrupt change points in the edge information of the workpiece to be measured, and the edge straight line of the workpiece to be measured is obtained.
[0022] With reference to the first aspect, the embodiments of the present application provide a sixth possible implementation manner of the first aspect, and the fitting of the edge straight line of the workpiece to be measured by using the random sample consensus algorithm comprises:
[0023] selecting a plurality of edge points of the workpiece to be measured to preliminarily obtain an edge straight line, and determining whether each edge point is an inlier according to the distance from each edge point to the current edge straight line;
[0024] if the distance from the edge point to the current edge straight line does not exceed a preset distance, the edge point is regarded as an inlier;
[0025] if the distance from the edge point to the current edge straight line exceeds the preset distance, the edge point is regarded as an outlier;
[0026] if the number of current inliers of the current edge straight line is greater than the historical number, the current edge straight line is updated according to the current inliers until an edge straight line with the maximum number of inliers is obtained.
[0027] In the second aspect, the embodiments of the present application provide a visual measurement device of a workpiece, comprising:
[0028] a collection and processing module, configured to collect an original image containing a workpiece to be measured, perform grayscale processing on the original image to obtain a grayscale image, and perform edge detection processing based on the grayscale image to obtain a workpiece image, wherein the workpiece image comprises edge information of the workpiece to be measured;
[0029] a contour extraction module, configured to obtain a histogram of oriented gradients (HOG) of the workpiece image based on the edge information, and extract contour information of the workpiece to be measured according to the HOG;
[0030] a matching module, configured to determine an image moment of the workpiece to be measured according to the grayscale image, and match the workpiece to be measured with a template workpiece according to the image moment and the contour information to determine whether the workpiece to be measured is rotated;
[0031] a fitting module, configured to, if the workpiece to be measured is rotated, fit an edge straight line of the workpiece to be measured according to the edge information of the workpiece to be measured;
[0032] a measurement module, configured to determine a rotation angle of the workpiece to be measured relative to a placement state of the template workpiece according to the edge straight line of the workpiece to be measured.
[0033] In a third aspect, an embodiment of the present application provides a terminal device, which comprises a processor and a memory, the memory stores a computer program, and the processor is configured to execute the computer program to implement the visual measurement method of the workpiece.
[0034] In a fourth aspect, an embodiment of the present application provides a computer readable storage medium, which stores a computer program, and the computer program, when executed on a processor, implements the visual measurement method of the workpiece.
[0035] The embodiments of the present application have the following beneficial effects:
[0036] The visual measurement method of the workpiece comprises: collecting an original image containing a workpiece to be measured, performing grayscale processing on the original image to obtain a grayscale image, and performing edge detection processing based on the grayscale image to obtain a workpiece image, wherein the workpiece image comprises edge information of the workpiece to be measured; obtaining a histogram of oriented gradients of the workpiece image based on the edge information, and extracting contour information of the workpiece to be measured according to the histogram of oriented gradients; determining an image moment of the workpiece to be measured according to the grayscale image, and matching the workpiece to be measured with a template workpiece according to the image moment and the contour information to determine whether the workpiece to be measured is rotated; if the workpiece to be measured is rotated, fitting an edge straight line of the workpiece to be measured according to the edge information of the workpiece to be measured; and determining a rotation angle of the workpiece to be measured relative to a placement state of the template workpiece according to the edge straight line of the workpiece to be measured. Based on the above scheme, the present application applies machine vision technology, image processing and image analysis technology, and has the advantages of non-contact, good flexibility, online real-time, high speed, high precision, strong anti-interference ability, high automation and intelligence level, etc. In addition, the measurement process of the workpiece to be measured is simple to operate and easy to maintain, and the labor cost can be saved, thereby ensuring the stability of product quality. BRIEF DESCRIPTION OF DRAWINGS
[0037] In order to more clearly illustrate the technical solutions of the embodiments of the present application, the following will briefly introduce the drawings needed to be used in the embodiments. It should be understood that the following drawings only show some embodiments of the present application, and therefore should not be regarded as a limitation on the scope. For those skilled in the art, other related drawings can also be obtained without creative labor.
[0038] Figure 1 Fig. 1 shows a first flowchart of the visual measurement method of the workpiece provided by an embodiment of the present application;
[0039] Figure 2 Fig. 2 shows a second flowchart of the visual measurement method of the workpiece provided by an embodiment of the present application;
[0040] Figure 3A schematic diagram showing actual measurement effect of the rotation angle of the workpiece to be measured according to an embodiment of the present application is shown.
[0041] Figure 4 A structural schematic diagram of the visual measurement device of the workpiece according to an embodiment of the present application is shown.
[0042] Main element symbol explanation:
[0043] 200 - visual measurement device of workpiece; 210 - acquisition processing module; 220 - profile extraction module; 230 - matching module; 240 - fitting module; 250 - measurement module. DETAILED DESCRIPTION
[0044] The technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the accompanying drawings of the embodiments of the present application. Obviously, the described embodiments are only some of the embodiments of the present application, but not all the embodiments of the present application.
[0045] The components of the embodiments of the present application generally described and illustrated herein can be arranged and designed in a variety of different configurations. Therefore, the following detailed description of the embodiments of the present application provided in the accompanying drawings is not intended to limit the scope of the claimed application, but merely represents selected embodiments of the present application. Based on the embodiments of the present application, all other embodiments obtained by those skilled in the art without creative work are within the scope of protection of the present application.
[0046] Hereinafter, the terms "include", "have", and their conjugates used in various embodiments of the present application are only intended to denote that specific features, numbers, steps, operations, elements, components, or combinations thereof are present, and should not be construed as excluding the presence or addition of one or more other features, numbers, steps, operations, elements, components, or combinations thereof. In addition, the terms "first", "second", "third", and the like are only used to distinguish descriptions, and cannot be understood as indicating or implying relative importance.
[0047] Unless otherwise defined, all terms (including technical and scientific terms) used herein have the same meaning as commonly understood by one of ordinary skill in the art to which various embodiments of the present application belong. The terms (such as those defined in commonly used dictionaries) will be interpreted as having a meaning that is the same as the contextual meaning in the relevant technical field and will not be interpreted as having an idealized or overly formal meaning, unless clearly defined in various embodiments of the present application.
[0048] Some embodiments of the present application will be described in detail with reference to the drawings. The following embodiments and features of the embodiments described below can be combined with each other without conflict.
[0049] The existing rotation angle measurement method of the workpiece cannot meet the non-contact measurement, and the manual operation process is inefficient. The present application proposes an accurate measurement of the rotation angle of the workpiece to be measured based on machine vision, shape feature matching of the workpiece to be measured in the workpiece image, accurate matching of the rotation of the workpiece to be measured, and elimination of the interference in the rotation angle measurement process of the workpiece, so as to accurately measure the rotation angle of the workpiece to be measured.
[0050] The workpiece visual measurement method will be described below in combination with some specific embodiments.
[0051] Figure 1 A flowchart of the workpiece visual measurement method of the embodiments of the present application is shown.
[0052] Exemplarily, the workpiece visual measurement method comprises the following steps:
[0053] S110, acquiring an original image containing a workpiece to be measured, performing gray scale processing on the original image to obtain a gray scale image, and performing edge detection processing based on the gray scale image to obtain a workpiece image, wherein the workpiece image comprises edge information of the workpiece to be measured.
[0054] Exemplarily, in the workpiece visual measurement process, the original image is first collected by using a camera, a computer lens or other camera equipment, and the color original image is converted into a gray scale image through gray scale processing, i.e. the optical three primary colors (RGB) value of each pixel point in the original image is converted into a gray scale value. The image preprocessing process also includes Gaussian blur processing, which eliminates the noise in the gray scale image and smoothes the gray scale image. Gaussian blur is a linear smoothing filter used to effectively remove noise in the gray scale image while preserving the details of the gray scale image. The process of Gaussian blur is to calculate a new value for each pixel point around the pixel point with a weight coefficient, thereby achieving smoothing processing. The image preprocessing process also includes edge detection processing, which is used to detect the edge information of the workpiece to be measured in the gray scale image. The edge is where the brightness or color changes abruptly, such as the edge of the workpiece to be measured or the lines in the gray scale image. The edge detection processing is used to detect the edge information in the gray scale image using a specific set of filters, and to obtain a plurality of edge points from the detected edges.
[0055] S120, obtaining a direction gradient histogram of the workpiece image based on the edge information, and extracting the contour information of the workpiece to be measured according to the direction gradient histogram.
[0056] Exemplarily, the direction gradient histogram is used to describe the local gradient distribution of the workpiece image. First, the gradient of the workpiece image is calculated. The edge information of the workpiece image is revealed by calculating the gradient amplitude and gradient direction of each pixel point. The gradient exceeding the threshold is retained. The gradient of a certain position of the workpiece image is the difference between the pixel value of the pixel point and the pixel value of the adjacent pixel point of the pixel point itself. When the preset threshold is set to 2, the gradient exceeding 2 is retained. At each pixel, the gradient has a size and a direction. The x-direction gradient image will enhance the vertical edge feature, and the y-direction gradient image will enhance the horizontal edge feature, so that the useful contour feature is retained. In the direction gradient histogram creation process, the direction interval to which the gradient direction of each pixel point in the workpiece image belongs in the preset field is counted, and a direction gradient histogram describing the gradient direction distribution is obtained. For example, the preset field is set to 3*3, the gradient direction includes left upper, upper, right upper, left, right, left lower, lower, and right lower, a total of 8 directions. If there are more than 5 preset quantities of gradient directions, they are retained, so as to obtain the direction gradient image of the whole image. Each entry of the direction gradient histogram represents the number of pixel points or the sum of gradient intensities in the direction interval. The contour feature of the workpiece is a significant visual feature of the object boundary in the workpiece image, and the direction gradient histogram is used to extract the edge information from the workpiece image and represent it in the form of a histogram.
[0057] For example, in an embodiment, the workpiece visual measurement method obtains the direction gradient histogram of the workpiece image based on the edge information, including: calculating the gradient and the gradient direction of each pixel point in the workpiece image, and retaining the gradient exceeding the preset threshold; counting the gradient direction in the preset neighborhood, retaining the gradient with the same gradient direction and exceeding the preset quantity, and obtaining the direction gradient histogram according to the retained gradient.
[0058] S130, determining the image moment of the workpiece to be measured according to the gray-scale image, and matching the workpiece to be measured with the template workpiece according to the image moment and the contour information to judge whether the workpiece to be measured is rotated.
[0059] Exemplarily, the workpiece visual measurement method uses the image moment to describe the features of the workpiece image, so as to quantify the features of the workpiece image and realize the workpiece image recognition. The image generally contains two directions of horizontal and vertical, so the k+l order image moment of the two-dimensional random variable is generally used to describe the features of the image. In addition, the workpiece visual measurement method uses the gray-scale image or the binary image to calculate the image moment. The pixel coordinates of the workpiece image are regarded as two-dimensional random variables (X, Y). The gray-scale image can be represented by a two-dimensional gray-scale image density function. The invariant moment in the image moment is a highly condensed image feature, which has translation, gray, scale, and rotation invariance, so it can be used as a stable feature quantity to describe the geometric shape features of the workpiece image. The invariant moment includes area invariant moment, center distance, normalized center distance, and rotation invariant moment, etc.
[0060] For example, in an embodiment, the visual measurement method of the workpiece determines whether the workpiece to be measured is consistent with the template workpiece according to the image moments and the contour information, and if the workpiece to be measured is consistent with the template workpiece, the workpiece to be measured does not rotate, and if the workpiece to be measured is not consistent with the template workpiece, it is considered that the workpiece to be measured is deflected. In the process of determining whether the workpiece to be measured is consistent with the template workpiece, the pyramid algorithm is used to process the workpiece image to improve the matching efficiency. The pyramid algorithm inserts new pixels on the workpiece image through upsampling operation to expand the size of the workpiece image, so as to obtain a workpiece image with higher resolution, so that the workpiece image and the template workpiece are matched in the same size, and the matching efficiency is improved. The upsampling method includes nearest neighbor interpolation, bilinear interpolation and bicubic interpolation, etc. Compared with the original workpiece image, the workpiece image after upsampling retains more image details.
[0061] For example, in an embodiment, the visual measurement method of the workpiece matches the workpiece to be measured with the template workpiece according to the image moments and the contour information, and further includes: upsampling the workpiece image through the pyramid algorithm to match the workpiece image with the template workpiece in the same size as the template workpiece.
[0062] In S140, if the workpiece to be measured rotates, the edge straight line of the workpiece to be measured is fitted according to the edge information of the workpiece to be measured.
[0063] For example, in an embodiment, the visual measurement method of the workpiece uses the random sample consensus algorithm to perform straight line fitting on the edge points obtained in the edge detection processing, filters out the points far away and isolated, and thus fits the edge straight line of the workpiece to be measured. The process of the random sample consensus algorithm includes: selecting continuous edge points for fitting to obtain more accurate edge straight line; for each edge point in the data set, it is determined whether each edge point is fitted with the current edge straight line, if the error is less than a certain system tolerance preset distance, it is regarded as an inner point, otherwise, it is regarded as an outlier or isolated point as an outer point, wherein the preset distance is an empirical value determined by specific application and data set; compare the current number of inner points with the maximum number of inner points before, if the current number of inner points exceeds the maximum number of inner points before, update the edge straight line; repeat for several times, and the edge straight line with the maximum number of inner points is the final edge straight line.
[0064] For example, in an embodiment, the visual measurement method of the workpiece fits the edge straight line of the workpiece to be measured according to the edge information of the workpiece to be measured, which includes: eliminating the edge mutation points in the edge information of the workpiece to be measured by using the random sample consensus algorithm to obtain the edge straight line of the workpiece to be measured.
[0065] For example, in an embodiment, as Figure 2As shown, the visual measurement method for this workpiece uses a random sample consensus algorithm to fit the edge line of the workpiece, including:
[0066] S141, Select several edge points of the workpiece to be tested and perform fitting to initially obtain the edge line. Based on the distance of each edge point to the current edge line, determine whether each edge point is an interior point.
[0067] S142, If the distance from the edge point to the current edge line does not exceed the preset distance, then the edge point is treated as an interior point;
[0068] S143, If the distance from the edge point to the current edge line exceeds the preset distance, then the edge point is regarded as an outlier.
[0069] S144: If the current number of inliers on the current edge line is greater than the historical number, update the current edge line based on the current number of inliers until the edge line with the maximum number of inliers is obtained.
[0070] S150, determine the rotation angle of the workpiece to be tested relative to the placement state of the template workpiece based on the edge line of the workpiece to be tested.
[0071] Exemplary, such as Figure 3 As shown, the visual measurement method for this workpiece establishes a local coordinate system based on the contour information of the template workpiece, displays the edge line of the workpiece to be measured on the local coordinate system, and extends the edge line to connect the origin of the local coordinate system to obtain the angle bisector of the included angle of the edge line. The visual measurement method for this workpiece uses the angle between the angle bisector and the vertical axis of the local coordinate system as the rotation angle θ of the workpiece to be measured, wherein the range of the rotation angle θ is [0-360°].
[0072] For example, in one embodiment, the visual measurement method for the workpiece further includes: establishing a local coordinate system in the workpiece image based on the contour information of the template workpiece, with the center position of the template workpiece as the origin, the central axis of the template workpiece as the vertical axis, and a straight line perpendicular to the central axis as the horizontal axis.
[0073] For example, in one embodiment, the visual measurement method for the workpiece fits the edge lines of the workpiece to be measured based on the edge information of the workpiece to be measured, including: in the local coordinate system, extending each edge line of the workpiece to be measured to the origin to obtain the angle bisector of the angle between the edge lines passing through the origin; and determining the angle between the angle bisector and the vertical axis of the local coordinate system as the rotation angle of the workpiece to be measured relative to the placement state of the template workpiece.
[0074] Figure 4 A schematic diagram of a workpiece visual measurement device 200 according to an embodiment of this application is shown. Exemplarily, the workpiece visual measurement device 200 includes:
[0075] The acquisition processing module 210 is configured to acquire an original image containing the workpiece to be measured, perform grayscale processing on the original image to obtain a grayscale image, and perform edge detection processing based on the grayscale image to obtain a workpiece image, wherein the workpiece image includes edge information of the workpiece to be measured.
[0076] The contour extraction module 220 is configured to obtain a histogram of oriented gradients of the workpiece image based on the edge information, and extract contour information of the workpiece to be measured according to the histogram of oriented gradients.
[0077] The matching module 230 is configured to determine an image moment of the workpiece to be measured according to the grayscale image, and match the workpiece to be measured with a template workpiece according to the image moment and the contour information, to determine whether the workpiece to be measured is rotated.
[0078] The fitting module 240 is configured to, if the workpiece to be measured is rotated, fit an edge straight line of the workpiece to be measured according to the edge information of the workpiece to be measured.
[0079] The measurement module 250 is configured to determine a rotation angle of the workpiece to be measured relative to a placement state of the template workpiece according to the edge straight line of the workpiece to be measured.
[0080] It can be understood that the device of the embodiment corresponds to the workpiece visual measurement method of the above-mentioned embodiment, and the optional items in the above-mentioned embodiment are also applicable to the embodiment, and therefore will not be described again here.
[0081] The application further provides a terminal device, which exemplarily includes a processor and a memory, wherein the memory stores a computer program, and the processor executes the computer program to enable the terminal device to perform the functions of each module in the workpiece visual measurement method or the workpiece visual measurement device.
[0082] The processor can be an integrated circuit chip with a signal processing capability. The processor can be a general-purpose processor, including a central processing unit (CPU), a graphics processing unit (GPU), and a network processor (NP), a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a field programmable gate array (FPGA), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, or at least one of the above. The general-purpose processor can be a microprocessor or the processor can also be any conventional processor, etc., which can implement or execute the disclosed methods, steps, and logic block diagrams in the embodiments of the application.
[0083] The memory can be, but is not limited to, a random access memory (RAM), a read only memory (ROM), a programmable read-only memory (PROM), an erasable programmable read-only memory (EPROM), an electrically erasable programmable read-only memory (EEPROM), and the like. Among them, the memory is used to store a computer program, and the processor can execute the computer program correspondingly after receiving an execution instruction.
[0084] The application further provides a computer readable storage medium for storing the computer program used in the terminal device. For example, the computer readable storage medium can include, but is not limited to, a U disk, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk, and various media that can store program codes.
[0085] In several embodiments provided in the present application, it should be understood that the disclosed apparatus and method can also be implemented by other ways. The apparatus embodiments described above are only schematic, for example, the flow charts and block diagrams in the drawings show the possible implementation architectures, functions and operations of the apparatus, method and computer program product according to the embodiments of the present application. In this regard, each block in the flow charts or block diagrams can represent a module, a program segment or a part of code, which contains one or more executable instructions for implementing the specified logical functions. It should also be noted that, in alternative implementation ways, the functions noted in the blocks can also occur in different orders from that noted in the drawings. For example, two consecutive blocks can actually be executed substantially in parallel, and sometimes they can be executed in reverse order, depending on the functions involved. It should also be noted that each block in the structural diagram and / or flow chart, and the combination of blocks in the structural diagram and / or flow chart, can be implemented by a dedicated hardware-based system for executing the specified functions or actions, or can be implemented by a combination of dedicated hardware and computer instructions.
[0086] In addition, each functional module or unit in each embodiment of the present application can be integrated together to form an independent part, or each module can exist independently, or two or more modules can be integrated to form an independent part.
[0087] If the functions are implemented in the form of software function modules and sold or used as independent products, they can be stored in a computer readable storage medium. Based on this understanding, the technical solutions of the present application can be embodied in the form of a software product, which is stored in a storage medium and includes a number of instructions for causing a computer device (which can be a smart phone, a personal computer, a server, or a network device, etc.) to execute all or part of the steps of the various embodiments of the method of the present application.
[0088] The above merely describes specific embodiments of the present application, but the protection scope of the present application is not limited thereto, and any person skilled in the art can easily think of changes or replacements within the technical scope disclosed by the present application, which should be covered within the protection scope of the present application.
Claims
1. A method of visual measurement of a workpiece, characterized by, The method comprises the following steps: An original image containing a workpiece to be measured is collected, the original image is subjected to grayscale processing to obtain a grayscale image, and edge detection processing is performed based on the grayscale image to obtain a workpiece image, wherein the workpiece image comprises edge information of the workpiece to be measured; A histogram of oriented gradients of the workpiece image is obtained based on the edge information, and profile information of the workpiece to be measured is extracted according to the histogram of oriented gradients; An image moment of the workpiece to be measured is determined according to the grayscale image, and the workpiece to be measured is matched with a template workpiece according to the image moment and the profile information to determine whether the workpiece to be measured has been rotated; If the workpiece to be measured has been rotated, an edge straight line of the workpiece to be measured is fitted according to the edge information of the workpiece to be measured; A rotation angle of the workpiece to be measured relative to a placement state of the template workpiece is determined according to the edge straight line of the workpiece to be measured.
2. The visual measurement method of a workpiece according to claim 1, wherein, Further comprising: A local coordinate system is established in the workpiece image with the center position of the template workpiece as an origin, with the central axis of the template workpiece as a longitudinal axis, and with a straight line perpendicular to the central axis as a transverse axis.
3. The visual measurement method of a workpiece according to claim 2, wherein, The determination of the rotation angle of the workpiece to be measured relative to the placement state of the template workpiece according to the edge straight line of the workpiece to be measured comprises: In the local coordinate system, each edge straight line of the workpiece to be measured is extended to the origin to obtain an angle bisector of the included angle of the edge straight line passing through the origin; An angle between the angle bisector and the longitudinal axis of the local coordinate system is determined as the rotation angle of the workpiece to be measured relative to the placement state of the template workpiece.
4. The visual measurement method of a workpiece according to claim 1, wherein, In the process of matching the workpiece to be measured with the template workpiece according to the image moment and the profile information, further comprising: The workpiece image is up-sampled by a pyramid algorithm to make the workpiece image have the same size as the template workpiece to match the workpiece image with the template workpiece.
5. The visual measurement method of a workpiece according to claim 1, wherein, The obtaining of the histogram of oriented gradients of the workpiece image based on the edge information comprises: The gradient and the gradient direction of each pixel point in the workpiece image are calculated, and the gradient exceeding a preset threshold is retained; The gradient directions in a preset neighborhood are counted, the gradients with the same gradient direction and exceeding a preset number are retained, and the histogram of oriented gradients is obtained according to the retained gradients.
6. The visual measurement method of a workpiece according to claim 1, wherein, The fitting of the edge straight line of the workpiece to be measured according to the edge information of the workpiece to be measured comprises: The edge straight line of the workpiece to be measured is fitted by a random sample consensus algorithm to eliminate edge abrupt points in the edge information of the workpiece to be measured to obtain the edge straight line of the workpiece to be measured.
7. The visual measurement method of a workpiece according to claim 6, wherein, The fitting of the edge straight line of the workpiece to be measured by the random sample consensus algorithm comprises: A plurality of edge points of the workpiece to be measured are selected to preliminarily obtain an edge straight line, and whether each edge point is an in-point is determined according to the distance of each edge point to a current edge straight line; If the distance of the edge point to the current edge straight line does not exceed a preset distance, the edge point is regarded as an in-point. If the distance from the edge point to the current edge line exceeds a preset distance, the edge point is taken as an outlier point; If the current number of inner points of the current edge line is greater than a historical number, the current edge line is updated according to the current inner points until an edge line with a maximum number of inner points is obtained.
8. A device for visual measurement of a workpiece, characterized by Comprise: The acquisition processing module is configured to acquire an original image containing a workpiece to be measured, perform grayscale processing on the original image to obtain a grayscale image, and perform edge detection processing based on the grayscale image to obtain a workpiece image, wherein the workpiece image includes edge information of the workpiece to be measured; The contour extraction module is configured to acquire a histogram of oriented gradients (HOG) of the workpiece image based on the edge information, and extract contour information of the workpiece to be measured according to the HOG; The matching module is configured to determine an image moment of the workpiece to be measured according to the grayscale image, and match the workpiece to be measured with a template workpiece according to the image moment and the contour information to determine whether the workpiece to be measured is rotated; The fitting module is configured to, if the workpiece to be measured is rotated, fit an edge line of the workpiece to be measured according to the edge information of the workpiece to be measured; The measurement module is configured to determine a rotation angle of the workpiece to be measured relative to a placement state of the template workpiece according to the edge line of the workpiece to be measured.
9. A terminal device, comprising: The terminal device comprises a processor and a memory, the memory stores a computer program, and the processor is configured to execute the computer program to implement the workpiece visual measurement method of any one of claims 1-7.
10. A computer-readable storage medium, characterized in that, The computer program is stored in the memory and executed on the processor to implement the workpiece visual measurement method of any one of claims 1-7.
Citation Information
Patent Citations
Machine vision measurement method and application thereof in bearing workpiece measurement
CN114359366A
Template matching method and device, equipment and storage medium
CN118279614A