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

Re: Exposure & Gain

#11

Post by 1CM69 »

Hi,

OK, just got home from work & couldn't resist firing up the PC and giving this another go with a simple TrackBar Test script.

Although this seems to have got me further along the path, it is still a way off working exactly as the slider in SharpCap.

I have included set variables for ExposureMinMs & ExposureMaxMs, so there is no need to connect a camera. These variables are real world ones taken from my camera.

You'll see that the Label.Text updates with the movement of the TrackBar but in rather cumbersome steps of 100, (either *100 or /100) depending on direction.

Also I have set the TrackBar.Maximum using the equation: math.log10(ExpMax/ExpMin)*100, which should equate using my variable as: 779.588....
but the TrackBar itself is only recognising it as 700 because the Max Exposure reading output is 320s.

Here's my dirty code:
TrackBar_Test.txt
(1.52 KiB) Downloaded 146 times
Any further tips? Please :)

Cheers

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

Re: Exposure & Gain

#12

Post by 1CM69 »

oopfan wrote: Sat Aug 18, 2018 4:16 am 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
Ah, sorry Brian, I obviously misread your post.

I can totally see what you were getting at now.

Apologies

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

Re: Exposure & Gain

#13

Post by 1CM69 »

OK, I think I may have just had a brain wave *very painful* :lol:

Either that or everything people have been saying has finally sunk!!

I set the TrackBar.Minimum = 0 & TrackBar.Maximum = ExposureMaxMs

I can then use an equation as:

ExposureMs = (ExposureMinMs + (TrackBar.Value / 1000))

So in my example variables ExposureMs would still equal 0.032 with the TrackBar all the way to the left or at Value 0

increasing the TrackBar 1 increment to the right would make ExposureMs = 0.033 etc...

OK, so far to the right extreme of the TrackBar the value is 2000000 given my example variables and this would equate as:

ExposureMs = (0.032 + (2000000 / 1000)) or 2000.032

a bit messy but I will have conditional formatting with any (ms) value greater or equal to 1500 to change the display to (s) just as the built in SharpCap slider does.

After just finishing a nightshift, I am off to bed now. I test some code later & post results.

Cheers

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

Re: Exposure & Gain

#14

Post by oopfan »

Kirk,

Your code in TrackBar_Test.txt looks good but I can't explain why it max's out at 700, not 779. I would stick with that code instead of mine. Try different factors other than 100. It seems to me that 779 intervals is too high. Try a factor of 50 or 20.

What you have discovered are the limitations of the TrackBar control when selecting from an extremely wide range of values. That, I think, is why SharpCap gives you three controls for selecting exposure: a TrackBar, a ComboBox, and a TextBox. Personally I don't use the TrackBar. I use the ComboBox to quickly get in the neighborhood of the desired exposure, and then I use the TextBox to fine tune it.

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

Re: Exposure & Gain

#15

Post by 1CM69 »

Right, so I changed the code around to get it to work as outlined in my last post & yes, it sort of works but there are still a number of limitations.

I have found that the step changes using a mouse are strictly dependent on the width of the control i.e. the wider the control is the finer the steps are. Not ideal when working with a large range and cumbersome to use :(

I added a label to show the actual TrackBar.Value in order to check in testing & also added the TrackBar.SmallChange property set to 1 to aid fine tuning using the keyboard arrows.

A real problem however is the part of the script where I wish the formatting of the Label to change from displaying in (ms) to now show (s).

So, I have tried to do this by choosing 1.5(s) as a threshold, as SharpCap does & have coded the ExpVal to recognise when a value which is greater than or equal to 1500(ms) is reached, then divide this value by a further 1000, moving the decimal point 3 places left.

This does work with a but that I cannot iron out.

It now outputs any value from 1500(ms) onwards as a conversion to (s) but it is maxing out at 2.0(s) instead of 2000(s) using my ExposureMaxMs value of 2000000

So, I may come back to this or a simpler road for me to take is utilise the built in slider/combo/textbox of SharpCap and just have a 'Grab Value' button on my form to collect the Exposure Setting Value for further processing.

Anyway, here is version 2 of my last posted code:
TrackBar_Test_II.txt
(1.79 KiB) Downloaded 141 times
Cheers

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

Re: Exposure & Gain

#16

Post by oopfan »

Kirk,

In your OnChange method change this line:

ExpVal = ExpMin + (val / 1000.0)

to this:

ExpVal = ExpMin + val

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

Re: Exposure & Gain

#17

Post by 1CM69 »

oopfan wrote: Sat Aug 18, 2018 5:02 pm Kirk,

In your OnChange method change this line:

ExpVal = ExpMin + (val / 1000.0)

to this:

ExpVal = ExpMin + val

Brian
Hi Brian,

yep, tried that but that solves the top end issue to the detriment of the bottom end.

All low exposure time increment in whole numbers and instead of changing from 1500ms to 1.5s the change is to 1500s

Thanks for the reply though.

Cheers

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

Re: Exposure & Gain

#18

Post by 1CM69 »

Finally have it solved & working - sort of :|

Looking over my previous code time & time again and not spotting the glaring error, doh!

The ExpMax value of 2000000 I used for the TrackBar.Maximum value was the culprit.

This value is the actual Max Exposure time of my selected camera but using this I did not take in to account that the lowest Exp value was n/1000 below zero to start with, thus multiplying this ExpMax value by 1000 is in effect moving the decimal point of the lowest Exp value 3 places to the left to basically to zero, therefore in line with the TrackBar.Minimum value.

When I have said - sort of working I actually mean that it does in fact do what it is supposed to do although I find it more or less useless for my project as the steps are just too great when using a mouse approx 4.4s at the width I have set and as stated previously, the wider the control the smaller the mouse steps but that just interfers with screen real estate.

I have included 1 step increments using the arrow keys but that takes for ever, I have even added the LargeChange option of 2500 steps using PageUp, PageDown or by clicking either side of the slider but this again is a compromise.

I am now taking a differing approach in my script but anyone is welcome to take this up & use the code:
TrackBar_Test_III.txt
(1.89 KiB) Downloaded 153 times
as they wish.

Regards..,

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

Re: Exposure & Gain

#19

Post by 1CM69 »

Slightly stuck again.

I have got my new approach script working fine and am now trying to refine & tidy it up somewhat.

I am attempting to create a custom function that can be used by 4 different button click events, the idea is to cut down drastically on the number of lines in my script.
However, I keep getting an error: global name 'get_EV' is not defined I after trying a number of fixes I have got no where.

Here is a slimmed down version of my script just showing the button click event functions:

Code: Select all

	def btnLE_Click(self, sender, event):
		if SharpCap.SelectedCamera != None:
			EV = SharpCap.SelectedCamera.Controls.Exposure.Value
			if EV > 50:
				self.lblLEv.Text = str(format(EV, '.0f')) + "(s)"
				self.appendMessageText("Got LUMINANCE Exposure Value of: " + str(EV))
			else:
				self.lblLEv.Text = str(EV)
		else:
			SharpCap.ShowNotification('No Camera Selected! Please Select A Camera.')
			self.appendMessageText("No Camera Selected!")
			
	def btnRE_Click(self, sender, event):
		if SharpCap.SelectedCamera != None:
			EV = SharpCap.SelectedCamera.Controls.Exposure.Value
			if EV > 50:
				self.lblREv.Text = str(format(EV, '.0f')) + "(s)"
				self.appendMessageText("Got RED Exposure Value of: " + str(EV))
			else:
				self.lblREv.Text = str(EV)
		else:
			SharpCap.ShowNotification('No Camera Selected! Please Select A Camera.')
			self.appendMessageText("No Camera Selected!")
			
	def btnGE_Click(self, sender, event):
		if SharpCap.SelectedCamera != None:
			EV = SharpCap.SelectedCamera.Controls.Exposure.Value
			if EV > 50:
				self.lblGEv.Text = str(format(EV, '.0f')) + "(s)"
				self.appendMessageText("Got GREEN Exposure Value of: " + str(EV))
			else:
				self.lblREv.Text = str(EV)
		else:
			SharpCap.ShowNotification('No Camera Selected! Please Select A Camera.')
			self.appendMessageText("No Camera Selected!")
			
	def btnBE_Click(self, sender, event):
		if SharpCap.SelectedCamera != None:
			EV = SharpCap.SelectedCamera.Controls.Exposure.Value
			if EV > 50:
				self.lblBEv.Text = str(format(EV, '.0f')) + "(s)"
				self.appendMessageText("Got GREEN Exposure Value of: " + str(EV))
			else:
				self.lblGEv.Text = str(EV)
		else:
			SharpCap.ShowNotification('No Camera Selected! Please Select A Camera.')
			self.appendMessageText("No Camera Selected!")
Here is a slimmed down version that I am trying to achieve using the 'get_EV' to do the majority of the work:

Code: Select all

	def get_EV():
		EV = SharpCap.SelectedCamera.Controls.Exposure.Value
		if EV > 50:
			EV = str(format(EV, '.0f')) + "(s)"
		else:
			EV = str(EV)
		
	def btnLE_Click(self, sender, event):
		if SharpCap.SelectedCamera != None:
			get_EV()
			self.lbl.LEv.Text = EV
		else:
			SharpCap.ShowNotification('No Camera Selected! Please Select A Camera.')
			self.appendMessageText("No Camera Selected!")
			
	def btnRE_Click(self, sender, event):
		if SharpCap.SelectedCamera != None:
			get_EV()
			self.lbl.REv.Text = EV
		else:
			SharpCap.ShowNotification('No Camera Selected! Please Select A Camera.')
			self.appendMessageText("No Camera Selected!")
			
	def btnGE_Click(self, sender, event):
		if SharpCap.SelectedCamera != None:
			get_EV()
			self.lbl.GEv.Text = EV
		else:
			SharpCap.ShowNotification('No Camera Selected! Please Select A Camera.')
			self.appendMessageText("No Camera Selected!")
			
	def btnBE_Click(self, sender, event):
		if SharpCap.SelectedCamera != None:
			get_EV()
			self.lbl.BEv.Text = EV
		else:
			SharpCap.ShowNotification('No Camera Selected! Please Select A Camera.')
			self.appendMessageText("No Camera Selected!")
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

#20

Post by admin »

How about

Code: Select all

	def get_EV():
		exp =  SharpCap.SelectedCamera.Controls.Exposure.ExposureMs/1000
		if exp > 50:
			return str(format(exp, '.0f')) + "(s)"
		else:
			return str(exp)
			
	def btnLE_Click(self, sender, event):
		if SharpCap.SelectedCamera != None:
			self.lbl.LEv.Text = get_EV()
		else:
			SharpCap.ShowNotification('No Camera Selected! Please Select A Camera.')

Basically this way your get_EV() function returns a value rather than trying to set a global variable (which I'm not sure would work), then you just use the value returned from the function - much cleaner.

cheers,

Robin
Post Reply