MATLAB: Is there a way to adjust camera properties such as ExposureTime in a model while simulation is running

Image Acquisition Toolbox

I am using the Image Acquisition Toolbox block, From Video Device. Many camera settings can be adjusted using the Properties settings prior to running, however these appear to be locked when the simulation is going. I would like to adjust the camera exposure time using the image mean; too dark or too bright then adjust expsoure.
Is there a way to programmatically adjust camera properties such as ExposureTime in a model while simulation is running?

Best Answer

Currently the "From Video Device" block does not allow setting the camera parameters as an input port, and there is no other dedicated block that does this.
However, depending on the application, the following workaround might be acceptable.
See a simplistic example (camera_property.slx and updateCameraProperty.m) attached, as proof of concept.
This is using a MATLAB interpreted function block to set the camera property if the conditions are not optimum. The example uses Brightness, but it can be modified to use other camera properties, such as ExposureTime.
Note that this is only an example on how to set the property while the simulation is running -- it's not intended as a great example for optimizing the camera parameters for optimum exposure (other criteria and optimization algorithm should be used).
Also note that some adaptors allow you to set the camera properties while the the acquisition is running (for example gentl or gige), whereas other adaptors (for example winvideo which is used with webcams) do not allow setting the camera properties while the acquisition is running. In this case you need to stop the acquisition, set the new property value, then restart the acquisition. Because of this there will be a lower effective frame rate when adjusting the camera properties. On the other hand, if using the gentl adaptor you can set the camera property without stopping and restarting the camera acquisition.