A ladder diagram analysis method, device, equipment, storage medium and program product
By acquiring and parsing the target image of the PLC, using component image templates to identify and segment images, and writing to configuration files, the application scenarios of ladder program migration between PLCs are solved, and cross-brand ladder program migration is realized, improving the Compatibility and versatility.
Patent Information
- Application Number
- CN202410911100.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-09
- Publication Date
- 2024-11-05
- Estimated Expiration
- 2044-07-09
AI Technical Summary
It is difficult to migrate ladder diagram programs between PLCs of different brands, and the existing technology cannot effectively solve the problem of limited migration application scenarios caused by PLC manufacturers not publishing file formats.
By obtaining the target image of the PLC, matching it using the component image template, segmenting the image to obtain component, text and connection line information, parsing this information and writing it into the configuration file of the target PLC, and generating a compatible ladder diagram program.
It realizes the analysis and migration of ladder diagram programs, expands the application scenarios of the program, does not rely on the file format of the PLC to be migrated, and improves the universality and compatibility of migration.
Smart Images

Figure CN118470359B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the technical field of ladder diagrams, and in particular to a ladder diagram analysis method, device, equipment, storage medium and program product. Background Art
[0002] In recent years, with the continuous expansion of the number of automation companies, the number of manufacturers producing programmable logic controllers (PLCs) has also increased. Ladder diagrams are the most commonly used programming language for PLC programming. They are intuitive and easy to understand, and can be easily mastered by factory electrical personnel. PLCs of different brands are incompatible with each other, making it very difficult to migrate ladder diagram programs. After users have built a system program for a PLC, if they need to migrate it to a PLC of a different brand, they need to rewrite the entire program.
[0003] In the prior art, in order to avoid rewriting the program, the ladder diagram program can be parsed and converted to achieve the migration of the ladder diagram program. Specifically, the component description information and configuration text information of the ladder diagram program can be obtained according to the file format of the ladder diagram program of the PLC of different brands, so as to use this information to implement the analysis of the ladder diagram program and then migrate it.
[0004] However, PLC manufacturers often do not disclose the file format of their ladder diagram programs, making such methods unapplicable. Therefore, the above ladder diagram program migration solution has the problem of limited application scenarios. Summary of the invention
[0005] The present application provides a ladder diagram analysis method, device, equipment, storage medium and program product to solve the problem of limited migration application scenarios of ladder diagram programs.
[0006] In a first aspect, the present application provides a ladder diagram analysis method, the method comprising:
[0007] Acquire a target image of a first ladder diagram of a first PLC;
[0008] Matching the target image with at least one pre-stored component image template to obtain first information of each component in the first ladder diagram, the first information including the type of the component and the position of the component in the first ladder diagram;
[0009] According to the first information of each component, the target image is segmented to obtain a component image set, a text image set and a connection line image set, wherein the component image set includes a regional image of at least one component in the target image, the text image set includes a regional image of texts corresponding to each component in the target image, and the connection line image set includes a regional image of connection lines connecting each component in the target image;
[0010] Parsing the component image set, the text image set and the connection line image set to obtain second information of each component in the first ladder diagram, the second information including text corresponding to the component and connection relationship between the components;
[0011] According to the configuration file format of the second ladder diagram of the second PLC, the first information and the second information are written into the configuration file in the second PLC to generate the second ladder diagram on the second PLC according to the configuration file.
[0012] Optionally, segmenting the target image according to the first information of each component to obtain a component image set, a text image set, and a connection line image set includes:
[0013] According to the position of each component in the first ladder diagram, the target image is segmented to obtain a component image set;
[0014] According to the preset width interval of the connection line, the connection line images are screened out from the target area of the target image to obtain a connection line image set, wherein the target area includes an area in the target image except the component image set;
[0015] The area in the target area except the connection line image set is segmented to obtain a text image set.
[0016] Optionally, after segmenting the area in the target area except the connection line image set to obtain the text image set, the method further includes:
[0017] Each connecting line image in the connecting line image set is extended to both ends of the connecting line by a preset number of pixels.
[0018] Optionally, parsing the component image set, the text image set, and the connection line image set to obtain second information of each component in the first ladder diagram includes:
[0019] Determine the text corresponding to each component according to the positional relationship between the image area of each component in the target image and the image area of each text in the target image;
[0020] The component image set and the connection line image set are parsed to obtain the connection relationship between the multiple components.
[0021] Optionally, the component image set and the connection line image set are parsed to obtain connection relationships between multiple components, including:
[0022] Matching the region image of each component in the component image set with the region image of each connection line in the connection line image set, and obtaining the connection line corresponding to the component when the region image of the component and the region image of the connection line are matched successfully;
[0023] Along each connection line of the component, the component image set is traversed to obtain the connection relationship between the component and other components.
[0024] Optionally, before matching the target image with at least one pre-stored component image template to obtain first information of each component in the first ladder diagram, the method further includes:
[0025] A plurality of standard ladder diagram images are acquired, and the type and shape of each component are extracted from the plurality of standard ladder diagram images to obtain at least one component image template.
[0026] In a second aspect, the present application provides a ladder diagram analysis device, the device comprising:
[0027] An acquisition module, used for acquiring a target image of a first ladder diagram of a first PLC;
[0028] A component matching module, used for matching the target image with at least one pre-stored component image template to obtain first information of each component in the first ladder diagram, wherein the first information includes the type of the component and the position of the component in the first ladder diagram;
[0029] a segmentation module, configured to segment the target image according to the first information of each component, and obtain a component image set, a text image set, and a connection line image set, wherein the component image set includes a regional image of at least one component in the target image, the text image set includes regional images of texts corresponding to each component in the target image, and the connection line image set includes regional images of connection lines connecting each component in the target image;
[0030] A parsing module, used to parse the component image set, the text image set and the connection line image set to obtain second information of each component in the first ladder diagram, wherein the second information includes text corresponding to the component and connection relationships between the components;
[0031] A generating module is used to write the first information and the second information into a configuration file in the second PLC according to the configuration file format of the second ladder diagram of the second PLC, so as to generate a second ladder diagram on the second PLC according to the configuration file.
[0032] In a third aspect, the present application provides an electronic device, comprising: a processor, and a memory communicatively connected to the processor;
[0033] Memory stores computer-executable instructions;
[0034] When the processor executes the computer execution instructions stored in the memory, it is used to implement a ladder diagram parsing method of the first aspect of the invention.
[0035] In a fourth aspect, the present application provides a computer-readable storage medium, in which computer execution instructions are stored. When the computer execution instructions are executed by a processor, a ladder diagram parsing method is used to implement the invention content of the first aspect.
[0036] In a fifth aspect, the present application provides a computer program product, including a computer program, which, when executed by a processor, is used to implement a ladder diagram parsing method of the invention content of the first aspect.
[0037] The present application provides a ladder diagram parsing method, device, equipment, storage medium and program product, including: obtaining a target image of a first ladder diagram of a first PLC; matching the target image with at least one pre-stored component image template to obtain first information of each component in the first ladder diagram; segmenting the target image according to the first information of each component to obtain a component image set, a text image set and a connection line image set; parsing the component image set, the text image set and the connection line image set to obtain second information of each component in the first ladder diagram; writing the first information and the second information into the configuration file in the second PLC according to the configuration file format of the second ladder diagram of the second PLC to generate a second ladder diagram on the second PLC according to the configuration file. The present application can extract the first information and the second information of each component in the ladder diagram from the ladder diagram through image analysis, realize the analysis and migration of the ladder diagram program, and does not need to obtain the file format of the ladder diagram program of the PLC to be migrated to realize the analysis of the ladder diagram program, thereby expanding the application scenario of the migration solution of the ladder diagram program. BRIEF DESCRIPTION OF THE DRAWINGS
[0038] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the following is a brief introduction to the drawings required for use in the embodiments or the description of the prior art. Obviously, the drawings described below are some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.
[0039] Figure 1 A schematic diagram of a ladder diagram analysis method provided in an embodiment of the present application Figure 1 ;
[0040] Figure 2 A schematic diagram of a ladder diagram analysis method provided in an embodiment of the present application Figure 2 ;
[0041] Figure 3 An example of an image of a ladder diagram provided in an embodiment of the present application;
[0042] Figure 4 The component image template provided in the embodiment of the present application;
[0043] Figure 5 The result of component image template matching provided in the embodiment of the present application;
[0044] Figure 6 A set of component images provided for embodiments of the present application;
[0045] Figure 7 A mixed image set of text and connecting lines provided in an embodiment of the present application;
[0046] Figure 8 A set of connection line images provided in the embodiments of the present application;
[0047] Fig. 9 A text image set provided for an embodiment of the present application;
[0048] Fig.10 A mixed image set of elements and texts provided in an embodiment of the present application;
[0049] Fig.11 A set of images corresponding to the elements and texts provided in the embodiments of the present application;
[0050] Fig.12 A schematic diagram of the structure of a ladder diagram analysis device provided in an embodiment of the present application;
[0051] Fig.13 A schematic diagram of the structure of the electronic device hardware provided in an embodiment of the present application.
[0052] Reference numerals:
[0053] 300- ladder diagram analysis device;
[0054] 310 - acquisition module; 320 - component matching module; 330 - segmentation module; 340 - analysis module; 350 - generation module;
[0055] 400 - electronic device; 410 - processor; 420 - memory; 430 - communication component; 440 - bus. DETAILED DESCRIPTION
[0056] Exemplary embodiments will be described in detail herein, examples of which are shown in the accompanying drawings. When the following description refers to the drawings, the same numbers in different drawings represent the same or similar elements unless otherwise indicated. The implementations described in the following exemplary embodiments do not represent all implementations consistent with the present application. Instead, they are merely examples of devices and methods consistent with some aspects of the present application as detailed in the appended claims.
[0057] In the embodiments of the present application, words such as "first" and "second" are used to distinguish between identical or similar items with substantially the same functions and effects. Those skilled in the art will understand that words such as "first" and "second" do not limit the quantity and execution order, and words such as "first" and "second" do not necessarily limit the difference. It should be noted that in the embodiments of the present application, words such as "exemplary" or "for example" are used to indicate examples, illustrations or explanations. Any embodiment or design described as "exemplary" or "for example" in the present application should not be interpreted as being more preferred or more advantageous than other embodiments or design. Specifically, the use of words such as "exemplary" or "for example" is intended to present related concepts in a specific way. In the embodiments of the present application, "at least one" refers to one or more, and "more" refers to two or more.
[0058] It should be noted that the "at..." in the embodiment of the present application can be the instant when a certain situation occurs, or can be a period of time after a certain situation occurs, and the embodiment of the present application does not specifically limit this. In addition, the ladder diagram analysis method provided in the embodiment of the present application is only used as an example, and the ladder diagram analysis method can also include more or less content.
[0059] Figure 1 A schematic diagram of a ladder diagram analysis method provided in an embodiment of the present application Figure 1 .like Figure 1 As shown, the method includes:
[0060] S101, obtaining a target image of a first ladder diagram of a first PLC.
[0061] Specifically, the first PLC and the second PLC are PLCs of different brands, and the target image is an image of a ladder diagram to be migrated, that is, an image containing a ladder diagram program to be migrated is acquired.
[0062] S102: Match the target image with at least one pre-stored component image template to obtain first information of each component in the first ladder diagram.
[0063] The first information is the image information of each component. Specifically, the first information includes the type of the component and the position of the component in the first ladder diagram; the component image template is used to represent the component through an image, including the shape image and type information of at least one component. The template matching algorithm is used to match the target image with the component image template, identify the components in the target image, and then parse out the type of each component in the target image and the position of the component in the ladder diagram.
[0064] S103 . Segment the target image according to the first information of each component to obtain a component image set, a text image set, and a connection line image set.
[0065] Specifically, the component image set includes a regional image of at least one component in the target image, the text image set includes a regional image of the text corresponding to each component in the target image, and the connection line image set includes a regional image of the connection lines connecting each component in the target image. According to the position of each component in the ladder diagram, each component image is segmented from the target image to form a component image set, and text recognition technology can be used to recognize text images in the target image other than the components, and then each text image is segmented to form a text image set, thereby obtaining a connection line image set other than component images and text images.
[0066] S104: Analyze the component image set, the text image set, and the connection line image set to obtain second information of each component in the first ladder diagram.
[0067] Specifically, the second information includes the text corresponding to the component and the connection relationship between each component; the components and texts in the component image set and the text image set that are located in the same area of the target image are matched to determine the text corresponding to each component. According to the position of each component in the ladder diagram, the input connection line and the output connection line of each component in the connection line image set are identified, and the connection relationship between each component is analyzed along the input connection line and the output connection line. Further, the input end and the output end of the component can be marked in the component image set, and the component image set and the connection line image set are matched. The connection line connected to the input end of the component is used as the input connection line, and the connection line connected to the output end of the component is used as the output connection line. Furthermore, when the image is not rotated or flipped, that is, when the ladder diagram composed of the image is executed from top to bottom and from left to right, the input connection line and the output connection line can also be directly marked according to the connection line being located at different ends of the left and right of the component.
[0068] S105. Write the first information and the second information into a configuration file in the second PLC according to the configuration file format of the second ladder diagram of the second PLC, so as to generate a second ladder diagram on the second PLC according to the configuration file.
[0069] It is understandable that the ladder diagram parsing method of the embodiment of the present application can be used in the ladder diagram program migration scenario. In the scenario of migrating the ladder diagram program from the first PLC to the second PLC, the ladder diagram parsing method of the embodiment of the present application is used to parse the ladder diagram program on the first PLC before migration to obtain the first information and the second information of each component; then, obtain the configuration file format of the ladder diagram program of the second PLC; then, according to the configuration file format, write the first information and the second information into the configuration file of the ladder diagram program of the second PLC; finally, import the configuration file of the ladder diagram program of the second PLC into the software programming tool of the second PLC, so that the software programming tool of the second PLC automatically constructs the ladder diagram program.
[0070] A ladder diagram parsing method provided in an embodiment of the present application includes: acquiring a target image of a first ladder diagram of a first PLC; matching the target image with at least one pre-stored component image template to obtain first information of each component in the first ladder diagram; segmenting the target image according to the first information of each component to obtain a component image set, a text image set, and a connecting line image set; parsing the component image set, the text image set, and the connecting line image set to obtain second information of each component in the first ladder diagram; writing the first information and the second information into a configuration file in the second PLC according to the configuration file format of the second ladder diagram of the second PLC to generate a second ladder diagram on the second PLC according to the configuration file, thereby achieving the following technical effects: by segmenting the target image according to the first information of each component to obtain a component image set, a text image set, and a connecting line image set, and parsing the component image set, the text image set, and the connecting line image set to obtain the second information of each component in the ladder diagram, the problem of limited migration application scenarios of ladder diagram programs is solved.
[0071] Figure 2 A schematic diagram of a ladder diagram analysis method provided in an embodiment of the present application Figure 2 In this embodiment Figure 1 Based on the embodiment, the ladder diagram analysis method is described in detail. Figure 2 As shown, the method includes:
[0072] S201 . Acquire multiple images of standard ladder diagrams, and extract the type and shape of each component from the images of the multiple standard ladder diagrams to obtain at least one component image template.
[0073] Specifically, the standard ladder diagram is a standardized ladder diagram. Images of multiple standard ladder diagrams are obtained, and the types and shapes of different components such as normally open contacts, normally closed contacts, coils, etc. in the standard ladder diagram, as well as the different texts inside the components, are extracted to obtain image templates of different ladder diagram components.
[0074] S202, obtaining a target image of a first ladder diagram of a first PLC.
[0075] Specifically, Figure 3 An example of an image of a ladder diagram provided by an embodiment of the present invention; Figure 4 The component image template provided in the embodiment of the present application. In one example, the target image of the ladder diagram obtained is as follows Figure 3As shown in the figure, the components in the target image include: normally open contact "#Contact1", normally open contact "#Contact2", normally open contact "#Contact11", normally closed contact "#Contact3", normally closed contact "#Contact7", normally closed contact "#Contact8", timer "IEC_Timer_0_DB", coil "#CoilY6", coil "#Coil16", and logic components. In the text corresponding to the timer, "%DB1" is the data block name, "T#30MS" is the name of the timer setting condition, and the text corresponding to each logic component "#Real4", "#Real5", "#Real17", "#Real18", "#Int9", and "#Int10" are the intermediate variable names. An image template containing multiple components is shown in the figure below. Figure 4 As shown, the left side is the image of the component in the standard ladder diagram, and the right side is the component image template obtained based on the image of the component in the standard ladder diagram.
[0076] S203: Match the target image with at least one pre-stored component image template to obtain first information of each component in the first ladder diagram.
[0077] Specifically, Figure 5 The template matching algorithm is used to match the target image with the component image template. The matching result is shown in FIG. Figure 5 As shown, Figure 5 Including image templates of each component in the target image. Identify the components in the ladder diagram image, and parse out the type of each component in the ladder diagram and the position of the component in the ladder diagram.
[0078] S204, segmenting the target image according to the position of each component in the first ladder diagram to obtain a component image set; filtering out connecting line images from a target area of the target image according to a preset width interval of the connecting lines to obtain a connecting line image set, wherein the target area includes an area in the target image excluding the component image set.
[0079] Specifically, the component image set includes a regional image of at least one component in the target image, the text image set includes regional images of texts corresponding to each component in the target image, and the connection line image set includes regional images of connection lines connecting each component in the target image.
[0080] Figure 6 A set of component images provided for embodiments of the present application; Figure 7 A mixed image set of text and connecting lines provided in an embodiment of the present application; Figure 8The connection line image set provided by the embodiment of the present application. According to the position of each component in the ladder diagram, each component image is separated from the target image to form a component image set. The component image set is as follows: Figure 6 As shown, Figure 6 Including each component image in the target image. At the same time, after segmenting the component image, the target image also includes a connecting line image and a text image, that is, a mixed image set of text and connecting lines. The mixed image set of text and connecting lines is as follows: Figure 7 As shown, Figure 7 The target area includes the area of the target image other than the component image set, that is, the area of the mixed image set of text and connecting lines. The pixels of the connecting lines are significantly different from the horizontal pixels of the text. The preset width interval is determined according to the width range of the connecting line pixels, and then the connecting line images within the preset width interval are screened from the target area of the target image, that is, the mixed image set of text and connecting lines, to obtain a connecting line image set. The connecting line image set is as follows: Figure 8 As shown, Figure 8 Includes each connecting line image in the target image.
[0081] S205 , segmenting the area in the target area except the connection line image set to obtain a text image set.
[0082] Specifically, Fig. 9 The text image set provided by the embodiment of the present application. The connecting line images in the target area, i.e., the mixed image set of text and connecting lines, are segmented out, and the difference set of the mixed image set of text and connecting lines and the connecting line image set is taken to obtain the text image set. The text image set is as follows: Fig. 9 As shown, Fig. 9 Include each text image in the target image.
[0083] S206: Extend each connecting line image in the connecting line image set to two ends of the connecting line by a preset number of pixels.
[0084] Each connection line image is extended by a preset number of pixels to both ends of the connection line, and the extended connection line image set and the component image set have overlapping images, so as to facilitate the subsequent identification of input and output connection lines. The preset number can be set according to the specific situation to ensure that there are overlapping images. For example, for horizontal connection lines, when the image is not rotated or flipped, each connection line image is extended by a preset number of pixels to the left and right ends of the connection line.
[0085] S207 : Determine the text corresponding to each component according to the positional relationship between the image area of each component in the target image and the image area of each text in the target image.
[0086] Specifically, Fig.10 A mixed image set of elements and texts provided in an embodiment of the present application; Fig.11 The component image set and the text image set are combined to obtain a component and text mixed image set. The component and text mixed image set is as follows: Fig.10 As shown, Fig.10 Including each component, the name of each component or the name of the intermediate variable of each component, etc. The closed operation algorithm is used to process the component and text mixed image set, and the component image and text image with similar positions are expanded and connected to form a separate area. The area includes the component and the text corresponding to the component, and then the image set corresponding to the component and the text is obtained. The image set corresponding to the component and the text is as follows: Fig.11 As shown, Fig.11 Each black area in the image contains a ladder diagram component and a corresponding text image. Sort the regions in the image set corresponding to the component and text by row and then by column to ensure that their positional relationship corresponds to the ladder diagram. Traverse the sorted image set corresponding to the component and text, use optical character recognition (OCR) technology to recognize the text, and parse the text corresponding to the component.
[0087] S208, matching the region image of each component in the component image set with the region image of each connection line in the connection line image set, and obtaining the connection line corresponding to the component when the region image of the component and the region image of the connection line are matched successfully; traversing the component image set along each connection line of the component to obtain the connection relationship between the component and the remaining components.
[0088] Specifically, taking a component as an example, the image of the component is matched with the image of the connection line after the extension of the area where the component is located, and the intersection is processed to obtain the two connection lines corresponding to the component. When the image is not rotated or flipped, the left connection line of the component is used as the input connection line, and the right connection line is used as the output connection line. Along the input and output connection lines of the component, the component image set is traversed respectively to obtain the input connection relationship on the left side and the output connection relationship on the right side of the current component. Each component is processed in turn to parse the connection relationship of all components in the ladder diagram. Further, taking the left input relationship of the parsed component as an example, the image of the component is matched with the image of the connecting line after the component is extended in the area, and the intersection is taken to obtain the extended part of the left connecting line. The midpoint of the extended part of the connecting line is taken as the intersection of the component image and the connecting line image, and the left connecting line connected to the intersection is taken as the input connecting line. The component image set is matched with the extended connecting line image set, and the intersections of each component image and the connecting line image are traversed along the input connecting line. When the intersection of the target component is located on the left side of the center coordinate of the input connecting line, the connection relationship between the target component and the component is the left input connection, which can be stored in the form of a matrix in the ladder diagram. For example, a matrix a is defined. ij (n×n), a ij The matrix indicates whether element i is an input connection of element j, n is the number of elements, a ij It can take values of 0 and 1, where 0 indicates that component i is not the input connection of component j, and 1 indicates that component i is the input connection of component j.
[0089] S209. According to the configuration file format of the second ladder diagram of the second PLC, write the first information and the second information into the configuration file in the second PLC to generate the second ladder diagram on the second PLC according to the configuration file.
[0090] S209 is similar to S105 and will not be described in detail in this embodiment.
[0091] A ladder diagram parsing method provided by an embodiment of the present application includes: obtaining a target image of a first ladder diagram of a first PLC; matching the target image with at least one pre-stored component image template to obtain first information of each component in the first ladder diagram; segmenting the target image according to the first information of each component to obtain a component image set, a text image set, and a connection line image set; parsing the component image set, the text image set, and the connection line image set to obtain second information of each component in the first ladder diagram; writing the first information and the second information into a configuration file in the second PLC according to the configuration file format of the second ladder diagram of the second PLC, so as to generate a second ladder diagram on the second PLC according to the configuration file, thereby achieving the following technical effects: by using the first information of each component, the target image is segmented to obtain a component image set, a text image set, and a connection line image set; parsing the component image set, the text image set, and the connection line image set to obtain second information of each component in the first ladder diagram; and writing the first information and the second information into a configuration file in the second PLC according to the configuration file format of the second ladder diagram of the second PLC to generate a second ladder diagram on the second PLC according to the configuration file. According to the first information of each component, the target image is segmented to obtain a component image set, a text image set and a connection line image set, and the component image set, text image set and connection line image set are parsed to obtain the second information of each component in the ladder diagram, thereby solving the problem of limited application scenarios of ladder diagram program migration; the ladder diagram components are parsed by template matching, and the parsing of each component does not depend on other components, thereby providing the possibility of adopting parallel computing technology and improving the parsing efficiency; the component type, connection relationship and text of the ladder diagram are parsed step by step, thereby solving the problem that complex ladder diagrams are difficult to parse accurately; the component image template is replaced according to the PLC ladder diagram components of different manufacturers to adapt to the ladder diagram parsing of different PLC manufacturers, thereby having universality and compatibility.
[0092] The embodiment of the present application can divide the functional modules of the electronic device or the main control device according to the above method example. For example, each functional module can be divided according to each function, or two or more functions can be integrated into one processing unit. The above integrated unit can be implemented in the form of hardware or in the form of software functional modules. It should be noted that the division of modules in the embodiment of the present application is schematic and is only a logical function division. There may be other division methods in actual implementation.
[0093] Fig.12 A schematic diagram of the structure of a ladder diagram analysis device provided in an embodiment of the present application. Fig.12 As shown, the ladder diagram analyzing device 300 includes: an acquisition module 310 , a component matching module 320 , a segmentation module 330 , a parsing module 340 and a generation module 350 .
[0094] The acquisition module 310 is used to acquire a target image of a first ladder diagram of a first PLC.
[0095] The component matching module 320 is used to match the target image with at least one pre-stored component image template to obtain first information of each component in the first ladder diagram, where the first information includes the type of the component and the position of the component in the first ladder diagram.
[0096] The segmentation module 330 is used to segment the target image according to the first information of each component to obtain a component image set, a text image set and a connection line image set. The component image set includes a regional image of at least one component in the target image, the text image set includes a regional image of the text corresponding to each component in the target image, and the connection line image set includes a regional image of the connection lines connecting each component in the target image.
[0097] The parsing module 340 is used to parse the component image set, the text image set and the connection line image set to obtain second information of each component in the first ladder diagram, wherein the second information includes text corresponding to the component and connection relationships between the components.
[0098] The generating module 350 is used to write the first information and the second information into the configuration file in the second PLC according to the configuration file format of the second ladder diagram of the second PLC, so as to generate the second ladder diagram on the second PLC according to the configuration file.
[0099] Optionally, the segmentation module 330 is specifically configured to:
[0100] According to the position of each component in the first ladder diagram, the target image is segmented to obtain a component image set; according to the preset width interval of the connecting line, the connecting line image is screened out from the target area of the target image to obtain a connecting line image set, and the target area includes the area in the target image except the component image set; the area in the target area except the connecting line image set is segmented to obtain a text image set.
[0101] Optionally, the segmentation module 330 is specifically configured to:
[0102] Each connecting line image in the connecting line image set is extended to both ends of the connecting line by a preset number of pixels.
[0103] Optionally, the parsing module 340 is specifically used for:
[0104] According to the positional relationship between the image area of each component in the target image and the image area of each text in the target image, the text corresponding to each component is determined; the component image set and the connection line image set are analyzed to obtain the connection relationship between multiple components.
[0105] Optionally, the parsing module 340 is specifically used for:
[0106] The regional image of each component in the component image set is matched with the regional image of each connecting line in the connecting line image set, and when the regional image of the component and the regional image of the connecting line are matched successfully, the connecting line corresponding to the component is obtained; along each connecting line of the component, the component image set is traversed to obtain the connection relationship between the component and the remaining components.
[0107] Optionally, the acquisition module 310 is specifically configured to:
[0108] A plurality of standard ladder diagram images are acquired, and the type and shape of each component are extracted from the plurality of standard ladder diagram images to obtain at least one component image template.
[0109] A ladder diagram analysis device provided in this embodiment can execute a ladder diagram analysis method of the above embodiment, and its implementation principle and technical effect are similar, which will not be described in detail in this embodiment.
[0110] In the specific implementation of the aforementioned ladder diagram analysis device, each module can be implemented as a processor, and the processor can execute computer execution instructions stored in the memory, so that the processor executes the aforementioned ladder diagram analysis method.
[0111] Fig.13 This is a schematic diagram of the structure of the electronic device hardware provided in the embodiment of the present application. Fig.13 As shown, the electronic device 400 includes: at least one processor 410 and a memory 420. The electronic device 400 also includes a communication component 430. The processor 410, the memory 420 and the communication component 430 are connected via a bus 440.
[0112] In a specific implementation process, at least one processor 410 executes the computer execution instructions stored in the memory 420, so that at least one processor 410 executes a ladder diagram parsing method executed by the electronic device side as described above.
[0113] The specific implementation process of the processor 410 can be found in the above method embodiment, and its implementation principle and technical effect are similar, so this embodiment will not be repeated here.
[0114] In the above embodiments, it should be understood that the processor may be a central processing unit (CPU), or other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), etc. The general-purpose processor may be a microprocessor or the processor may be any conventional processor, etc. The steps of the method disclosed in the invention may be directly embodied as being executed by a hardware processor, or may be executed by a combination of hardware and software modules in the processor.
[0115] The memory may include high-speed random-access memory (RAM) and may also include non-volatile memory (NVM), such as at least one disk storage.
[0116] The bus can be an Industry Standard Architecture (ISA) bus, a Peripheral Component Interconnect (PCI) bus, or an Extended Industry Standard Architecture (EISA) bus, etc. The bus can be divided into an address bus, a data bus, a control bus, etc. For ease of representation, the bus in the drawings of this application is not limited to only one bus or one type of bus.
[0117] The above functions implemented by the electronic device and the main control device introduce the scheme provided by the embodiment of the present application. It is understandable that in order to implement the above functions, the electronic device or the main control device includes a hardware structure and / or software module corresponding to each function. In combination with the units and algorithm steps of each example described in the embodiment disclosed in the embodiment of the present application, the embodiment of the present application can be implemented in the form of hardware or a combination of hardware and computer software. Whether a function is executed in the form of hardware or computer software driving hardware depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementation should not be considered to exceed the scope of the technical solution of the embodiment of the present application.
[0118] The present application also provides a computer-readable storage medium, in which computer-executable instructions are stored. When a processor executes the computer-executable instructions, it is used to implement the above ladder diagram parsing method.
[0119] The above-mentioned readable storage medium can be any type of volatile or non-volatile storage device or a combination thereof, such as static random access memory (SRAM), electrically erasable programmable read-only memory (EEPROM), erasable programmable read-only memory (EPROM), programmable read-only memory (PROM), read-only memory (ROM), magnetic memory, flash memory, magnetic disk or optical disk. The readable storage medium can be any available medium that can be accessed by a general or special-purpose computer.
[0120] An exemplary readable storage medium is coupled to a processor so that the processor can read information from the readable storage medium and write information to the readable storage medium. Of course, the readable storage medium can also be a component of the processor. The processor and the readable storage medium can be located in a dedicated integrated circuit. Of course, the processor and the readable storage medium can also exist as discrete components in an electronic device or a main control device.
[0121] The present application also provides a computer program product, which includes: a computer program, which is stored in a readable storage medium. At least one processor of an electronic device can read the computer program from the readable storage medium, and at least one processor executes the computer program so that the electronic device executes the solution provided by any of the above embodiments.
[0122] Those skilled in the art can understand that all or part of the steps of implementing the above-mentioned method embodiments can be completed by hardware related to program instructions. The aforementioned program can be stored in a computer-readable storage medium. When the program is executed, the steps of the above-mentioned method embodiments are executed; and the aforementioned storage medium includes: ROM, RAM, disk or optical disk and other media that can store program codes.
[0123] So far, the technical solution of the present application has been described in conjunction with the preferred embodiments shown in the accompanying drawings. However, it is easy for those skilled in the art to understand that the protection scope of the present application is obviously not limited to these specific embodiments, and the above embodiments are only used to illustrate the technical solution 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 replace some or all of the technical features therein by equivalents. However, these modifications or replacements do not cause the essence of the corresponding technical solutions to deviate from the scope of the technical solutions of the embodiments of the present application.
Claims
1. A ladder diagram analysis method, It is characterized in that include: Acquire a target image of a first ladder diagram of a first PLC; Matching the target image with at least one pre-stored component image template to obtain first information of each component in the first ladder diagram, wherein the first information includes the type of the component and the position of the component in the first ladder diagram; According to the first information of each of the components, the target image is segmented to obtain a component image set, a text image set and a connection line image set, wherein the component image set includes a regional image of at least one component in the target image, the text image set includes a regional image of text corresponding to each component in the target image, and the connection line image set includes a regional image of connection lines connecting each component in the target image; Parsing the component image set, the text image set and the connection line image set to obtain second information of each component in the first ladder diagram, wherein the second information includes text corresponding to the component and connection relationships between the components; According to the configuration file format of the second ladder diagram of the second PLC, write the first information and the second information into the configuration file in the second PLC to generate the second ladder diagram on the second PLC according to the configuration file; Wherein, generating a second ladder diagram on the second PLC according to the configuration file includes: Importing the configuration file into a software programming tool of the second PLC so that the software programming tool generates a second ladder diagram on the second PLC; The step of parsing the component image set, the text image set, and the connection line image set to obtain second information of each component in the first ladder diagram includes: Determining the text corresponding to each of the components according to the positional relationship between the image area of each of the components in the target image and the image area of each of the texts in the target image; The component image set and the connection line image set are analyzed to obtain connection relationships between the multiple components.
2. The method according to claim 1, It is characterized in that The step of segmenting the target image according to the first information of each component to obtain a component image set, a text image set and a connection line image set includes: Segmenting the target image according to the position of each of the components in the first ladder diagram to obtain the component image set; According to the preset width interval of the connecting line, the connecting line images are screened out from the target area of the target image to obtain the connecting line image set, wherein the target area includes the area of the target image excluding the component image set; The area in the target area except the connection line image set is segmented to obtain the text image set.
3. The method according to claim 2, It is characterized in that After segmenting the area in the target area except the connecting line image set to obtain the text image set, the method further includes: Each connection line image in the connection line image set is extended toward both ends of the connection line by a preset number of pixels.
4. The method according to claim 1, It is characterized in that The step of parsing the component image set and the connection line image set to obtain connection relationships between the plurality of components includes: Matching the region image of each component in the component image set with the region image of each connection line in the connection line image set, and obtaining the connection line corresponding to the component when the region image of the component and the region image of the connection line are successfully matched; The component image set is traversed along each connection line of the component to obtain the connection relationship between the component and other components.
5. The method according to any one of claims 1 to 4, It is characterized in that Before matching the target image with at least one pre-stored component image template to obtain first information of each component in the first ladder diagram of the ladder diagram, the method further includes: A plurality of standard ladder diagram images are acquired, and the type and shape of each component are extracted from the plurality of standard ladder diagram images to obtain at least one component image template.
6. A ladder diagram analysis device, It is characterized in that The device comprises: An acquisition module, used for acquiring a target image of a first ladder diagram of a first PLC; A component matching module, used for matching the target image with at least one pre-stored component image template to obtain first information of each component in the ladder diagram, wherein the first information includes the type of the component and the position of the component in the ladder diagram; a segmentation module, configured to segment the target image according to the first information of each of the components to obtain a component image set, a text image set and a connection line image set, wherein the component image set includes a region image of at least one component in the target image, the text image set includes a region image of text corresponding to each component in the target image, and the connection line image set includes a region image of connection lines connecting each component in the target image; A parsing module, used to parse the component image set, the text image set and the connection line image set to obtain second information of each component in the ladder diagram, wherein the second information includes text corresponding to the component and connection relationships between the components; A generating module, configured to write the first information and the second information into a configuration file in the second PLC according to a configuration file format of a second ladder diagram of the second PLC, so as to generate a second ladder diagram on the second PLC according to the configuration file; Wherein, the generating module is also used for: Importing the configuration file into a software programming tool of the second PLC so that the software programming tool generates a second ladder diagram on the second PLC; The parsing module is specifically used to determine the text corresponding to each of the components according to the positional relationship between the image area of each of the components in the target image and the image area of each of the texts in the target image; The component image set and the connection line image set are analyzed to obtain connection relationships between the multiple components.
7. An electronic device, It is characterized in that include: A processor, and a memory communicatively connected to the processor; The memory stores computer-executable instructions; When the processor executes the computer-executable instructions stored in the memory, the instructions are used to implement the method according to any one of claims 1 to 5.
8. A computer-readable storage medium, It is characterized in that The computer-readable storage medium stores computer-executable instructions, and when the computer-executable instructions are executed by a processor, they are used to implement the method according to any one of claims 1 to 5.
9. A computer program product, comprising a computer program, wherein when the computer program is executed by a processor, the method according to any one of claims 1 to 5 is implemented.
