Exposure & Gain

Discussions on extending SharpCap using the built in Python scripting functionality
User avatar
1CM69
Posts: 63
Joined: Tue Nov 14, 2017 9:49 pm

Exposure & Gain

#1

Post by 1CM69 »

Is it possible to retrieve the camera specific exposure & gain settings from SharpCap.

i.e. I wish to populate a dropdown list on a GUI with the MIN to MAX exposure times for the given connected camera

also I would have a Trackbar on the GUI to mirror the Gain trackbar in SharpCap e.g only up to 100 for MONO etc...

Thanks in advance
User avatar
admin
Site Admin
Posts: 13122
Joined: Sat Feb 11, 2017 3:52 pm
Location: Vale of the White Horse, UK
Contact:

Re: Exposure & Gain

#2

Post by admin »

Hi,

yes, of course...

Code: Select all

>>> print SharpCap.SelectedCamera.Controls.Exposure.Minimum
0.001
>>> print SharpCap.SelectedCamera.Controls.Exposure.Maximum
1200000.0
>>> print SharpCap.SelectedCamera.Controls.Exposure.Value
20.0
>>> print SharpCap.SelectedCamera.Controls.Exposure.ExposureMs
20.0
>>> print SharpCap.SelectedCamera.Controls.Exposure.RawControl.ExposureValueType
MilliSeconds

Code: Select all

>>> print SharpCap.SelectedCamera.Controls.Gain.Minimum
0.0
>>> print SharpCap.SelectedCamera.Controls.Gain.Maximum
51.0
>>> print SharpCap.SelectedCamera.Controls.Gain.Value
40
Note that some cameras may not have a Gain control (some may not even have an exposure control - various webcams for instance). Also, the units of Min/Max/Value for exposure depend on the type of camera (see the ExposureValueType). ExposureMs is always in milliseconds though.

cheers,

Robin
User avatar
1CM69
Posts: 63
Joined: Tue Nov 14, 2017 9:49 pm

Re: Exposure & Gain

#3

Post by 1CM69 »

admin wrote: Thu Aug 16, 2018 4:19 pm Hi,

yes, of course...

Code: Select all

>>> print SharpCap.SelectedCamera.Controls.Exposure.Minimum
0.001
>>> print SharpCap.SelectedCamera.Controls.Exposure.Maximum
1200000.0
>>> print SharpCap.SelectedCamera.Controls.Exposure.Value
20.0
>>> print SharpCap.SelectedCamera.Controls.Exposure.ExposureMs
20.0
>>> print SharpCap.SelectedCamera.Controls.Exposure.RawControl.ExposureValueType
MilliSeconds

Code: Select all

>>> print SharpCap.SelectedCamera.Controls.Gain.Minimum
0.0
>>> print SharpCap.SelectedCamera.Controls.Gain.Maximum
51.0
>>> print SharpCap.SelectedCamera.Controls.Gain.Value
40
Note that some cameras may not have a Gain control (some may not even have an exposure control - various webcams for instance). Also, the units of Min/Max/Value for exposure depend on the type of camera (see the ExposureValueType). ExposureMs is always in milliseconds though.

cheers,

Robin
Hi Robin,

thanks for the reply, strangely I had just been messing around with lines similar to those myself.

Was really hoping to use the 'AvailableValues' property of Exposure but it just outputs as 'none', pity as that would have been very simple :lol:

Cheers

Kirk
User avatar
admin
Site Admin
Posts: 13122
Joined: Sat Feb 11, 2017 3:52 pm
Location: Vale of the White Horse, UK
Contact:

Re: Exposure & Gain

#4

Post by admin »

Hi Kirk,

AvailableValues is for controls that take multiple choice options (like 'On'/'Off', or 'Avi', 'Fits', 'Png' etc). It doesn't apply to controls that have numeric values.

cheers,

Robin
User avatar
1CM69
Posts: 63
Joined: Tue Nov 14, 2017 9:49 pm

Re: Exposure & Gain

#5

Post by 1CM69 »

admin wrote: Thu Aug 16, 2018 8:17 pm Hi Kirk,

AvailableValues is for controls that take multiple choice options (like 'On'/'Off', or 'Avi', 'Fits', 'Png' etc). It doesn't apply to controls that have numeric values.

cheers,

Robin
Thanks Robin.

A big ask now.

I am trying to emulate the Exposure TrackBar from SharpCap on to my script's GUI & while it sort of works I am having real trouble with the floating values because the TrackBar only excepts Integers.

So for instance, I can get the shortest exposure for my connected camera as 0.032ms but when I set this as the TrackBar.Minimum, it effectively starts at 0.0 & then the next increment up is 1.0, 2.0 & so on instead of 0.032, 0.033, 0.034 as shown in SharpCap.

How did you overcome this limitation of the TrackBar component?

Cheers

Kirk
User avatar
oopfan
Posts: 1320
Joined: Sat Jul 08, 2017 2:37 pm
Location: New York
Contact:

Re: Exposure & Gain

#6

Post by oopfan »

Kirk,

An example would be this:

Challenge: Use a TrackBar to select one of three colors: "Red", "Green" or "Blue"

Solution: Create a Label control next to your TrackBar control and set the value to "Red". Define your TrackBar control's range from integer 1 through 3. Set the initial value to 1. Write a procedure that responds to TrackBar notifications and then register it with the control. When the current TrackBar value changes, read it, and then update the Label's value with the corresponding string (i.e. 1="Red", 2="Green", 3="Blue")

Brian
User avatar
admin
Site Admin
Posts: 13122
Joined: Sat Feb 11, 2017 3:52 pm
Location: Vale of the White Horse, UK
Contact:

Re: Exposure & Gain

#7

Post by admin »

Hi Kirk,

the TrackBar (slider) controls that I use are happy with floating point values - that of course just means that someone else has solved the problem for me and I don't have to worry about it...

If I had to deal with integer only track bars I'd start off by setting the limits so for instance

Track Bar Value 0 <=> Exposure 0.032ms
Track Bar Value 10000 <=> Exposure 60s

from this we can calculate that

ExposureMS = 6 * track bar value + 0.032

Now the problem here is that you haven't really got enough range at the top (60s limit) and the accuracy at the bottom is limited (6ms increments), so actually it's better to use a logarithmic scale instead...

ExposureMs = A * Pow(10, TrackBarValue / B)

If we set B to say 100 then a change in value of the track bar by 100 will multiple or divide the exposure by 10. Make A 0.032ms then the minimum works out correctly when TrackBarValue = 0. If you let the track bar value go up to 700, then that gives a maximum exposure of 320s, let it go up to 800 and you get a maximum of 3200s.

If you need the formulat the other way around then

TrackBarValue = Log10(ExposureMs/A) *B

Hope this helps,

Robin
User avatar
1CM69
Posts: 63
Joined: Tue Nov 14, 2017 9:49 pm

Re: Exposure & Gain

#8

Post by 1CM69 »

admin wrote: Fri Aug 17, 2018 8:27 pm Hi Kirk,

the TrackBar (slider) controls that I use are happy with floating point values - that of course just means that someone else has solved the problem for me and I don't have to worry about it...

If I had to deal with integer only track bars I'd start off by setting the limits so for instance

Track Bar Value 0 <=> Exposure 0.032ms
Track Bar Value 10000 <=> Exposure 60s

from this we can calculate that

ExposureMS = 6 * track bar value + 0.032

Now the problem here is that you haven't really got enough range at the top (60s limit) and the accuracy at the bottom is limited (6ms increments), so actually it's better to use a logarithmic scale instead...

ExposureMs = A * Pow(10, TrackBarValue / B)

If we set B to say 100 then a change in value of the track bar by 100 will multiple or divide the exposure by 10. Make A 0.032ms then the minimum works out correctly when TrackBarValue = 0. If you let the track bar value go up to 700, then that gives a maximum exposure of 320s, let it go up to 800 and you get a maximum of 3200s.

If you need the formulat the other way around then

TrackBarValue = Log10(ExposureMs/A) *B

Hope this helps,

Robin
Thanks Robin,

that gives me plenty to work with.

Cheers

Kirk
User avatar
1CM69
Posts: 63
Joined: Tue Nov 14, 2017 9:49 pm

Re: Exposure & Gain

#9

Post by 1CM69 »

oopfan wrote: Fri Aug 17, 2018 5:17 pm Kirk,

An example would be this:

Challenge: Use a TrackBar to select one of three colors: "Red", "Green" or "Blue"

Solution: Create a Label control next to your TrackBar control and set the value to "Red". Define your TrackBar control's range from integer 1 through 3. Set the initial value to 1. Write a procedure that responds to TrackBar notifications and then register it with the control. When the current TrackBar value changes, read it, and then update the Label's value with the corresponding string (i.e. 1="Red", 2="Green", 3="Blue")

Brian
Hi Brian

thanks for your reply.

I’m fine coding the TrackBar within set given limits but the issue is that the Minimum & Maximum values are not fixed and vary depending on attached camera.

At the moment I have set the TrackBar.Minimum to SelectedCamera.ExposureMinMs & TrackBar.Maximum to Selected.Camera.ExposureMaxMs

For my test camera these values are 0.032ms & 2000000ms respectively.

With formatting I am appending the TrackBar.Value to a Label() component, much as you have outlined, that’s not a problem.

Unfortunately it’s the steadfast use of int32 that the TrackBar uses which means that it does/is not allowing fractional increments.

It looks like I’ll need to implement something as Robin has posted with an equation to correct the required values.

I’ll post back my results as soon as I have a workaround.

Cheers

Kirk
User avatar
oopfan
Posts: 1320
Joined: Sat Jul 08, 2017 2:37 pm
Location: New York
Contact:

Re: Exposure & Gain

#10

Post by oopfan »

Kirk,

Robin and I are in agreement, we just used different examples. You need to set up the control so that you are notified of changes via a user function. Your function needs to convert the integer value to a floating value that is equivalent to the exposure in milliseconds or whatever units you prefer. I am guessing that the default behavior of the control is to display the integer value. You need to find a property that tells it to suppress that. You need to display your computed value instead. You can do that with a Label control, or perhaps the TrackBar control offers you a method.

You should not set TrackBar.Minimum = SelectedCamera.ExposureMinMs since the right-hand-side is a float and the left-hand-side is an integer. You need to set TrackBar.Minimum and Maximum to integers, for example 0 to 10, then your function that I talked about earlier computes the floating value from that integer, for example: floatingValue = integerValue * (SelectedCamera.ExposureMaxMs - SelectedCamera.ExposureMinMs) / 10 + SelectedCamera.ExposureMinMs. In this example there are 10 equal intervals from MinMs to MaxMs. Your requirements may differ but the key point is that this is how GUI frameworks achieve reusability. Every application can use this control but they need to define a mapping function from the integer to the float.

Brian
Post Reply