A polygon workpiece positioning method, device, equipment and storage medium

By combining template matching and line detection algorithms, high-precision positioning of polygonal workpieces was achieved, solving the problem of inaccurate positioning caused by changes in scale and angle in existing technologies.

CN116777889BActive Publication Date: 2026-01-30AINNOVATION NANJING TECH CO LTD
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202310796754.1
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-06-30
Publication Date
2026-01-30
Estimated Expiration
2043-06-30

AI Technical Summary

Technical Problem

Existing template matching methods are not sensitive to changes in the size and angle of polygonal workpieces, resulting in low positioning accuracy.

Method used

The initial positioning is performed using a template matching algorithm, followed by position correction and line detection using a line detection algorithm. The secondary positioning is then performed using the positioning positions of each edge of the polygonal workpiece.

Benefits of technology

It improves the positioning accuracy of polygonal workpieces, ensuring accurate positioning under conditions of changes in size and angle.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN116777889B_ABST
    Figure CN116777889B_ABST
Patent Text Reader

Abstract

This invention provides a method, apparatus, device, and storage medium for locating polygonal workpieces, relating to the field of image processing technology. The polygonal workpiece positioning method includes: using a template matching algorithm to locate a reference workpiece and a workpiece to be inspected in a workpiece image, obtaining the positioning position of the reference workpiece and the initial positioning position of the workpiece to be inspected; based on the positioning positions of the reference workpiece and the initial positioning positions of the workpiece to be inspected, performing position correction on the reference region of interest images of each side of the reference workpiece, correspondingly obtaining the reference region of interest images of each side of the workpiece to be inspected; using a line detection algorithm to perform line detection on the reference region of interest images of each side of the workpiece to be inspected, obtaining the positioning positions of each side of the workpiece to be inspected; and combining the positioning positions of each side of the workpiece to be inspected to obtain the secondary positioning position of the workpiece to be inspected. This invention can improve the positioning accuracy of polygonal workpieces.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of image processing technology, and more specifically, to a method, apparatus, device, and storage medium for locating polygonal workpieces. Background Technology

[0002] Currently, template matching is widely used to detect and locate workpieces from workpiece images. Template matching involves sliding and cropping multiple test images from the source image, calculating the similarity between each test image and a given target image (template image), and locating the target based on the test image with the highest similarity to the template image. However, template matching is insensitive to slight scale and angular changes, resulting in low workpiece positioning accuracy. Summary of the Invention

[0003] The purpose of this invention is to provide a method, apparatus, device, and storage medium for positioning polygonal workpieces, so as to achieve the technical effect of improving the positioning accuracy of polygonal workpieces.

[0004] In a first aspect, embodiments of the present invention provide a method for positioning a polygonal workpiece, comprising:

[0005] A template matching algorithm is used to locate the reference workpiece and the workpiece to be inspected in the workpiece image, so as to obtain the positioning position of the reference workpiece and the initial positioning position of the workpiece to be inspected.

[0006] Based on the positioning position of the reference workpiece and the initial positioning position of the workpiece to be inspected, the reference region of interest images of each side of the reference workpiece are corrected to obtain the corresponding reference region of interest images of each side of the workpiece to be inspected.

[0007] A line detection algorithm is used to perform line detection on the reference region of interest image of each side of the workpiece to be inspected, so as to obtain the positioning position of each side of the workpiece to be inspected.

[0008] By combining the positioning positions of each edge of the workpiece to be inspected, the secondary positioning position of the workpiece to be inspected is obtained.

[0009] In the above implementation process, by using a template matching algorithm to locate the polygonal workpiece in the workpiece image once, using a line detection algorithm to locate each edge of the polygonal workpiece, and combining the location of each edge of the polygonal workpiece to locate the polygonal workpiece a second time, the positioning accuracy of the polygonal workpiece can be improved.

[0010] Furthermore, before using a template matching algorithm to locate the reference workpiece and the workpiece to be inspected in the workpiece image, and obtaining the positioning position of the reference workpiece and the initial positioning position of the workpiece to be inspected, the method further includes:

[0011] Obtain the original workpiece image, and perform image preprocessing on the original workpiece image to obtain the workpiece image; wherein, the image preprocessing includes image grayscale conversion.

[0012] In the above implementation process, by first performing image preprocessing on the original workpiece image to obtain the workpiece image, and then using a template matching algorithm to locate the polygonal workpiece in the workpiece image in one step, it is possible to ensure that the positioning position of the polygonal workpiece is obtained quickly and accurately in the subsequent process.

[0013] Furthermore, the step of using a template matching algorithm to locate the reference workpiece and the workpiece to be inspected in the workpiece image, and obtaining the positioning position of the reference workpiece and the initial positioning position of the workpiece to be inspected, specifically includes:

[0014] Create a reference workpiece region image, extract the feature information of the reference workpiece from the reference workpiece region image, and obtain a template feature information file;

[0015] A template matching algorithm is used to locate the reference workpiece based on the template feature information file, thereby obtaining the location of the reference workpiece.

[0016] A template matching algorithm is used to locate the workpiece to be inspected based on the template feature information file, thereby obtaining the initial positioning position of the workpiece to be inspected.

[0017] In the above implementation process, by extracting all feature information of the polygonal workpiece from the created polygonal workpiece area image, a template feature information file is obtained. The template matching algorithm is then used to locate the polygonal workpiece once based on the template feature information file, which can quickly and accurately extract all feature information of the polygonal workpiece for one-time positioning.

[0018] Further, the step of correcting the position of the reference region of interest (ROI) image of each edge of the reference workpiece based on the positioning position of the reference workpiece and the initial positioning position of the workpiece to be inspected, to obtain the corresponding reference ROI image of each edge of the workpiece to be inspected, specifically includes:

[0019] Traverse each edge of the reference workpiece on the workpiece image, create a reference region of interest image of the current edge of the reference workpiece, and obtain the positioning position of the reference region of interest image of the current edge of the reference workpiece.

[0020] By combining the positioning position of the reference workpiece and the initial positioning position of the workpiece to be inspected, the positioning position of the reference region of interest image of the current side of the reference workpiece is corrected, so as to obtain the positioning position of the reference region of interest image of the corresponding side of the workpiece to be inspected.

[0021] The reference region of interest image of the corresponding side of the workpiece to be inspected is obtained based on the positioning position of the reference region of interest image of the corresponding side of the workpiece to be inspected.

[0022] In the above implementation process, by correcting the positioning position of the reference region of interest image of each side of the reference workpiece according to the positioning position of the reference workpiece and the initial positioning position of the workpiece to be inspected, the reference region of interest image of each side of the workpiece to be inspected is obtained, which can quickly and accurately obtain the reference region of interest image of each side of the workpiece to be inspected.

[0023] Furthermore, the positioning position of the reference workpiece is (x, y, r);

[0024] Where x is the x-coordinate of the center point of the reference workpiece in the image; y is the y-coordinate of the center point of the reference workpiece in the image; and r is the rotation angle of the reference workpiece image.

[0025] The initial positioning position of the workpiece to be inspected is (x1, y1, r1);

[0026] Where x1 is the x-coordinate of the center point of the workpiece to be inspected; y1 is the y-coordinate of the center point of the workpiece to be inspected; and r1 is the rotation angle of the workpiece image.

[0027] The location of the reference region of interest image of the current side of the reference workpiece is (roix, roiy, roiw, roih, roir);

[0028] Wherein, roix is ​​the image x-coordinate of the center point of the reference region of interest image of the current side of the reference workpiece; roiy is the image y-coordinate of the center point of the reference region of interest image of the current side of the reference workpiece; roiw is the image width of the reference region of interest image of the current side of the reference workpiece; roih is the image height of the reference region of interest of the current side of the reference workpiece; and roir is the image rotation angle of the reference region of interest of the current side of the reference workpiece.

[0029] The location of the reference region of interest image of the corresponding side of the workpiece to be inspected is (roix1,roiy1,roiw,roih,roir1).

[0030] Wherein, roix1 is the image x-coordinate of the center point of the reference region of interest image of the corresponding side of the workpiece to be inspected, roix1 = roix + (x1 - x); roiy1 is the image y-coordinate of the center point of the reference region of interest image of the corresponding side of the workpiece to be inspected, roiy1 = roiy + (y1 - y); roir1 is the image rotation angle of the reference region of interest of the corresponding side of the workpiece to be inspected, roir1 = roir + (r1 - r).

[0031] In the above implementation process, by correcting the positioning position of the reference region of interest image of each side of the reference workpiece according to the positioning position of the reference workpiece and the initial positioning position of the workpiece to be inspected, the reference region of interest image of each side of the workpiece to be inspected is obtained, which can quickly and accurately obtain the reference region of interest image of each side of the workpiece to be inspected.

[0032] Furthermore, the step of using a line detection algorithm to perform line detection on the reference region of interest image of each edge of the workpiece to be inspected, and obtaining the positioning position of each edge of the workpiece to be inspected, specifically includes:

[0033] A one-dimensional edge detection algorithm is used to perform edge sampling on the reference region of interest image of each edge of the workpiece to be inspected, thereby obtaining all edge points of each edge of the workpiece to be inspected.

[0034] The positioning positions of each edge of the workpiece under inspection are obtained by performing straight line fitting on all edge points of each edge.

[0035] In the above implementation process, a one-dimensional edge detection algorithm is used to extract all edge points of each edge of the workpiece to be inspected. Based on all edge points of each edge of the workpiece to be inspected, a straight line is fitted to locate each edge of the workpiece to be inspected. This can quickly and accurately obtain the positioning position of each edge of the workpiece to be inspected, and further improve the positioning accuracy of polygonal workpieces.

[0036] Furthermore, the step of obtaining the secondary positioning position of the workpiece by combining the positioning positions of each edge of the workpiece to be inspected specifically includes:

[0037] Based on the positioning positions of each edge of the workpiece to be inspected, determine the positions of each vertex and the center point of the workpiece to be inspected;

[0038] The secondary positioning position of the workpiece to be inspected is obtained based on the positions of each vertex and the center point.

[0039] In the above implementation process, by using the geometric relationship of each edge of the polygon and the positioning position of each edge of the polygonal workpiece for secondary positioning, the polygonal workpiece can be positioned quickly and accurately, further improving the positioning accuracy of the polygonal workpiece.

[0040] In a second aspect, embodiments of the present invention provide a polygonal workpiece positioning device, comprising:

[0041] The template matching module is used to locate the reference workpiece and the workpiece to be inspected in the workpiece image using a template matching algorithm, so as to obtain the positioning position of the reference workpiece and the initial positioning position of the workpiece to be inspected.

[0042] The position correction module is used to correct the position of the reference region of interest image of each side of the reference workpiece according to the positioning position of the reference workpiece and the initial positioning position of the workpiece to be inspected, so as to obtain the reference region of interest image of each side of the workpiece to be inspected.

[0043] The line detection module is used to perform line detection on the reference region of interest image of each side of the workpiece under inspection using a line detection algorithm, so as to obtain the positioning position of each side of the workpiece under inspection.

[0044] The workpiece positioning module is used to obtain the secondary positioning position of the workpiece by combining the positioning positions of each edge of the workpiece to be inspected.

[0045] Thirdly, embodiments of the present invention provide an electronic device including a processor, a memory, and a computer program stored in the memory and configured to be executed by the processor; the memory is coupled to the processor, and the processor implements the polygonal workpiece positioning method as described above when executing the computer program.

[0046] Fourthly, embodiments of the present invention provide a computer-readable storage medium, the computer-readable storage medium including a stored computer program; wherein, when the computer program is executed, it controls the device where the computer-readable storage medium is located to perform the polygonal workpiece positioning method as described above. Attached Figure Description

[0047] To more clearly illustrate the technical solutions of the embodiments of the present invention, the accompanying drawings used in the embodiments of the present invention will be briefly introduced below. It should be understood that the following drawings only show some embodiments of the present invention and should not be regarded as a limitation on the scope. For those skilled in the art, other related drawings can be obtained based on these drawings without creative effort.

[0048] Figure 1 This is a flowchart illustrating a polygonal workpiece positioning method provided in the first embodiment of the present invention.

[0049] Figure 2 This is a schematic diagram of an example workpiece image in the first embodiment of the present invention;

[0050] Figure 3 This is a data flow diagram of the polygonal workpiece positioning method exemplified in the first embodiment of the present invention;

[0051] Figure 4 This is a schematic diagram of a polygonal workpiece positioning device provided in the second embodiment of the present invention;

[0052] Figure 5 This is a schematic diagram of the structure of an electronic device provided in the third embodiment of the present invention. Detailed Implementation

[0053] The technical solutions of the present invention will now be described with reference to the accompanying drawings in the embodiments of the present invention.

[0054] It should be noted that in the description of this invention, the terms "first," "second," etc., are used only for distinguishing descriptions and should not be construed as indicating or implying relative importance. Furthermore, the step numbers in the text are only for the convenience of explaining the embodiments of this invention and are not intended to limit the order in which the steps are executed. The method provided in the embodiments of this invention can be executed by relevant terminal devices, and the following description uses a processor as the execution subject.

[0055] Please refer to Figure 1 , Figure 1 This is a flowchart illustrating a polygonal workpiece positioning method according to a first embodiment of the present invention. The first embodiment of the present invention provides a polygonal workpiece positioning method, including steps S101 to S104:

[0056] S101. Use template matching algorithm to locate the reference workpiece and the workpiece to be inspected in the workpiece image, and obtain the positioning position of the reference workpiece and the initial positioning position of the workpiece to be inspected.

[0057] S102. Based on the positioning position of the reference workpiece and the initial positioning position of the workpiece to be inspected, the position of the reference region of interest image of each side of the reference workpiece is corrected to obtain the corresponding reference region of interest image of each side of the workpiece to be inspected.

[0058] S103. A line detection algorithm is used to perform line detection on the reference region of interest image of each side of the workpiece to be inspected, so as to obtain the positioning position of each side of the workpiece to be inspected.

[0059] S104. By combining the positioning positions of each edge of the workpiece to be inspected, the secondary positioning position of the workpiece to be inspected is obtained.

[0060] As an example, an image acquisition device is used to photograph all polygonal workpieces on the production line to obtain workpiece images. One polygonal workpiece is selected from the workpiece images as a reference workpiece, and the remaining polygonal workpieces are used as workpieces to be inspected. For example, any polygonal workpiece with a preset scale and angle, such as 0°, can be selected as the reference workpiece. A template matching algorithm is used to locate the reference workpiece, obtaining its initial position. Similarly, a template matching algorithm is used to locate any workpiece to be inspected, obtaining its initial position.

[0061] The process involves acquiring reference regions of interest (ROI) images of each edge of the reference workpiece, created by the user on the workpiece image, and determining their positioning positions. Based on the positioning positions of the reference workpiece and the initial positioning position of the workpiece to be inspected, the positioning positions of the reference ROI images of each edge of the reference workpiece are corrected, thus obtaining the corresponding positioning positions of the reference ROI images of each edge of the workpiece to be inspected. Finally, based on the positioning positions of the reference ROI images of each edge of the workpiece to be inspected, the corresponding reference ROI images of each edge of the workpiece to be inspected are extracted from the workpiece image.

[0062] A line detection algorithm is used to detect lines in the reference region of interest image of each edge of the workpiece to be inspected, so as to obtain the positioning position of each edge of the workpiece.

[0063] The line detection algorithm operates on the reference region of interest image of each edge of the workpiece to be inspected, which is extracted from the workpiece image. Compared with the template matching algorithm, it not only does not require feature extraction of the template image, but is also more sensitive to scale and angle changes, and can achieve a high target positioning accuracy.

[0064] After obtaining the positioning positions of each edge of the workpiece to be inspected, the workpiece as a whole is positioned in combination with the positioning positions of each edge of the workpiece to be inspected to obtain the secondary positioning position of the workpiece to be inspected.

[0065] This invention improves the positioning accuracy of polygonal workpieces by using a template matching algorithm to locate polygonal workpieces in a workpiece image for the first time, using a line detection algorithm to locate each edge of the polygonal workpiece, and combining the positioning positions of each edge of the polygonal workpiece for the second time.

[0066] In an optional embodiment, before using a template matching algorithm to locate the reference workpiece and the workpiece to be inspected in the workpiece image to obtain the positioning position of the reference workpiece and the initial positioning position of the workpiece to be inspected, the method further includes: acquiring an original workpiece image and performing image preprocessing on the original workpiece image to obtain a workpiece image; wherein, the image preprocessing includes image grayscale conversion.

[0067] As an example, an image acquisition device is used to photograph all polygonal workpieces on the production line to obtain original workpiece images. In order to quickly and accurately extract target features from the images for template matching in the future, image preprocessing such as image grayscale conversion is performed on the original workpiece images to obtain workpiece images.

[0068] The embodiments of the present invention obtain a workpiece image by first performing image preprocessing on the original workpiece image, and then using a template matching algorithm to locate the polygonal workpiece in the workpiece image in one step, which can ensure that the positioning position of the polygonal workpiece is obtained quickly and accurately in the subsequent process.

[0069] In an optional embodiment, the step of using a template matching algorithm to locate the reference workpiece and the workpiece to be inspected in the workpiece image to obtain the location position of the reference workpiece and the initial location position of the workpiece to be inspected specifically includes: creating a reference workpiece area image; extracting the feature information of the reference workpiece from the reference workpiece area image to obtain a template feature information file; using a template matching algorithm to locate the reference workpiece according to the template feature information file to obtain the location position of the reference workpiece; and using a template matching algorithm to locate the workpiece to be inspected according to the template feature information file to obtain the initial location position of the workpiece to be inspected.

[0070] As an example, a user can select a polygonal workpiece in a workpiece image and initiate a request to create a polygonal workpiece area image.

[0071] When a request to create a polygonal workpiece region image is received from a user for a reference workpiece, the system responds by cropping the reference workpiece selected by the user from the workpiece image to obtain the reference workpiece region image.

[0072] Feature information of the reference workpiece, such as its grayscale value, is extracted from the image of the reference workpiece region. All feature information of the reference workpiece is stored in a template feature information file. A template matching algorithm is then used to locate the reference workpiece based on the template feature information file, thus obtaining the workpiece's position.

[0073] When positioning the workpiece to be inspected, it is determined whether a template feature information file has been created. If no template feature information file exists, a template is created to generate the template feature information file. If a template feature information file exists, a template matching algorithm is used to position the workpiece to be inspected according to the template feature information file to obtain the initial positioning position of the workpiece to be inspected.

[0074] The template matching algorithm works by sliding and cropping multiple test images from the workpiece image. Based on all feature information in each test image and all feature information of the polygonal workpiece in the template feature information file, the similarity between each test image and the given polygonal workpiece region image, i.e., the template image, is calculated. The polygonal workpiece is located based on the test image with the highest similarity to the template image.

[0075] This invention extracts all feature information of the polygonal workpiece from the created polygonal workpiece area image to obtain a template feature information file. Then, it uses a template matching algorithm to locate the polygonal workpiece once based on the template feature information file, which can quickly and accurately extract all feature information of the polygonal workpiece for one-time positioning.

[0076] In an optional embodiment, the step of correcting the position of the reference region of interest (ROI) images of each edge of the reference workpiece based on the positioning position of the reference workpiece and the initial positioning position of the workpiece to be inspected, to obtain the corresponding ROI images of each edge of the workpiece to be inspected, specifically includes: traversing each edge of the reference workpiece on the workpiece image, creating a ROI image of the current edge of the reference workpiece, and obtaining the positioning position of the ROI image of the current edge of the reference workpiece; correcting the positioning position of the ROI image of the current edge of the reference workpiece based on the positioning position of the reference workpiece and the initial positioning position of the workpiece to be inspected, to obtain the positioning position of the ROI image of the corresponding edge of the workpiece to be inspected; and obtaining the ROI image of the corresponding edge of the workpiece to be inspected based on the positioning position of the ROI image of the corresponding edge of the workpiece to be inspected.

[0077] As an example, after obtaining the location of the reference workpiece, the user can determine the approximate area of ​​the reference workpiece on the workpiece image, traverse each edge of the reference workpiece, select the current edge of the reference workpiece on the workpiece image, and initiate a request to create a reference region of interest image.

[0078] When a user requests the creation of a reference region of interest image for the current edge of a reference workpiece, the system responds to the request by cropping the current edge of the reference workpiece selected by the user in the workpiece image, obtaining the reference region of interest image of the current edge of the reference workpiece, and acquiring the positioning position of the reference region of interest image of the current edge of the reference workpiece.

[0079] By combining the positioning positions of the reference workpiece and the initial positioning positions of the workpiece to be inspected, the positioning position of the reference region of interest (ROI) image of the current edge of the reference workpiece is corrected, thus obtaining the positioning position of the ROI image of the corresponding edge of the workpiece to be inspected. Based on the positioning positions of the ROI images of the corresponding edges of the workpiece to be inspected, the ROI images of the corresponding edges of the workpiece to be inspected are extracted from the workpiece image. After the user has traversed each edge of the reference workpiece, the ROI images of each edge of the workpiece to be inspected are obtained.

[0080] This invention, through its embodiments, corrects the positioning positions of the reference region of interest (ROI) images of each edge of the reference workpiece based on the positioning position of the reference workpiece and the initial positioning position of the workpiece to be inspected, thereby obtaining the ROI images of each edge of the workpiece to be inspected quickly and accurately.

[0081] In an optional embodiment, the positioning position of the reference workpiece is (x, y, r); where x is the image x-coordinate of the center point of the reference workpiece; y is the image y-coordinate of the center point of the reference workpiece; and r is the image rotation angle of the reference workpiece. The initial positioning position of the workpiece to be inspected is (x1, y1, r1); where x1 is the image x-coordinate of the center point of the workpiece to be inspected; y1 is the image y-coordinate of the center point of the workpiece to be inspected; and r1 is the image rotation angle of the workpiece to be inspected. The positioning position of the reference region of interest image of the current side of the reference workpiece is (roix, roiy, roiw, roih, roir); where roix is ​​the image x-coordinate of the center point of the reference region of interest image of the current side of the reference workpiece; roiy is the image y-coordinate of the center point of the reference region of interest image of the current side of the reference workpiece; and roiw is the image rotation angle of the reference workpiece. The image width of the reference region of interest (ROI) image of the current side of the workpiece; roih is the image height of the reference ROI image of the current side of the workpiece; roir is the rotation angle of the reference ROI image of the current side of the workpiece; the positioning position of the reference ROI image of the corresponding side of the workpiece to be inspected is (roix1, roiy1, roiw, roih, roir1); where roix1 is the image x-coordinate of the center point of the reference ROI image of the corresponding side of the workpiece to be inspected, roix1 = roix + (x1 - x); roiy1 is the image y-coordinate of the center point of the reference ROI image of the corresponding side of the workpiece to be inspected, roiy1 = roiy + (y1 - y); roir1 is the image rotation angle of the reference ROI image of the corresponding side of the workpiece to be inspected, roir1 = roir + (r1 - r).

[0082] As an example, suppose the acquired workpiece image is as follows: Figure 2 As shown, we get:

[0083] The reference workpiece's positioning position is (x, y, r);

[0084] Where x is the x-coordinate of the center point of the reference workpiece in the image; y is the y-coordinate of the center point of the reference workpiece in the image; and r is the rotation angle of the reference workpiece image.

[0085] The initial positioning position of the workpiece to be inspected is (x1, y1, r1); where x1 is the image x-coordinate of the center point of the workpiece to be inspected; y1 is the image y-coordinate of the center point of the workpiece to be inspected; and r1 is the image rotation angle of the workpiece to be inspected.

[0086] The location of the reference region of interest image of the current edge of the workpiece is (roix, roiy, roiw, roih, roir);

[0087] Wherein, roix is ​​the image x-coordinate of the center point of the reference region of interest image of the current edge of the workpiece; roiy is the image y-coordinate of the center point of the reference region of interest image of the current edge of the workpiece; roiw is the image width of the reference region of interest image of the current edge of the workpiece; roih is the image height of the reference region of interest image of the current edge of the workpiece; and roir is the image rotation angle of the reference region of interest image of the current edge of the workpiece.

[0088] After obtaining the positioning positions (x, y, r) of the reference workpiece and the initial positioning positions (x1, y1, r1) of the workpiece to be inspected, the positioning positions (roix, roiy, roiw, roih, roir) of the reference region of interest image of the current side of the reference workpiece are corrected according to the positioning positions (x, y, r) of the reference workpiece and the initial positioning positions (x1, y1, r1) of the workpiece to be inspected, so as to obtain the positioning positions (roix1, roiy1, roiw, roih, roir1) of the reference region of interest image of the corresponding side of the workpiece to be inspected. The position correction process is as follows:

[0089] Image coordinate correction includes:

[0090] roix1 = roix + (x1 - x)(1);

[0091] roiy1=roiy+(y1-y)(2);

[0092] Line angle correction includes:

[0093] roir1=roir+(r1-r)(3).

[0094] Rotate (roix1, roiy1) clockwise by (r1-r)° around (x1, y1) to obtain the image coordinates of the center point of the reference region of interest image of the corresponding side of the workpiece to be inspected.

[0095] This invention, through its embodiments, corrects the positioning positions of the reference region of interest (ROI) images of each edge of the reference workpiece based on the positioning position of the reference workpiece and the initial positioning position of the workpiece to be inspected, thereby obtaining the ROI images of each edge of the workpiece to be inspected quickly and accurately.

[0096] In an optional embodiment, the method of using a line detection algorithm to perform line detection on the reference region of interest image of each edge of the workpiece to obtain the positioning position of each edge of the workpiece specifically includes: using a one-dimensional edge detection algorithm to perform edge sampling on the reference region of interest image of each edge of the workpiece to obtain all edge points of each edge of the workpiece to be inspected; and performing line fitting based on all edge points of each edge of the workpiece to obtain the positioning position of each edge of the workpiece to be inspected.

[0097] As an example, a one-dimensional edge detection algorithm is an image processing algorithm. Using a one-dimensional edge detection algorithm, edge sampling is performed on the reference region of interest image for each edge of the workpiece to be inspected, obtaining all edge points for each edge of the workpiece.

[0098] After obtaining all edge points of each side of the workpiece to be inspected, straight line fitting is performed based on all edge points of each side of the workpiece to be inspected to obtain the positioning position of each side of the workpiece to be inspected, thereby realizing the detection of each edge line of the workpiece to be inspected.

[0099] This invention employs a one-dimensional edge detection algorithm to extract all edge points of each edge of the workpiece to be inspected. Based on all edge points of each edge of the workpiece to be inspected, a straight line is fitted to locate each edge of the workpiece. This enables the quick and accurate acquisition of the positioning position of each edge of the workpiece to be inspected, further improving the positioning accuracy of polygonal workpieces.

[0100] In an optional embodiment, obtaining the secondary positioning position of the workpiece by combining the positioning positions of each edge of the workpiece to be inspected specifically includes: determining the position of each vertex and the position of the center point of the workpiece to be inspected by combining the positioning positions of each edge of the workpiece to be inspected; and obtaining the secondary positioning position of the workpiece to be inspected based on the position of each vertex and the position of the center point of the workpiece to be inspected.

[0101] As an example, based on the geometric relationships of the edges of the polygon and the positioning positions of the edges of the workpiece to be inspected, the positions of each vertex and the center point of the workpiece to be inspected are calculated. Based on the positions of each vertex and the center point of the workpiece to be inspected, the entire workpiece is positioned to obtain its secondary positioning position.

[0102] For example, assuming the workpiece to be inspected is a rectangular workpiece, after obtaining the positioning positions of the top, bottom, left, and right sides of the workpiece, firstly, based on the positioning positions of the top, bottom, left, and right sides of the workpiece, find the intersection points of the pairs of straight lines to calculate the positions of the top left, bottom left, top right, and bottom right vertices of the workpiece. Next, based on the positions of the top left, bottom left, top right, and bottom right vertices of the workpiece, connect the top left vertex and the bottom right vertex, and connect the bottom left vertex and the top right vertex, find the intersection points of the two lines obtained, and calculate the position of the center point of the workpiece. Finally, based on the positions of the four vertices and the position of the center point of the workpiece, the workpiece is positioned as a whole to obtain the secondary positioning position of the workpiece.

[0103] This invention provides a method for secondary positioning of a polygonal workpiece by using the geometric relationships of each side of the polygon and the positioning positions of each side of the polygonal workpiece. This method enables the polygonal workpiece to be positioned quickly and accurately, thereby improving the positioning accuracy of the polygonal workpiece.

[0104] As an example, to more clearly illustrate the polygonal workpiece positioning method provided in the first embodiment of the present invention, the polygonal workpiece positioning method is applied to locate a polygonal workpiece in a workpiece image. The data flow diagram of the polygonal workpiece positioning method is as follows: Figure 3 As shown.

[0105] Please refer to Figure 4 , Figure 4 This is a flowchart illustrating a polygonal workpiece positioning device according to a second embodiment of the present invention. The second embodiment of the present invention provides a polygonal workpiece positioning device, comprising: a template matching module 201, used to locate a reference workpiece and a workpiece to be inspected in a workpiece image using a template matching algorithm, to obtain the positioning position of the reference workpiece and the initial positioning position of the workpiece to be inspected; a position correction module 202, used to correct the position of the reference region of interest (ROI) image of each side of the reference workpiece according to the positioning position of the reference workpiece and the initial positioning position of the workpiece to be inspected, to obtain the corresponding ROI image of each side of the workpiece to be inspected; a line detection module 203, used to perform line detection on the ROI image of each side of the workpiece to be inspected using a line detection algorithm, to obtain the positioning position of each side of the workpiece to be inspected; and a workpiece positioning module 204, used to combine the positioning positions of each side of the workpiece to be inspected to obtain the secondary positioning position of the workpiece to be inspected.

[0106] In an optional embodiment, the template matching module 201 is further configured to acquire an original workpiece image and perform image preprocessing on the original workpiece image to obtain a workpiece image before the template matching algorithm is used to locate the reference workpiece and the workpiece to be inspected in the workpiece image to obtain the positioning position of the reference workpiece and the initial positioning position of the workpiece to be inspected; wherein, the image preprocessing includes image grayscale conversion.

[0107] In an optional embodiment, the step of using a template matching algorithm to locate the reference workpiece and the workpiece to be inspected in the workpiece image to obtain the location position of the reference workpiece and the initial location position of the workpiece to be inspected specifically includes: creating a reference workpiece area image; extracting the feature information of the reference workpiece from the reference workpiece area image to obtain a template feature information file; using a template matching algorithm to locate the reference workpiece according to the template feature information file to obtain the location position of the reference workpiece; and using a template matching algorithm to locate the workpiece to be inspected according to the template feature information file to obtain the initial location position of the workpiece to be inspected.

[0108] In an optional embodiment, the step of correcting the position of the reference region of interest (ROI) images of each edge of the reference workpiece based on the positioning position of the reference workpiece and the initial positioning position of the workpiece to be inspected, to obtain the corresponding ROI images of each edge of the workpiece to be inspected, specifically includes: traversing each edge of the reference workpiece on the workpiece image, creating a ROI image of the current edge of the reference workpiece, and obtaining the positioning position of the ROI image of the current edge of the reference workpiece; correcting the positioning position of the ROI image of the current edge of the reference workpiece based on the positioning position of the reference workpiece and the initial positioning position of the workpiece to be inspected, to obtain the positioning position of the ROI image of the corresponding edge of the workpiece to be inspected; and obtaining the ROI image of the corresponding edge of the workpiece to be inspected based on the positioning position of the ROI image of the corresponding edge of the workpiece to be inspected.

[0109] In an optional embodiment, the positioning position of the reference workpiece is (x, y, r); where x is the image x-coordinate of the center point of the reference workpiece; y is the image y-coordinate of the center point of the reference workpiece; and r is the image rotation angle of the reference workpiece. The initial positioning position of the workpiece to be inspected is (x1, y1, r1); where x1 is the image x-coordinate of the center point of the workpiece to be inspected; and y1 is the image y-coordinate of the center point of the workpiece to be inspected. 1 The image y-coordinate of the center point of the workpiece to be inspected; r 1 The rotation angle of the image of the workpiece to be inspected is given by (roix, roiy, roiw, roih, roir). The positioning position of the reference region of interest (ROI) image of the current side of the workpiece is (roix, roiy, roiw, roih, roir). Here, roix is ​​the x-coordinate of the center point of the reference ROI image of the current side of the workpiece; roiy is the y-coordinate of the center point of the reference ROI image of the current side of the workpiece; roiw is the width of the reference ROI image of the current side of the workpiece; roih is the height of the reference ROI image of the current side of the workpiece; and roir is the rotation angle of the reference ROI image of the current side of the workpiece. The rotation angle; the positioning position of the reference region of interest image of the corresponding side of the workpiece to be inspected is (roix1, roiy1, roiw, roih, roir1); where roix1 is the image x-coordinate of the center point of the reference region of interest image of the corresponding side of the workpiece to be inspected, roix1 = roix + (x1 - x); roiy1 is the image y-coordinate of the center point of the reference region of interest image of the corresponding side of the workpiece to be inspected, roiy1 = roiy + (y1 - y); roir1 is the rotation angle of the reference region of interest image of the corresponding side of the workpiece to be inspected, roir1 = roir + (r1 - r).

[0110] In an optional embodiment, the method of using a line detection algorithm to perform line detection on the reference region of interest image of each edge of the workpiece to obtain the positioning position of each edge of the workpiece specifically includes: using a one-dimensional edge detection algorithm to perform edge sampling on the reference region of interest image of each edge of the workpiece to obtain all edge points of each edge of the workpiece to be inspected; and performing line fitting based on all edge points of each edge of the workpiece to obtain the positioning position of each edge of the workpiece to be inspected.

[0111] In an optional embodiment, obtaining the secondary positioning position of the workpiece by combining the positioning positions of each edge of the workpiece to be inspected specifically includes: determining the position of each vertex and the position of the center point of the workpiece to be inspected by combining the positioning positions of each edge of the workpiece to be inspected; and obtaining the secondary positioning position of the workpiece to be inspected based on the position of each vertex and the position of the center point of the workpiece to be inspected.

[0112] The specific implementation process of the functions and roles of each module in the above device can be found in the implementation process of the corresponding steps in the above method, and will not be repeated here.

[0113] Please refer to Figure 5 , Figure 5 This is a schematic diagram of the structure of an electronic device provided in the third embodiment of the present invention. The third embodiment of the present invention provides an electronic device 30, including a processor 301, a memory 302, and a computer program stored in the memory 302 and configured to be executed by the processor 301; the memory 302 is coupled to the processor 301, and when the processor 301 executes the computer program, it implements the polygonal workpiece positioning method as described in the first embodiment of the present invention, and can achieve the same beneficial effects.

[0114] When the processor 301 reads the computer program from the memory 302 via the bus 303 and executes the computer program, it can implement any of the methods included in the polygonal workpiece positioning method described in the first embodiment of the present invention.

[0115] Processor 301 can process digital signals and may include various computing architectures. For example, it may be a complex instruction set computer architecture, a reduced instruction set computer architecture, or an architecture that implements multiple instruction set combinations. In some examples, processor 301 may be a microprocessor.

[0116] The memory 302 can be used to store instructions executed by the processor 301 or data related to the execution of instructions. These instructions and / or data may include code for implementing some or all of the functions of one or more modules described in the embodiments of the present invention. The processor 301 of this disclosure embodiment can be used to execute instructions in the memory 302 to implement the polygonal workpiece positioning method as described in the first embodiment of the present invention. The memory 302 includes dynamic random access memory, static random access memory, flash memory, optical memory, or other memories well known to those skilled in the art.

[0117] The fourth embodiment of the present invention provides a computer-readable storage medium, which includes a stored computer program; wherein, when the computer program is running, it controls the device where the computer-readable storage medium is located to execute the polygonal workpiece positioning method as described in the first embodiment of the present invention, and can achieve the same beneficial effects.

[0118] In summary, embodiments of the present invention provide a method, apparatus, device, and storage medium for locating polygonal workpieces. The polygonal workpiece positioning method includes: using a template matching algorithm to locate a reference workpiece and a workpiece to be inspected in a workpiece image, obtaining the positioning position of the reference workpiece and the initial positioning position of the workpiece to be inspected; based on the positioning positions of the reference workpiece and the initial positioning positions of the workpiece to be inspected, performing position correction on the reference region of interest images of each side of the reference workpiece, correspondingly obtaining the reference region of interest images of each side of the workpiece to be inspected; using a line detection algorithm to perform line detection on the reference region of interest images of each side of the workpiece to be inspected, obtaining the positioning positions of each side of the workpiece to be inspected; and combining the positioning positions of each side of the workpiece to be inspected, obtaining the secondary positioning position of the workpiece to be inspected. Embodiments of the present invention improve the positioning accuracy of polygonal workpieces by using a template matching algorithm to locate the polygonal workpiece in a workpiece image once, using a line detection algorithm to locate each side of the polygonal workpiece, and combining the positioning positions of each side of the polygonal workpiece for secondary positioning.

[0119] In the several embodiments provided by this invention, it should be understood that the disclosed apparatus and methods can also be implemented in other ways. The apparatus embodiments described above are merely illustrative; for example, the flowcharts and block diagrams in the accompanying drawings illustrate the architecture, functionality, and operation of possible implementations of apparatus, methods, and computer program products according to various embodiments of the present invention. In this regard, each block in a flowchart or block diagram may represent a module, segment, or portion of code containing one or more executable instructions for implementing a specified logical function. It should also be noted that in some alternative implementations, the functions marked in the blocks may occur in a different order than those marked in the drawings. For example, two consecutive blocks may actually be executed substantially in parallel, and they may sometimes be executed in reverse order, depending on the functions involved. It should also be noted that each block in a block diagram and / or flowchart, and combinations of blocks in block diagrams and / or flowcharts, can be implemented using a dedicated hardware-based system that performs the specified function or action, or using a combination of dedicated hardware and computer instructions.

[0120] In addition, the functional modules in the various embodiments of the present invention 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.

[0121] If the aforementioned functions are implemented as software functional modules and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of this invention, essentially, or the part that contributes to the prior art, or a portion of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of this invention. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.

[0122] The above description is merely a specific embodiment of the present invention, but the scope of protection of the present invention is not limited thereto. Any variations or substitutions that can be easily conceived by those skilled in the art within the technical scope disclosed in the present invention should be included within the scope of protection of the present invention. Therefore, the scope of protection of the present invention should be determined by the scope of the claims.

Claims

1. A method of positioning a polygonal workpiece, characterized by, The method comprises the following steps: Positioning the reference workpiece and the workpiece to be detected in the workpiece image by using a template matching algorithm to obtain the positioning position of the reference workpiece and the initial positioning position of the workpiece to be detected; wherein the workpiece image is obtained by using an image acquisition device to shoot all polygonal workpieces on a production line; According to the positioning position of the reference workpiece and the initial positioning position of the workpiece to be detected, the reference interest region image of each edge of the reference workpiece is positionally corrected to correspondingly obtain the reference interest region image of each edge of the workpiece to be detected; The method according to the positioning position of the reference workpiece and the initial positioning position of the workpiece to be detected, the reference interest region image of each edge of the reference workpiece is positionally corrected to correspondingly obtain the reference interest region image of each edge of the workpiece to be detected, specifically comprises: Traverse each edge of the reference workpiece on the workpiece image to create the reference interest region image of the current edge of the reference workpiece and obtain the positioning position of the reference interest region image of the current edge of the reference workpiece; Combine the positioning position of the reference workpiece and the initial positioning position of the workpiece to be detected to correct the positioning position of the reference interest region image of the current edge of the reference workpiece to obtain the positioning position of the reference interest region image of the corresponding edge of the workpiece to be detected; According to the positioning position of the reference interest region image of the corresponding edge of the workpiece to be detected, obtain the reference interest region image of the corresponding edge of the workpiece to be detected; Detect the straight line of the reference interest region image of each edge of the workpiece to be detected by using a straight line detection algorithm to obtain the positioning position of each edge of the workpiece to be detected; Combine the positioning position of each edge of the workpiece to be detected to obtain the secondary positioning position of the workpiece to be detected.

2. The polygonal workpiece positioning method of claim 1, wherein, Before the step of positioning the reference workpiece and the workpiece to be detected in the workpiece image by using a template matching algorithm to obtain the positioning position of the reference workpiece and the initial positioning position of the workpiece to be detected, the method further comprises the following steps: Obtain an original workpiece image, perform image preprocessing on the original workpiece image to obtain the workpiece image; wherein the image preprocessing comprises image graying.

3. The polygonal workpiece positioning method of claim 1, wherein, The step of positioning the reference workpiece and the workpiece to be detected in the workpiece image by using a template matching algorithm to obtain the positioning position of the reference workpiece and the initial positioning position of the workpiece to be detected, specifically comprises: Create a reference workpiece region image, extract the feature information of the reference workpiece from the reference workpiece region image to obtain a template feature information file; Position the reference workpiece according to the template feature information file by using a template matching algorithm to obtain the positioning position of the reference workpiece; Position the workpiece to be detected according to the template feature information file by using a template matching algorithm to obtain the initial positioning position of the workpiece to be detected.

4. The polygonal workpiece positioning method of claim 1, wherein, The positioning position of the reference workpiece is ; wherein, is an image x coordinate of a center point of the reference workpiece; is an image y coordinate of a center point of the reference workpiece; is an image rotation angle of the reference workpiece; The initial positioning position of the workpiece to be inspected is ; wherein, is an image x coordinate of a center point of the workpiece under inspection; is an image y coordinate of a center point of the workpiece under inspection; is an image rotation angle of the workpiece under inspection; The positioning position of the reference region of interest image of the current edge of the reference workpiece is ; wherein, is an image x-coordinate of a center point of a reference region of interest image of the current edge of the workpiece; is an image y-coordinate of a center point of a reference region of interest image of the current edge of the workpiece; is an image width of a reference region of interest image of the current edge of the workpiece; is an image height of a reference region of interest of the current edge of the workpiece; is an image rotation angle of a reference region of interest of the current edge of the workpiece; The positioning position of the reference region of interest image corresponding to the edge of the workpiece to be inspected is ; wherein, is an image x-coordinate of a center point of a reference region of interest image of the corresponding edge of the workpiece to be inspected, ; is an image y-coordinate of a center point of a reference region of interest image of the corresponding edge of the workpiece to be inspected, ; is an image rotation angle of a reference region of interest of the corresponding edge of the workpiece to be inspected, .

5. The polygonal workpiece positioning method of claim 1, wherein, The step of detecting the straight line of the reference interest region image of each edge of the workpiece to be detected by using a straight line detection algorithm to obtain the positioning position of each edge of the workpiece to be detected, specifically comprises: Use a one-dimensional edge detection algorithm to sample the edge of the reference interest region image of each edge of the workpiece to be detected to correspondingly obtain all edge points of each edge of the workpiece to be detected; Respectively according to all edge points of each edge of the to-be-inspected workpiece, straight line fitting is performed to obtain the positioning position of each edge of the to-be-inspected workpiece.

6. The polygonal workpiece positioning method of claim 1, wherein, The positioning position of each edge of the to-be-inspected workpiece is combined to obtain the secondary positioning position of the to-be-inspected workpiece, and specifically includes: The positioning position of each edge of the to-be-inspected workpiece is combined to determine the position of each vertex and the position of the center point of the to-be-inspected workpiece; According to the position of each vertex and the position of the center point of the to-be-inspected workpiece, the secondary positioning position of the to-be-inspected workpiece is obtained.

7. A polygonal workpiece positioning device, characterized by, It includes: The template matching module is used to adopt a template matching algorithm to position the reference workpiece and the to-be-inspected workpiece in the workpiece image to obtain the positioning position of the reference workpiece and the initial positioning position of the to-be-inspected workpiece; wherein the workpiece image is obtained by using an image acquisition device to shoot all polygonal workpieces on a production line; The position correction module is used to correct the position of the reference workpiece according to the positioning position of the reference workpiece and the initial positioning position of the to-be-inspected workpiece, and to obtain the reference region of interest image of each edge of the to-be-inspected workpiece; The reference workpiece is combined with the positioning position of the reference workpiece and the initial positioning position of the to-be-inspected workpiece to correct the positioning position of the reference region of interest image of the current edge of the reference workpiece to obtain the positioning position of the reference region of interest image of the corresponding edge of the to-be-inspected workpiece; The positioning position of the reference workpiece is combined with the positioning position of the reference workpiece and the initial positioning position of the to-be-inspected workpiece to correct the positioning position of the reference region of interest image of the current edge of the reference workpiece to obtain the positioning position of the reference region of interest image of the corresponding edge of the to-be-inspected workpiece; According to the positioning position of the reference region of interest image of the corresponding edge of the to-be-inspected workpiece, the reference region of interest image of the corresponding edge of the to-be-inspected workpiece is obtained. The straight line detection module is used to adopt a straight line detection algorithm to detect the reference region of interest image of each edge of the to-be-inspected workpiece to obtain the positioning position of each edge of the to-be-inspected workpiece; The workpiece positioning module is used to combine the positioning position of each edge of the to-be-inspected workpiece to obtain the secondary positioning position of the to-be-inspected workpiece. The computer readable storage medium includes a stored computer program; wherein when the computer program runs, the device where the computer readable storage medium is located executes the polygonal workpiece positioning method according to any one of claims 1 to 6.

8. An electronic device, comprising: The computer readable storage medium includes a stored computer program; wherein when the computer program runs, the device where the computer readable storage medium is located executes the polygonal workpiece positioning method according to any one of claims 1 to 6.

9. A computer-readable storage medium, characterized in that, ​

Citation Information

Patent Citations

  • Visual positioning method and system in complex environment

    CN115937318A