Industrial detection method and device
By determining the reference line segment based on the initial contour point in the target detection application, updating the contour point and reference line segment, the problem of low detection efficiency in the prior art is solved, and a more efficient detection process is achieved.
Patent Information
- Application Number
- CN202411791412.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-06
- Publication Date
- 2025-04-22
AI Technical Summary
In the prior art, in object detection applications, a large amount of labeled data is required for training, and the performance of the model is affected by the quality and quantity of training data, and the calculation complexity is high, resulting in low detection efficiency.
By determining the reference line segment based on the initial contour point, updating the contour point and reference line segment, reducing the number of contour points, thereby improving detection efficiency.
The number of contour points concentrated in the initial contour point is effectively reduced, the detection efficiency is improved, the calculation amount is reduced, and the detection needs are met.
Smart Images

Figure CN119863604A_ABST
Abstract
Description
Technical Field
[0001] The present application belongs to the field of industrial detection technology, and in particular, relates to an industrial detection method and device. Background Art
[0002] In target detection applications, the contour points of a graphic are usually extracted, located at the contour position, and then other operations are performed according to application requirements. In some project detection applications, to perform shape analysis on a contour, it is only necessary to extract the key extraction points of the graphic, and there is no need to analyze all the contour points. This can improve processing efficiency while meeting detection requirements. In the related art, there is a method of learning contour key points by training a large amount of image data through a deep learning model, but this method requires a large amount of labeled data for training, and the performance of the model is affected by the quality and quantity of the training data. The computational complexity is high and more computing resources are required, which is not conducive to subsequent contour detection and coarse positioning of the object to be tested, and the detection efficiency is low. Summary of the invention
[0003] The present application aims to solve at least one of the technical problems existing in the related art. To this end, the present application proposes an industrial detection method and device, which effectively reduces the number of contour points in the initial contour point set, so that industrial detection and rough positioning can be performed based on the target contour, which not only meets the detection requirements but also improves the detection efficiency and reduces the amount of calculation in the detection process.
[0004] In a first aspect, the present application provides an industrial detection method, the method comprising:
[0005] Determine a reference line segment based on two target contour points in an initial contour point set; the initial contour point set is obtained by extracting the initial contour of the target object to be measured in the first image, and the two target contour points are contour points with the largest distance in the initial contour point set;
[0006] Determine a maximum distance from the distances between each contour point between the two target contour points and the reference line segment, and a first contour point corresponding to the maximum distance;
[0007] In the case where the maximum distance is greater than a first threshold, updating any target contour point of the two target contour points based on the first contour point, and updating the reference line segment based on the current two target contour points;
[0008] In a case where the maximum distance is not greater than the first threshold, determining the two target contour points as extraction points on the initial contour corresponding to the two target contour points;
[0009] Based on each of the extraction points, a target contour corresponding to the target object to be measured is obtained; the target contour is used to perform industrial inspection on the target object to be measured.
[0010] According to the industrial detection method provided by the embodiment of the present application, for the currently obtained baseline segment, it can be determined whether there is a more prominent first contour point among the multiple contour points corresponding to the baseline segment, and if the first contour point exists, the baseline segment is updated based on the first contour point, and it is determined again whether the baseline segment corresponds to the first contour point. If the first contour point does not exist, two target contour points are determined as extraction points corresponding to the segment contour, until multiple extraction points are obtained to obtain the target contour corresponding to the target object to be measured, thereby effectively reducing the number of contour points in the initial contour point set, so that industrial detection and coarse positioning can be performed based on the target contour, which not only meets the detection requirements but also improves the detection efficiency and reduces the amount of calculation in the detection process.
[0011] In an industrial detection method according to an embodiment of the present application, the updating of any target contour point among the two target contour points based on the first contour point, and the updating of the reference line segment based on the current two target contour points, comprises:
[0012] The first target contour point of the two target contour points is updated to the first contour point, and the reference line segment is updated to the line segment between the first contour point and the second target contour point of the two target contour points, and the line segment between the first target contour point before updating and the first contour point.
[0013] An industrial detection method according to an embodiment of the present application, obtaining the distance between each contour point between the two target contour points and the reference line segment, includes:
[0014] Acquire a first vector between the contour point and a first target contour point of the two target contour points, and a second vector between the contour point and a second target contour point of the two target contour points;
[0015] Calculate at least one of a first dot product between the first vector and a target vector corresponding to the reference line segment, a second dot product between the second vector and the target vector, a first cross product between the first vector and the target vector, and a second cross product between the second vector and the target vector;
[0016] Based on at least one of the first dot product, the second dot product, the first cross product, and the second cross product, a distance between the contour point and the reference line segment is determined.
[0017] In an industrial detection method according to an embodiment of the present application, determining the distance between the contour point and the reference line segment based on at least one of the first dot product, the second dot product, the first cross product, and the second cross product includes:
[0018] In a case where it is determined based on the first dot product and / or the second dot product that the foot of the perpendicular between the contour point and the reference line segment is not located on the reference line segment, determining the distance between the contour point and the reference line segment based on the distance between the contour point and the first target contour point or the distance between the contour point and the second target contour point;
[0019] When it is determined based on the first dot product and the second dot product that the foot of the perpendicular between the contour point and the reference line segment is located on the reference line segment, the distance between the contour point and the reference line segment is determined based on the first cross product or the second cross product.
[0020] An industrial detection method according to an embodiment of the present application, obtaining a target contour corresponding to the target object to be detected based on each of the extraction points, includes:
[0021] Obtain any three adjacent extraction points from the plurality of extraction points;
[0022] Based on the distance between the line segments corresponding to the first extraction point and the other two extraction points among the three extraction points and a second threshold, determining the positional relationship between the first extraction point and the other two extraction points; the positional relationship includes that the first extraction point and the other two extraction points are collinear, or the first extraction point and the other two extraction points are not collinear;
[0023] Based on the positional relationship, the plurality of extraction points are screened to obtain a plurality of target extraction points;
[0024] The plurality of target extraction points are connected in sequence to obtain the target contour.
[0025] The industrial detection method of an embodiment of the present application, after obtaining the target contour corresponding to the target object to be detected based on each of the extraction points, the method further includes:
[0026] Based on the target contour, obtaining position information corresponding to the target object to be measured, so as to locate the target object to be measured;
[0027] and / or,
[0028] In the case where the target contour matches a preset contour corresponding to the target object to be measured, it is determined that the target object to be measured meets industrial production requirements.
[0029] In a second aspect, the present application provides an industrial detection device, comprising:
[0030] A first processing module is used to determine a reference line segment based on two target contour points in an initial contour point set; the initial contour point set is obtained by extracting the initial contour of the target object to be measured in the first image, and the two target contour points are contour points with the largest distance in the initial contour point set;
[0031] A second processing module, configured to determine a maximum distance from the distances between each contour point between the two target contour points and the reference line segment, and a first contour point corresponding to the maximum distance;
[0032] A third processing module, configured to update any target contour point of the two target contour points based on the first contour point, and update the reference line segment based on the current two target contour points, when the maximum distance is greater than a first threshold;
[0033] A fourth processing module, configured to determine the two target contour points as extraction points on the initial contour corresponding to the two target contour points when the maximum distance is not greater than the first threshold;
[0034] The fifth processing module is used to obtain a target contour corresponding to the target object to be tested based on each of the extraction points; the target contour is used to perform industrial inspection on the target object to be tested.
[0035] According to the industrial inspection device provided by the embodiment of the present application, for the currently obtained baseline segment, it can be determined whether there is a more prominent first contour point among the multiple contour points corresponding to the baseline segment, and if the first contour point exists, the baseline segment is updated based on the first contour point, and it is determined again whether the baseline segment corresponds to the first contour point. If the first contour point does not exist, two target contour points are determined as extraction points corresponding to the segment contour, until multiple extraction points are obtained to obtain the target contour corresponding to the target object to be measured, thereby effectively reducing the number of contour points in the initial contour point set, so that industrial inspection and coarse positioning can be performed based on the target contour, which not only meets the inspection requirements but also improves the inspection efficiency and reduces the amount of calculation in the inspection process.
[0036] In a third aspect, the present application provides an electronic device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the industrial detection method as described in the first aspect above when executing the computer program.
[0037] In a fourth aspect, the present application provides a non-transitory computer-readable storage medium having a computer program stored thereon, wherein the computer program, when executed by a processor, implements the industrial detection method as described in the first aspect above.
[0038] In a fifth aspect, the present application provides a computer program product, including a computer program, which, when executed by a processor, implements the industrial detection method as described in the first aspect above.
[0039] The above one or more technical solutions in the embodiments of the present application have at least one of the following technical effects:
[0040] For the currently obtained baseline segment, it can be determined whether there is a more prominent first contour point among the multiple contour points corresponding to the baseline segment. If the first contour point exists, the baseline segment is updated based on the first contour point, and it is determined again whether the baseline segment corresponds to the first contour point. If the first contour point does not exist, the two target contour points are determined as the extraction points corresponding to the segment contour, until multiple extraction points are obtained to obtain the target contour corresponding to the target object to be measured, which effectively reduces the number of contour points in the initial contour point set, so that industrial detection and coarse positioning can be performed based on the target contour, which not only meets the detection requirements but also improves the detection efficiency and reduces the amount of calculation in the detection process.
[0041] Furthermore, by searching and judging multiple contour points corresponding to the baseline line segment, and when the distance between the contour point and the baseline line segment is greater than the approximation accuracy error (i.e., the first threshold), the baseline line segment is split into two segments, and the search and judgment operations are repeated until the distance between each contour point corresponding to the current baseline line segment and the baseline line segment is no greater than the approximation accuracy error, multiple polygon contour points are obtained to output polygon data, which is suitable for contour approximation of various complex shapes, has a wide range of applicable scenarios, and has a small amount of calculation, thereby improving processing efficiency.
[0042] Additional aspects and advantages of the present application will be given in part in the description below, and in part will become apparent from the description below, or will be learned through the practice of the present application. BRIEF DESCRIPTION OF THE DRAWINGS
[0043] The above and / or additional aspects and advantages of the present application will become apparent and easily understood from the description of the embodiments in conjunction with the following drawings, in which:
[0044] Figure 1 This is one of the flow diagrams of the industrial detection method provided in the embodiment of the present application;
[0045] Figure 2 This is one of the principle schematic diagrams of the industrial detection method provided in the embodiment of the present application;
[0046] Figure 3 This is the second flow chart of the industrial detection method provided in the embodiment of the present application;
[0047] Figure 4This is the third flow chart of the industrial detection method provided in the embodiment of the present application;
[0048] Figure 5 This is the second principle schematic diagram of the industrial detection method provided in the embodiment of the present application;
[0049] Figure 6 This is the fourth flow chart of the industrial detection method provided in the embodiment of the present application;
[0050] Figure 7 This is the third principle schematic diagram of the industrial detection method provided in the embodiment of the present application;
[0051] Figure 8 This is the fourth principle schematic diagram of the industrial detection method provided in the embodiment of the present application;
[0052] Fig. 9 It is a schematic diagram of the test results of the industrial detection method provided in the embodiment of the present application;
[0053] Fig.10 is a schematic diagram of the structure of an industrial detection device provided in an embodiment of the present application;
[0054] Fig.11 It is a schematic diagram of the structure of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0055] The following will be combined with the drawings in the embodiments of the present application to clearly describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are part of the embodiments of the present application, rather than all the embodiments. All other embodiments obtained by ordinary technicians in this field based on the embodiments in the present application belong to the scope of protection of this application.
[0056] The terms "first", "second", etc. in the specification and claims of the present application are used to distinguish similar objects, and are not used to describe a specific order or sequence. It should be understood that the data used in this way can be interchangeable under appropriate circumstances, so that the embodiments of the present application can be implemented in an order other than those illustrated or described here, and the objects distinguished by "first", "second", etc. are generally of one type, and the number of objects is not limited. For example, the first object can be one or more. In addition, "and / or" in the specification and claims represents at least one of the connected objects, and the character " / " generally indicates that the objects associated with each other are in an "or" relationship.
[0057] The industrial detection method, industrial detection device, electronic device and readable storage medium provided in the embodiments of the present application are described in detail below with reference to the accompanying drawings through specific embodiments and their application scenarios.
[0058] The industrial detection method may be applied to a terminal, and may be specifically executed by hardware or software in the terminal.
[0059] The terminal includes, but is not limited to, a portable communication device such as a mobile phone or tablet computer with a touch-sensitive surface (e.g., a touch screen display and / or a touch pad). It should also be understood that in some embodiments, the terminal may not be a portable communication device, but a desktop computer with a touch-sensitive surface (e.g., a touch screen display and / or a touch pad).
[0060] In the following various embodiments, a terminal including a display and a touch-sensitive surface is described. However, it should be understood that the terminal may include one or more other physical user interface devices such as a physical keyboard, a mouse and a joystick.
[0061] The industrial detection method provided in the embodiment of the present application may be executed by an electronic device or a functional module or functional entity in the electronic device that can implement the industrial detection method. The electronic devices mentioned in the embodiment of the present application include but are not limited to mobile phones, tablet computers, computers, cameras, and wearable devices. The industrial detection method provided in the embodiment of the present application is described below using the electronic device as an example of the execution subject.
[0062] like Figure 1 As shown, the industrial detection method includes: step 110, step 120, step 130, step 140 and step 150.
[0063] Step 110, determining a reference line segment based on two target contour points in the initial contour point set;
[0064] In this step, the initial contour point set is obtained by extracting the initial contour of the target object to be measured in the first image.
[0065] The initial contour point set includes multiple contour points, such as Figure 2 (a) Contour points 1-10 are shown.
[0066] The two target contour points are the contour points with the largest distance in the initial contour point set.
[0067] The distance between any two contour points can be obtained, and then the two contour points corresponding to the maximum distance are determined as two target contour points.
[0068] like Figure 2 As shown in (a), the line segment between contour point 1 and contour point 10 can be determined as the reference line segment.
[0069] Step 120, determining a maximum distance from the distances between each contour point and the reference line segment between two target contour points, and a first contour point corresponding to the maximum distance;
[0070] In this step, there are multiple contour points on the contour between two target contour points, and for each contour point, the distance between the contour point and the reference line segment can be calculated.
[0071] For example, the distance between the contour point and the reference line segment can be calculated using a geometric formula for the distance from a point to a straight line.
[0072] In the actual execution process, for multiple contour points between two target contour points, when calculating the distance between each contour point and the reference line segment one by one, a variable can be maintained to record the calculated maximum distance, and another variable can be maintained to record the contour point corresponding to the maximum distance.
[0073] After traversing all contour points between two target contour points and calculating the distance, a maximum distance value and the contour point corresponding to the maximum distance, that is, the first contour point, can be obtained.
[0074] like Figure 2 As shown in (a), the distance between each contour point (point 2, 3, 4, 5, 6, 7, 8 and 9) and the baseline segment can be calculated, the maximum distance (i.e., the distance between point 7 and the baseline segment) can be obtained from multiple distances, and point 7 can be determined as the first contour point.
[0075] Step 130: when the maximum distance is greater than the first threshold, update any target contour point of the two target contour points based on the first contour point, and update the reference line segment based on the current two target contour points;
[0076] In this step, an initial contour of the target object to be measured corresponds to the distance between the two target contour points, and there are multiple contour points on the initial contour.
[0077] The size of the first threshold can be determined based on actual project requirements. For example, if the project requires a higher accuracy of the extracted contour, the first threshold can be set to a smaller value, such as the first threshold can be set to 1 pixel or 2 pixels; if the project requires a lower accuracy of the extracted contour, the first threshold can be set to a larger value, such as the first threshold can be set to 4 pixels or 5 pixels, or can be set to 10 pixels or 20 pixels, etc., which is not limited in this application.
[0078] like Figure 2 As shown in (a), the distance between each contour point (point 2, 3, 4, 5, 6, 7, 8 and 9) and the baseline segment can be calculated, and the maximum distance (i.e., the distance between point 7 and the baseline segment) can be obtained from multiple distances, and then it is determined whether the maximum distance is greater than the first threshold.
[0079] When the distance between point 7 (the first contour point) and the reference line segment is greater than the first threshold, the first contour point may be considered as a more prominent contour point.
[0080] like Figure 2 As shown in (b), any of the two target contour points can be updated based on point 7, and the reference line segment can be updated based on the current two target contour points.
[0081] Step 140: when the maximum distance is not greater than the first threshold, determine the two target contour points as extraction points on the initial contour corresponding to the two target contour points;
[0082] In this step, when it is determined that the maximum distance is not greater than the first threshold, that is, the distance between each contour point between the two target contour points and the reference line segment is not greater than the first threshold, it can be determined that there is no more prominent contour point between the two target contour points, that is, the two target contour points can be directly determined as extraction points on their corresponding initial contours.
[0083] In some embodiments, after updating the baseline line segment and the two target contour points, it is possible to continue to determine whether the maximum distance between each contour point between the two updated target contour points and the updated baseline line segment is greater than a first threshold, and if the new maximum distance is greater than the first threshold, execute step 130; if the new maximum distance is not greater than the first threshold, execute step 140.
[0084] Step 150: based on each extraction point, obtain a target contour corresponding to the target object to be measured;
[0085] In this step, the extraction points may be connected in sequence to obtain a target contour corresponding to the target object to be measured. For example, the target contour may include multiple line segments, arcs, or other vector-shaped contour segments for characterizing the contour of the target object to be measured.
[0086] The inventor has tested and found that if Fig. 9 As shown, when the project requires that the accuracy of the extracted contour is higher, the first threshold can be set to 5, and the polygon shown in column (a) can be extracted based on the industrial detection method provided in the embodiment of the present application; when the project requires that the accuracy of the extracted contour is lower, the first threshold can be set to 20, and the polygon shown in column (b) can be extracted.
[0087] The target contour is used for industrial detection of the target object to be tested. For example, in an autonomous driving system, the vehicle can be identified based on the target contour; in industrial production, the product shape can be detected based on the target contour; in robot vision and navigation applications, the object can be tracked and located based on the target contour, and then the navigation path can be planned; or it can also be applied to other application scenarios, which are not limited by this application.
[0088] According to the industrial detection method provided by the embodiment of the present application, for the currently obtained baseline segment, it can be determined whether there is a more prominent first contour point among the multiple contour points corresponding to the baseline segment, and if the first contour point exists, the baseline segment is updated based on the first contour point, and it is determined again whether the baseline segment corresponds to the first contour point. If the first contour point does not exist, two target contour points are determined as extraction points corresponding to the segment contour, until multiple extraction points are obtained to obtain the target contour corresponding to the target object to be measured, thereby effectively reducing the number of contour points in the initial contour point set, so that industrial detection and coarse positioning can be performed based on the target contour, which not only meets the detection requirements but also improves the detection efficiency and reduces the amount of calculation in the detection process.
[0089] In some embodiments, after step 150, the industrial detection method may further include:
[0090] Based on the target contour, the position information corresponding to the target object to be measured is obtained to locate the target object to be measured.
[0091] In this embodiment, based on the extracted target contour, the position information of the target object to be measured can be determined to locate the target object to be measured.
[0092] It can be applied to scenarios such as video surveillance, autonomous driving or robot navigation. For example, in video surveillance, the tracking and positioning of pedestrians can be achieved by extracting the target contours of pedestrians and matching their motion trajectories; in autonomous driving systems, the target contours of vehicles on the road can be extracted to roughly position the vehicles on the road, so that the driving vehicles can better avoid obstacles on the road; in robot vision and navigation applications, objects can be tracked and positioned based on the target contours, and then a navigation path can be planned; or it can also be applied to other application scenarios, which are not limited in this application.
[0093] In some embodiments, after step 150, the industrial detection method may further include:
[0094] In the case where the target contour matches the preset contour corresponding to the target object to be measured, it is determined that the target object to be measured meets the industrial production requirements.
[0095] In this embodiment, the preset profile may be a standard model or a series of allowable profile ranges.
[0096] The preset contour is used to characterize the standard shape features of the target object to be tested, etc.
[0097] The target contour includes a plurality of line segments, arcs or other vector-shaped contour segments used to characterize the contour of the target object to be measured.
[0098] Whether the target contour matches the preset contour may be determined based on the geometric features of the target contour and the geometric features of the preset contour.
[0099] Alternatively, it may be based on manual observation of whether the target contour matches the preset contour, which is not limited in the present application.
[0100] The geometric features may include information such as the shape and size of the target contour. For example, the geometric features may include information such as the perimeter, area, and curvature of the target contour.
[0101] The detection result may be quantified as a matching degree. For example, when the matching degree is higher than a preset threshold, it is determined that the target contour matches the preset contour.
[0102] When the target contour matches the preset contour, it is determined that the target object to be measured meets the industrial production requirements, wherein the industrial production requirements may include that the workpiece meets the standard shape and meets the standard size.
[0103] In the case where the target profile does not match the preset profile, the production process can be adjusted or the equipment accuracy can be checked to ensure that the subsequently produced products meet the requirements.
[0104] In some embodiments, updating any target contour point of the two target contour points based on the first contour point, and updating the reference line segment based on the current two target contour points may include:
[0105] The first target contour point of the two target contour points is updated to the first contour point, and the reference line segment is updated to the line segment between the first contour point and the second target contour point of the two target contour points, and the line segment between the first target contour point before updating and the first contour point.
[0106] In this embodiment, the first target contour point is any one of the two target contour points, and the second target contour point is the remaining contour point of the two contour points except the first target contour point.
[0107] When it is necessary to update two target contour points based on the first contour point, the first target contour point can be updated to the first contour point, and then the reference line segment can be updated to the line segment between the first contour point and the second target contour point of the two target contour points, and the line segment between the first target contour point and the first contour point before the update.
[0108] Among them, the line segment between the first contour point and the second target contour point among the two target contour points, and the line segment between the first target contour point and the first contour point before the update can be updated as the baseline line segment at the same time, or the line segment between the first contour point and the second target contour point among the two target contour points, and the line segment between the first target contour point and the first contour point before the update can be updated as the baseline line segment in sequence, and this application does not limit this.
[0109] like Figure 2 As shown, the two target contour points include point 1 and point 10. Point 10 can be determined as the first target contour point, and point 1 can be determined as the second target contour point. Based on the distances from each point to the reference line segment, it can be determined that there is a first contour point 7 between point 1 and point 10. Then, the first target contour point can be updated to point 7, and the reference line segment can be updated to the line segment between point 1 and point 7, and the line segment between point 10 and point 7, respectively.
[0110] In the actual execution process, the line segment between point 1 and point 7 can be first determined as the baseline line segment, and then step 120 can be repeated until there is no first contour point between the current two target contour points, and then the line segment between point 10 and point 7 can be determined as the baseline line segment, and step 120 can be repeated until there is no first contour point between the current two target contour points.
[0111] In the actual implementation process, Figure 3 As shown, different processing methods can be adopted according to the type of the initial contour corresponding to the target object to be measured, and a container stack can be used to record the middle split line segments.
[0112] For example, when the initial contour is an open contour, the first and last points of the contour may be connected to form a line segment as the initial line segment, ie, the reference line segment, and then the reference line segment is saved in the stack stackSlice.
[0113] When the initial contour is a closed contour, the point farthest from the starting point can be searched. When the distance between the farthest point and the starting point is greater than the first threshold, the initial contour can be divided into two segments with the farthest point as the boundary, and the two segments are used as baseline segments respectively, and the two segments rightslice and silce are saved to the stack stackSlice in turn.
[0114] like Figure 4As shown, the line segment stack stackSlice can be traversed, and when stackSlice is not empty, the top line segment AB (reference line segment) on the stack is obtained, and the top line segment on the stack is removed from the stack column, and the point C with the largest distance from point A and point B to line segment AB is found. When the distance between point C and line segment AB is greater than a first threshold, line segment AB is split into two segments (i.e., line segment AC and line segment BC), and the two line segments are respectively stored in the stack column.
[0115] When the distance between point C and line segment AB is not greater than the first threshold, point A and point B may be saved in the polygon contour point list.
[0116] When the segment stack is empty, determine whether the initial contour is an open contour.
[0117] When the initial contour is an open contour, the last searched contour point corresponding to the initial contour is saved in the polygon contour point list, and then the obtained polygon contour points are collinearly processed. The collinear contour points in the polygon contour points can be merged and deleted, and finally the polygon data is output.
[0118] According to the industrial detection method provided in the embodiment of the present application, by searching and judging multiple contour points corresponding to the baseline line segment, and when the distance between the contour point and the baseline line segment is greater than the approximation accuracy error (i.e., the first threshold), the baseline line segment is split into two segments, and the search and judgment operations are repeated until the distance between each contour point corresponding to the current baseline line segment and the baseline line segment is no greater than the approximation accuracy error, multiple polygon contour points are obtained to output polygon data, which is suitable for contour approximation of various complex shapes, has a wide range of applicable scenarios, and has a small amount of calculation, thereby improving processing efficiency.
[0119] In some embodiments, obtaining the distance between each contour point and the reference line segment between two target contour points may include:
[0120] Acquire a first vector between the contour point and a first target contour point of the two target contour points, and a second vector between the contour point and a second target contour point of the two target contour points;
[0121] Calculating at least one of a first dot product between the first vector and a target vector corresponding to the reference line segment, a second dot product between the second vector and the target vector, a first cross product between the first vector and the target vector, and a second cross product between the second vector and the target vector;
[0122] A distance between the contour point and the reference line segment is determined based on at least one of the first dot product, the second dot product, the first cross product, and the second cross product.
[0123] In this embodiment, the two target contour points include a first target contour point and a second target contour point, and a first vector between each contour point and the first target contour point and a second vector between each contour point and the second target contour point can be provided between the two target contour points.
[0124] like Figure 5 As shown, the first vector between point P and the first target contour point A is AP, the second vector between point P and the second target contour point B is BP, and the target vector is AB.
[0125] The first dot product is the dot product (or dot product, scalar product) between the first vector and the target vector, which can be calculated based on the following formula: AP·AB=|AP||AB|cosα, where Ap·AB is the first dot product, AP is the first vector, AB is the target vector, and α is the angle between the first vector and the target vector.
[0126] The second dot product is the dot product between the second vector and the target vector, which can be calculated based on the following formula: BP·AB=|BP||AB|cosβ, where BP·AB is the second dot product, BP is the first vector, AB is the target vector, and β is the angle between the second vector and the target vector.
[0127] like Figure 7 As shown, the cross product can be calculated based on the following formula:
[0128]
[0129] in, is the cross product of two vectors, such as Figure 8 As shown, θ is the angle between vector a and vector b, and n is a unit vector perpendicular to vector a and vector b.
[0130] The first cross product is the cross product (cross product) between the first vector and the target vector, and the second cross product is the cross product between the second vector and the target vector.
[0131] like Figure 6 As shown, in some embodiments, determining the distance between the contour point and the reference line segment based on at least one of the first dot product, the second dot product, the first cross product, and the second cross product may include:
[0132] When it is determined based on the first dot product and / or the second dot product that the foot of the perpendicular between the contour point and the reference line segment is not located on the reference line segment, determining the distance between the contour point and the reference line segment based on the distance between the contour point and the first target contour point or the distance between the contour point and the second target contour point;
[0133] When it is determined based on the first dot product and the second dot product that the foot of the perpendicular between the contour point and the reference line segment is located on the reference line segment, the distance between the contour point and the reference line segment is determined based on the first cross product or the second cross product.
[0134] In this embodiment, when the first dot product is less than 0, it can be determined that the foot of the perpendicular between the contour point P and the reference line segment AB is on the extension line on one side of point A, such as Figure 5 As shown in (c), the length of line segment AP can be determined as the distance between contour point P and the reference line segment.
[0135] When the first dot product is not less than 0 and the second dot product is greater than 0, it can be determined that the foot of the perpendicular between the contour point P and the reference line segment is on the extension line on one side of point B, such as Figure 5 As shown in (b), the length of the line segment BP can be determined as the distance between the contour point P and the reference line segment.
[0136] When the first dot product is not less than 0 and the second dot product is not greater than 0, it is determined whether the reference line segment is a vertical line segment.
[0137] In the case where the reference line segment is a vertical line segment, the deviation between the x-coordinate of the contour point and the first target contour point or the second target contour point may be determined as the distance between the contour point and the reference line segment.
[0138] In the case where the reference line segment is a horizontal line segment, the deviation between the y-coordinates of the contour point and the first target contour point or the second target contour point may be determined as the distance between the contour point and the reference line segment.
[0139] When the reference line segment is neither a vertical line segment nor a horizontal line segment, the distance between the contour point and the reference line segment may be determined based on the first cross product or the second cross product.
[0140] like Figure 5 As shown in (a), PC is the distance between the contour point and the reference line segment, which can be calculated based on the following formula: PC = (AB × AP) / |AB|, where AB × AP is the first cross product between the first vector and the target vector.
[0141] In some embodiments, step 140 may include:
[0142] Get any three adjacent extraction points from multiple extraction points;
[0143] Determine the positional relationship between the first extraction point and the other two extraction points based on the distance between the line segments corresponding to the first extraction point and the other two extraction points among the three extraction points and a second threshold;
[0144] Based on the position relationship, multiple extraction points are screened to obtain multiple target extraction points;
[0145] Connect multiple target extraction points sequentially to obtain the target contour.
[0146] In this embodiment, there may be collinear extraction points among the plurality of extraction points.
[0147] The first extraction point may be any one of the multiple extraction points.
[0148] For any extraction point, the distance between it and the line segment formed by two adjacent extraction points can be calculated.
[0149] For example, the distance between any extraction point and a line segment formed by two adjacent extraction points on the left and right may be calculated, or the distance between any extraction point and a line segment formed by two extraction points on the left or two extraction points on the right may be calculated.
[0150] The positional relationship includes that the first extraction point is collinear with the other two extraction points, or the first extraction point is not collinear with the other two extraction points.
[0151] For example, when the distance between the line segments corresponding to the first extraction point and the other two extraction points is not greater than the second threshold, it can be determined that the first extraction point is on the same line as the other two extraction points.
[0152] The second threshold may be a value close to 0.
[0153] When the distance between the line segments corresponding to the first extraction point and the other two extraction points is greater than the second threshold, it can be determined that the first extraction point and the other two extraction points are not collinear.
[0154] When the first extraction point is on the same line as the other two extraction points, the first extraction point can be deleted from the multiple extraction points, and when all the extraction points are traversed, multiple target extraction points can be obtained.
[0155] By sequentially connecting multiple target extraction points, polygonal data, i.e., the target outline, can be obtained.
[0156] In the actual execution process, for example, the three extraction points are A, C, and B respectively, and the distance Dist from point C to line segment AB can be calculated, where Dist = pow (cross product of vector AC and AB) / length of AB. When Dist <= FLT_EPSILON (second threshold) and the number of multiple extraction points > 3, point C is deleted from the multiple extraction points.
[0157] The industrial detection device provided in the present application is described below. The industrial detection device described below and the industrial detection method described above can be referenced to each other.
[0158] The industrial detection method provided in the embodiment of the present application can be executed by an industrial detection device. The industrial detection device provided in the embodiment of the present application is described by taking an industrial detection device executing the industrial detection method as an example.
[0159] The embodiment of the present application also provides an industrial detection device.
[0160] like Fig.10 As shown, the industrial detection device includes: a first processing module 1010 , a second processing module 1020 , a third processing module 1030 , a fourth processing module 1040 and a fifth processing module 1050 .
[0161] The first processing module 1010 is used to determine a reference line segment based on two target contour points in an initial contour point set; the initial contour point set is obtained by extracting the initial contour of the target object to be measured in the first image, and the two target contour points are contour points with the largest distance in the initial contour point set;
[0162] A second processing module 1020 is used to determine a maximum distance from the distances between each contour point and the reference line segment between two target contour points, and a first contour point corresponding to the maximum distance;
[0163] A third processing module 1030 is configured to update any target contour point of the two target contour points based on the first contour point when the maximum distance is greater than the first threshold, and to update the reference line segment based on the current two target contour points;
[0164] A fourth processing module 1040 is used to determine the two target contour points as extraction points on the initial contour corresponding to the two target contour points when the maximum distance is not greater than the first threshold;
[0165] The fifth processing module 1050 is used to obtain a target contour corresponding to the target object to be tested based on each extraction point; the target contour is used to perform industrial inspection on the target object to be tested.
[0166] According to the industrial inspection device provided by the embodiment of the present application, for the currently obtained baseline segment, it can be determined whether there is a more prominent first contour point among the multiple contour points corresponding to the baseline segment, and if the first contour point exists, the baseline segment is updated based on the first contour point, and it is determined again whether the baseline segment corresponds to the first contour point. If the first contour point does not exist, two target contour points are determined as extraction points corresponding to the segment contour, until multiple extraction points are obtained to obtain the target contour corresponding to the target object to be measured, thereby effectively reducing the number of contour points in the initial contour point set, so that industrial inspection and coarse positioning can be performed based on the target contour, which not only meets the inspection requirements but also improves the inspection efficiency and reduces the amount of calculation in the inspection process.
[0167] In some embodiments, the third processing module 1030 may also be used to:
[0168] The first target contour point of the two target contour points is updated to the first contour point, and the reference line segment is updated to the line segment between the first contour point and the second target contour point of the two target contour points, and the line segment between the first target contour point before updating and the first contour point.
[0169] In some embodiments, the industrial detection device may further include a sixth processing module for obtaining a first vector between the contour point and a first target contour point of the two target contour points, and a second vector between the contour point and a second target contour point of the two target contour points before determining the maximum distance from the distances between each contour point and the reference line segment between the two target contour points;
[0170] Calculating at least one of a first dot product between the first vector and a target vector corresponding to the reference line segment, a second dot product between the second vector and the target vector, a first cross product between the first vector and the target vector, and a second cross product between the second vector and the target vector;
[0171] A distance between the contour point and the reference line segment is determined based on at least one of the first dot product, the second dot product, the first cross product, and the second cross product.
[0172] In some embodiments, the sixth processing module may also be used to:
[0173] When it is determined based on the first dot product and / or the second dot product that the foot of the perpendicular between the contour point and the reference line segment is not located on the reference line segment, determining the distance between the contour point and the reference line segment based on the distance between the contour point and the first target contour point or the distance between the contour point and the second target contour point;
[0174] When it is determined based on the first dot product and the second dot product that the foot of the perpendicular between the contour point and the reference line segment is located on the reference line segment, the distance between the contour point and the reference line segment is determined based on the first cross product or the second cross product.
[0175] In some embodiments, the fifth processing module 1050 may also be used to:
[0176] Get any three adjacent extraction points from multiple extraction points;
[0177] Based on the distance between the line segments corresponding to the first extraction point and the other two extraction points among the three extraction points and a second threshold, determining the positional relationship between the first extraction point and the other two extraction points; the positional relationship includes that the first extraction point is collinear with the other two extraction points, or the first extraction point is not collinear with the other two extraction points;
[0178] Based on the position relationship, multiple extraction points are screened to obtain multiple target extraction points;
[0179] Connect multiple target extraction points sequentially to obtain the target contour.
[0180] In some embodiments, the industrial detection device may further include a seventh processing module, which is used to obtain the position information corresponding to the target object to be detected based on the target contour after obtaining the target contour corresponding to the target object to be detected based on each extraction point, so as to locate the target object to be detected;
[0181] and / or,
[0182] In the case where the target contour matches the preset contour corresponding to the target object to be measured, it is determined that the target object to be measured meets the industrial production requirements.
[0183] The industrial detection device in the embodiment of the present application can be an electronic device, or a component in an electronic device, such as an integrated circuit or a chip. The electronic device can be a terminal, or other devices other than a terminal. Exemplarily, the electronic device can be a mobile phone, a tablet computer, a laptop computer, a PDA, a vehicle-mounted electronic device, a mobile Internet device (Mobile Internet Device, MID), an augmented reality (augmented reality, AR) / virtual reality (virtualreality, VR) device, a robot, a wearable device, an ultra-mobile personal computer (ultra-mobile personal computer, UMPC), a netbook or a personal digital assistant (personal digital assistant, PDA), etc., and can also be a server, a network attached storage (Network Attached Storage, NAS), a personal computer (personalcomputer, PC), a television (television, TV), a teller machine or a self-service machine, etc., and the embodiment of the present application is not specifically limited.
[0184] The industrial detection device in the embodiment of the present application may be a device having an operating system. The operating system may be an Android operating system, an IOS operating system, or other possible operating systems, which are not specifically limited in the embodiment of the present application.
[0185] The industrial detection device provided in the embodiment of the present application can achieve Figures 1 to 9 To avoid repetition, the various processes implemented by the method embodiment are not described here.
[0186] In some embodiments, Fig.11As shown, an embodiment of the present application also provides an electronic device 1100, including a processor 1101, a memory 1102, and a computer program stored in the memory 1102 and executable on the processor 1101. When the program is executed by the processor 1101, each process of the above-mentioned industrial detection method embodiment is implemented, and the same technical effect can be achieved. To avoid repetition, it will not be described here.
[0187] It should be noted that the electronic devices in the embodiments of the present application include the mobile electronic devices and non-mobile electronic devices mentioned above.
[0188] On the other hand, the present application also provides a computer program product, which includes a computer program stored on a non-transitory computer-readable storage medium, and the computer program includes program instructions. When the program instructions are executed by a computer, the computer can execute the various processes of the above-mentioned industrial detection method embodiment and can achieve the same technical effect. To avoid repetition, it will not be repeated here.
[0189] On the other hand, the present application also provides a non-transitory computer-readable storage medium on which a computer program is stored. When the computer program is executed by a processor, it is implemented to perform the various processes of the above-mentioned industrial detection method embodiment and can achieve the same technical effect. To avoid repetition, it will not be repeated here.
[0190] On the other hand, an embodiment of the present application further provides a chip, which includes a processor and a communication interface, wherein the communication interface is coupled to the processor, and the processor is used to run programs or instructions to implement the various processes of the above-mentioned industrial detection method embodiment, and can achieve the same technical effect. To avoid repetition, it will not be repeated here.
[0191] It should be understood that the chip mentioned in the embodiments of the present application can also be called a system-level chip, a system chip, a chip system or a system-on-chip chip, etc.
[0192] The device embodiments described above are merely illustrative, wherein the units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they may be located in one place, or they may be distributed on multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the scheme of this embodiment. Ordinary technicians in this field can understand and implement it without paying creative labor.
[0193] Through the description of the above implementation methods, those skilled in the art can clearly understand that each implementation method can be implemented by means of software plus a necessary general hardware platform, and of course, by hardware. Based on this understanding, the above technical solution can be essentially or in other words, the part that contributes to the relevant technology can be embodied in the form of a software product, which can be stored in a computer-readable storage medium, such as ROM / RAM, a disk, an optical disk, etc., including a number of instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to execute the methods described in each embodiment or some parts of the embodiment.
[0194] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present application, rather than to limit it. Although the present application has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present application.
Claims
1. An industrial detection method, characterized in that: include: Determine a reference line segment based on two target contour points in an initial contour point set; the initial contour point set is obtained by extracting the initial contour of the target object to be measured in the first image, and the two target contour points are contour points with the largest distance in the initial contour point set; Determine a maximum distance from the distances between each contour point between the two target contour points and the reference line segment, and a first contour point corresponding to the maximum distance; In the case where the maximum distance is greater than a first threshold, updating any target contour point of the two target contour points based on the first contour point, and updating the reference line segment based on the current two target contour points; In a case where the maximum distance is not greater than the first threshold, determining the two target contour points as extraction points on the initial contour corresponding to the two target contour points; Based on each of the extraction points, a target contour corresponding to the target object to be measured is obtained; the target contour is used to perform industrial inspection on the target object to be measured.
2. The industrial detection method according to claim 1, characterized in that: The updating of any target contour point among the two target contour points based on the first contour point, and updating of the reference line segment based on the current two target contour points, comprises: The first target contour point of the two target contour points is updated to the first contour point, and the reference line segment is updated to the line segment between the first contour point and the second target contour point of the two target contour points, and the line segment between the first target contour point before updating and the first contour point.
3. The industrial detection method according to claim 1, characterized in that: Before determining the maximum distance from the distances between each contour point between the two target contour points and the reference line segment, obtaining the distances between each contour point between the two target contour points and the reference line segment includes: Acquire a first vector between the contour point and a first target contour point of the two target contour points, and a second vector between the contour point and a second target contour point of the two target contour points; Calculate at least one of a first dot product between the first vector and a target vector corresponding to the reference line segment, a second dot product between the second vector and the target vector, a first cross product between the first vector and the target vector, and a second cross product between the second vector and the target vector; Based on at least one of the first dot product, the second dot product, the first cross product, and the second cross product, a distance between the contour point and the reference line segment is determined.
4. The industrial detection method according to claim 3, characterized in that: The determining, based on at least one of the first dot product, the second dot product, the first cross product, and the second cross product, a distance between the contour point and the reference line segment comprises: In a case where it is determined based on the first dot product and / or the second dot product that the foot of the perpendicular between the contour point and the reference line segment is not located on the reference line segment, determining the distance between the contour point and the reference line segment based on the distance between the contour point and the first target contour point or the distance between the contour point and the second target contour point; When it is determined based on the first dot product and the second dot product that the foot of the perpendicular between the contour point and the reference line segment is located on the reference line segment, the distance between the contour point and the reference line segment is determined based on the first cross product or the second cross product.
5. The industrial detection method according to any one of claims 1 to 4, characterized in that: The step of obtaining a target contour corresponding to the target object to be measured based on each of the extraction points includes: Obtain any three adjacent extraction points from the plurality of extraction points; Based on the distance between the line segments corresponding to the first extraction point and the other two extraction points among the three extraction points and a second threshold, determining the positional relationship between the first extraction point and the other two extraction points; the positional relationship includes that the first extraction point and the other two extraction points are collinear, or the first extraction point and the other two extraction points are not collinear; Based on the positional relationship, the plurality of extraction points are screened to obtain a plurality of target extraction points; The plurality of target extraction points are connected in sequence to obtain the target contour.
6. The industrial detection method according to any one of claims 1 to 4, characterized in that: After obtaining the target contour corresponding to the target object to be measured based on each of the extraction points, the method further includes: Based on the target contour, obtaining position information corresponding to the target object to be measured, so as to locate the target object to be measured; and / or, In the case where the target contour matches a preset contour corresponding to the target object to be measured, it is determined that the target object to be measured meets industrial production requirements.
7. An industrial detection device, characterized in that: include: A first processing module is used to determine a reference line segment based on two target contour points in an initial contour point set; The initial contour point set is obtained by extracting the initial contour of the target object to be measured in the first image, and the two target contour points are contour points with the largest distance in the initial contour point set; A second processing module, configured to determine a maximum distance from the distances between each contour point between the two target contour points and the reference line segment, and a first contour point corresponding to the maximum distance; A third processing module, configured to update any target contour point of the two target contour points based on the first contour point, and update the reference line segment based on the current two target contour points, when the maximum distance is greater than a first threshold; A fourth processing module, configured to determine the two target contour points as extraction points on the initial contour corresponding to the two target contour points when the maximum distance is not greater than the first threshold; The fifth processing module is used to obtain a target contour corresponding to the target object to be measured based on each of the extraction points; the target contour is used to perform industrial inspection on the target object to be measured.
8. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the program, the industrial detection method according to any one of claims 1 to 6 is implemented.
9. A non-transitory computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the industrial detection method according to any one of claims 1 to 6 is implemented.
10. A computer program product, comprising a computer program, characterized in that When the computer program is executed by a processor, the industrial detection method according to any one of claims 1 to 6 is implemented.