AutoCAD two-dimensional drawing automatic labeling method and system based on matlab image recognition
By building an AutoCAD system that includes image recognition and automatic annotation programs, and using matlab image processing capabilities and VBA language, the problems of slow automatic annotation speed and inconsistent format in AutoCAD are solved, and efficient automatic annotation and format uniformity of large batches of drawings are achieved. .
Patent Information
- Application Number
- CN202410765649.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-06-14
- Publication Date
- 2024-10-11
AI Technical Summary
The existing technology's automatic annotation speed in AutoCAD is slow and cannot achieve large-scale annotation, and the manual annotation format is not uniform, resulting in low efficiency and confusing annotation.
The automatic annotation method of AutoCAD two-dimensional drawings based on matlab image recognition is used to build an automatic annotation system including a two-dimensional drawing database, an image recognition program and an automatic annotation program. The automatic annotation of drawings is realized through similarity calculation and VBA function, and the automatic annotation is implemented in the image library. Update annotation information.
It improves the efficiency of automatic annotation of drawings, solves the problem of large-volume annotation, ensures the unity and accuracy of annotation format, lowers the design threshold of automatic annotation program, and has strong adaptability.
Smart Images

Figure CN118762379A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of automatic annotation in AutoCAD using VBA programming language, and in particular to a method and system for automatic annotation of AutoCAD two-dimensional drawings based on matlab image recognition. Background Art
[0002] Judging from the current status of my country's manufacturing industry, two-dimensional drawings are still the main form of guiding parts processing and are important technical documents submitted by product design departments to production departments. Dimensioning is one of the most important parts of engineering drawings. How to shorten the drawing cycle and improve work efficiency through computer-aided technology has always been a difficult problem in the field of mechanical drawing. Secondly, the design departments of many companies or institutions have the good habit of saving previous design drawings, and in new design tasks, they often encounter situations similar to previous design drawings. How to use previous design experience to achieve the purpose of reusing existing drawings and improving efficiency has always been an important research direction.
[0003] In a Chinese patent document with publication number CN109033571A, an automatic drawing module based on CAD is disclosed, which includes the following steps: step one, a design step based on CAD that meets the design requirements; step two, a step of obtaining parameter information; step three, organizing the scattered design requirements and parameter information into steps that meet the program language specifications. The method of automatic drawing includes: 1) designing the drawing scale and creating a layer; 2) obtaining control parameters; 3) obtaining coordinate points of different views; 4) drawing a material table; 5) drawing a detailed processing part drawing; drawing is completed; although this patent document can also perform automatic marking, the speed is slow and large-scale marking cannot be performed, so the above-mentioned problems cannot be solved.
[0004] In a Chinese patent document with publication number CN110348155A, a method for marking the dimensions of graphics in CAD software is disclosed, including: obtaining an instruction for a user to select a line unit; selecting and obtaining a line unit from a graphic; determining the line type of the selected and obtained line unit; determining the type of dimension to be marked according to the line type; calculating the dimension value corresponding to the type of dimension to be marked; marking the dimension value at a preset position. After the CAD software switches to the dimensioning state, the mouse can be used to select the line to be marked, and the type of dimension to be marked can be automatically identified, thereby avoiding switching the annotation type by clicking to switch the annotation window. However, this patent document cannot perform large-scale annotation, nor can it solve the above-mentioned problems. Summary of the invention
[0005] In view of the defects in the prior art, the purpose of the present invention is to provide a method and system for automatic annotation of AutoCAD two-dimensional drawings based on MATLAB image recognition.
[0006] According to the present invention, a method for automatically marking AutoCAD two-dimensional drawings based on matlab image recognition includes:
[0007] Step S1: construct an automatic annotation system;
[0008] The system includes a two-dimensional drawing database, an image recognition program, an automatic marking program and a program expansion module; the two-dimensional drawing database includes a drawing library;
[0009] Step S2: Collect unlabeled drawing parameters and calculate similarity with drawings in the drawing library;
[0010] Step S3: If the similarity calculation result obtained reaches a preset value, the unmarked drawings are marked.
[0011] Preferably, the two-dimensional drawing database includes image recognition basis and automatic marking basis for unmarked drawings;
[0012] The image recognition program includes distinguishing unlabeled drawings based on traversing the two-dimensional drawing database and calculating the calculateSimilarity function;
[0013] The automatic marking program includes calling VBA functions and graphic element information of the data storage module based on the two-dimensional drawing database to mark the drawings;
[0014] The program expansion module includes updating the two-dimensional drawing database and the automatic marking program after marking the drawings that do not exist in the database.
[0015] Preferably, the two-dimensional drawing database also includes an image library for an image recognition program and a drawing library for an automatic labeling program, and the two-dimensional drawing database provides data support for the image recognition program and the automatic labeling program.
[0016] Preferably, the automatic labeling program includes a judgment module, a data storage module, an element sorting module and an automatic labeling module.
[0017] Preferably, step S3 includes storing characteristic data of graphic elements and key serial numbers of unlabeled drawings based on the judgment module and the data storage module, calling the VBA function corresponding to the drawing library in the two-dimensional drawing database based on the graphic recognition result, and labeling the drawings in combination with the graphic element information of the data storage module.
[0018] Preferably, it is characterized in that the image recognition program also includes a target reading module, a database traversal module, a similarity calculation module and a result output module.
[0019] According to the present invention, a system for automatically marking AutoCAD two-dimensional drawings based on matlab image recognition is provided, comprising:
[0020] Module M1: Building an automatic annotation system;
[0021] The system includes a two-dimensional drawing database, an image recognition program, an automatic marking program and a program expansion module; the two-dimensional drawing database includes a drawing library;
[0022] Module M2: Collect unlabeled drawing parameters and calculate similarity with drawings in the drawing library;
[0023] Module M3: If the similarity calculation result reaches the preset value, the unmarked drawings are marked.
[0024] Preferably, the two-dimensional drawing database includes image recognition basis and automatic marking basis for unmarked drawings;
[0025] The image recognition program includes distinguishing unlabeled drawings based on traversing the two-dimensional drawing database and calculating the calculateSimilarity function;
[0026] The automatic marking program includes calling VBA functions and graphic element information of the data storage module based on the two-dimensional drawing database to mark the drawings;
[0027] The program expansion module includes updating the two-dimensional drawing database and the automatic marking program after marking the drawings that do not exist in the database.
[0028] Preferably, the two-dimensional drawing database also includes an image library for an image recognition program and a drawing library for an automatic labeling program, and the two-dimensional drawing database provides data support for the image recognition program and the automatic labeling program.
[0029] Preferably, the automatic labeling program includes a judgment module, a data storage module, an element sorting module and an automatic labeling module.
[0030] Preferably, the module M3 includes storing characteristic data of graphic elements and key serial numbers of unlabeled drawings based on the judgment module and the data storage module, calling the VBA function corresponding to the drawing library in the two-dimensional drawing database based on the graphic recognition result, and labeling the drawings in combination with the graphic element information of the data storage module.
[0031] Preferably, it is characterized in that the image recognition program also includes a target reading module, a database traversal module, a similarity calculation module and a result output module.
[0032] Compared with the prior art, the present invention has the following beneficial effects:
[0033] 1. The present invention solves the complex problem of using VBA language to judge the similarity of two drawings based on the image processing capability of MATLAB program; by using a unified file naming method and a program for automatically retrieving the target image sequence number, it solves the problem of draftsmen looking for annotation functions in a huge function library and quickly realizing automatic annotation of large quantities of drawings, thereby improving efficiency and having high practicality.
[0034] 2. The present invention defines the automatic annotation function for each template in a targeted manner, thereby solving the problems of inconsistent manual annotation formats and no annotation and the problem of chaotic annotation in comprehensive automatic annotation programs. The VBA language, which has a low entry difficulty and strong adaptability to AutoCAD software, solves the difficulty of subsequent program expansion and has a good prospect for use.
[0035] Other beneficial effects of the present invention will be explained in the specific implementation manner through the introduction of specific technical features and technical solutions. Through the introduction of these technical features and technical solutions, those skilled in the art should be able to understand the beneficial technical effects brought about by the technical features and technical solutions. BRIEF DESCRIPTION OF THE DRAWINGS
[0036] Other features, objects and advantages of the present invention will become more apparent from the detailed description of non-limiting embodiments made with reference to the following drawings:
[0037] Figure 1 The figure is a flow chart of the method of the present invention.
[0038] Figure 2 It is a schematic diagram of the program function module of the present invention. DETAILED DESCRIPTION
[0039] The present invention is described in detail below in conjunction with specific embodiments. The following embodiments will help those skilled in the art to further understand the present invention, but are not intended to limit the present invention in any form. It should be noted that, for those of ordinary skill in the art, several changes and improvements can also be made without departing from the concept of the present invention. These all belong to the protection scope of the present invention.
[0040] In the prior art, it is very complicated to use VBA language to judge the similarity of two drawings, and the manual annotation format is not unified and unannotated, and the comprehensive automatic annotation program is prone to annotation confusion. The present invention first constructs a system consisting of a two-dimensional drawing database, an image recognition program, an automatic annotation program and a program expansion module. The two-dimensional drawing database is used for the image library of the image recognition program and the drawing library for the automatic annotation program; the image recognition program determines whether it can annotate unannotated drawings by reading the target, traversing the database and calculating the similarity; the automatic annotation program realizes automatic annotation of unannotated drawings by calling the drawing library program; the program expansion module is used to solve the problem of not finding the corresponding target image in the image library. Based on the constructed system, the image processing capability of the matlab program is used to solve the deficiencies in the prior art.
[0041] Reference Figure 1 As shown, a method for automatic annotation of AutoCAD two-dimensional drawings based on matlab image recognition comprises:
[0042] First, build the automatic annotation system: two-dimensional drawing database, image recognition program, automatic annotation program and program expansion module.
[0043] The 2D drawing database includes an image library for image recognition programs and a drawing library for automatic annotation programs. The image library contains JPG format photos of all drawings in the drawing library, and the naming rules are the same as the files in the drawing library, which is serial number-drawing name-version-other. The serial number starts from 1;
[0044] The image recognition program includes a target reading module, a database traversal module, a similarity calculation module, and a result output module. The target reading module uses the cell function to create an array that can store image information of a specific scale. The database traversal module and the similarity calculation module are composed of a set of for loop statements. The similarity calculation method between images uses the cosine similarity calculation. The calculation principle of cosine similarity is as follows:
[0045]
[0046] In the formula, cosine_similarity is the cosine similarity of the two images. The closer the absolute value is to 1, the more similar they are, and the closer it is to 0, the greater the difference. A and B are the vector data formats of the two images, A = (x1, x2, ..., x n ),B=(y1,y2,...,y n ).
[0047] The result output module consists of an integer array with a length equal to the number of input images. The order of the array represents the order of the input images, and the value of the array represents the serial number of the target image in the image library corresponding to the input image at that position, where "0" represents that there is no image similar to the input image in the image library. In the similarity calculation module, a similarity threshold is set in the loop. If the maximum similarity after looping through all the images in the image library is greater than the threshold, it is considered that the target image is found, and the serial number corresponding to the target image is filled in the output array; if the maximum similarity after looping through all the images in the image library is still less than the threshold, it is determined that there is no target image in the image library, and 0 is filled in the corresponding position of the target image serial number array in the final output.
[0048] The automatic annotation program, each individual function includes a judgment module, a data storage module, an element sorting module, and an automatic annotation module. The judgment module includes block judgment and element judgment. First, it determines whether the object in the DWG file is a block. If so, the decomposition program is executed to decompose it into separate elements; if not, the program is skipped. Next, each graphic element is divided into sets such as horizontal lines, vertical lines, and circles according to its own data characteristics through element judgment. The data storage module stores the data and keys of the classified graphic elements in a certain order in preparation for the call of the element sorting module. The element sorting module reorders the graphic elements according to the sorting principles from left to right and from top to bottom, and simultaneously updates the characteristic data and key order of the graphic elements in the data storage module. The automatic annotation module calls the VBA function and the graphic element information of the data storage module according to the two-dimensional graphics of the drawing to standardly annotate the drawing;
[0049] The program expansion module is used to solve the problem of not being able to find the corresponding target image in the image library. If a similar target image cannot be found in the image library, it is necessary to manually update the two-dimensional drawing database and the automatic annotation program. First, new images in JPG format and new drawings in DWG format need to be added to the two-dimensional drawing database; then open the automatic annotation program text in txt format to add the annotation function of the new drawing. During the process, attention should be paid to the consistency of the file name; finally, the updated program is repackaged into a program file in dvb format.
[0050] The present invention aims at the problem of batch automatic annotation of two-dimensional engineering drawings, solves the problem that the previous automatic annotation program design method is too dependent on the data of the automatic drawing steps and cannot realize the demand for rapid automatic annotation of large quantities of drawings, and designs a method for automatic annotation of AutoCAD two-dimensional drawings based on MATLAB image recognition.
[0051] This automatic annotation program design achieves four goals: it solves the problem of judging the similarity of two drawings, solves the problem of inconsistent manual annotation formats and no annotation, and the problem of annotation confusion in comprehensive automatic annotation programs, lowers the entry threshold and subsequent expansion problems of automatic annotation program design, and solves the problem of batch automatic annotation of two-dimensional engineering drawings.
[0052] The present invention also provides a system for automatic labeling of AutoCAD two-dimensional drawings based on matlab image recognition. The system for automatic labeling of AutoCAD two-dimensional drawings based on matlab image recognition can be realized by executing the process steps of the method for automatic labeling of AutoCAD two-dimensional drawings based on matlab image recognition, that is, those skilled in the art can understand the method for automatic labeling of AutoCAD two-dimensional drawings based on matlab image recognition as a preferred implementation of the system for automatic labeling of AutoCAD two-dimensional drawings based on matlab image recognition.
[0053] Reference Figure 2 As shown, specifically, a system for automatic annotation of AutoCAD two-dimensional drawings based on matlab image recognition includes:
[0054] Module M1: Building an automatic annotation system;
[0055] The system includes a two-dimensional drawing database, an image recognition program, an automatic marking program and a program expansion module; the two-dimensional drawing database includes a drawing library;
[0056] Module M2: Collect unlabeled drawing parameters and calculate similarity with drawings in the drawing library;
[0057] Module M3: If the similarity calculation result reaches the preset value, the unmarked drawings are marked.
[0058] The two-dimensional drawing database includes providing image recognition basis and automatic marking basis for unmarked drawings;
[0059] The image recognition program includes distinguishing unlabeled drawings based on traversing the two-dimensional drawing database and calculating the calculateSimilarity function;
[0060] The automatic marking program includes calling VBA functions and graphic element information of the data storage module based on the two-dimensional drawing database to mark the drawings;
[0061] The program expansion module includes updating the two-dimensional drawing database and the automatic marking program after marking the drawings that do not exist in the database.
[0062] The two-dimensional drawing database also includes an image library for an image recognition program and a drawing library for an automatic marking program, and the two-dimensional drawing database provides data support for the image recognition program and the automatic marking program.
[0063] The automatic labeling program includes a judgment module, a data storage module, an element sorting module and an automatic labeling module.
[0064] The module M3 includes storing the characteristic data of the graphic elements and the key serial numbers of the unlabeled drawings based on the judgment module and the data storage module, calling the VBA function corresponding to the drawing library in the two-dimensional drawing database based on the graphic recognition result, and labeling the drawings in combination with the graphic element information of the data storage module.
[0065] It is characterized in that the image recognition program also includes a target reading module, a database traversal module, a similarity calculation module and a result output module.
[0066] Those skilled in the art know that, in addition to realizing the system and its various devices, modules, and units provided by the present invention in a purely computer-readable program code, it is entirely possible to realize the same functions in the form of logic gates, switches, application-specific integrated circuits, programmable logic controllers, and embedded microcontrollers by logically programming the method steps. Therefore, the system and its various devices, modules, and units provided by the present invention can be considered as a hardware component, and the devices, modules, and units included therein for realizing various functions can also be regarded as structures within the hardware component; the devices, modules, and units for realizing various functions can also be regarded as both software modules for realizing the method and structures within the hardware component.
[0067] In the description of the present application, it should be understood that the terms "up", "down", "front", "back", "left", "right", "vertical", "horizontal", "top", "bottom", "inside", "outside", etc., indicating orientations or positional relationships, are based on the orientations or positional relationships shown in the accompanying drawings, and are only for the convenience of describing the present application and simplifying the description, and do not indicate or imply that the referred device or element must have a specific orientation, be constructed and operated in a specific orientation, and therefore should not be understood as a limitation on the present application.
[0068] The above describes the specific embodiments of the present invention. It should be understood that the present invention is not limited to the above specific embodiments, and those skilled in the art can make various changes or modifications within the scope of the claims, which does not affect the essence of the present invention. In the absence of conflict, the embodiments of the present application and the features in the embodiments can be combined with each other arbitrarily.
Claims
1. A method for automatic annotation of AutoCAD two-dimensional drawings based on matlab image recognition, characterized in that: include: Step S1: construct an automatic annotation system; The system includes a two-dimensional drawing database, an image recognition program, an automatic marking program and a program expansion module; The two-dimensional drawing database includes a drawing library; Step S2: Collect unlabeled drawing parameters and calculate similarity with drawings in the drawing library; Step S3: If the similarity calculation result obtained reaches a preset value, the unmarked drawings are marked.
2. The method for automatically marking AutoCAD two-dimensional drawings based on matlab image recognition according to claim 1, characterized in that: The two-dimensional drawing database includes providing image recognition basis and automatic marking basis for unmarked drawings; The image recognition program includes distinguishing unlabeled drawings based on traversing the two-dimensional drawing database and calculating the calculateSimilarity function; The automatic marking program includes calling VBA functions and graphic element information of the data storage module based on the two-dimensional drawing database to mark the drawings; The program expansion module includes updating the two-dimensional drawing database and the automatic marking program after marking the drawings that do not exist in the database.
3. A method for automatic annotation of AutoCAD two-dimensional drawings based on matlab image recognition according to claim 2, characterized in that: The two-dimensional drawing database also includes an image library for an image recognition program and a drawing library for an automatic marking program, and the two-dimensional drawing database provides data support for the image recognition program and the automatic marking program.
4. The method for automatically marking AutoCAD two-dimensional drawings based on matlab image recognition according to claim 2, characterized in that: The automatic labeling program includes a judgment module, a data storage module, an element sorting module and an automatic labeling module.
5. The method for automatic annotation of AutoCAD two-dimensional drawings based on matlab image recognition according to claim 4, characterized in that: The step S3 includes storing the characteristic data of the graphic elements and the key serial numbers of the unlabeled drawings based on the judgment module and the data storage module, calling the VBA function corresponding to the drawing library in the two-dimensional drawing database based on the graphic recognition result, and labeling the drawings in combination with the graphic element information of the data storage module.
6. The method for automatically marking AutoCAD two-dimensional drawings based on matlab image recognition according to claim 2, characterized in that: The image recognition program also includes a target reading module, a database traversal module, a similarity calculation module and a result output module.
7. A system for automatic annotation of AutoCAD two-dimensional drawings based on matlab image recognition, characterized in that: include: Module M1: Building an automatic annotation system; The system includes a two-dimensional drawing database, an image recognition program, an automatic marking program and a program expansion module; the two-dimensional drawing database includes a drawing library; Module M2: Collect unlabeled drawing parameters and calculate similarity with drawings in the drawing library; Module M3: If the similarity calculation result reaches the preset value, the unmarked drawings are marked.
8. The system for automatic annotation of AutoCAD two-dimensional drawings based on matlab image recognition according to claim 7 is characterized in that: The two-dimensional drawing database includes providing image recognition basis and automatic marking basis for unmarked drawings; The image recognition program includes distinguishing unlabeled drawings based on traversing the two-dimensional drawing database and calculating the calculateSimilarity function; The automatic marking program includes calling VBA functions and graphic element information of the data storage module based on the two-dimensional drawing database to mark the drawings; The program expansion module includes updating the two-dimensional drawing database and the automatic marking program after marking the drawings that do not exist in the database.
9. The system for automatic annotation of AutoCAD two-dimensional drawings based on matlab image recognition according to claim 8, characterized in that: The two-dimensional drawing database also includes an image library for an image recognition program and a drawing library for an automatic marking program, and the two-dimensional drawing database provides data support for the image recognition program and the automatic marking program.
10. The system for automatic annotation of AutoCAD two-dimensional drawings based on matlab image recognition according to claim 8, characterized in that: The automatic labeling program includes a judgment module, a data storage module, an element sorting module and an automatic labeling module.
Citation Information
Patent Citations
CAD-based automatic drawing module and drawing method
CN109033571A
Method for marking size of graph in CAD software
CN110348155A
Coordinate identification method and device, equipment and computer readable storage medium
CN110390279A
Drawing labeling method and related product
CN111143925A
Element labeling method, device and equipment, storage medium and computer program product
CN112509135A
