Visual measurement method, device and equipment of workpiece and storage medium

Through machine vision technology, the non-contact and automated rotation angle measurement of the workpiece is achieved through machine vision technology, which solves the problems of low efficiency and insufficient accuracy in the existing technology, and is suitable for large-scale production and improves measurement accuracy and efficiency.

CN119130999AActive Publication Date: 2024-12-13SHENZHEN RUIPO PRECISION CO LTD

Patent Information

Application Number
CN202411295971.3
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-09-14
Publication Date
2024-12-13
Estimated Expiration
2044-09-14

AI Technical Summary

Technical Problem

The existing workpiece rotation angle measurement methods have problems such as insufficient contactless measurement capabilities, low manual operation efficiency, and inaccurate measurement results, especially in large-scale production, which is difficult to meet the needs of high precision and high efficiency.

Method used

Using machine vision technology, by collecting the original image of the workpiece for grayscale processing and edge detection, the direction gradient histogram is obtained, the outline information is extracted, and the template workpiece is matched, the edge line is fitted to determine the rotation angle, and non-contact and automation are achieved. rotation angle measurement.

Benefits of technology

It realizes accurate, fast and non-contact rotation angle measurement of the workpiece, improves measurement accuracy and efficiency, reduces manual operation costs, is suitable for large-scale production, and can handle some workpieces that are not suitable for contact measurement.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119130999A_ABST
    Figure CN119130999A_ABST
Patent Text Reader

Abstract

The invention relates to the technical field of machine vision measurement, and discloses a workpiece vision measurement method, device and equipment and a storage medium, and the workpiece vision measurement method comprises the steps: collecting an original image, carrying out the graying processing of the original image, and carrying out the edge detection processing based on a gray image, and obtaining a workpiece image; obtaining a histogram of oriented gradients of the workpiece image to obtain contour information of the to-be-detected workpiece; determining an image moment of the to-be-detected workpiece according to the grayscale image, matching the to-be-detected workpiece with the template workpiece according to the image moment and the contour information, and judging whether the to-be-detected workpiece rotates or not; if the to-be-measured workpiece rotates, fitting according to the edge information of the to-be-measured workpiece to obtain an edge straight line of the to-be-measured workpiece; and according to the edge straight line of the to-be-measured workpiece, determining the rotation angle of the to-be-measured workpiece relative to the placement state of the template workpiece. The device is simple in operation in the measurement process of the workpiece to be measured, is easy to maintain, can save the labor cost, and guarantees the stability of the product quality.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of machine vision measurement technology, and in particular to a method, device, equipment and storage medium for visually measuring a workpiece. Background Art

[0002] With the progress and development of modern manufacturing industry, the accuracy and speed of measuring the key position dimensions of finished products or semi-finished products are increasingly required. The traditional method of measuring the rotation angle of the workpiece is to use reusable measuring tools such as vernier calipers or plug gauges to obtain information such as the rotation angle of the workpiece during the processing. Although the traditional measurement method meets the detection accuracy requirements to a large extent, it requires manual operation, the operation process is relatively cumbersome, and the work efficiency is not high in mass production. There are certain defects, and manual operation has certain subjectivity. It is difficult to achieve a unified degree of grasp of the measurement standard, resulting in inaccurate measurement results. In addition, due to some objective conditions, some workpieces are not suitable for contact measurement. Summary of the invention

[0003] In view of this, the embodiments of the present application provide a method, device, equipment and storage medium for visual measurement of a workpiece, which can perform non-contact and accurate measurement of the workpiece to be measured, and are simple to operate and save labor costs.

[0004] In a first aspect, an embodiment of the present application provides a method for visually measuring a workpiece, comprising:

[0005] 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;

[0006] Acquire a directional gradient histogram of the workpiece image based on the edge information, and extract contour information of the workpiece to be measured according to the directional gradient histogram;

[0007] 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;

[0008] If the workpiece to be measured rotates, an edge straight line of the workpiece to be measured is obtained by fitting according to the edge information of the workpiece to be measured;

[0009] According to the edge straight line of the workpiece to be measured, the rotation angle of the workpiece to be measured relative to the placement state of the template workpiece is determined.

[0010] In combination with the first aspect, the embodiment of the present application provides a first possible implementation of the first aspect, which further includes:

[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 the origin, the central axis of the template workpiece as the longitudinal axis, and a straight line perpendicular to the central axis as the horizontal axis.

[0012] In combination with the first aspect, the embodiment of the present application provides a second possible implementation of the first aspect, wherein determining 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 includes:

[0013] 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 angle of the edge straight lines 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] In combination with the first aspect, the embodiment of the present application provides a third possible implementation manner of the first aspect, wherein the process of matching the workpiece to be measured with the template workpiece according to the image moment and the contour information further includes:

[0016] The workpiece image is up-sampled by a pyramid algorithm so that the workpiece image is matched with the template workpiece at the same size as the template workpiece.

[0017] In combination with the first aspect, an embodiment of the present application provides a fourth possible implementation of the first aspect, wherein the step of acquiring a directional gradient histogram of the workpiece image based on the edge information includes:

[0018] Calculating the gradient of each pixel in the workpiece image and the gradient direction of the gradient, and retaining the gradient exceeding a preset threshold;

[0019] The gradient directions are counted within a preset neighborhood, the gradients having the same gradient directions and exceeding a preset number are retained, and the directional gradient histogram is obtained according to the retained gradients.

[0020] In combination with the first aspect, the embodiment of the present application provides a fifth possible implementation of the first aspect, wherein the step of fitting the edge straight line of the workpiece to be measured according to the edge information of the workpiece to be measured comprises:

[0021] The edge straight line of the workpiece to be measured is fitted by a random sample consistency algorithm to eliminate edge mutation points in the edge information of the workpiece to be measured, and obtain the edge straight line of the workpiece to be measured.

[0022] In combination with the first aspect, the embodiment of the present application provides a sixth possible implementation of the first aspect, wherein the step of fitting the edge straight line of the workpiece to be measured by using a random sample consistency algorithm includes:

[0023] Selecting several edge points of the workpiece to be measured to perform fitting to preliminarily obtain an edge straight line, and judging whether each edge point is an inner point 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 line does not exceed a preset distance, the edge point is regarded as an inner point;

[0025] If the distance from the edge point to the current edge line exceeds a preset distance, the edge point is regarded as an outlier;

[0026] If the current number of inliers of the current edge line is greater than the historical number, the current edge line is updated according to the current inliers until an edge line with a maximum number of inliers is obtained.

[0027] In a second aspect, an embodiment of the present application provides a visual measurement device for a workpiece, comprising:

[0028] An acquisition and processing module, used for acquiring an original image containing a workpiece to be measured, graying 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 includes edge information of the workpiece to be measured;

[0029] A contour extraction module, used to obtain a directional gradient histogram of the workpiece image based on the edge information, and extract contour information of the workpiece to be measured according to the directional gradient histogram;

[0030] A matching module, used for 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;

[0031] A fitting module, used for fitting an edge straight line of the workpiece to be measured according to the edge information of the workpiece to be measured if the workpiece to be measured rotates;

[0032] The measuring module is used to determine 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.

[0033] In a third aspect, an embodiment of the present application provides a terminal device, the terminal device comprising a processor and a memory, the memory storing a computer program, and the processor being used 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 storing a computer program, wherein when the computer program is executed on a processor, the visual measurement method of the workpiece is implemented.

[0035] The embodiments of the present application have the following beneficial effects:

[0036] A visual measurement method for a workpiece of an embodiment of the present application comprises: collecting an original image containing a workpiece to be measured, graying 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 includes edge information of the workpiece to be measured; obtaining a directional 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 directional gradient histogram; determining the image moment of the workpiece to be measured according to the grayscale image, and matching the workpiece to be measured with the template workpiece according to the image moment and the contour information to determine whether the workpiece to be measured rotates; if the workpiece to be measured rotates, the edge straight line of the workpiece to be measured is obtained by fitting the edge information of the workpiece to be measured; and determining 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. 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, fast 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, easy to maintain, and can save labor costs, ensuring the stability of product quality. BRIEF DESCRIPTION OF THE DRAWINGS

[0037] In order to more clearly illustrate the technical solutions of the embodiments of the present application, the drawings required for use in the embodiments will be briefly introduced below. It should be understood that the following drawings only show certain embodiments of the present application and therefore should not be regarded as limiting the scope. For ordinary technicians in this field, other related drawings can be obtained based on these drawings without paying creative work.

[0038] Figure 1 A first schematic diagram of a process of a visual measurement method for a workpiece provided in an embodiment of the present application is shown;

[0039] Figure 2 A second schematic flow chart of the visual measurement method for a workpiece provided in an embodiment of the present application is shown;

[0040] Figure 3A schematic diagram showing the actual measurement effect of the rotation angle of the workpiece to be measured provided by the embodiment of the present application is shown;

[0041] Figure 4 A schematic structural diagram of a workpiece visual measurement device provided in an embodiment of the present application is shown.

[0042] Description of main component symbols:

[0043] 200 - visual measurement device for workpiece; 210 - acquisition and processing module; 220 - contour 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 described clearly and completely below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, rather than all of the embodiments.

[0045] The components of the embodiments of the present application generally described and shown in the drawings herein may be arranged and designed in various configurations. Therefore, the following detailed description of the embodiments of the present application provided in the drawings is not intended to limit the scope of the application claimed for protection, but merely represents the 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 making creative work belong to the scope of protection of the present application.

[0046] Hereinafter, the terms "including", "having" and their cognates that can be used in various embodiments of the present application are intended only to indicate specific features, numbers, steps, operations, elements, components or a combination of the foregoing items, and should not be understood as first excluding the existence of one or more other features, numbers, steps, operations, elements, components or a combination of the foregoing items or increasing the possibility of one or more features, numbers, steps, operations, elements, components or a combination of the foregoing items. 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 terms and scientific terms) used herein have the same meanings as those generally understood by those skilled in the art to which the various embodiments of the present application belong. The terms (such as those defined in generally used dictionaries) will be interpreted as having the same meanings as the contextual meanings in the relevant technical field and will not be interpreted as having idealized meanings or overly formal meanings unless clearly defined in the various embodiments of the present application.

[0048] In conjunction with the accompanying drawings, some embodiments of the present application are described in detail below. In the absence of conflict, the following embodiments and features in the embodiments can be combined with each other.

[0049] The existing methods for measuring the rotation angle of a workpiece cannot meet the requirements of non-contact measurement and the manual operation process is inefficient. This application proposes to accurately measure the rotation angle of the workpiece to be measured based on machine vision, match the shape features of the workpiece to be measured in the workpiece image, accurately match the rotation of the workpiece to be measured, and eliminate interference in the measurement process of the rotation angle of the workpiece, so as to accurately measure the rotation angle of the workpiece to be measured.

[0050] The visual measurement method of the workpiece is described below in conjunction with some specific embodiments.

[0051] Figure 1 A flow chart showing a method for visually measuring a workpiece according to an embodiment of the present application is shown.

[0052] Exemplarily, the visual measurement method of the workpiece includes the following steps:

[0053] S110, collecting an original image containing the workpiece to be measured, graying 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 includes edge information of the workpiece to be measured.

[0054] Exemplarily, in the process of visual measurement of workpieces, the original image is first collected using a camera, a computer lens or other camera equipment, and the original color image is converted into a grayscale image through grayscale processing, that is, the optical three primary colors (RGB) value of each pixel in the original image is converted into a grayscale value. The image preprocessing process also includes Gaussian blur processing, which eliminates the noise in the grayscale image and smoothes the grayscale image. Gaussian blur is a linear smoothing filter used to effectively remove noise in the grayscale image while maintaining the details of the grayscale image. The Gaussian blur process is to calculate a new value for the pixels around each pixel with the weight coefficient, thereby achieving smoothing. 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 grayscale image. The edge is where the brightness or color changes suddenly, such as the edge of the workpiece to be measured or the line in the grayscale image. The edge detection processing is used to use a set of specific filters to detect the edge information in the grayscale image and obtain multiple edge points from the detected edge.

[0055] S120, obtaining a directional gradient histogram of the workpiece image based on the edge information, and extracting contour information of the workpiece to be measured according to the directional gradient histogram.

[0056] Exemplarily, the directional 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, and 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 at that position and its own adjacent pixel point. When the preset threshold is set to 2, the gradient exceeding 2 is retained. At each pixel, the gradient has a magnitude and a direction. The x-direction gradient map will strengthen the vertical edge feature, and the y-direction gradient map will strengthen the horizontal edge feature, which allows the useful contour feature to be retained. In the process of creating the directional gradient histogram, the direction interval of the gradient direction of each pixel point in the workpiece image within the preset domain is counted to obtain a directional gradient histogram describing the distribution of the gradient direction. For example, the preset domain is set to 3*3, and the gradient direction includes 8 directions including upper left, upper, upper right, left, right, lower left, lower, and lower right. If there are more than 5 preset gradient directions, they are retained, thereby obtaining the directional gradient map of the entire image. Each entry of the directional gradient histogram represents the number of pixels or the sum of gradient intensities within the directional interval. The contour feature of the workpiece is a significant visual feature of the object boundary in the workpiece image, and the directional gradient histogram is used to extract edge information from the workpiece image and represent it in the form of a histogram.

[0057] For example, in one embodiment, the visual measurement method of the workpiece obtains a directional gradient histogram of the workpiece image based on edge information, including: calculating the gradient and the gradient direction of each pixel point in the workpiece image, and retaining the gradients exceeding a preset threshold; counting the gradient directions within a preset neighborhood, retaining the gradients with the same gradient direction and exceeding a preset number, and obtaining a directional gradient histogram based on the retained gradients.

[0058] S130, determining the image moment of the workpiece to be measured according to the grayscale image, and matching the workpiece to be measured with the template workpiece according to the image moment and contour information to determine whether the workpiece to be measured is rotated.

[0059] Demonstratively, the visual measurement method of the workpiece uses image moments to describe the features of the workpiece image, thereby quantifying the features of the workpiece image and realizing workpiece image recognition. The image usually contains two directions, horizontal and vertical, so the k+l order image moments of two-dimensional random variables are generally used to describe the features of the image. In addition, the visual measurement method of the workpiece uses a grayscale image or a binary image to calculate the image moment, and the pixel coordinates of the workpiece image are regarded as two-dimensional random variables (X, Y). The grayscale image can be represented by a two-dimensional grayscale image density function, wherein the invariant moment in the image moment is a highly concentrated image feature with translation, grayscale, scale, and rotation invariance, and therefore can be used as a stable feature quantity to describe the geometric shape features of the workpiece image, wherein the invariant moment includes area invariant moment, center distance, normalized center distance, and rotation invariant moment, etc.

[0060] Exemplarily, the visual measurement method of the workpiece determines whether the workpiece to be measured is consistent with the template workpiece based on the image moment and contour information. If the workpiece to be measured is consistent with the template workpiece, the workpiece to be measured has not rotated. If the workpiece to be measured is inconsistent with the template workpiece, it is considered that the workpiece to be measured has deflected. In the process of judging whether the workpiece to be measured is consistent with the template workpiece, the present application uses a pyramid algorithm to process the workpiece image to improve the matching efficiency. The pyramid algorithm is used to insert new pixels on the workpiece image through an upsampling operation to expand the size of the workpiece image, thereby obtaining a higher resolution workpiece image, so as to match the workpiece image with the template workpiece at the same size, thereby improving the matching efficiency. Upsampling methods include nearest neighbor interpolation, bilinear interpolation, and bicubic interpolation. Compared with the original workpiece image, the upsampled workpiece image retains more image details.

[0061] For example, in one embodiment, the visual measurement method of the workpiece further includes: upsampling the workpiece image through a pyramid algorithm so that the workpiece image matches the template workpiece at the same size as the template workpiece.

[0062] S140: If the workpiece to be measured rotates, an edge straight line of the workpiece to be measured is obtained by fitting according to edge information of the workpiece to be measured.

[0063] Exemplarily, the visual measurement method of the workpiece adopts a random sample consistency algorithm to perform straight line fitting on the edge points obtained in the edge detection process, and filters out the distant and isolated points, so as to fit the edge straight line of the workpiece to be measured. The process of the random sample consistency algorithm includes: selecting continuous edge points for fitting, so as to fit a more accurate edge straight line; for each edge point in the data set, judging whether each edge point fits the current edge straight line, if the error is less than a certain preset distance tolerated by the system, it is regarded as an inner point, otherwise, it is regarded as an outlier or an isolated point, as an outer point, wherein the preset distance is an empirical value determined by the specific application and data set; comparing the current number of inner points with the previous maximum number of inner points, if the current number of inner points exceeds the previous maximum number of inner points, the edge straight line is updated; repeating the execution several times, and finding the edge straight line with the maximum number of inner points is the final edge straight line.

[0064] For example, in one embodiment, the visual measurement method of the workpiece obtains an edge straight line of the workpiece to be measured according to the edge information of the workpiece to be measured, including: using a random sample consistency algorithm to preset a threshold of the workpiece to be measured to eliminate edge mutation points in the edge information of the workpiece to be measured, so as to obtain the edge straight line of the workpiece to be measured.

[0065] For example, in one embodiment, Figure 2As shown, the visual measurement method of the workpiece uses a random sample consistency algorithm to fit the edge straight line of the workpiece to be measured, including:

[0066] S141, selecting several edge points of the workpiece to be measured to perform fitting to preliminarily obtain edge straight lines, and judging whether each edge point is an inner point according to the distance from each edge point to the current edge straight line;

[0067] S142, if the distance from the edge point to the current edge line does not exceed the preset distance, the edge point is regarded as an inner point;

[0068] S143, if the distance from the edge point to the current edge line exceeds a preset distance, the edge point is regarded as an outlier;

[0069] S144, if the current number of inliers of the current edge line is greater than the historical number, the current edge line is updated according to the current inliers until an edge line with a maximum number of inliers is obtained.

[0070] S150, determining a rotation angle of the workpiece to be measured relative to a placement state of the template workpiece according to an edge straight line of the workpiece to be measured.

[0071] Exemplary, such as Figure 3 As shown, the visual measurement method of the workpiece establishes a local coordinate system according to the contour information of the template workpiece, displays the edge straight line of the workpiece to be measured on the local coordinate system, and extends the edge straight line to connect the origin of the local coordinate system to obtain the angular bisector of the angle of the edge straight line. The visual measurement method of the workpiece uses the angle between the angular bisector and the longitudinal 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 of the workpiece also 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 longitudinal axis, and the straight line perpendicular to the central axis as the horizontal axis.

[0073] For example, in one embodiment, the visual measurement method of the workpiece obtains edge straight lines of the workpiece to be measured by fitting according to edge information of the workpiece to be measured, including: in the local coordinate system, extending each edge straight line of the workpiece to be measured to the origin to obtain an angle bisector of the angle of the edge straight lines passing through the origin; and determining the angle between the angle bisector and the longitudinal 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 structural diagram of a workpiece visual measurement device 200 according to an embodiment of the present application is shown. Exemplarily, the workpiece visual measurement device 200 includes:

[0075] The acquisition and processing module 210 is used to acquire an original image containing the workpiece to be measured, grayscale 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 used to obtain a directional gradient histogram of the workpiece image based on edge information, and extract contour information of the workpiece to be measured according to the directional gradient histogram;

[0077] A matching module 230 is used to determine the image moment of the workpiece to be measured according to the grayscale image, and match the workpiece to be measured with the template workpiece according to the image moment and contour information to determine whether the workpiece to be measured is rotated;

[0078] A fitting module 240 is used for fitting an edge straight line of the workpiece to be measured according to edge information of the workpiece to be measured if the workpiece to be measured rotates;

[0079] The measuring module 250 is used to determine 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.

[0080] It can be understood that the device of this embodiment corresponds to the visual measurement method of the workpiece in the above embodiment, and the options in the above embodiment are also applicable to this embodiment, so they will not be described repeatedly here.

[0081] The present application also provides a terminal device. Exemplarily, the terminal device includes a processor and a memory, wherein the memory stores a computer program, and the processor runs the computer program to enable the terminal device to execute the functions of each module in the above-mentioned visual measurement method of the workpiece or the above-mentioned visual measurement device of the workpiece.

[0082] Among them, the processor can be an integrated circuit chip with signal processing capabilities. 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 at least one of other programmable logic devices, discrete gates or transistor logic devices, and discrete hardware components. 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 present application.

[0083] The memory may 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), etc. Among them, the memory is used to store a computer program, and the processor can execute the computer program accordingly after receiving an execution instruction.

[0084] The present application also provides a computer-readable storage medium for storing a computer program used in the above-mentioned terminal device. For example, the computer-readable storage medium may include, but is not limited to, various media that can store program codes, such as a USB flash drive, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk.

[0085] In several embodiments provided in the present application, it should be understood that the disclosed apparatus and method can also be implemented in other ways. The apparatus embodiments described above are merely schematic, for example, the flowcharts and structure diagrams in the accompanying drawings show the possible architecture, functions and operations of the apparatus, method and computer program product according to multiple embodiments of the present application. In this regard, each box in the flowchart or block diagram can represent a module, a program segment or a part of a code, and a module, a program segment or a part of a code contains one or more executable instructions for implementing a specified logical function. It should also be noted that in an alternative implementation, the functions marked in the box can also occur in a different order from that marked in the accompanying drawings. For example, two consecutive boxes can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the structure diagram and / or the flow diagram, and the combination of boxes in the structure diagram and / or the flow diagram, can be implemented with a dedicated hardware-based system that performs a specified function or action, or can be implemented with a combination of dedicated hardware and computer instructions.

[0086] In addition, the functional modules or units in the various embodiments of the present application may be integrated together to form an independent part, or each module may exist separately, or two or more modules may be integrated to form an independent part.

[0087] If the function is implemented in the form of a software function module and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present application, or the part that contributes to the prior art, or the part of the technical solution, can be embodied in the form of a software product, which is stored in a storage medium and includes several instructions for a computer device (which can be a smart phone, a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the methods of each embodiment of the present application.

[0088] The above are only specific implementation methods of the present application, but the protection scope of the present application is not limited thereto. Any technician familiar with the technical field can easily think of changes or substitutions within the technical scope disclosed in the present application, which should be covered by the protection scope of the present application.

Claims

1. A method for visual measurement of a workpiece, characterized in that: include: 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; Acquire a directional gradient histogram of the workpiece image based on the edge information, and extract contour information of the workpiece to be measured according to the directional gradient histogram; 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 rotates, an edge straight line of the workpiece to be measured is obtained by fitting according to the edge information of the workpiece to be measured; According to the edge straight line of the workpiece to be measured, the rotation angle of the workpiece to be measured relative to the placement state of the template workpiece is determined.

2. The visual measurement method of a workpiece according to claim 1, characterized in that: Also includes: 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 the origin, the central axis of the template workpiece as the longitudinal axis, and a straight line perpendicular to the central axis as the horizontal axis.

3. The method for visually measuring a workpiece according to claim 2, characterized in that: The step of determining 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 angle of the edge straight lines passing through the origin; 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.

4. The method for visually measuring a workpiece according to claim 1, characterized in that: The process of matching the workpiece to be measured with the template workpiece according to the image moment and the contour information also includes: The workpiece image is up-sampled by a pyramid algorithm so that the workpiece image is matched with the template workpiece at the same size as the template workpiece.

5. The method for visually measuring a workpiece according to claim 1, characterized in that: The step of acquiring a directional gradient histogram of the workpiece image based on the edge information comprises: Calculating the gradient of each pixel in the workpiece image and the gradient direction of the gradient, and retaining the gradient exceeding a preset threshold; The gradient directions are counted within a preset neighborhood, the gradients having the same gradient directions and exceeding a preset number are retained, and the directional gradient histogram is obtained according to the retained gradients.

6. The method for visually measuring a workpiece according to claim 1, characterized in that: The step of fitting an 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 consistency algorithm to eliminate edge mutation points in the edge information of the workpiece to be measured, and obtain the edge straight line of the workpiece to be measured.

7. The method for visually measuring a workpiece according to claim 6, characterized in that: The step of fitting the edge straight line of the workpiece to be measured by using a random sample consistency algorithm includes: Selecting several edge points of the workpiece to be measured to perform fitting to preliminarily obtain an edge straight line, and judging whether each edge point is an inner point according to the distance from each edge point to the current edge straight line; If the distance from the edge point to the current edge line does not exceed a preset distance, the edge point is regarded as an inner point; If the distance from the edge point to the current edge line exceeds a preset distance, the edge point is regarded as an outlier; If the current number of inliers of the current edge line is greater than the historical number, the current edge line is updated according to the current inliers until an edge line with a maximum number of inliers is obtained.

8. A visual measuring device for a workpiece, characterized in that: include: An acquisition and processing module, used for acquiring an original image containing a workpiece to be measured, graying 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 includes edge information of the workpiece to be measured; A contour extraction module, used to obtain a directional gradient histogram of the workpiece image based on the edge information, and extract contour information of the workpiece to be measured according to the directional gradient histogram; A matching module, used for 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; A fitting module, used for fitting an edge straight line of the workpiece to be measured according to the edge information of the workpiece to be measured if the workpiece to be measured rotates; The measuring module is used to determine 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.

9. A terminal device, characterized in that: The terminal device comprises a processor and a memory, wherein the memory stores a computer program, and the processor is configured to execute the computer program to implement the visual measurement method for a workpiece according to any one of claims 1 to 7.

10. A computer-readable storage medium, characterized in that: The computer program is stored therein, and when the computer program is executed on a processor, the visual measurement method for a workpiece according to any one of claims 1 to 7 is implemented.

Citation Information

Patent Citations

  • Template-matching-based element positioning method

    CN106485284A

  • Machine vision measurement method and application thereof in bearing workpiece measurement

    CN114359366A

  • Quad flat no-lead (QFN) element rapid and accurate identification and positioning method and device and storage medium

    CN115578571A

  • Template matching method and device, equipment and storage medium

    CN118279614A

Cited By

  • Edge measurement method and device, storage medium and computer equipment

    CN120538441A

  • Machine vision angular bisector measuring method, system, storage medium and device

    CN122281825A