# Camera parameters update

**URL:** <https://discourse.farm-ng.com/t/camera-parameters-update/242>\
**Category:** development\
**Tags:** amiga\
**Created:** [August 28, 2023, 10:40pm UTC](https://discourse.farm-ng.com/t/camera-parameters-update/242 "2023-08-28T22:40:18Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![dariojavo](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.farm-ng.com/dariojavo/32/186_2.png) [@dariojavo](https://discourse.farm-ng.com/u/dariojavo)\
**Post date:** [August 28, 2023, 10:40pm UTC](https://discourse.farm-ng.com/t/camera-parameters-update/242/1 "2023-08-28T22:40:18Z")

</div>

Hi,

I’m trying to change the camera parameters of multiple cameras from a kivy app. Unfortunately, for now I have only been able to change the parameters when the code starts since I am not able to re-write the configuration while streaming. How can I change the parameters while streaming, or how can I stop the camera stream, in order to modify the parameters and start the stream again?

Thanks in advance!

Best,  
Dario

---

<div class="post-metadata">

**Author:** ![kylecoble](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.farm-ng.com/kylecoble/32/12_2.png) [@kylecoble](https://discourse.farm-ng.com/u/kylecoble)\
**Post date:** [August 29, 2023, 4:21pm UTC](https://discourse.farm-ng.com/t/camera-parameters-update/242/2 "2023-08-29T16:21:52Z")

</div>

Hello @dariojavo ,

This should be possible through the Oak client, assuming you want to change something in the `CameraSettings` proto definition (e.g. exposure time).

> <https://github.com/farm-ng/farm-ng-amiga/blob/main-v2/protos/farm_ng/oak/oak.proto#L21-L26>

There are some parameters that have to be set when the camera is connected to, so can you be more specific on what it is exactly you want to do?

Also, can you please provide what version of the brainOS you have or a picture of the home screen?

Thank you.

– Kyle

---

<div class="post-metadata">

**Author:** ![dariojavo](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.farm-ng.com/dariojavo/32/186_2.png) [@dariojavo](https://discourse.farm-ng.com/u/dariojavo)\
**Post date:** [August 29, 2023, 5:16pm UTC](https://discourse.farm-ng.com/t/camera-parameters-update/242/3 "2023-08-29T17:16:03Z")

</div>

Hi Kyle,

Thanks for your response. Yes, that is in fact what I have used to modify the settings. I have been able to do it before the stream is created. Following you camera streaming template that would be in here:

```auto
# Create the stream
            if response_stream is None:
                 #Change camera settings (Change exposure, iso, ....)
                 response_stream = client.stream_frames(every_n=self.stream_every_n)

```

However, I have been able to do this only before streaming, once the camera start streaming I can not change the camera settings without getting the camera going down. Is there a way to change the camera settings in live or either stop the camera service in order to change the parameters and start the service again?

I’m currently on Amiga OS 1.2.

Thanks,  
Dario

---

<div class="post-metadata">

**Author:** ![kylecoble](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.farm-ng.com/kylecoble/32/12_2.png) [@kylecoble](https://discourse.farm-ng.com/u/kylecoble)\
**Post date:** [August 29, 2023, 5:37pm UTC](https://discourse.farm-ng.com/t/camera-parameters-update/242/4 "2023-08-29T17:37:09Z")

</div>

Thank you for the clarification @dariojavo ,

Have you tried using the `update_rgb_settings` or `update_mono_settings` methods of the `OakCameraClient` , followed by `send_settings`?

`update_rgb_settings` and `update_mono_settings` take a `CameraSettings` proto as an argument. You should be able to do this while the cameras are streaming and the stream will continue on with the new settings. If you want to change the rate with the `every_n` argument, you should cancel the stream and restart it.

See:

> <https://github.com/farm-ng/farm-ng-amiga/blob/main/py/farm_ng/oak/camera_client.py#L113-L121>

And:

> <https://github.com/farm-ng/farm-ng-amiga/blob/main/py/farm_ng/oak/camera_client.py#L98-L103>

– Kyle

---

<div class="post-metadata">

**Author:** ![dariojavo](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.farm-ng.com/dariojavo/32/186_2.png) [@dariojavo](https://discourse.farm-ng.com/u/dariojavo)\
**Post date:** [August 29, 2023, 5:52pm UTC](https://discourse.farm-ng.com/t/camera-parameters-update/242/5 "2023-08-29T17:52:38Z")

</div>

Hi Kyle,

Thanks for the fast response.

Yes, I have used update\_rgb\_settings, update\_mono\_settings, and send\_settings, and they worked, that is how I was able to change the parameters before streaming. Please see below how I am currently changing the parameters.

```auto
            # Create the stream
            if response_stream is None:
                # Update camera parameters
                # Create a new instance of CameraSettings with desired parameters
                new_rgb_settings = new_mono_settings = oak_pb2.CameraSettings(
                    auto_exposure = self.auto_exposure, # Set auto exposure
                    exposure_time = self.exposure_time, # Assume this is in us
                    iso_value = self.iso # ISO value
                )
                               
                # Assuming new_rgb_settings is a protobuf object of CameraSettings type
                client.update_rgb_settings(new_rgb_settings)

                # Similarly for mono camera
                client.update_mono_settings(new_mono_settings)
                await asyncio.sleep(1)
                # Send modified settings to the camera
                response = await client.send_settings()

                if response:
                    print(f"Ok, parameters have been updated for {port}")

                response_stream = client.stream_frames(every_n=self.stream_every_n)

```

Thanks in advance.

Best,  
Dario.

---

<div class="post-metadata">

**Author:** ![kylecoble](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.farm-ng.com/kylecoble/32/12_2.png) [@kylecoble](https://discourse.farm-ng.com/u/kylecoble)\
**Post date:** [August 29, 2023, 6:33pm UTC](https://discourse.farm-ng.com/t/camera-parameters-update/242/6 "2023-08-29T18:33:51Z")

</div>

@dariojavo that looks good.

For what you want to do, you can:

1. Make `client` a class arg (e.g., `self.client`).
2. Create a separate asyncio task that only does the parameter changes and does NOT call `stream_frames`. (see example below based on your code)
3. Call this function when a button is pressed, or make this a forever running loop that checks for settings changes and sends the update when they’re changed. Something along those lines.

```python
            async def update_settings(self):
                new_rgb_settings = oak_pb2.CameraSettings(
                    auto_exposure = self.auto_exposure, # Set auto exposure
                    exposure_time = self.exposure_time, # Assume this is in us
                    iso_value = self.iso # ISO value
                )
                new_mono_settings = new_rgb_settings
                               
                # Assuming new_rgb_settings is a protobuf object of CameraSettings type
                self.client.update_rgb_settings(new_rgb_settings)

                # Similarly for mono camera
                self.client.update_mono_settings(new_mono_settings)

                # Send modified settings to the camera
                response = await self.client.send_settings()

                print(response)

```

What is important is that you let the while loop with `stream_frames` keep running and do this settings change in a separate function.

– Kyle

---

<div class="post-metadata">

**Author:** ![dariojavo](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.farm-ng.com/dariojavo/32/186_2.png) [@dariojavo](https://discourse.farm-ng.com/u/dariojavo)\
**Post date:** [August 29, 2023, 7:48pm UTC](https://discourse.farm-ng.com/t/camera-parameters-update/242/7 "2023-08-29T19:48:32Z")

</div>

Thanks Kyle, I will take a look on this during the week and let you know how it goes.

Best,  
Dario

---

<div class="post-metadata">

**Author:** ![kylecoble](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.farm-ng.com/kylecoble/32/12_2.png) [@kylecoble](https://discourse.farm-ng.com/u/kylecoble)\
**Post date:** [August 29, 2023, 7:55pm UTC](https://discourse.farm-ng.com/t/camera-parameters-update/242/8 "2023-08-29T19:55:30Z")

</div>

Looking forward to hearing about it.

– Kyle

---

<div class="post-metadata">

**Author:** ![dariojavo](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.farm-ng.com/dariojavo/32/186_2.png) [@dariojavo](https://discourse.farm-ng.com/u/dariojavo)\
**Post date:** [September 16, 2023, 12:54am UTC](https://discourse.farm-ng.com/t/camera-parameters-update/242/9 "2023-09-16T00:54:00Z")

</div>

Hi Kyle,

I have been working now with the OS 2.0, and the recorder\_v2 app. Considering this, it has been difficult for me to understand how to change the parameters of the camera in the `stream_camera` function. I have tried for example to see the camera calibration:

```
    camera_subscription = SubscribeRequest(
        uri=uri_pb2.Uri(
            # path=f"/{service_name}/{stream_name}",
            path=f"/calibration",
            query=f"service_name={service_name}",
        ),
        every_n=1,
    )        

```

> async for \_, message in camera\_client.subscribe(  
> camera\_subscription, decode=True  
> ):
> 
> ```
> print(message)
> 
> ```

and it works! However, when I tried to access in the same way the `/camera_settings/rgb` to see them and modifying if keeps forever in a loop. How can I access and modify the camera parameters, similar to what I was doing before, with this new pipeline?

Thanks in advance Kyle!

Best,  
Dario

---

<div class="post-metadata">

**Author:** ![kylecoble](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.farm-ng.com/kylecoble/32/12_2.png) [@kylecoble](https://discourse.farm-ng.com/u/kylecoble)\
**Post date:** [September 25, 2023, 3:33pm UTC](https://discourse.farm-ng.com/t/camera-parameters-update/242/10 "2023-09-25T15:33:02Z")

</div>

Hello @dariojavo ,

I apologize for the delayed response, we were very busy with preparations for and attending the FIRA conference.

We have a good example for exactly what you want to do! It’s not yet merged into [GitHub - farm-ng/farm-ng-amiga at main-v2](https://github.com/farm-ng/farm-ng-amiga/tree/main-v2) (the `farm-ng-amiga` branch that corresponds to AmigaOS v2.x), so it would’ve been hard for you to find this.

The takeaway is that you want to use the `request_reply` method of the `EventClient` for single message queries like `calibration` & `/camera_settings/rgb`. There is no need to create a full “subscribe” loop for these single requests.

For calibration, you can do something like:

```plaintext
    # get the calibration message
    reply = await camera_client.request_reply("/calibration", Empty())

    # parse the reply
    calibration: oak_pb2.OakCalibration = payload_to_protobuf(reply.event, reply.payload)
    print(calibration)

```

For camera settings, you can do something like:

```plaintext
    camera_settings_request = oak_pb2.CameraSettings(
    # Enter your parameters here
    )
    reply = await camera_client.request_reply(f"/camera_settings/{stream_name}", camera_settings_request)

    # parse the reply
    camera_settings: oak_pb2.CameraSettings = payload_to_protobuf(reply.event, reply.payload)
    print(camera_settings)

```

**Check out the full examples here:**

Camera calibration example:

> <https://github.com/farm-ng/farm-ng-amiga/blob/a6c7f5051df4fda6bf62402c61fb519ee15ffccc/py/examples/camera_calibration/main.py>

Camera settings example:

> <https://github.com/farm-ng/farm-ng-amiga/blob/a6c7f5051df4fda6bf62402c61fb519ee15ffccc/py/examples/camera_settings/main.py>

Good luck!  
Kyle
