Title: Unable to change PixelFormat with AccessMode.Full · Issue #178 · alliedvision/VimbaPython · GitHub
Open Graph Title: Unable to change PixelFormat with AccessMode.Full · Issue #178 · alliedvision/VimbaPython
X Title: Unable to change PixelFormat with AccessMode.Full · Issue #178 · alliedvision/VimbaPython
Description: Hello, I am modifying the asynchronous_grab_opencv.py example to set the camera's configuration from an XML file that I have, which contains exposure / color balance configuration that I like. However, when I try to call cam.load_setting...
Open Graph Description: Hello, I am modifying the asynchronous_grab_opencv.py example to set the camera's configuration from an XML file that I have, which contains exposure / color balance configuration that I like. Howe...
X Description: Hello, I am modifying the asynchronous_grab_opencv.py example to set the camera's configuration from an XML file that I have, which contains exposure / color balance configuration that I like. ...
Opengraph URL: https://github.com/alliedvision/VimbaPython/issues/178
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Unable to change PixelFormat with AccessMode.Full","articleBody":"Hello,\r\n\r\nI am modifying the asynchronous_grab_opencv.py example to set the camera's configuration from an XML file that I have, which contains exposure / color balance configuration that I like.\r\n\r\nHowever, when I try to call cam.load_settings() I get an exception:\r\n`vmbpy.error.VmbFeatureError: Invalid access while calling 'set()' of Feature 'PixelFormat'. Read access: allowed. Write access: not allowed. `\r\n\r\nI have added a call to set the access mode of the camera to \"Full\", in the get_camera method (it's the only place where the cam object is not in a with context block)\r\n\r\nI have checked that the access mode is still set to Full later when I call load_settings.\r\nI am at a loss as to why this doesn't work, I can change the PixelFormat no problem in VimbaXViewr, that's how I generated this XML file in the first place.\r\n\r\nAny help would be appreciated. Thanks in advance.\r\n\r\nHere is the python script in its entirety:\r\n\r\n```\r\n\"\"\"BSD 2-Clause License\r\n\r\nCopyright (c) 2023, Allied Vision Technologies GmbH\r\nAll rights reserved.\r\n\r\nRedistribution and use in source and binary forms, with or without\r\nmodification, are permitted provided that the following conditions are met:\r\n\r\n1. Redistributions of source code must retain the above copyright notice, this\r\n list of conditions and the following disclaimer.\r\n\r\n2. Redistributions in binary form must reproduce the above copyright notice,\r\n this list of conditions and the following disclaimer in the documentation\r\n and/or other materials provided with the distribution.\r\n\r\nTHIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \"AS IS\"\r\nAND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r\nIMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE\r\nDISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE\r\nFOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r\nDAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR\r\nSERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER\r\nCAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,\r\nOR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\r\nOF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r\n\"\"\"\r\nimport sys\r\nfrom typing import Optional\r\nfrom queue import Queue\r\n\r\nfrom vmbpy import *\r\n\r\n\r\n# All frames will either be recorded in this format, or transformed to it before being displayed\r\nopencv_display_format = PixelFormat.Bgr8\r\n\r\n\r\ndef print_preamble():\r\n print('///////////////////////////////////////////////////')\r\n print('/// VmbPy Asynchronous Grab with OpenCV Example ///')\r\n print('///////////////////////////////////////////////////\\n')\r\n\r\n\r\ndef print_usage():\r\n print('Usage:')\r\n print(' python asynchronous_grab_opencv.py [camera_id]')\r\n print(' python asynchronous_grab_opencv.py [/h] [-h]')\r\n print()\r\n print('Parameters:')\r\n print(' camera_id ID of the camera to use (using first camera if not specified)')\r\n print()\r\n\r\n\r\ndef abort(reason: str, return_code: int = 1, usage: bool = False):\r\n print(reason + '\\n')\r\n\r\n if usage:\r\n print_usage()\r\n\r\n sys.exit(return_code)\r\n\r\n\r\ndef parse_args() -\u003e Optional[str]:\r\n args = sys.argv[1:]\r\n argc = len(args)\r\n\r\n for arg in args:\r\n if arg in ('/h', '-h'):\r\n print_usage()\r\n sys.exit(0)\r\n\r\n if argc \u003e 1:\r\n abort(reason=\"Invalid number of arguments. Abort.\", return_code=2, usage=True)\r\n\r\n return None if argc == 0 else args[0]\r\n\r\n\r\ndef get_camera(camera_id: Optional[str]) -\u003e Camera:\r\n with VmbSystem.get_instance() as vmb:\r\n if camera_id:\r\n try:\r\n return vmb.get_camera_by_id(camera_id)\r\n\r\n except VmbCameraError:\r\n abort('Failed to access Camera \\'{}\\'. Abort.'.format(camera_id))\r\n\r\n else:\r\n cams = vmb.get_all_cameras()\r\n if not cams:\r\n abort('No Cameras accessible. Abort.')\r\n cam = cams[0]\r\n cam.set_access_mode(AccessMode.Full)\r\n\r\n return cams[0]\r\n\r\n\r\ndef setup_camera(cam: Camera):\r\n #cam.set_access_mode(AccessMode.Full)\r\n\r\n with cam:\r\n #try to set the camera's config from an XML file\r\n try:\r\n print(cam.get_access_mode())\r\n print(\"LOADING SETTINGS FROM XML\")\r\n cam.load_settings(\"my_camera_settings.xml\", PersistType.All)\r\n except (AttributeError, VmbFeatureError):\r\n print(\"Failed to load settings from XML file\")\r\n pass\r\n \r\n # # Enable auto exposure time setting if camera supports it\r\n \r\n # try:\r\n # cam.ExposureAuto.set('Continuous')\r\n\r\n # except (AttributeError, VmbFeatureError):\r\n # pass\r\n\r\n # # Enable white balancing if camera supports it\r\n # try:\r\n # cam.BalanceWhiteAuto.set('Continuous')\r\n\r\n # except (AttributeError, VmbFeatureError):\r\n # pass\r\n \r\n \r\n\r\n # Try to adjust GeV packet size. This Feature is only available for GigE - Cameras.\r\n try:\r\n stream = cam.get_streams()[0]\r\n stream.GVSPAdjustPacketSize.run()\r\n while not stream.GVSPAdjustPacketSize.is_done():\r\n pass\r\n\r\n except (AttributeError, VmbFeatureError):\r\n pass\r\n\r\n\r\ndef setup_pixel_format(cam: Camera):\r\n # Query available pixel formats. Prefer color formats over monochrome formats\r\n cam_formats = cam.get_pixel_formats()\r\n cam_color_formats = intersect_pixel_formats(cam_formats, COLOR_PIXEL_FORMATS)\r\n convertible_color_formats = tuple(f for f in cam_color_formats\r\n if opencv_display_format in f.get_convertible_formats())\r\n\r\n cam_mono_formats = intersect_pixel_formats(cam_formats, MONO_PIXEL_FORMATS)\r\n convertible_mono_formats = tuple(f for f in cam_mono_formats\r\n if opencv_display_format in f.get_convertible_formats())\r\n\r\n # if OpenCV compatible color format is supported directly, use that\r\n if opencv_display_format in cam_formats:\r\n cam.set_pixel_format(opencv_display_format)\r\n\r\n # else if existing color format can be converted to OpenCV format do that\r\n elif convertible_color_formats:\r\n cam.set_pixel_format(convertible_color_formats[0])\r\n\r\n # fall back to a mono format that can be converted\r\n elif convertible_mono_formats:\r\n cam.set_pixel_format(convertible_mono_formats[0])\r\n\r\n else:\r\n abort('Camera does not support an OpenCV compatible format. Abort.')\r\n\r\n\r\nclass Handler:\r\n def __init__(self):\r\n self.display_queue = Queue(10)\r\n\r\n def get_image(self):\r\n return self.display_queue.get(True)\r\n\r\n def __call__(self, cam: Camera, stream: Stream, frame: Frame):\r\n if frame.get_status() == FrameStatus.Complete:\r\n print('{} acquired {}'.format(cam, frame), flush=True)\r\n\r\n # Convert frame if it is not already the correct format\r\n if frame.get_pixel_format() == opencv_display_format:\r\n display = frame\r\n else:\r\n # This creates a copy of the frame. The original `frame` object can be requeued\r\n # safely while `display` is used\r\n display = frame.convert_pixel_format(opencv_display_format)\r\n\r\n self.display_queue.put(display.as_opencv_image(), True)\r\n\r\n cam.queue_frame(frame)\r\n\r\n\r\ndef main():\r\n print_preamble()\r\n cam_id = parse_args()\r\n\r\n with VmbSystem.get_instance():\r\n with get_camera(cam_id) as cam:\r\n # setup general camera settings and the pixel format in which frames are recorded\r\n setup_camera(cam)\r\n setup_pixel_format(cam)\r\n handler = Handler()\r\n\r\n try:\r\n # Start Streaming with a custom a buffer of 10 Frames (defaults to 5)\r\n cam.start_streaming(handler=handler, buffer_count=10)\r\n\r\n msg = 'Stream from \\'{}\\'. Press \u003cEnter\u003e to stop stream.'\r\n import cv2\r\n ENTER_KEY_CODE = 13\r\n while True:\r\n key = cv2.waitKey(1)\r\n if key == ENTER_KEY_CODE:\r\n cv2.destroyWindow(msg.format(cam.get_name()))\r\n break\r\n\r\n display = handler.get_image()\r\n #resize display to 1080p\r\n display = cv2.resize(display, (1920, 1080))\r\n cv2.imshow(msg.format(cam.get_name()), display)\r\n\r\n finally:\r\n cam.stop_streaming()\r\n\r\n\r\nif __name__ == '__main__':\r\n main()\r\n\r\n```","author":{"url":"https://github.com/nparker2020","@type":"Person","name":"nparker2020"},"datePublished":"2024-01-05T17:16:22.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":3},"url":"https://github.com/178/VimbaPython/issues/178"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:fa1d34ab-282d-f40a-ee62-9153afa09f53 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | B4FE:282357:2649441:35ED323:6A4CE480 |
| html-safe-nonce | f56f097675dcd5eb5a60cb9ed399608a0c63d6b9bb4fa9227283e24b896c30e5 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCNEZFOjI4MjM1NzoyNjQ5NDQxOjM1RUQzMjM6NkE0Q0U0ODAiLCJ2aXNpdG9yX2lkIjoiNTQ2ODcyNzA4MTc2NzMzMDk0NCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | bff3bcbb84985070b27b2d157ba73640512d6f765424ff7b4300555793907229 |
| hovercard-subject-tag | issue:2067729178 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/alliedvision/VimbaPython/178/issue_layout |
| twitter:image | https://opengraph.githubassets.com/983b9937c22cb41cf89e3ce057df6ad19728a0f19620b08468da9d47d8f7e47a/alliedvision/VimbaPython/issues/178 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/983b9937c22cb41cf89e3ce057df6ad19728a0f19620b08468da9d47d8f7e47a/alliedvision/VimbaPython/issues/178 |
| og:image:alt | Hello, I am modifying the asynchronous_grab_opencv.py example to set the camera's configuration from an XML file that I have, which contains exposure / color balance configuration that I like. Howe... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | nparker2020 |
| hostname | github.com |
| expected-hostname | github.com |
| None | 299b43bca6e02ad35197ffeba30d2466846d5fb02ab96fbced5b5e6cec589fb8 |
| turbo-cache-control | no-preview |
| go-import | github.com/alliedvision/VimbaPython git https://github.com/alliedvision/VimbaPython.git |
| octolytics-dimension-user_id | 26818220 |
| octolytics-dimension-user_login | alliedvision |
| octolytics-dimension-repository_id | 224388237 |
| octolytics-dimension-repository_nwo | alliedvision/VimbaPython |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 224388237 |
| octolytics-dimension-repository_network_root_nwo | alliedvision/VimbaPython |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | c5a57f04eeb310f57c73fd6d751d957e2ca27ed2 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width