marcolivierarsenault / moonraker-home-assistant

Home Assistant integration for Moonraker, Klipper and Mainsail
https://moonraker-home-assistant.readthedocs.io
MIT License
245 stars 26 forks source link

Rotation parameters for webcam #118

Closed goeland86 closed 6 months ago

goeland86 commented 1 year ago

Hi,

I love the integration, thank you so much for your extension! Lets me manage my printer farm efficiently.

I was just wondering, since on one of my machines the webcam is mounted upside down, what would I need to do to pull the webcam parameters from mainsail regarding rotation or flip of the image?

Or, maybe simpler, adding a property allowing the flip in horizontal or vertical modes just as the mainsail interface allows?

I'm happy to contribute the code needed for it, I'm just short on time to dig through and digest the whole code at the moment, so any pointers to get me started quickly would be great.

marcolivierarsenault commented 1 year ago

Hey, I have been looking at this and the Home Assistant camera platform we use (MJPEG) does not seems to support it natively.

I will look to see if there is a workaround, but it won't be a quick fix

goeland86 commented 1 year ago

Understood, let me know if there's anything I can do to help. If it's easier to modify the Mjpeg add-on to provide the functionality instead, I'll direct my efforts there.

marcolivierarsenault commented 1 year ago

Couple of things: 1) we can get the flip/rotation information easily from moonraker API:

{"result": {"webcam": {"name": "webcam", "location": "printer", "service": "mjpegstreamer-adaptive", "target_fps": "15", "stream_url": "/webcam/?action=stream", "snapshot_url": "/webcam/?action=snapshot", "flip_horizontal": false, "flip_vertical": false, "rotation": 0, "source": "database"}}}

2) We use the MJPEG object from core home assistant and I think we need to extend it. https://github.com/home-assistant/core/blob/609a7ccda85a48e3d14c14f789a66c5445bdd733/homeassistant/components/mjpeg/camera.py#L83

Best way to start for you is to clone this repo, open vscode which should open dev container. That will allow you to test (including modification of core HASS (for testing purposes))

Feel free to join our Slack if you want to chat about it

Kixel commented 1 year ago

I haven't read too much about it, but could a solution like in here be integrated into this? Not necessarily depending on card-mod, but re-use a part of it? https://community.home-assistant.io/t/rotate-webcam-feed-mjpeg-in-a-lovelace/164418/14

mk-maddin commented 1 year ago

Would be interested, too

Think a solution via e.g. card-mod would not help with as external services (like e.g. taking a snapshot etc.) would still be upside down. Re-Using the information from moonraker seems to be like the most beneficial information

goeland86 commented 1 year ago

I need to double check the code, but iirc Moonraker doesn't flip the video feed itself, it just rotates the display of the video in the UI (whether MS or Fluidd), and then whatever tool is taking a snapshot uses the rotation info to rotate the image after the snapshot is captured...

mk-maddin commented 1 year ago

maybe an option would be to rotate directly within webcam.txt / octoprint.txt..

https://community.home-assistant.io/t/rotate-a-camera-image-90-degrees/14539/11?u=mk-maddin

need to test it

marcolivierarsenault commented 1 year ago

Also looks like you can rotate it in lovelace: https://community.home-assistant.io/t/mjpeg-camera-rotation/130299

Snuffy2 commented 10 months ago

Anyone ever have success with any of these options? I've not gotten any of them to work to show both the still image and the livestream right side up.

marcolivierarsenault commented 10 months ago

AFAIK, no one is working on fixing this

pinkfloydFR commented 6 months ago

just use card mod :

card:
  type: picture-entity
  entity: camera.mkspi_webcam
  camera_view: live
  show_name: false
  show_state: false
  card_mod:
    style: |
      hui-image{
        transform: rotate(-180deg);        
      }
marcolivierarsenault commented 6 months ago

@pinkfloydFR this is fantastic, I will add to the documentation

Thanks that has been one of the annoying one for a long time.

marcolivierarsenault commented 6 months ago

added in the doc.