{
  "id": 416333,
  "title": "How to supress output of pycolmap.incremental_mapping?",
  "url": "/competitions/image-matching-challenge-2023/discussion/416333",
  "author_name": "",
  "post_date": "2023-06-10T19:43:15.309997100Z",
  "votes": 2,
  "comment_count": 2,
  "views": 0,
  "content": "<p>I am attempting to mute the verbosity of the <code>pycolmap.incremental_mapping</code> function. I couldn't find any argument designed for that purpose. I'm curious to know if anyone has any insights or suggestions on how to do that.</p>",
  "messages": [
    {
      "id": "2295324",
      "postDate": "06/10/2023 19:43:15",
      "content": "<p>I am attempting to mute the verbosity of the <code>pycolmap.incremental_mapping</code> function. I couldn't find any argument designed for that purpose. I'm curious to know if anyone has any insights or suggestions on how to do that.</p>",
      "rawMarkdown": "I am attempting to mute the verbosity of the `pycolmap.incremental_mapping` function. I couldn't find any argument designed for that purpose. I'm curious to know if anyone has any insights or suggestions on how to do that.",
      "votes": null
    },
    {
      "id": "2299888",
      "postDate": "06/12/2023 23:18:40",
      "content": "<p>I learned from the hloc toolbox code how to suppress the output of colmap. pycolmap seems to have <a href=\"https://github.com/colmap/pycolmap/blob/master/main.cc#LL107C9-L107C29\" target=\"_blank\">an API to redirect ostreams</a>. This makes it possible to ignore the output.</p>\n<pre><code> contextlib\n io\n sys\n logging  getLogger\n\nlogger = getLogger(__name__)\n\n\n\n :\n     ():\n        self.verbose = verbose\n\n     ():\n          self.verbose:\n            self.capture = contextlib.redirect_stdout(io.StringIO())\n            self.out = self.capture.__enter__()\n\n     ():\n          self.verbose:\n            self.capture.__exit__(exc_type, *args)\n             exc_type   :\n                logger.error(, self.out.getvalue())\n        sys.stdout.flush()\n\n\n OutputCapture():\n     pycolmap.ostream():\n        maps = pycolmap.incremental_mapping(\n            database_path=database_path,\n            image_path=img_dir,\n            output_path=output_path,\n            options=mapper_options,\n        )\n</code></pre>",
      "rawMarkdown": "I learned from the hloc toolbox code how to suppress the output of colmap. pycolmap seems to have [an API to redirect ostreams](https://github.com/colmap/pycolmap/blob/master/main.cc#LL107C9-L107C29). This makes it possible to ignore the output.\n\n```python\nimport contextlib\nimport io\nimport sys\nfrom logging import getLogger\n\nlogger = getLogger(__name__)\n\n\n# ref: https://github.com/cvg/Hierarchical-Localization/blob/master/hloc/triangulation.py#L18\nclass OutputCapture:\n    def __init__(self, verbose: bool):\n        self.verbose = verbose\n\n    def __enter__(self):\n        if not self.verbose:\n            self.capture = contextlib.redirect_stdout(io.StringIO())\n            self.out = self.capture.__enter__()\n\n    def __exit__(self, exc_type, *args):\n        if not self.verbose:\n            self.capture.__exit__(exc_type, *args)\n            if exc_type is not None:\n                logger.error(\"Failed with output:\\n%s\", self.out.getvalue())\n        sys.stdout.flush()\n\n\nwith OutputCapture(False):\n    with pycolmap.ostream():\n        maps = pycolmap.incremental_mapping(\n            database_path=database_path,\n            image_path=img_dir,\n            output_path=output_path,\n            options=mapper_options,\n        )\n```",
      "votes": null
    },
    {
      "id": "2300708",
      "postDate": "06/13/2023 11:31:22",
      "content": "<p>I tried to redirect output to <code>/dev/null</code>, but didn't work. <br>\nI didn't know they had an api to redirect output.<br>\nThanks for the solution.</p>",
      "rawMarkdown": "I tried to redirect output to `/dev/null`, but didn't work. \nI didn't know they had an api to redirect output.\nThanks for the solution.",
      "votes": null
    }
  ],
  "comments": [
    {
      "id": 2299888,
      "author_name": "confirm",
      "author_url": "",
      "post_date": "06/12/2023 23:18:40",
      "content": "<p>I learned from the hloc toolbox code how to suppress the output of colmap. pycolmap seems to have <a href=\"https://github.com/colmap/pycolmap/blob/master/main.cc#LL107C9-L107C29\" target=\"_blank\">an API to redirect ostreams</a>. This makes it possible to ignore the output.</p>\n<pre><code> contextlib\n io\n sys\n logging  getLogger\n\nlogger = getLogger(__name__)\n\n\n\n :\n     ():\n        self.verbose = verbose\n\n     ():\n          self.verbose:\n            self.capture = contextlib.redirect_stdout(io.StringIO())\n            self.out = self.capture.__enter__()\n\n     ():\n          self.verbose:\n            self.capture.__exit__(exc_type, *args)\n             exc_type   :\n                logger.error(, self.out.getvalue())\n        sys.stdout.flush()\n\n\n OutputCapture():\n     pycolmap.ostream():\n        maps = pycolmap.incremental_mapping(\n            database_path=database_path,\n            image_path=img_dir,\n            output_path=output_path,\n            options=mapper_options,\n        )\n</code></pre>",
      "votes": null,
      "replies": [
        {
          "id": 2300708,
          "author_name": "tanjiroll",
          "author_url": "",
          "post_date": "06/13/2023 11:31:22",
          "content": "<p>I tried to redirect output to <code>/dev/null</code>, but didn't work. <br>\nI didn't know they had an api to redirect output.<br>\nThanks for the solution.</p>",
          "votes": null,
          "replies": []
        }
      ]
    }
  ],
  "raw_markdown_by_id": {
    "2295324": "I am attempting to mute the verbosity of the `pycolmap.incremental_mapping` function. I couldn't find any argument designed for that purpose. I'm curious to know if anyone has any insights or suggestions on how to do that.",
    "2299888": "I learned from the hloc toolbox code how to suppress the output of colmap. pycolmap seems to have [an API to redirect ostreams](https://github.com/colmap/pycolmap/blob/master/main.cc#LL107C9-L107C29). This makes it possible to ignore the output.\n\n```python\nimport contextlib\nimport io\nimport sys\nfrom logging import getLogger\n\nlogger = getLogger(__name__)\n\n\n# ref: https://github.com/cvg/Hierarchical-Localization/blob/master/hloc/triangulation.py#L18\nclass OutputCapture:\n    def __init__(self, verbose: bool):\n        self.verbose = verbose\n\n    def __enter__(self):\n        if not self.verbose:\n            self.capture = contextlib.redirect_stdout(io.StringIO())\n            self.out = self.capture.__enter__()\n\n    def __exit__(self, exc_type, *args):\n        if not self.verbose:\n            self.capture.__exit__(exc_type, *args)\n            if exc_type is not None:\n                logger.error(\"Failed with output:\\n%s\", self.out.getvalue())\n        sys.stdout.flush()\n\n\nwith OutputCapture(False):\n    with pycolmap.ostream():\n        maps = pycolmap.incremental_mapping(\n            database_path=database_path,\n            image_path=img_dir,\n            output_path=output_path,\n            options=mapper_options,\n        )\n```",
    "2300708": "I tried to redirect output to `/dev/null`, but didn't work. \nI didn't know they had an api to redirect output.\nThanks for the solution."
  },
  "source": "meta"
}