g.gui.photo2image.py 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. #!/usr/bin/env python3
  2. ############################################################################
  3. #
  4. # MODULE: Correcting distortions of a scanned photo (modified from GCP Manager)
  5. # AUTHOR(S): Yann modified the code (was Markus Metz for the GCP Manager)
  6. # PURPOSE: Takes a scanned photo and fits fiducial points to known geometry
  7. # COPYRIGHT: (C) 2012-2017 by Markus Metz, and the GRASS Development Team
  8. #
  9. # This program is free software; you can redistribute it and/or modify
  10. # it under the terms of the GNU General Public License as published by
  11. # the Free Software Foundation; either version 2 of the License, or
  12. # (at your option) any later version.
  13. #
  14. # This program is distributed in the hope that it will be useful,
  15. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. # GNU General Public License for more details.
  18. #
  19. ############################################################################
  20. #%module
  21. #% description: Corrects scanning distortions of a paper photo.
  22. #% keyword: imagery
  23. #% keyword: GUI
  24. #% keyword: aerial
  25. #% keyword: photo
  26. #% keyword: georectification
  27. #% keyword: geometry
  28. #% keyword: GCP
  29. #%end
  30. #%option G_OPT_I_GROUP
  31. #% key: group
  32. #% required: yes
  33. #%end
  34. #%option G_OPT_R_INPUT
  35. #% key: raster
  36. #% required: yes
  37. #%end
  38. #%option
  39. #% key: camera
  40. #% type: string
  41. #% label: The name of the camera (generated in i.ortho.camera)
  42. #% description: The name of the camera (generated in i.ortho.camera)
  43. #% required: yes
  44. #%end
  45. #%option
  46. #% key: order
  47. #% type: string
  48. #% label: The rectification order (no of Fiducial=4 -> order=1, no of Fiducial=8 -> order=2)
  49. #% description: The rectification order (no of Fiducial=4 -> order=1, no of Fiducial=8 -> order=2)
  50. #% required: yes
  51. #% answer: 1
  52. #%end
  53. #%option
  54. #% key: extension
  55. #% type: string
  56. #% label: The name of the output files extension (used in i.rectify)
  57. #% description: The name of the output files extension (used in i.rectify)
  58. #% required: yes
  59. #% answer: _ip2i_out
  60. #%end
  61. """
  62. Module to run GCP management tool as stadalone application.
  63. @author Vaclav Petras <wenzeslaus gmail.com> (standalone module)
  64. """
  65. import os
  66. import grass.script as gscript
  67. def main():
  68. """Sets the GRASS display driver"""
  69. options, flags = gscript.parser()
  70. import wx
  71. from grass.script.setup import set_gui_path
  72. set_gui_path()
  73. from core.settings import UserSettings
  74. from core.giface import StandaloneGrassInterface
  75. from photo2image.ip2i_manager import GCPWizard
  76. driver = UserSettings.Get(group="display", key="driver", subkey="type")
  77. if driver == "png":
  78. os.environ["GRASS_RENDER_IMMEDIATE"] = "png"
  79. else:
  80. os.environ["GRASS_RENDER_IMMEDIATE"] = "cairo"
  81. if options["group"]:
  82. group = options["group"]
  83. else:
  84. gscript.fatal(_("Please provide a group name to process"))
  85. if options["raster"]:
  86. raster = options["raster"]
  87. else:
  88. gscript.fatal(_("Please provide a raster map name to process"))
  89. if options["camera"]:
  90. camera = options["camera"]
  91. else:
  92. gscript.fatal(_("Please provide a camera name (generated by i.ortho.camera)"))
  93. if options["order"]:
  94. order = options["order"]
  95. else:
  96. gscript.fatal(
  97. _("Please provive an order value (1 if 4 Fiducials, 2 if 8 Fiducials)")
  98. )
  99. if options["extension"]:
  100. extension = options["extension"]
  101. else:
  102. gscript.fatal(_("Please provive an output files extension (used by i.rectify)"))
  103. app = wx.App()
  104. wizard = GCPWizard(
  105. parent=None,
  106. giface=StandaloneGrassInterface(),
  107. group=group,
  108. raster=raster,
  109. raster1=raster,
  110. camera=camera,
  111. order=order,
  112. extension=extension,
  113. )
  114. app.MainLoop()
  115. if __name__ == "__main__":
  116. main()