├── LICENSE ├── README.rst └── ar_tags ├── blend └── Marker0.png ├── images ├── Marker0.png ├── Marker1.png ├── Marker10.png ├── Marker11.png ├── Marker12.png ├── Marker13.png ├── Marker14.png ├── Marker15.png ├── Marker16.png ├── Marker17.png ├── Marker2.png ├── Marker3.png ├── Marker4.png ├── Marker5.png ├── Marker6.png ├── Marker7.png ├── Marker8.png └── Marker9.png ├── model └── marker0 │ ├── materials │ └── textures │ │ └── Marker0.png │ ├── meshes │ └── Marker0.dae │ ├── model-1_4.sdf │ ├── model-1_5.sdf │ ├── model.config │ └── model.sdf └── scripts └── generate_markers_model.py /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright {yyyy} {name of copyright owner} 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | 203 | -------------------------------------------------------------------------------- /README.rst: -------------------------------------------------------------------------------- 1 | gazebo_models 2 | ============== 3 | 4 | ar_tag models for gazebo 5 | 6 | script allowing to generate gazebo models for all the AR tags in the images folder. 7 | 8 | How to use 9 | ---------- 10 | 11 | .. code-block:: bash 12 | 13 | $ ./generate_markers_model.py -h 14 | usage: generate gazebo models for AR tags 15 | 16 | optional arguments: 17 | -h, --help show this help message and exit 18 | -i IMAGES_DIR, --images-dir IMAGES_DIR 19 | directory where the marker images are located 20 | (default: $HOME/gazebo_models/ar_tags/images) 21 | -g GAZEBODIR, --gazebodir GAZEBODIR 22 | Gazebo models directory (default: 23 | $HOME/.gazebo/models) 24 | -s SIZE, --size SIZE marker size in mm (default: 500) 25 | -v, --verbose verbose mode (default: False) 26 | -w WHITE_CONTOUR_SIZE_MM, --white-contour-size-mm WHITE_CONTOUR_SIZE_MM 27 | Add white contour around images, default to no contour 28 | (default: 0) 29 | 30 | .. code-block:: bash 31 | 32 | ./generate_markers_model.py -i IMAGE_DIRECTORY -g GAZEBO_MODELS_DIRECTORY -s SIZE_IN_MILLIMETER -w CONTOUR_SIZE_IN_MM 33 | 34 | For example the following command will generate markers of 1m side + 0.5m white contour on each side, resulting in a 2mx2m gazebo model. 35 | 36 | .. code-block:: bash 37 | 38 | ./generate_markers_model.py -i IMAGE_DIRECTORY -s 1000 -w 500 39 | 40 | Limitations 41 | ----------- 42 | Assumes png images, dimensions 170*170px 43 | 44 | blender file provided to test on other image size 45 | 46 | TODO 47 | ----- 48 | Support other image formats 49 | -------------------------------------------------------------------------------- /ar_tags/blend/Marker0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mikaelarguedas/gazebo_models/532b60a7d3874be914812fb322436e640fd291d8/ar_tags/blend/Marker0.png -------------------------------------------------------------------------------- /ar_tags/images/Marker0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mikaelarguedas/gazebo_models/532b60a7d3874be914812fb322436e640fd291d8/ar_tags/images/Marker0.png -------------------------------------------------------------------------------- /ar_tags/images/Marker1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mikaelarguedas/gazebo_models/532b60a7d3874be914812fb322436e640fd291d8/ar_tags/images/Marker1.png -------------------------------------------------------------------------------- /ar_tags/images/Marker10.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mikaelarguedas/gazebo_models/532b60a7d3874be914812fb322436e640fd291d8/ar_tags/images/Marker10.png -------------------------------------------------------------------------------- /ar_tags/images/Marker11.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mikaelarguedas/gazebo_models/532b60a7d3874be914812fb322436e640fd291d8/ar_tags/images/Marker11.png -------------------------------------------------------------------------------- /ar_tags/images/Marker12.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mikaelarguedas/gazebo_models/532b60a7d3874be914812fb322436e640fd291d8/ar_tags/images/Marker12.png -------------------------------------------------------------------------------- /ar_tags/images/Marker13.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mikaelarguedas/gazebo_models/532b60a7d3874be914812fb322436e640fd291d8/ar_tags/images/Marker13.png -------------------------------------------------------------------------------- /ar_tags/images/Marker14.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mikaelarguedas/gazebo_models/532b60a7d3874be914812fb322436e640fd291d8/ar_tags/images/Marker14.png -------------------------------------------------------------------------------- /ar_tags/images/Marker15.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mikaelarguedas/gazebo_models/532b60a7d3874be914812fb322436e640fd291d8/ar_tags/images/Marker15.png -------------------------------------------------------------------------------- /ar_tags/images/Marker16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mikaelarguedas/gazebo_models/532b60a7d3874be914812fb322436e640fd291d8/ar_tags/images/Marker16.png -------------------------------------------------------------------------------- /ar_tags/images/Marker17.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mikaelarguedas/gazebo_models/532b60a7d3874be914812fb322436e640fd291d8/ar_tags/images/Marker17.png -------------------------------------------------------------------------------- /ar_tags/images/Marker2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mikaelarguedas/gazebo_models/532b60a7d3874be914812fb322436e640fd291d8/ar_tags/images/Marker2.png -------------------------------------------------------------------------------- /ar_tags/images/Marker3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mikaelarguedas/gazebo_models/532b60a7d3874be914812fb322436e640fd291d8/ar_tags/images/Marker3.png -------------------------------------------------------------------------------- /ar_tags/images/Marker4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mikaelarguedas/gazebo_models/532b60a7d3874be914812fb322436e640fd291d8/ar_tags/images/Marker4.png -------------------------------------------------------------------------------- /ar_tags/images/Marker5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mikaelarguedas/gazebo_models/532b60a7d3874be914812fb322436e640fd291d8/ar_tags/images/Marker5.png -------------------------------------------------------------------------------- /ar_tags/images/Marker6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mikaelarguedas/gazebo_models/532b60a7d3874be914812fb322436e640fd291d8/ar_tags/images/Marker6.png -------------------------------------------------------------------------------- /ar_tags/images/Marker7.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mikaelarguedas/gazebo_models/532b60a7d3874be914812fb322436e640fd291d8/ar_tags/images/Marker7.png -------------------------------------------------------------------------------- /ar_tags/images/Marker8.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mikaelarguedas/gazebo_models/532b60a7d3874be914812fb322436e640fd291d8/ar_tags/images/Marker8.png -------------------------------------------------------------------------------- /ar_tags/images/Marker9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mikaelarguedas/gazebo_models/532b60a7d3874be914812fb322436e640fd291d8/ar_tags/images/Marker9.png -------------------------------------------------------------------------------- /ar_tags/model/marker0/materials/textures/Marker0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mikaelarguedas/gazebo_models/532b60a7d3874be914812fb322436e640fd291d8/ar_tags/model/marker0/materials/textures/Marker0.png -------------------------------------------------------------------------------- /ar_tags/model/marker0/meshes/Marker0.dae: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Blender User 6 | Blender 2.74.0 commit date:2015-03-31, commit time:13:39, hash:000dfc0 7 | 8 | 2015-04-05T02:03:25 9 | 2015-04-05T02:03:25 10 | 11 | Z_UP 12 | 13 | 14 | 15 | Marker0.png 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | Marker0_png 24 | 25 | 26 | 27 | 28 | Marker0_png-surface 29 | 30 | 31 | 32 | 33 | 34 | 0 0 0 1 35 | 36 | 37 | 0.9 0.9 0.9 1 38 | 39 | 40 | 41 | 42 | 43 | 0.5 0.5 0.5 1 44 | 45 | 46 | 50 47 | 48 | 49 | 1 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 1 0.9999999 -9.41753e-6 1 -1 -9.41753e-6 -1 -0.9999998 -9.41753e-6 -0.9999997 1 -9.41753e-6 1 0.9999994 1.999991 0.9999994 -1.000001 1.999991 -1 -0.9999997 1.999991 -0.9999999 1 1.999991 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 0 0 -1 0 0 1 1 -5.66244e-7 3.27825e-7 -4.76837e-7 -1 0 -1 2.38419e-7 -1.19209e-7 2.38419e-7 1 1.78814e-7 0 0 -1 0 0 1 1 0 -2.38419e-7 0 -1 -2.98023e-7 -1 2.38419e-7 0 2.98023e-7 1 2.38418e-7 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 0 0 0 0 0 0 0 0 0 0 0 0 0.9999 0.9940189 9.96856e-5 0.9940189 1.00079e-4 9.97642e-5 0 0 0 0 0 0 9.96856e-5 0.9940191 9.98823e-5 9.96856e-5 0.9999004 9.98429e-5 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.9999004 9.96856e-5 0.9999 0.9940189 1.00079e-4 9.97642e-5 0 0 0 0 0 0 0.9999004 0.9940191 9.96856e-5 0.9940191 0.9999004 9.98429e-5 0 0 0 0 0 0 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 3 3 3 3 3 3 3 3 3 3 3 3 101 |

0 0 0 1 0 1 2 0 2 7 1 3 6 1 4 5 1 5 4 2 6 5 2 7 1 2 8 5 3 9 6 3 10 2 3 11 2 4 12 6 4 13 7 4 14 0 5 15 3 5 16 7 5 17 3 6 18 0 6 19 2 6 20 4 7 21 7 7 22 5 7 23 0 8 24 4 8 25 1 8 26 1 9 27 5 9 28 2 9 29 3 10 30 2 10 31 7 10 32 4 11 33 0 11 34 7 11 35

102 |
103 |
104 |
105 |
106 | 107 | 108 | 109 | 110 | 0.004999998 0 0 0 0 0.2499999 0 0 0 0 0.25 0 0 0 0 1 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 |
127 | -------------------------------------------------------------------------------- /ar_tags/model/marker0/model-1_4.sdf: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | true 5 | 6 | 7 | 8 | 9 | model://marker0/meshes/Marker0.dae 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /ar_tags/model/marker0/model-1_5.sdf: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | true 5 | 6 | 7 | 8 | 9 | model://marker0/meshes/Marker0.dae 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /ar_tags/model/marker0/model.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Marker0 5 | 1.0 6 | model.sdf 7 | model-1_5.sdf 8 | model-1_4.sdf 9 | 10 | 11 | Mikael Arguedas 12 | mikael.arguedas@gmail.com 13 | 14 | 15 | 16 | A model of AR marker 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /ar_tags/model/marker0/model.sdf: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | true 5 | 6 | 7 | 8 | 9 | model://marker0/meshes/Marker0.dae 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /ar_tags/scripts/generate_markers_model.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python 2 | from __future__ import print_function 3 | 4 | import argparse 5 | from xml.dom.minidom import parse 6 | import os 7 | import sys 8 | 9 | parser = argparse.ArgumentParser( 10 | usage='generate gazebo models for AR tags', 11 | formatter_class=argparse.ArgumentDefaultsHelpFormatter 12 | ) 13 | parser.add_argument( 14 | '-i', '--images-dir', 15 | default="$HOME/gazebo_models/ar_tags/images", 16 | help='directory where the marker images are located') 17 | parser.add_argument( 18 | '-g', '--gazebodir', 19 | default="$HOME/.gazebo/models", 20 | help='Gazebo models directory') 21 | parser.add_argument( 22 | '-s', '--size', 23 | default=500, type=int, 24 | help='marker size in mm') 25 | parser.add_argument( 26 | '-v', '--verbose', 27 | dest='verbose', action='store_true', 28 | help='verbose mode') 29 | 30 | parser.add_argument( 31 | '-w', '--white-contour-size-mm', 32 | default=0, type=int, 33 | help='Add white contour around images, default to no contour') 34 | parser.set_defaults(verbose=False) 35 | 36 | args = parser.parse_args() 37 | 38 | args.gazebodir = os.path.expandvars(args.gazebodir) 39 | args.images_dir = os.path.expandvars(args.images_dir) 40 | script_path = os.path.dirname(os.path.realpath(__file__)) 41 | model_dir = os.path.join(os.path.dirname(script_path), 'model') 42 | ORIGINAL_MARKER_SIZE_MM = 500 43 | ORIGINAL_IMAGE_SIZE_PX = 170 44 | white_contour_px = \ 45 | args.white_contour_size_mm * ORIGINAL_IMAGE_SIZE_PX / args.size 46 | 47 | if not os.path.isdir(args.images_dir): 48 | print("provided image directory '%s' is not a directory" % args.images_dir) 49 | sys.exit() 50 | 51 | # Open every collada file 52 | if args.verbose: 53 | print(args.images_dir) 54 | 55 | # Copy marker0 directory into gazebo model directory 56 | cp_marker0_cmd = "cp -r " + os.path.join(model_dir, 'marker0') + \ 57 | " " + os.path.join(args.gazebodir, "marker0") 58 | if args.verbose: 59 | print(cp_marker0_cmd) 60 | os.system(cp_marker0_cmd) 61 | 62 | file_list = sorted(os.listdir(args.images_dir)) 63 | for image_file in file_list: 64 | if not image_file.endswith('.png'): 65 | continue 66 | image_file_path = os.path.join(args.images_dir, image_file) 67 | filename_without_ext = image_file[0:image_file.rfind('.')] 68 | # ignore marker0 as it has already been copied above 69 | if not filename_without_ext.lower() == 'marker0': 70 | cmd = "cp -r " + os.path.join(args.gazebodir, "marker0") + \ 71 | " " + os.path.join(args.gazebodir, filename_without_ext.lower()) 72 | if args.verbose: 73 | print(cmd) 74 | os.system(cmd) 75 | 76 | cmd = "rm " + os.path.join( 77 | args.gazebodir, filename_without_ext.lower(), 78 | "materials", "textures", "Marker0.png") 79 | if args.verbose: 80 | print(cmd) 81 | os.system(cmd) 82 | image_dest_path = os.path.join( 83 | args.gazebodir, 84 | filename_without_ext.lower(), 85 | "materials", "textures", image_file) 86 | cmd = "cp " + image_file_path + " " + \ 87 | image_dest_path 88 | if args.verbose: 89 | print(cmd) 90 | os.system(cmd) 91 | 92 | # add white contour if applicable: 93 | if white_contour_px > 0: 94 | convert_cmd = "convert %s -bordercolor white -border %dx%d %s" % ( 95 | image_dest_path, white_contour_px, 96 | white_contour_px, image_dest_path) 97 | if args.verbose: 98 | print(convert_cmd) 99 | os.system(convert_cmd) 100 | 101 | model_config_path = os.path.join( 102 | args.gazebodir, filename_without_ext.lower(), "model.config") 103 | if args.verbose: 104 | print(model_config_path) 105 | dom = parse(model_config_path) 106 | # modify model.config 107 | for node in dom.getElementsByTagName('name'): 108 | node.firstChild.nodeValue = filename_without_ext 109 | if args.verbose: 110 | print(node.firstChild.nodeValue) 111 | break 112 | f = open(os.path.join( 113 | args.gazebodir, filename_without_ext.lower(), "model.config"), 'w+') 114 | # Write the modified xml file 115 | f.write(dom.toxml()) 116 | f.close() 117 | 118 | # modify model.sdf 119 | model_noversion_sdf_path = os.path.join( 120 | args.gazebodir, filename_without_ext.lower(), "model.sdf") 121 | if args.verbose: 122 | print("open model.sdf") 123 | print(model_noversion_sdf_path) 124 | dom = parse(model_noversion_sdf_path) 125 | for node in dom.getElementsByTagName('model'): 126 | node.attributes["name"].value = filename_without_ext 127 | if args.verbose: 128 | print("model tag found") 129 | break 130 | 131 | scaleModified = False 132 | scale = (args.size + 2 * args.white_contour_size_mm) / \ 133 | float(ORIGINAL_MARKER_SIZE_MM) 134 | for node in dom.getElementsByTagName('mesh'): 135 | for child in node.childNodes: 136 | if child.nodeName == "scale": 137 | child.firstChild.nodeValue = \ 138 | "{} {} {}".format(scale, scale, scale) 139 | scaleModified = True 140 | if child.nodeName == "uri": 141 | child.firstChild.nodeValue = "model://" + os.path.join( 142 | filename_without_ext.lower(), "meshes", 143 | filename_without_ext + ".dae") 144 | if args.verbose: 145 | print("uri tag found") 146 | print(node.firstChild.nodeValue) 147 | if not scaleModified: 148 | if args.verbose: 149 | print("creating scale tag") 150 | x = dom.createElement("scale") 151 | y = dom.createTextNode("{} {} {}".format(scale, scale, scale)) 152 | x.appendChild(y) 153 | node.appendChild(x) 154 | 155 | f = open(model_noversion_sdf_path, 'w+') 156 | # Write the modified xml file 157 | f.write(dom.toxml()) 158 | f.close() 159 | 160 | # modify model-1_4.sdf 161 | model_sdf_path = os.path.join( 162 | args.gazebodir, filename_without_ext.lower(), "model-1_4.sdf") 163 | cmd = "cp " + model_noversion_sdf_path + " " + model_sdf_path 164 | if args.verbose: 165 | print(cmd) 166 | os.system(cmd) 167 | 168 | if args.verbose: 169 | print("open model-1_4.sdf") 170 | print(model_sdf_path) 171 | dom = parse(model_sdf_path) 172 | for node in dom.getElementsByTagName('sdf'): 173 | node.attributes["version"].value = "1.4" 174 | break 175 | f = open(model_sdf_path, 'w+') 176 | # Write the modified xml file 177 | f.write(dom.toxml()) 178 | f.close() 179 | 180 | # modify model-1_5.sdf 181 | model_sdf_path = os.path.join( 182 | args.gazebodir, filename_without_ext.lower(), "model-1_5.sdf") 183 | cmd = "cp " + model_noversion_sdf_path + \ 184 | " " + model_sdf_path 185 | if args.verbose: 186 | print(cmd) 187 | os.system(cmd) 188 | 189 | if args.verbose: 190 | print("open model-1_5.sdf") 191 | print(model_sdf_path) 192 | dom = parse(model_sdf_path) 193 | for node in dom.getElementsByTagName('sdf'): 194 | node.attributes["version"].value = "1.5" 195 | break 196 | f = open(model_sdf_path, 'w+') 197 | # Write the modified xml file 198 | f.write(dom.toxml()) 199 | f.close() 200 | 201 | meshes_dir = os.path.join( 202 | args.gazebodir, filename_without_ext.lower(), "meshes") 203 | if args.verbose: 204 | print(os.path.join(meshes_dir, "Marker0.dae") + 205 | " newname " + os.path.join( 206 | meshes_dir, filename_without_ext + ".dae")) 207 | os.rename( 208 | os.path.join(meshes_dir, "Marker0.dae"), 209 | os.path.join(meshes_dir, filename_without_ext + ".dae")) 210 | 211 | # modify ModelX.dae 212 | if args.verbose: 213 | print("open ModelX.dae") 214 | print(os.path.join(meshes_dir, filename_without_ext + ".dae")) 215 | dom = parse(os.path.join(meshes_dir, filename_without_ext + ".dae")) 216 | for node in dom.getElementsByTagName('init_from'): 217 | node.firstChild.nodeValue = image_file 218 | if args.verbose: 219 | print("init_from tag found") 220 | break 221 | 222 | f = open(os.path.join( 223 | meshes_dir, filename_without_ext + ".dae"), 'w+') 224 | # Write the modified xml file 225 | f.write(dom.toxml()) 226 | f.close() 227 | --------------------------------------------------------------------------------