Template generation method and apparatus, electronic device, and storage medium
By drawing and extracting combined edges in the interactive interface to generate templates, the problem of inaccurate template detection in existing technologies is solved, achieving higher precision and robust target object detection.
Patent Information
- Authority / Receiving Office
- WO · WO
- Patent Type
- Applications
- Current Assignee / Owner
- HANGZHOU HIKROBOT TECH CO LTD
- Filing Date
- 2025-11-13
- Publication Date
- 2026-05-21
AI Technical Summary
In existing technologies, templates generated based on a single object image are difficult to accurately detect the location of the same object in different images, leading to missed detections and false detections.
By combining edge drawing and edge extraction in the interactive interface, a template of the target object is generated. The edge drawing is obtained by the user drawing on the interactive interface, and combined with the edge generated by the edge extraction algorithm, a more accurate edge of the target object is determined.
It improves the accuracy and efficiency of matching target objects in images, reduces missed detections and false detections, and enhances the accuracy and robustness of template generation.
Smart Images

Figure CN2025134616_21052026_PF_FP_ABST
Abstract
Description
A template generation method, apparatus, electronic device, and storage medium
[0001] This application claims priority to Chinese Patent Application No. 202411654530.8, filed on November 18, 2024, entitled "A Template Generation Method, Apparatus, Electronic Device and Storage Medium", the entire contents of which are incorporated herein by reference. Technical Field
[0002] This application relates to the field of machine vision technology, and in particular to a template generation method, apparatus, electronic device, and storage medium. Background Technology
[0003] Machine vision technology is involved in automated industrial production, for example, acquiring images of objects to be inspected and determining the object's pose.
[0004] In existing technologies, objects that match the template in an image of the object are typically identified, and thus the object's pose and other information are determined. Therefore, the object's template is crucial in determining the object's pose, and an accurate object template needs to be generated. Summary of the Invention
[0005] The purpose of this application is to provide a template generation method, apparatus, electronic device, and storage medium to generate accurate templates for target objects. The specific technical solution is as follows:
[0006] According to one aspect of the embodiments of this application, a template generation method is provided, the method comprising:
[0007] Display the first image of the target object in the interactive interface;
[0008] In response to an edge drawing operation of a target object in a first image displayed on the interactive interface, a second edge of the target object in the first image is determined based on the drawn edge drawn by the edge drawing operation and / or the first edge of the target object extracted from the first image;
[0009] Based on the second edge, a template for the target object is generated.
[0010] In one embodiment of this application, the edge drawing operation is responded to in the following manner:
[0011] In response to a line-drawing operation of a touch object on a first image displayed on the interactive interface, the touch points of the touch object on the first image are collected;
[0012] Obtain the curve generated based on the collected touch points, and use it as the drawing edge of the target object;
[0013] The drawn edges are displayed in the interactive interface.
[0014] In one embodiment of this application, obtaining the curve generated based on the collected touch points as the drawing edge of the target object includes:
[0015] Obtain the object contour line generated based on the collected touch points, as the drawing edge of the target object, wherein the object contour line includes: the outer contour line and / or the inner contour line of the target object, and the object contour line includes: closed curve and / or non-closed curve.
[0016] In one embodiment of this application, the interactive interface displays a contour shape control. Before collecting the touch points of the touch object on the first image in response to a line-drawing operation of the touch object on the first image displayed on the interactive interface, the method further includes:
[0017] In response to a selection operation on the outline shape control, the target outline shape corresponding to the selected target control is determined;
[0018] The step of obtaining the curve generated based on the collected touch points as the drawing edge of the target object includes:
[0019] Based on the collected touch points, a curve representing the outline shape of the target object is generated, which serves as the drawing edge of the target object.
[0020] In one embodiment of this application, after determining the target contour shape corresponding to the selected target control in response to the selection operation for the contour shape control, the method further includes:
[0021] In response to a first operation of dragging the target outline shape on the interactive interface, the target outline shape is displayed at the position after dragging;
[0022] In response to a second operation that adjusts the size of the target contour shape on the interactive interface, the adjusted target contour shape is displayed;
[0023] The step of generating a curve representing the target contour shape based on the collected touch points, as the drawing edge of the target object, includes:
[0024] Based on the touch points within a preset range of the adjusted target contour shape, a curve of the target contour shape is generated as the drawing edge of the target object.
[0025] In one embodiment of this application, after the drawn edge is displayed in the interactive interface, the method further includes:
[0026] Determine whether the drawing edges displayed in the interactive interface meet the drawing requirements;
[0027] If the determination is yes, then the steps of drawing the edge based on the edge drawing operation and the first edge of the target object extracted from the first image are executed to determine the second edge of the target object in the first image;
[0028] The following methods should be used to determine whether the displayed drawing edges meet the drawing requirements:
[0029] If the user clicks the "Draw OK" button on the interactive interface, the displayed drawing edges will meet the drawing requirements.
[0030] or
[0031] If the user does not perform edge drawing operations on the target object in the first image displayed on the interactive interface within a time limit greater than the preset operation time, then it is determined that the displayed drawing edges meet the drawing requirements.
[0032] In one embodiment of this application, the edge drawing operation is responded to in the following manner:
[0033] In response to a selection operation of the structure diagram of a target object in the first image displayed on the interactive interface, the outline of the structure diagram of the target object is loaded.
[0034] The loaded contour lines are adjusted according to the pose of the target object in the first image, and the adjusted contour lines are displayed in the interactive interface and used as the drawing edge of the target object.
[0035] In one embodiment of this application, adjusting the loaded contour line according to the pose of the target object in the first image and displaying the adjusted contour line in the interactive interface includes:
[0036] The loaded contour line is adjusted to the target pose, wherein the target pose is the pose of the target object such that the edge of the target object in the first image and the loaded contour line satisfy the matching condition.
[0037] The adjusted outline is displayed on the layer above the first image in the interactive interface.
[0038] In one embodiment of this application, adjusting the loaded contour line according to the pose of the target object in the first image and displaying the adjusted contour line in the interactive interface includes:
[0039] Obtain the first scale of the structural diagram;
[0040] Obtain a second scale bar between the target object in the first image and the target object in the actual scene;
[0041] Based on the first and second scales, the scale of the loaded contour lines is adjusted.
[0042] Based on the pose of the target object in the first image, the adjusted loaded contour line is displayed on the interactive interface.
[0043] In one embodiment of this application, determining the second edge of the target object in the first image based on the drawn edge drawn by the edge drawing operation and / or the first edge of the target object extracted from the first image includes:
[0044] Based on the drawn edges, a first mask image of the drawn edges is generated;
[0045] The edge polarity of the edge point corresponding to the drawn edge in the first mask image along a set direction is obtained as the first edge polarity, wherein the edge polarity represents the direction of gray value change of the pixels on both sides of the edge point along the set direction.
[0046] The edge polarity of the edge point corresponding to the first edge in the second mask image along a set direction is obtained as the second edge polarity, wherein the second mask image is: the mask image obtained by edge extraction of the first image;
[0047] Based on the obtained first edge polarity and second edge polarity, target edge points in the drawn edge are determined, wherein the first edge polarity of the target edge point is opposite to the second edge polarity of the corresponding edge point in the first edge;
[0048] Based on the determined target edge points, the second edge of the target object in the first image is obtained.
[0049] In one embodiment of this application, determining the second edge of the target object in the first image based on the drawn edge drawn by the edge drawing operation and / or the first edge of the target object extracted from the first image includes:
[0050] Determine matching edge point pairs in the drawn edge and the first edge, wherein each matching edge point pair includes an edge point in the drawn edge and an edge point in the first edge;
[0051] For the first type of edge point pair, the edge points belonging to the drawn edge in the first type of edge point pair are determined as edge points in the second edge of the target object in the first image. The first type of edge point pair is: a matching edge point pair where the distance between two edge points is less than a preset distance threshold.
[0052] For the second type of edge point pair, the edge points belonging to the first edge in the second type of edge point pair are used to correct the edge points belonging to the drawn edge, and the corrected points are used as the edge points in the second edge of the target object in the first image. The second type of edge point pair is: the edge point pair excluding the first type of edge points in the determined matching edge point pair.
[0053] According to another aspect of the embodiments of this application, a template generation apparatus is provided, the apparatus comprising:
[0054] The first image display module is used to display the first image of the target object in the interactive interface;
[0055] The second edge determination module is used to respond to an edge drawing operation of a target object in a first image displayed on the interactive interface, and to determine a second edge of the target object in the first image based on the drawn edge drawn by the edge drawing operation and / or the first edge of the target object extracted from the first image.
[0056] The template generation module is used to generate a template of the target object based on the second edge.
[0057] In one embodiment of this application, the second edge determination module is specifically configured to respond to the edge drawing operation in the following manner: in response to a line drawing operation of a touch object on a first image displayed on the interactive interface, the module collects touch points of the touch object on the first image; obtains a curve generated based on the collected touch points as the drawing edge of the target object; and displays the drawing edge in the interactive interface.
[0058] In one embodiment of this application, the second edge determination module is specifically used to obtain an object contour line generated based on the collected touch points as the drawing edge of the target object, wherein the object contour line includes: the outer contour line and / or the inner contour line of the target object, and the object contour line includes: a closed curve and / or a non-closed curve.
[0059] In one embodiment of this application, the interactive interface displays a contour shape control, and the second edge determination module is further configured to determine the target contour shape corresponding to the selected target control in response to a selection operation on the contour shape control; specifically, it is configured to generate a curve of the target contour shape based on the collected touch points, as the drawing edge of the target object.
[0060] In one embodiment of this application, the second edge determination module is further configured to, in response to a first operation of dragging the target contour shape on the interactive interface, display the target contour shape at the position after dragging; in response to a second operation of adjusting the size of the target contour shape on the interactive interface, display the adjusted target contour shape; and generate a curve of the target contour shape based on touch points within a preset range of the adjusted target contour shape, as the drawing edge of the target object.
[0061] In one embodiment of this application, the second edge determination module is further configured to determine whether the drawing edge displayed in the interactive interface meets the drawing requirements; if the determination is yes, then the step of determining the second edge of the target object in the first image is performed by drawing the drawing edge based on the edge drawing operation and the first edge of the target object extracted from the first image.
[0062] The following methods should be used to determine whether the displayed drawing edges meet the drawing requirements:
[0063] If the user clicks the "Draw OK" button on the interactive interface, the displayed drawing edges will meet the drawing requirements.
[0064] or
[0065] If the user does not perform edge drawing operations on the target object in the first image displayed on the interactive interface within a time limit greater than the preset operation time, then it is determined that the displayed drawing edges meet the drawing requirements.
[0066] In one embodiment of this application, the second edge determination module is specifically configured to respond to the edge drawing operation in the following manner: in response to a structural diagram selection operation of a target object in a first image displayed on the interactive interface, load the contour line in the structural diagram of the target object; adjust the loaded contour line according to the pose of the target object in the first image, display the adjusted contour line in the interactive interface, and use the adjusted contour line as the drawing edge of the target object.
[0067] In one embodiment of this application, the second edge determination module is specifically used to adjust the loaded contour line to a target pose, wherein the target pose is: the pose of the target object in the first image such that the edge of the target object and the loaded contour line meet the matching conditions; and the adjusted contour line is displayed on the layer above the first image displayed in the interactive interface.
[0068] In one embodiment of this application, the second edge determination module is specifically used to obtain a first scale of the structure diagram; obtain a second scale between the target object in the first image and the target object in the actual scene; adjust the scale of the loaded contour line based on the first scale and the second scale; and display the adjusted loaded contour line on the interactive interface according to the pose of the target object in the first image.
[0069] In one embodiment of this application, the second edge determination module is specifically configured to: generate a first mask image of the drawn edge based on the drawn edge; obtain the edge polarity of the edge point corresponding to the drawn edge in the first mask image along a set direction as a first edge polarity, wherein the edge polarity characterizes the direction of grayscale value change of pixels on both sides of the edge point along the set direction; obtain the edge polarity of the edge point corresponding to the first edge in a second mask image along a set direction as a second edge polarity, wherein the second mask image is: a mask image obtained by edge extraction of the first image; determine a target edge point in the drawn edge based on the obtained first edge polarity and second edge polarity, wherein the first edge polarity of the target edge point is opposite to the second edge polarity of the corresponding edge point in the first edge; and obtain the second edge of the target object in the first image based on the determined target edge point.
[0070] In one embodiment of this application, the second edge determination module is specifically configured to: determine matching edge point pairs between the drawn edge and the first edge, wherein each matching edge point pair includes an edge point in the drawn edge and an edge point in the first edge; for a first type of edge point pair, determine the edge points belonging to the drawn edge in the first type of edge point pair as edge points in the second edge of the target object in the first image, wherein the first type of edge point pair is a matching edge point pair where the distance between two edge points is less than a preset distance threshold; for a second type of edge point pair, use the edge points belonging to the first edge in the second type of edge point pair to correct the edge points belonging to the drawn edge, and obtain corrected points as edge points in the second edge of the target object in the first image, wherein the second type of edge point pair is an edge point pair excluding the first type of edge points in the determined matching edge point pairs.
[0071] According to another aspect of the embodiments of this application, an electronic device is provided, comprising:
[0072] Memory, used to store computer programs;
[0073] When a processor executes a program stored in memory, it implements any of the template generation methods described above.
[0074] According to another aspect of the embodiments of this application, a computer-readable storage medium is provided, wherein a computer program is stored therein, and the computer program, when executed by a processor, implements any of the template generation methods described above.
[0075] This application also provides a computer program product containing instructions that, when run on a computer, cause the computer to execute any of the template generation methods described above.
[0076] Beneficial effects of the embodiments in this application:
[0077] As can be seen from the above, in the solution provided by the embodiments of this application, the second edge is used to generate the template of the target object. The second edge is determined based on the drawn edge and the first edge. The first edge is obtained by edge extraction, and the drawn edge is obtained by drawing the edge of the target object in the first image displayed on the interactive interface. Therefore, the position of the real edge of the target object can be determined more accurately based on the drawn edge, reducing the influence of interference information in the first image of the target object on the template generation. The second edge determined by combining the drawn edge and the first edge can more accurately represent the real edge of the target object. The second edge integrates the edge information provided by both the drawn edge and the first edge, and thus an accurate template of the target object can be generated based on the second edge.
[0078] Of course, implementing any product or method of this application does not necessarily require achieving all of the advantages described above at the same time. Attached Figure Description
[0079] The accompanying drawings, which are provided to further illustrate this application and form part of this application, illustrate exemplary embodiments of this application and are used to explain this application, but do not constitute an undue limitation of this application.
[0080] Figure 1a is a schematic diagram of the structure of the first object provided in an embodiment of this application;
[0081] Figure 1b is a schematic diagram of the first template provided in an embodiment of this application;
[0082] Figure 1c is a schematic diagram of the structure of the second object provided in an embodiment of this application;
[0083] Figure 1d is a comparative diagram of the first template and the second object provided in the embodiment of this application;
[0084] Figure 2 is a schematic flowchart of a template generation method provided in an embodiment of this application;
[0085] Figure 3a is a schematic diagram of a target object provided in an embodiment of this application;
[0086] Figure 3b is a schematic diagram of a first image provided in an embodiment of this application;
[0087] Figure 4 is a schematic flowchart of a second edge determination method provided in an embodiment of this application;
[0088] Figure 5 is a schematic flowchart of another second edge determination method provided in an embodiment of this application;
[0089] Figure 6a is a schematic diagram of a touch point provided in an embodiment of this application;
[0090] Figure 6b is a schematic diagram of the closed outer contour of a target object provided in an embodiment of this application;
[0091] Figure 6c is a schematic diagram of a closed outer contour line and a non-closed inner contour line of a target object provided in an embodiment of this application;
[0092] Figure 6d is a schematic diagram of the outline shape of an interactive interface provided in an embodiment of this application;
[0093] Figure 7a is a schematic diagram of a template of a target object provided in an embodiment of this application;
[0094] Figure 7b is a schematic diagram of a template for another target object provided in an embodiment of this application;
[0095] Figure 8 is a schematic diagram of a template generation device provided in an embodiment of this application;
[0096] Figure 9 is a schematic diagram of the structure of an electronic device provided in an embodiment of this application. Detailed Implementation
[0097] To make the objectives, technical solutions, and advantages of this invention clearer, the invention will be further described in detail below with reference to the accompanying drawings and embodiments. Obviously, the described embodiments are merely some embodiments of this invention, and not all embodiments. All other embodiments obtained by those skilled in the art based on the embodiments of this invention are within the scope of protection of this invention.
[0098] The application scenarios and prior art of the embodiments of this application are described below.
[0099] Machine vision technology is used in automated industrial production to perform various inspections on the objects to be inspected. For example, in the automated production process of an assembly line, it is usually necessary to perform quality inspection, quantity inspection, etc. on the objects to be inspected on the assembly line, or to detect the pose of the objects to be inspected installed in a preset position.
[0100] When performing various detections on an object to be detected, it is necessary to acquire an image of the object. Then, based on a template of the object to be detected, the object matching the template is identified in the acquired image, thereby determining the pose and scale information of the object to be detected. The template of the object to be detected is usually obtained based on an image of the object. For example, referring to the structural schematic diagram of the first object provided in Figure 1a, if the template of the first object is obtained based on the image of the first object shown in Figure 1a, then the first template shown in the schematic diagram of the first template provided in Figure 1b can be obtained.
[0101] However, the same object may have different scratches, residues, or other processing marks due to different processing methods, or the same object itself may have different textures. Therefore, using a template obtained from an image of one object may make it difficult to detect objects in other images. For example, when using the first template shown in Figure 1b to determine objects matching the first template in other images that contain the same object as the first object, it may be difficult to detect objects matching the first template in other images. For example, referring to the structural diagram of the second object provided in Figure 1c, the second object shown in Figure 1c and the first object shown in Figure 1a are the same object. When using Figure 1b as a template to determine the object in the image provided in Figure 1c, the matching degree between the second object in Figure 1c and the first template shown in Figure 1b may be lower than the preset matching degree threshold because the position of the circle in the first template shown in Figure 1b is different from the position of the circle in Figure 1c. Consequently, the detection result is: no object is found in the image provided in Figure 1c. For example, referring to the comparison diagram of the first template and the second object provided in Figure 1d, it can be clearly seen from Figure 1d that the positions of the circles are different. It is evident that object detection based on such a first template can lead to problems such as missed detections and false detections.
[0102] The execution subject of the embodiments of this application will be described below.
[0103] The solutions provided in this application can be applied to electronic devices such as desktop computers, laptops, tablets, and smartphones. Specifically, a client can be installed on the aforementioned electronic devices, and the template generation method provided in this application can also be applied to the aforementioned client. For ease of description, the executing entity of the template generation method provided in this application is collectively referred to as a template generation device.
[0104] The template generation method provided in this application will be described below with reference to specific embodiments.
[0105] In one embodiment of this application, referring to Figure 2, a schematic flowchart of a template generation method is provided. The method includes the following steps S201-S203.
[0106] Step S201: Display the first image of the target object on the interactive interface.
[0107] The interactive interface is used for interaction with the user. The first image is an image used to generate a template of the target object, and the first image can be an image containing one target object. When the target object is a circular object, refer to Figure 3a for a schematic diagram of a target object. In Figure 3a, multiple target objects are arranged sequentially, and each target object's circle contains different irregular lines. For this type of target object, the first image can be an image of one of the target objects shown in Figure 3a. For example, taking a target object within the dashed box in Figure 3a as an example, refer to Figure 3b for a schematic diagram of a first image. Furthermore, the screen displayed by the template generation device on the interactive interface can be the first image provided in Figure 3b.
[0108] The method for obtaining the first image is explained below.
[0109] Specifically, if the template generation device can obtain the first image, it can directly display the obtained first image on the interactive interface. If the image obtained by the template generation device is an image to be processed containing multiple target objects, or if the obtained image to be processed contains other content that interferes, the image to be processed can also be displayed on the interactive interface. The user can perform a cropping operation on the displayed image to be processed in the interactive interface, and the template generation device can crop the image to be processed according to the cropping operation on the displayed image to obtain the first image, and then display the obtained first image on the interactive interface.
[0110] Step S202: In response to the edge drawing operation of the target object in the first image displayed on the interactive interface, determine the second edge of the target object in the first image based on the drawn edge drawn by the edge drawing operation and / or the first edge of the target object extracted from the first image.
[0111] Specifically, the first edge is generated in the following manner: the template generation device can use an edge extraction algorithm to extract the edge of the first image. For example, the edge extraction algorithm can be the Canny edge detection algorithm (a multi-level edge detection algorithm) and edge operator algorithms, etc.
[0112] In addition, after the user performs edge drawing operations on the target object in the first image displayed on the interactive interface, the template generation device can display the drawing edge drawn by the user, and then determine whether the drawing edge displayed in the interactive interface meets the drawing requirements. If the drawing edge displayed meets the drawing requirements, the second edge of the target object in the first image is determined based on the drawing edge and the first edge.
[0113] The following explains the situation where the drawn edges meet the drawing requirements.
[0114] In one scenario, a "Draw Confirm" button can be set in the interactive interface. If the user clicks the "Draw Confirm" button in the interactive interface, that is, after the template generation device detects that the "Draw Confirm" button has been triggered, it determines that the displayed drawing edge meets the drawing requirements.
[0115] In another scenario, if the template generation device detects that the user has not performed edge drawing operations on the target object in the first image displayed on the interactive interface for a period of time longer than the preset operation time, then it is determined that the displayed drawing edges meet the drawing requirements.
[0116] Determining the drawing edge in this way satisfies the drawing requirements, and then determining the second edge of the target object in the first image based on the drawing edge and the first edge, can improve the accuracy of generating the second edge.
[0117] The implementation method of drawing the edge in step S202 is described in the following embodiments, and will not be detailed here.
[0118] The method for determining the second edge in step S202 is explained below.
[0119] In one implementation, the template generation device can determine the overlapping edge points between the drawn edge and the first edge, and then determine the overlapping edge line based on the overlapping edge points as the second edge of the target object in the first image. Specifically, the method for determining the overlapping edge based on the overlapping edge points can employ discrete point interpolation, curve fitting, and other methods.
[0120] Other implementations of step S202, which determines the second edge, will be described in the following embodiments and will not be detailed here.
[0121] Step S203: Generate a template for the target object based on the second edge.
[0122] Specifically, the template generation device generates a mask image of the second edge based on the second edge, and uses the mask image of the second edge as a template for the target object.
[0123] As can be seen from the above, in the solution provided by the embodiments of this application, the second edge is used to generate the template of the target object. The second edge is determined based on the drawn edge and the first edge. The first edge is obtained by edge extraction, and the drawn edge is obtained by drawing the edge of the target object in the first image displayed on the interactive interface. Therefore, the position of the real edge of the target object can be determined more accurately based on the drawn edge, reducing the influence of interference information in the first image of the target object on the template generation. The second edge determined by combining the drawn edge and the first edge can more accurately represent the real edge of the target object. The second edge integrates the edge information provided by both the drawn edge and the first edge, and thus an accurate template of the target object can be generated based on the second edge.
[0124] The template generated using the scheme provided in the embodiments of this application is more accurate. Determining the pose of the target object based on the aforementioned template improves the accuracy and efficiency of identifying target objects that match the template in an image, and reduces the occurrence of missed and false detections. For example, for the image of the first object provided in Figure 1a, the generated target object template only has a triangular outline, excluding the central circular outline. Therefore, in the process of identifying target objects that match the template in the image, it avoids situations where the target object in the image has a large number of outline points that cannot match the model. Furthermore, because the second edge combines information from the drawn edge and the first edge, edges that are difficult to extract using edge extraction can be supplemented by combining edge information from the drawn edge. Thus, the generated target object template can include edges that are difficult to extract using conventional edge extraction, further improving the accuracy of the generated target object template.
[0125] Furthermore, the solution provided in this application embodiment can be used to generate templates for objects of any shape, or objects with scratches, residue, or other interfering contours. The solution provided in this application embodiment has higher scene adaptability and improves the robustness of the generated templates.
[0126] The following describes other implementation methods for determining the second edge in step S202.
[0127] In one embodiment of this application, referring to FIG4, a flowchart of a second edge determination method is provided. The method includes the following steps S401-S405.
[0128] Step S401: Generate a first mask image of the drawn edges based on the drawn edges.
[0129] Edge drawing is the process of drawing edges on the target object in the first image displayed in the interactive interface. Therefore, a first mask image for the drawn edges can be generated based on their positions in the first image. Specifically, in the generated first mask image, the pixel positions belonging to the drawn edges can have values of 1, while the values of other pixel positions can be 0.
[0130] Step S402: Obtain the edge polarity of the edge point corresponding to the drawn edge in the first mask image along the set direction, and use it as the first edge polarity.
[0131] The edge polarity represents the direction of grayscale value change of pixels on both sides of the edge point along a set direction. The edge polarity can be positive or negative. A positive edge polarity indicates that the grayscale value change of pixels on both sides of the edge point along the set direction is an increasing change, while a negative edge polarity indicates that the grayscale value change of pixels on both sides of the edge point along the set direction is a decreasing change.
[0132] Specifically, for each edge point of the drawn edge, the template generation device detects the change in grayscale value of the pixels on both sides of each edge point along a set direction, and then determines that the first edge polarity of the edge point with an increasing grayscale value change is positive, and determines that the first edge polarity of the edge point with a decreasing grayscale value change is negative.
[0133] The template generation device detects changes in the grayscale values of pixels in the mask image. It determines that points with a value of 1 are black, and points with a value of 0 are white, thus identifying the lowest grayscale value (1) and the highest grayscale value (0). The set direction can be the search direction for detecting edge points; for example, the set direction can include left-to-right, right-to-left, top-to-bottom, bottom-to-top, etc., within the mask image.
[0134] Step S403: Obtain the edge polarity of the edge point corresponding to the first edge in the second mask image along a set direction, and use it as the second edge polarity.
[0135] The second mask image is the mask image obtained by edge extraction of the first image.
[0136] Specifically, for each edge point of the first edge, the template generation device detects the change in grayscale value of the pixels on both sides of each edge point along a set direction, and then determines that the second edge polarity of the edge point with increasing grayscale value change is positive, and determines that the second edge polarity of the edge point with decreasing grayscale value change is negative.
[0137] For details on edge polarity, grayscale value, and setting direction, please refer to step S402.
[0138] Step S404: Based on the obtained first edge polarity and second edge polarity, determine the target edge points in the drawn edge.
[0139] Specifically, the first edge polarity of the target edge point is opposite to the second edge polarity of the corresponding edge point in the first edge. For ease of description, the edge point in the first edge that corresponds to the edge point in the drawn edge is simply referred to as the first corresponding point.
[0140] Specifically, the template generation device determines a target edge point in the drawn edge whose first edge polarity and second edge polarity are opposite, based on the first edge polarity of the edge point in the drawn edge obtained in step S402 and the second edge polarity of the edge point in the first edge obtained in step S403. For example, if the first edge polarity of an edge point in the drawn edge is positive and the second edge polarity of the first corresponding point of the aforementioned edge point is negative, then the edge point in the drawn edge is a target edge point. Similarly, if the first edge polarity of an edge point in the drawn edge is negative and the second edge polarity of the first corresponding point of the aforementioned edge point is positive, then the edge point in the drawn edge is also a target edge point.
[0141] The following explains how to determine the first corresponding point of the edge point in the drawn edge in step S404.
[0142] In one implementation, the template generation device determines the first edge point in the first edge that is closest to the position of the edge point in the drawn edge, based on the position of each edge point in the first image and the position of each edge point in the first edge in the first image, and uses it as the first corresponding point of the edge point in the drawn edge.
[0143] In another implementation, the template generation device determines the first corresponding point of the edge point in the drawing edge, based on the position of each edge point in the first image and the position of each edge point in the first edge in the first image, which is the same as the position of the edge point in the drawing edge.
[0144] In another implementation, the template generation device can detect the nearest edge point in the first edge along the horizontal direction to the edge point in the drawing edge, and use it as the first corresponding point of the edge point in the drawing edge. The template generation device can also detect the nearest edge point in the first edge along the vertical direction to the edge point in the drawing edge, and use it as the first corresponding point of the edge point in the drawing edge.
[0145] Step S405: Based on the determined target edge points, obtain the second edge of the target object in the first image.
[0146] In one implementation, curve fitting can be performed on the determined target edge points, and the fitted curve can be used as the second edge.
[0147] In another implementation, discrete point interpolation can be used to interpolate the determined target edge points. After interpolating for a preset number of times, curve fitting is performed on the target edge points and the interpolated points, and the fitted curve is used as the second edge.
[0148] As can be seen from the above, the target edge point is the edge point whose polarity is opposite to that of the second edge point of the corresponding edge point in the first edge. In this way, by drawing the edge polarity of the edge and the edge polarity of the first edge respectively, the edge characteristics of the drawn edge and the first edge can be combined to generate the second edge more accurately, and thus generate a more accurate template of the target object.
[0149] The following describes another implementation method for determining the second edge in step S202.
[0150] In one embodiment of this application, referring to Figure 5, another schematic flowchart of a second edge determination method is provided. The method includes the following steps S501-S503.
[0151] Step S501: Determine the matching edge point pairs in the drawn edge and the first edge.
[0152] Each pair of matching edge points includes an edge point in the drawn edge and an edge point in the first edge.
[0153] The method for determining the matching edge point pair in step S501 is similar to the method for determining the first corresponding point of the edge point in the drawn edge in step S404 above, the only difference being the name. For example, the first corresponding point of the edge point in the drawn edge can be determined in the way of step S404, and the edge point in the drawn edge and the first corresponding point can be used as the matching edge point pair.
[0154] Step S502: For the first type of edge point pair, determine the edge points belonging to the drawing edge in the first type of edge point pair as edge points in the second edge of the target object in the first image.
[0155] The first type of edge point pair is defined as a matching edge point pair where the distance between two edge points is less than a preset distance threshold. In other words, if the two edge points in the first type of edge point pair are close enough, it means that the drawn edge at that edge point location is similar to the first edge identified, and it also means that the edge point in the drawn edge is more accurate. Therefore, the edge point belonging to the drawn edge in the first type of edge point pair can be determined as the edge point in the second edge of the target object in the first image.
[0156] Step S503: For the second type of edge point pair, use the edge points belonging to the first edge in the second type of edge point pair to correct the edge points belonging to the drawing edge, and obtain the corrected points as the edge points in the second edge of the target object in the first image.
[0157] The second type of edge points refers to edge point pairs that exclude the first type of edge points from the determined matched edge point pairs. In other words, if the two edge points in a second type of edge point pair are too far apart, it indicates that the drawn edge at that edge point location differs significantly from the identified first edge. Therefore, the drawn edge may contain errors and needs correction. The corrected points are then used as edge points in the second edge of the target object in the first image.
[0158] The following explains how to correct edge points that belong to the drawn edge.
[0159] In one implementation, the midpoint of the line connecting the edge point belonging to the first edge and the edge point belonging to the drawing edge in the second type of edge point pair can be used as the correction point.
[0160] In another implementation, the distance between the edge point belonging to the first edge and the edge point belonging to the drawing edge in the second type of edge point pair exceeds a preset distance threshold, which is taken as the first value. Then, along the direction of the line connecting the edge point belonging to the first edge and the edge point belonging to the drawing edge in the second type of edge point pair towards the edge point of the first edge, the edge point belonging to the drawing edge is moved by the aforementioned first value, which is taken as the correction point.
[0161] As can be seen from the above, this method can correct the edge points of the drawn edge when the difference between the drawn edge and the first edge is too large, reduce the impact of the deviation of the drawn edge on the second edge, improve the accuracy of the second edge determined based on the drawn edge and the first edge, and thus improve the accuracy of the generated target object template.
[0162] The following explains how step S202, in response to the edge drawing operation, displays the drawn edge in the interactive interface.
[0163] In one embodiment of this application, the drawn edge can be displayed in the interactive interface in the following manner: the user can use the touch object to draw a line on the first image displayed on the interactive interface; in response to the line drawing operation of the touch object on the first image displayed on the interactive interface, the touch points of the touch object on the first image are collected; a curve generated based on the collected touch points is obtained as the drawing edge of the target object; and the drawing edge is displayed in the interactive interface.
[0164] The edge drawing operation can include line drawing operations. The touch object can be a finger or pen that draws lines on the touch screen of the template generation device. If the template generation device is an electronic device such as a computer or laptop, the touch object can also be a mouse or an object that draws lines on a touchpad.
[0165] The following are examples illustrating touch points.
[0166] Taking the first image shown in Figure 3b as an example, after the first image is displayed in the interactive interface, the user can use the touch object to draw lines on the first image displayed in the interactive interface according to the circles in the figure. For example, see the schematic diagram of a touch point provided in Figure 6a. In Figure 6a, the circles around the figure are the touch points of the collected touch object on the first image.
[0167] The method of generating curves based on the collected touch points is similar to the implementation method of obtaining the second edge based on the target edge points in step S405. The only difference is the name, which will not be described in detail here.
[0168] In this way, the first image displayed on the interactive interface allows users to clearly see the image used to generate the template. Furthermore, by drawing lines on the first image displayed on the interactive interface using touch objects, users can obtain more accurate drawing edges. Combining the more accurate drawing edges drawn by the user using touch objects with the first edge can reduce interference in the first image, thereby generating a more accurate template for the target object.
[0169] The following explains how to obtain a curve generated based on the collected touch points as the drawing edge of the target object.
[0170] In one implementation, the outline of the object generated based on the collected touch points is obtained as the drawing edge of the target object.
[0171] The object contour line includes: the outer contour line and / or inner contour line of the target object, and the object contour line includes: closed curves and / or non-closed curves.
[0172] The outer contour line can be a contour line that is not completely enclosed by other closed curves, while the inner contour line can include contour lines other than the outer contour line.
[0173] For example, after determining that the curve generated based on the touch point in Figure 6a is a closed curve, a schematic diagram of the closed outer contour of the target object can be obtained as shown in Figure 6b. The bold lines in the figure are the outer contour lines, and they are closed curves. It can be seen that the contour shown in Figure 6b is relatively simple.
[0174] For objects with complex outlines, the drawing edges of the target object can be obtained by drawing its outer and inner contour lines. For example, see Figure 6c, which provides a schematic diagram of a closed outer contour line and a non-closed inner contour line of a target object, where the bold lines represent the contour lines. This allows for the drawing of closed or non-closed outer and inner contour lines as the drawing edges of complex and diverse objects, making it applicable to various drawing scenarios, producing contours that better reflect reality, and improving the accuracy of the obtained drawing edge information.
[0175] This allows for the flexible drawing of closed and / or open contours of objects. Such curve generation can accommodate the outer and / or inner contours of objects with a wider range of shapes, simplifying line drawing operations and improving the ease of template generation. Furthermore, drawing the outer and inner contours of an object more accurately represents its contour features, resulting in more precise drawn edges and thus improving the accuracy of generating templates for the target object.
[0176] The following describes another method for obtaining curves generated based on the collected touch points as the drawing edge of the target object.
[0177] Before acquiring the touch points of the touch object on the first image displayed on the interactive interface in response to a line drawing operation by the touch object, the template generation device can determine the target contour shape corresponding to the selected target control in the contour shape control displayed on the interactive interface. Then, based on the acquired touch points, a curve of the target contour shape is generated as the drawing edge of the target object.
[0178] The following explains how to determine the target outline shape corresponding to the selected target control in the outline shape control displayed in the interactive interface.
[0179] Specifically, various contour shape controls can be preset, and users can then select a target contour shape that matches the contour of the target object from the contour shape controls displayed on the interactive interface. Then, based on the target contour shape and the collected touch points, a target contour shape curve is generated.
[0180] For example, referring to Figure 6d, which provides a schematic diagram of an interactive interface displaying an outline shape, the left side of the interactive interface shown in Figure 6d displays selectable outline shape controls. It can be seen that the outline in the first image displayed in the interactive interface of Figure 6d is circular. Therefore, a button representing a circular outline shape control can be found from the selectable outline shape controls. Selecting this button determines the target outline shape to be circular. Then, a circle fitting is performed on the collected touch points to obtain a circular curve, which serves as the drawing edge of the target object. In addition, the outline shape control can also include non-closed outlines and closed outlines. For example, non-closed outlines can include non-closed arcs, straight lines, etc., while closed outlines can include circles, trapezoids, and rectangles, etc.
[0181] Furthermore, after selecting the outline shape control, the user can drag the selected target outline shape to the position corresponding to the outer outline of the target object in the first image displayed on the interactive interface. After detecting the user's first dragging operation on the interactive interface, the template generation device displays the target outline shape at the dragged position, such as at the position corresponding to the outer outline of the target object in the first image displayed on the interactive interface. The user can adjust the size of the target outline shape to match the outer outline of the target object. After detecting the user's second adjustment operation on the interactive interface, the template generation device displays the adjusted target outline shape, such as displaying a target outline shape whose size matches the outer outline of the target object. In this way, the template generation device can generate the curve of the target outline shape based on the touch points within a preset range of the user-adjusted target outline shape, serving as the drawing edge of the target object. Through simple operations such as dragging and resizing the selected target outline shape, users can efficiently perform edge drawing operations by adjusting the target outline shape, improving the convenience of user operation.
[0182] Among them, methods for generating curves based on touch points include discrete point interpolation and curve fitting, etc.
[0183] This allows users to complete line drawing operations more quickly and conveniently using the outline shape control displayed on the interactive interface. Furthermore, the preset outline shape control is more accurate. When the outline of the target object is a standard geometric shape such as a circle, ellipse, or rectangle, the outline of the target object can be drawn quickly and accurately, improving the accuracy of the drawn edges and thus improving the accuracy of the generated target object model.
[0184] The following describes another implementation method for step S202, which responds to the edge drawing operation and displays the drawn edge in the interactive interface.
[0185] In one embodiment of this application, the drawn drawing edge can be displayed in the interactive interface in the following manner: the user can select the structure diagram of the target object in the interactive interface, and in response to the selection operation of the structure diagram of the target object in the first image displayed in the interactive interface, the outline of the structure diagram of the target object is loaded; according to the pose of the target object in the first image, the loaded outline is adjusted, the adjusted outline is displayed in the interactive interface, and the adjusted outline is used as the drawing edge of the target object.
[0186] The edge drawing operation can include a structure diagram selection operation, where the structure diagram of the target object can be a design drawing, CAD drawing, or other similar document.
[0187] Specifically, a "Load Structure Diagram" button can be set in the interactive interface. After the user triggers the "Load Structure Diagram" button, they can select the structure diagram corresponding to the target object, thus realizing the selection operation of the structure diagram of the target object in the first image displayed in the interactive interface.
[0188] The following describes how to adjust the loaded contour lines according to the pose of the target object in the first image.
[0189] In one implementation, the loaded contour line is adjusted to the target pose, and the adjusted contour line is displayed on the layer above the first image in the interactive interface.
[0190] The target pose is defined as the pose of the target object such that the edges of the target object in the first image satisfy the matching condition with the loaded contour line.
[0191] The method for determining the target pose is explained below.
[0192] In one approach, the loaded contour line can be displayed on the layer above the first image displayed in the interactive interface. Position adjustment buttons, pose adjustment buttons, and scale adjustment buttons can be provided for the loaded contour line. Users can adjust the position, pose, and scale of the loaded contour line using these buttons in the interactive interface. The template generation device can adjust the position, pose, and scale of the loaded contour line according to the adjustment instructions of the position and pose adjustment buttons, and use the adjusted position and pose as the target pose.
[0193] In another approach, edge extraction can be performed on the first image to obtain a first edge. The first edge and the loaded contour line can be matched to determine the pose of the loaded contour line that results in the highest matching degree, which is then used as the target pose.
[0194] In this way, the loaded contour lines can be adjusted to match the target pose of the target object's edge, improving the accuracy of the contour lines displayed in the interactive interface, improving the accuracy of the drawn edges, and thus improving the accuracy of the template generated for the target object.
[0195] The following describes another implementation method for adjusting the loaded contour lines according to the pose of the target object in the first image.
[0196] Obtain a first scale for the structural diagram; obtain a second scale between the target object in the first image and the target object in the actual scene. Based on the first and second scales, adjust the scale of the loaded contour lines. Display the adjusted loaded contour lines on the interactive interface according to the pose of the target object in the first image.
[0197] Specifically, the structural diagram of the target object is marked with a first scale bar representing the scale of the target object in the structural diagram and the scale of the target object in the actual scene. The template generation device can load the first scale bar from the attribute information of the structural diagram. When the image acquisition device acquires the first image, a calibration board can be used to calibrate and record the second scale bar between the scale of the target object in the acquired first image and the scale of the target object in the actual scene. In this way, the scale of the target object in the actual scene will not change. Therefore, the template generation device can establish the proportional relationship between the target object in the first image and the target object in the structural diagram using the first and second scale bars, and then adjust the scale of the loaded contour lines to the same scale as the target object in the first image.
[0198] This allows for easier adjustment of the scale of the loaded outline, simplifying user operations and making it easier for users to generate templates for target objects.
[0199] In this way, the outline of the target object's structure diagram can be selected as the drawing edge of the target object. The outline of the target object's structure diagram is more accurate, and the drawing edge of the target object can be drawn more quickly and accurately. The second edge generated using such a drawing edge is more accurate, thereby improving the accuracy of generating the template of the target object.
[0200] In one embodiment of this application, taking the first image provided in FIG3b as an example, if edge extraction is directly performed on the image and the extracted edges are used as templates for the target object, the resulting template can be seen in FIG7a, which provides a schematic diagram of a target object template. It can be seen that in FIG7a, due to the indistinct edge traces at the intersection of the two circles, it is difficult to extract the edge lines at the junctions of the target object and other circular target objects. Furthermore, other interferences in the target object in the first image can lead to excessive interfering edge lines in the target object template, such as the messy lines in the middle of FIG7a.
[0201] If the template generation is performed using the scheme provided in the embodiments of this application, the resulting template can be seen in Figure 7b, which provides another schematic diagram of a target object template. It is evident that the drawn target object template is more accurate in areas with weak edge strength and can also avoid other interference from the target object in the first image.
[0202] Corresponding to the above template generation method, this application provides a template generation device. Referring to Figure 8, which provides a schematic diagram of a template generation device, the device includes:
[0203] The first image display module 801 is used to display the first image of the target object in the interactive interface.
[0204] The second edge determination module 802 is used to respond to the edge drawing operation of the target object in the first image displayed on the interactive interface, and determine the second edge of the target object in the first image based on the drawn edge drawn by the edge drawing operation and / or the first edge of the target object extracted from the first image.
[0205] Template generation module 803 is used to generate a template for the target object based on the second edge.
[0206] As can be seen from the above, in the solution provided by the embodiments of this application, the second edge is used to generate the template of the target object. The second edge is determined based on the drawn edge and the first edge. The first edge is obtained by edge extraction, and the drawn edge is obtained by drawing the edge of the target object in the first image displayed on the interactive interface. Therefore, the position of the real edge of the target object can be determined more accurately based on the drawn edge, reducing the influence of interference information in the first image of the target object on the template generation. The second edge determined by combining the drawn edge and the first edge can more accurately represent the real edge of the target object. The second edge integrates the edge information provided by both the drawn edge and the first edge, and thus an accurate template of the target object can be generated based on the second edge.
[0207] In one embodiment of this application, the second edge determination module is specifically used to respond to the edge drawing operation in the following manner: in response to the line drawing operation of the touch object on the first image displayed on the interactive interface, the module collects the touch points of the touch object on the first image; obtains the curve generated based on the collected touch points as the drawing edge of the target object; and displays the drawing edge in the interactive interface.
[0208] In this way, the first image displayed on the interactive interface allows users to clearly see the image used to generate the template. Furthermore, by drawing lines on the first image displayed on the interactive interface using touch objects, users can obtain more accurate drawing edges. Combining the more accurate drawing edges drawn by the user using touch objects with the first edge can reduce interference in the first image, thereby generating a more accurate template for the target object.
[0209] In one embodiment of this application, the second edge determination module is specifically used to obtain an object contour line generated based on the collected touch points as the drawing edge of the target object, wherein the object contour line includes: the outer contour line and / or the inner contour line of the target object, and the object contour line includes: a closed curve and / or a non-closed curve.
[0210] This allows for the flexible drawing of closed and / or open contours of objects. Such curve generation can accommodate the outer and / or inner contours of objects with a wider range of shapes, simplifying line drawing operations and improving the ease of template generation. Furthermore, drawing the outer and inner contours of an object more accurately represents its contour features, resulting in more precise drawn edges and thus improving the accuracy of generating templates for the target object.
[0211] In one embodiment of this application, the interactive interface displays a contour shape control. The second edge determination module is further configured to determine the target contour shape corresponding to the selected target control in response to a selection operation on the contour shape control; specifically, it is configured to generate a curve of the target contour shape based on the collected touch points, as the drawing edge of the target object.
[0212] This allows users to complete line drawing operations more quickly and conveniently using the outline shape control displayed on the interactive interface. Furthermore, the preset outline shape control is more accurate. When the outline of the target object is a standard geometric shape such as a circle, ellipse, or rectangle, the outline of the target object can be drawn quickly and accurately, improving the accuracy of the drawn edges and thus improving the accuracy of the generated target object model.
[0213] In one embodiment of this application, the second edge determination module is further configured to, in response to a first operation of dragging the target contour shape on the interactive interface, display the target contour shape at the position after dragging; in response to a second operation of adjusting the size of the target contour shape on the interactive interface, display the adjusted target contour shape; and generate a curve of the target contour shape based on touch points within a preset range of the adjusted target contour shape, as the drawing edge of the target object.
[0214] By allowing users to easily drag and resize the selected target outline shape, edge drawing can be performed efficiently, improving user convenience.
[0215] In one embodiment of this application, the second edge determination module is further configured to determine whether the drawing edge displayed in the interactive interface meets the drawing requirements; if the determination is yes, then the step of determining the second edge of the target object in the first image is performed by drawing the drawing edge based on the edge drawing operation and the first edge of the target object extracted from the first image.
[0216] The following methods should be used to determine whether the displayed drawing edges meet the drawing requirements:
[0217] If the user clicks the "Draw OK" button on the interactive interface, the displayed drawing edges will meet the drawing requirements.
[0218] or
[0219] If the user does not perform edge drawing operations on the target object in the first image displayed on the interactive interface within a time limit greater than the preset operation time, then it is determined that the displayed drawing edges meet the drawing requirements.
[0220] Determining the drawing edge in this way satisfies the drawing requirements, and then determining the second edge of the target object in the first image based on the drawing edge and the first edge, can improve the accuracy of generating the second edge.
[0221] In one embodiment of this application, the second edge determination module is specifically configured to respond to the edge drawing operation in the following manner: in response to the selection operation of the structure map of the target object in the first image displayed on the interactive interface, load the contour line in the structure map of the target object; adjust the loaded contour line according to the pose of the target object in the first image, display the adjusted contour line in the interactive interface, and use the adjusted contour line as the drawing edge of the target object.
[0222] In this way, the outline of the target object's structure diagram can be selected as the drawing edge of the target object. The outline of the target object's structure diagram is more accurate, and the drawing edge of the target object can be drawn more quickly and accurately. The second edge generated using such a drawing edge is more accurate, thereby improving the accuracy of generating the template of the target object.
[0223] In one embodiment of this application, the second edge determination module is specifically used to adjust the loaded contour line to a target pose, wherein the target pose is: the pose of the target object such that the edge of the target object in the first image and the loaded contour line meet the matching conditions; and the adjusted contour line is displayed on the layer above the first image in the interactive interface.
[0224] In this way, the loaded contour lines can be adjusted to match the target pose of the target object's edge, improving the accuracy of the contour lines displayed in the interactive interface, improving the accuracy of the drawn edges, and thus improving the accuracy of the template generated for the target object.
[0225] In one embodiment of this application, the second edge determination module is specifically used to obtain a first scale of the structural diagram; obtain a second scale between the target object in the first image and the target object in the actual scene; adjust the scale of the loaded contour line based on the first scale and the second scale; and display the adjusted loaded contour line on the interactive interface according to the pose of the target object in the first image.
[0226] This allows for easier adjustment of the scale of the loaded outline, simplifying user operations and making it easier for users to generate templates for target objects.
[0227] In one embodiment of this application, the second edge determination module is specifically used for: generating a first mask image of the drawn edge based on the drawn edge; obtaining the edge polarity of the edge point corresponding to the drawn edge in the first mask image along a set direction as the first edge polarity, wherein the edge polarity represents the direction of gray value change of the pixels on both sides of the edge point along the set direction; obtaining the edge polarity of the edge point corresponding to the first edge in a second mask image along a set direction as the second edge polarity, wherein the second mask image is: a mask image obtained by edge extraction of the first image; determining the target edge point in the drawn edge based on the obtained first edge polarity and second edge polarity, wherein the first edge polarity of the target edge point is opposite to the second edge polarity of the corresponding edge point in the first edge; and obtaining the second edge of the target object in the first image based on the determined target edge point.
[0228] As can be seen from the above, the target edge point is the edge point whose polarity is opposite to that of the second edge point of the corresponding edge point in the first edge. In this way, by drawing the edge polarity of the edge and the edge polarity of the first edge respectively, the edge characteristics of the drawn edge and the first edge can be combined to generate the second edge more accurately, and thus generate a more accurate template of the target object.
[0229] In one embodiment of this application, the second edge determination module is specifically used for: determining matching edge point pairs in the drawn edge and the first edge, wherein each matching edge point pair includes an edge point in the drawn edge and an edge point in the first edge; for a first type of edge point pair, determining the edge points belonging to the drawn edge in the first type of edge point pair as edge points in the second edge of the target object in the first image, wherein the first type of edge point pair is: a matching edge point pair where the distance between two edge points is less than a preset distance threshold; for a second type of edge point pair, using the edge points belonging to the first edge in the second type of edge point pair to correct the edge points belonging to the drawn edge, obtaining corrected points, which are used as edge points in the second edge of the target object in the first image, wherein the second type of edge point pair is: the edge point pairs excluding the first type of edge points in the determined matching edge point pairs.
[0230] As can be seen from the above, this method can correct the edge points of the drawn edge when the difference between the drawn edge and the first edge is too large, reduce the impact of the deviation of the drawn edge on the second edge, improve the accuracy of the second edge determined based on the drawn edge and the first edge, and thus improve the accuracy of the generated target object template.
[0231] This application also provides an electronic device, as shown in FIG9, including:
[0232] Memory 901 is used to store computer programs;
[0233] The processor 902, when executing the program stored in the memory 901, implements the template generation method in any of the above embodiments.
[0234] Furthermore, the aforementioned electronic device may also include a communication bus and / or a communication interface, with the processor 902, communication interface, and memory 901 communicating with each other via the communication bus.
[0235] The communication bus mentioned in the above electronic devices can be a Peripheral Component Interconnect (PCI) bus or an Extended Industry Standard Architecture (EISA) bus, etc. This communication bus can be divided into address bus, data bus, control bus, etc. For ease of illustration, only one thick line is used to represent it in the diagram, but this does not mean that there is only one bus or one type of bus.
[0236] The communication interface is used for communication between the aforementioned electronic devices and other devices.
[0237] The memory may include random access memory (RAM) or non-volatile memory (NVM), such as at least one disk storage device. Optionally, the memory may also be at least one storage device located remotely from the aforementioned processor.
[0238] The processors mentioned above can be general-purpose processors, including central processing units (CPUs), network processors (NPs), etc.; they can also be digital signal processors (DSPs), application-specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), or other programmable logic devices, discrete gate or transistor logic devices, or discrete hardware components.
[0239] In another embodiment provided in this application, a computer-readable storage medium is also provided, which stores a computer program that, when executed by a processor, implements the steps of any of the template generation methods described above.
[0240] In another embodiment provided in this application, a computer program product containing instructions is also provided, which, when run on a computer, causes the computer to execute any of the template generation methods described above.
[0241] In the above embodiments, implementation can be achieved entirely or partially through software, hardware, firmware, or any combination thereof. When implemented using software, it can be implemented entirely or partially in the form of a computer program product. The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, all or part of the processes or functions described in the embodiments of this application are generated. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions can be stored in a computer-readable storage medium or transmitted from one computer-readable storage medium to another. For example, the computer instructions can be transmitted from one website, computer, server, or data center to another website, computer, server, or data center via wired (e.g., coaxial cable, fiber optic, digital subscriber line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.) means. The computer-readable storage medium can be any available medium that a computer can access or a data storage device such as a server or data center that integrates one or more available media. The available medium can be a magnetic medium (e.g., floppy disk, hard disk, magnetic tape), an optical medium (e.g., DVD), or a solid-state drive (SSD), etc.
[0242] It should be noted that, in this document, relational terms such as "first" and "second" are used only to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Furthermore, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitations, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes said element.
[0243] The various embodiments in this specification are described in a related manner. Similar or identical parts between embodiments can be referred to mutually. Each embodiment focuses on describing the differences from other embodiments. In particular, the embodiments of apparatus, electronic devices, storage media, and computer program products are basically similar to the method embodiments, so the descriptions are relatively simple; relevant parts can be referred to the descriptions of the method embodiments.
[0244] The above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of the present invention should be included within the scope of protection of the present invention.
Claims
1. A template generation method characterized by, The method includes: Display the first image of the target object in the interactive interface; In response to an edge drawing operation of a target object in a first image displayed on the interactive interface, a second edge of the target object in the first image is determined based on the drawn edge drawn by the edge drawing operation and / or the first edge of the target object extracted from the first image; Based on the second edge, a template for the target object is generated.
2. The method of claim 1, wherein, Respond to the edge drawing operation in the following manner: In response to a line-drawing operation of a touch object on a first image displayed on the interactive interface, the touch points of the touch object on the first image are collected; Obtain the curve generated based on the collected touch points, and use it as the drawing edge of the target object; The drawn edges are displayed in the interactive interface.
3. The method of claim 2, wherein, The step of obtaining the curve generated based on the collected touch points as the drawing edge of the target object includes: Obtain the object contour line generated based on the collected touch points, as the drawing edge of the target object, wherein the object contour line includes: the outer contour line and / or the inner contour line of the target object, and the object contour line includes: closed curve and / or non-closed curve.
4. The method of claim 2, wherein, The interactive interface displays an outline shape control. Before collecting the touch point of the touch object on the first image displayed on the interactive interface in response to the line drawing operation of the touch object, the method further includes: In response to a selection operation on the outline shape control, the target outline shape corresponding to the selected target control is determined; The step of obtaining the curve generated based on the collected touch points as the drawing edge of the target object includes: Based on the collected touch points, a curve representing the outline shape of the target object is generated, which serves as the drawing edge of the target object.
5. The method of claim 4, wherein, After determining the target contour shape corresponding to the selected target control in response to a selection operation on the contour shape control, the method further includes: In response to a first operation of dragging the target outline shape on the interactive interface, the target outline shape is displayed at the position after dragging; In response to a second operation that adjusts the size of the target contour shape on the interactive interface, the adjusted target contour shape is displayed; The step of generating a curve representing the target contour shape based on the collected touch points, as the drawing edge of the target object, includes: Based on the touch points within a preset range of the adjusted target contour shape, a curve of the target contour shape is generated as the drawing edge of the target object.
6. The method of claim 2, wherein, After displaying the drawn edge in the interactive interface, the method further includes: Determine whether the drawing edges displayed in the interactive interface meet the drawing requirements; If the determination is yes, then the steps of drawing the edge based on the edge drawing operation and the first edge of the target object extracted from the first image are executed to determine the second edge of the target object in the first image; The following methods should be used to determine whether the displayed drawing edges meet the drawing requirements: If the user clicks the "Draw OK" button on the interactive interface, the displayed drawing edges will meet the drawing requirements. or If the user does not perform edge drawing operations on the target object in the first image displayed on the interactive interface within a time limit greater than the preset operation time, then it is determined that the displayed drawing edges meet the drawing requirements.
7. The method of claim 1, wherein, Respond to the edge drawing operation in the following manner: In response to a selection operation of the structure diagram of a target object in the first image displayed on the interactive interface, the outline of the structure diagram of the target object is loaded. The loaded contour lines are adjusted according to the pose of the target object in the first image, and the adjusted contour lines are displayed in the interactive interface and used as the drawing edge of the target object.
8. The method of claim 7, wherein, The step of adjusting the loaded contour line according to the pose of the target object in the first image and displaying the adjusted contour line in the interactive interface includes: The loaded contour line is adjusted to the target pose, wherein the target pose is the pose of the target object such that the edge of the target object in the first image and the loaded contour line satisfy the matching condition. The adjusted outline is displayed on the layer above the first image in the interactive interface.
9. The method of claim 7, wherein, The step of adjusting the loaded contour line according to the pose of the target object in the first image and displaying the adjusted contour line in the interactive interface includes: Obtain the first scale of the structural diagram; Obtain a second scale bar between the target object in the first image and the target object in the actual scene; Based on the first and second scales, the scale of the loaded contour lines is adjusted. Based on the pose of the target object in the first image, the adjusted loaded contour line is displayed on the interactive interface.
10. The method according to any one of claims 1-9, characterized in that, The determination of the second edge of the target object in the first image based on the drawn edge drawn by the edge drawing operation and / or the first edge of the target object extracted from the first image includes: Based on the drawn edges, a first mask image of the drawn edges is generated; The edge polarity of the edge point corresponding to the drawn edge in the first mask image along a set direction is obtained as the first edge polarity, wherein the edge polarity represents the direction of gray value change of the pixels on both sides of the edge point along the set direction. The edge polarity of the edge point corresponding to the first edge in the second mask image along a set direction is obtained as the second edge polarity, wherein the second mask image is: the mask image obtained by edge extraction of the first image; Based on the obtained first edge polarity and second edge polarity, target edge points in the drawn edge are determined, wherein the first edge polarity of the target edge point is opposite to the second edge polarity of the corresponding edge point in the first edge; Based on the determined target edge points, the second edge of the target object in the first image is obtained.
11. The method according to any one of claims 1-9, characterized in that, The determination of the second edge of the target object in the first image based on the drawn edge drawn by the edge drawing operation and / or the first edge of the target object extracted from the first image includes: Determine matching edge point pairs in the drawn edge and the first edge, wherein each matching edge point pair includes an edge point in the drawn edge and an edge point in the first edge; For the first type of edge point pair, the edge points belonging to the drawn edge in the first type of edge point pair are determined as edge points in the second edge of the target object in the first image. The first type of edge point pair is: a matching edge point pair where the distance between two edge points is less than a preset distance threshold. For the second type of edge point pair, the edge points belonging to the first edge in the second type of edge point pair are used to correct the edge points belonging to the drawn edge, and the corrected points are used as the edge points in the second edge of the target object in the first image. The second type of edge point pair is: the edge point pair excluding the first type of edge points in the determined matching edge point pair.
12. A template generation apparatus characterized by comprising: The device includes: The first image display module is used to display the first image of the target object in the interactive interface; The second edge determination module is used to respond to an edge drawing operation of a target object in a first image displayed on the interactive interface, and to determine a second edge of the target object in the first image based on the drawn edge drawn by the edge drawing operation and / or the first edge of the target object extracted from the first image. The template generation module is used to generate a template of the target object based on the second edge.
13. The apparatus according to claim 12, characterized in that, The second edge determination module is specifically used to respond to the edge drawing operation in the following manner: in response to the line drawing operation of the touch object on the first image displayed on the interactive interface, the touch point of the touch object on the first image is collected; Obtain a curve generated based on the collected touch points as the drawing edge of the target object; display the drawing edge in the interactive interface; and / or The second edge determination module is specifically used to respond to the edge drawing operation in the following manner: in response to the selection operation of the structure map of the target object in the first image displayed on the interactive interface, loading the outline of the structure map of the target object; adjusting the loaded outline according to the pose of the target object in the first image, displaying the adjusted outline in the interactive interface, and using the adjusted outline as the drawing edge of the target object.
14. An electronic device, comprising: include: Memory, used to store computer programs; A processor, when executing a program stored in memory, implements the method described in any one of claims 1-11.
15. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a computer program that, when executed by a processor, implements the method described in any one of claims 1-11.