Help for Scripting my AVI camera

Discussions on extending SharpCap using the built in Python scripting functionality
DavidCollings
Posts: 7
Joined: Thu Apr 20, 2017 4:21 am

Help for Scripting my AVI camera

#1

Post by DavidCollings »

Can anyone help with simple camera scripting?
I am trying to execute a script to begin an AVI capture with my camera, for 15 secs, save the AVI file to disk, delay for 3 minutes, then resume 15 sec captures and 3 min delays with saves to disk for a total of 1hr 21 mins. then stop.
I would have the camera in Live mode, file name for saves set, focused, gamma set, exposure set, gain set, as well as brightness and contrast prior to executing the script.
I just do not know what the syntax is in the parenthesis for the commands to begin capture for 'x' secs and delay 'x' secs, and resume capture until end of sequence 'x'.

Appreciate any help that someone can give if this has been done before.

Example #1 : RunCapture () What syntax goes in between the parenthesis to make the command work?
Example #2 : CaptureConfig () Same question as above. What syntax in between the parenthesis?

Thank you for any help
Dave Collings
pgn
Posts: 17
Joined: Wed Mar 08, 2017 9:46 am

Re: Help for Scripting my AVI camera

#2

Post by pgn »

Hi, there are experts here, but having struggled myself you might find this helps.

Firstly the time issue.

At the start of your script you can import the time module and then use it to generate delays.

import time
time.sleep(0.1) # to put in a delay of 0.1 seconds - obviously you need bigger values

Then for much of the rest I there are two avenues to get info. you may be missing.

1) on the home page, the scripting item in the table is a link; easy to miss. This takes you to this page

http://www.sharpcap.co.uk/sharpcap/sharpcap-scripting

2) In the Console (with camera attached - seems to make a difference sometimes) are you getting the help prompts both for the possible command completion and info as you scroll down the table on each possible code completion

EG if you type in
SharpCap.SelectedCamera.CaptureConfig.
do you get a pop up window as you type the final "." and if you highlight an option by scrolling down do you see any additional info?

If you have already been using these I may be able to help if you can sedn lines that are failing.

Hope that helps; the struggles are very recent for me too.

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

Re: Help for Scripting my AVI camera

#3

Post by admin »

Hi Dave,

you will find a good deal of help in the sources Peter has quoted, but here are some more snippets to get you going

Code: Select all

# Select a camera by name
SharpCap.SelectedCamera = SharpCap.Cameras.Find(lambda x:x.DeviceName == 'GPCAMAR0130C')

Code: Select all

# Setup a capture limited to 15s, then 120s wait, repeat 10 times
import clr
clr.AddReference("SharpCap")
from SharpCap.UI import CaptureLimitType
SharpCap.SelectedCamera.CaptureConfig.CaptureLimitType = CaptureLimitType.TimeLimited
SharpCap.SelectedCamera.CaptureConfig.CaptureLimitValue = 15
SharpCap.SelectedCamera.CaptureConfig.CaptureSequenceCount = 10
SharpCap.SelectedCamera.CaptureConfig.CaptureSequenceInterval = 120

Code: Select all

#start the capture
SharpCap.SelectedCamera.PrepareToCapture()
SharpCap.SelectedCamera.RunCapture()
Hope that helps,

Robin
DavidCollings
Posts: 7
Joined: Thu Apr 20, 2017 4:21 am

Re: Help for Scripting my AVI camera

#4

Post by DavidCollings »

Thank you for the info Peter!

I will try again and look for the popups with my camera connected.

If you could send me any scripting you may have written with your comments that would help me to understand more of the environment even though your application may be different from what I am trying to do.

Just trying to do these simple tasks but is more complex than I thought!

Dave
DavidCollings
Posts: 7
Joined: Thu Apr 20, 2017 4:21 am

Re: Help for Scripting my AVI camera

#5

Post by DavidCollings »

Thank you Robin!! Just saw your post.

I will give all this a try and let you all know how I make out.

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

Re: Help for Scripting my AVI camera

#6

Post by admin »

Hi Dave,

good luck :)

Note that the capture limit configuration bit currently doesn't work in the 3.0 beta build (only just found this out) - working out why and will fix. You will need to test in 2.9 for now.

cheers,

Robin
pgn
Posts: 17
Joined: Wed Mar 08, 2017 9:46 am

Re: Help for Scripting my AVI camera

#7

Post by pgn »

Dave

You ask for any script - the problem I had (also solved by info. from Robin) is outlined in the "Skip Advanced Capture" topic raised just a few days ago; so still shown as "active" and some lines of script there. Look forward to hearing how you get on.

Peter
DavidCollings
Posts: 7
Joined: Thu Apr 20, 2017 4:21 am

Re: Help for Scripting my AVI camera

#8

Post by DavidCollings »

Thank you Robin and the group. :D

I was able to write 4 modules of code so far with great success!! I have a few minor issues I am working on but I will be able to figure those out.

I do have another question.... Is there a "clock module".... Some code that can poll the computers clock and then move to the next line of code when the time equals the defined time needed?

Thanks again for all the help. All my scripts are running when tested individually...just need to bring them all together and add a computer clock read if the code exists.

I will share this program when I get it completed and working and what I am going to use it for. I know others will be interested in the application.

Dave
pgn
Posts: 17
Joined: Wed Mar 08, 2017 9:46 am

Re: Help for Scripting my AVI camera

#9

Post by pgn »

Dave

I do not know if there is anything "built in" to SharpCap. I don't know it that well.

The time module mentioned earlier does more than allow a pre-set delay. See https://docs.python.org/2/library/time.html. You can delay until a specific time. It is also used by (Robin?) in his code; at the end of that link to http://www.sharpcap.co.uk/sharpcap/sharpcap-scripting mentioned earlier.
If you are actually wanting to execute python lines at set times (sort of spewing them forth on command) that too is also do-able but not sure it's what you meant. If you did mean that I shall just sit back listen and learn; it would be a good trick to master well.

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

Re: Help for Scripting my AVI camera

#10

Post by admin »

Yes, you can almost certainly build what you need by using time.sleep() to delay for a number of seconds - working out the number of seconds to sleep isn't too hard either.

Code: Select all

import datetime
import time
from datetime import date, time

now = datetime.now()
# Calculate the datetime representing 22:30 today - 
later = datetime.combine(date.today(), time(22,30))

delay=(later-now).total_seconds()
time.sleep(delay)
cheers,

Robin
Post Reply