Created
May 19, 2016 07:10
-
-
Save pzwang/31523df8316d992a89f6f8cb51b93c12 to your computer and use it in GitHub Desktop.
cleaned up version of SharpCap capture script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## IronPython Script v1.0 for SharpCap - v2.9 2529beta only | |
## Capture series of PNGs pics for specificed count at specified intervals (clears stack for each pic) | |
## Good for capturing series of pics of Comets to create a movie | |
import clr ## These four lines are for Thread.Sleep and DoEvents | |
clr.AddReference('System.Windows.Forms') ## | |
from System.Windows.Forms import * ## | |
from System.Threading import * ## | |
clr.AddReference('System.Drawing') | |
from System.Drawing import Point | |
# Default values | |
ACQUIRE_CNT = 1000 ## number of PNG pics to capture | |
ACQUIRE_WAIT_SEC = 30 ## interval between captures in seconds | |
cnt = 0 | |
sec = 0 | |
msec = 0 | |
g_MyExit = 0 ## Used as global, must use "global MyExit" preceeding a write | |
## | |
## Capture series of PNGs pics without stacking running for specificed count at specified intervals | |
## Good for capturing series of pics of terrestrial objects to create a time lapse movie | |
## | |
def runMyCaptureNonStackPNG(acquire_count=ACQUIRE_CNT, wait_sec=ACQUIRE_WAIT_SEC): | |
SharpCap.AddCustomButton("Stop Seq", None, None, runMyExit) | |
for cnt in range(acquire_count): | |
try: | |
SharpCap.Transforms.SelectedTransform.FrameTransform.Reset() ## clear stacking count | |
except: | |
pass | |
print "Waiting...." | |
for sec in range(wait_sec): ## cut into 1sec intervals to shorten lockup of other threads | |
Thread.Sleep(1000) ## wait 1 second (should cut into 100ms sleeps when stacking) | |
Application.DoEvents() ## free bandwidth for other threads, prevents SharpCap lockup | |
if(g_MyExit == 1): | |
break | |
if(g_MyExit == 1): | |
global g_MyExit | |
g_MyExit = 0 | |
break | |
else: | |
filename = "%s\\EarthSequence\\%s\\%s_%ds_%03d.png" % (SharpCap.CaptureFolder, SharpCap.TargetName, SharpCap.TargetName, wait_sec, cnt) | |
print "CAPTURING IMAGE: " + filename | |
try: | |
## SharpCap 2.8 has a bug that throws an exception | |
## when saving frames from DirectShow devices, | |
## ignore exceptions for now. | |
SharpCap.SelectedCamera.CaptureSingleFrameTo(filename) | |
except: | |
print "Unable to save file '%s'" % filename | |
SharpCap.RemoveCustomButton(SharpCap.CustomButtons[0]) ## remove "Stop Seq" button | |
## | |
## Capture series of PNGs pics while stacking for specificed count at specified intervals (clears stack for each pic) | |
## Good for capturing series of pics of Comets to create a movie | |
## | |
def runMyCaptureStackPNG(acquire_count=ACQUIRE_CNT, wait_sec=ACQUIRE_WAIT_SEC): | |
SharpCap.AddCustomButton("Stop Seq", None, None, runMyExit) | |
for cnt in range(acquire_count): | |
try: | |
SharpCap.Transforms.SelectedTransform.FrameTransform.Reset() ## clear stacking count | |
except: | |
pass | |
print "Waiting...." | |
for sec in range(wait_sec): ## cut into 1sec intervals to shorten lockup of other threads | |
for msec in range(99): ## cut into 10ms increments - Wait for one second | |
Thread.Sleep(10) ## wait 10ms | |
Application.DoEvents() ## free bandwidth for other threads, prevents SharpCap lockup | |
if(g_MyExit == 1): | |
break | |
if(g_MyExit == 1): | |
global g_MyExit | |
g_MyExit = 0 | |
break | |
else: | |
filename = "%s\\CometSequence\\%s\\%s_%ds_%03d.png" % (SharpCap.CaptureFolder, SharpCap.TargetName, SharpCap.TargetName, wait_sec, cnt) | |
print "CAPTURING IMAGE: " + filename | |
try: | |
## SharpCap 2.8 has a bug that throws an exception | |
## when saving frames from DirectShow devices, | |
## ignore exceptions for now. | |
##SharpCap.SelectedCamera.CaptureSingleFrameTo(filename) | |
SharpCap.Transforms.SelectedTransform.FrameTransform.SaveFrameAsSeen(filename) | |
except: | |
print "Unable to save file '%s'" % filename | |
SharpCap.RemoveCustomButton(SharpCap.CustomButtons[0]) ## remove "Stop Seq" button | |
## | |
## Capture series of FIT32 pics for specificed count at specified intervals (does not clear stack for each pic) | |
## Good for capturing series of pics of object at progressive intervals | |
## | |
def runMyCaptureStackFIT32(acquire_count=ACQUIRE_CNT, wait_sec=ACQUIRE_WAIT_SEC): | |
SharpCap.AddCustomButton("Stop Seq", None, None, runMyExit) | |
SharpCap.Transforms.SelectedTransform.FrameTransform.Reset() ## clear stacking count | |
for cnt in range(acquire_count): | |
print "Waiting...." | |
for sec in range(wait_sec): ## cut into 1sec intervals to shorten lockup of other threads | |
Thread.Sleep(1000) ## wait 1 second (should cut into 100ms sleeps when stacking) | |
Application.DoEvents() ## free bandwidth for other threads, prevents SharpCap lockup | |
if(g_MyExit == 1): | |
break | |
if(g_MyExit == 1): | |
global g_MyExit | |
g_MyExit = 0 | |
break | |
else: | |
print "CAPTURING 32bit FITS IMAGE." | |
SharpCap.Transforms.SelectedTransform.FrameTransform.SaveFrame(32, False) | |
SharpCap.RemoveCustomButton(SharpCap.CustomButtons[0]) ## remove "Stop Seq" button | |
def runMyExit(): | |
global g_MyExit | |
g_MyExit = 1 | |
class SimpleTextBoxForm(Form): | |
def __init__(self): | |
self.Text = "Iron Python Time Lapse Capture Scripts" | |
self.Width = 375 | |
self.Height = 300 | |
self.label = Label() | |
self.label.Text = "STATUS: Iterations = " | |
self.label.Location = Point(125, 50) | |
self.label.Height = 25 | |
self.label.Width = 250 | |
self.label1 = Label() | |
self.label1.Text = "Seconds" | |
self.label1.Location = Point(25, 50) | |
self.label1.Height = 25 | |
self.label1.Width = 50 | |
self.label2 = Label() | |
self.label2.Text = "Iterations" | |
self.label2.Location = Point(25, 125) | |
self.label2.Height = 25 | |
self.label2.Width = 50 | |
self.textbox1 = TextBox() | |
self.textbox1.Text = "30" | |
self.textbox1.Location = Point(25, 75) | |
self.textbox1.Width = 50 | |
self.textbox2 = TextBox() | |
self.textbox2.Text = "100" | |
self.textbox2.Location = Point(25, 150) | |
self.textbox2.Width = 50 | |
self.button1 = Button() | |
self.button1.Text = 'Stop Seq' | |
self.button1.Location = Point(125, 200) | |
self.button1.Click += self.stop_seq | |
self.button3 = Button() | |
self.button3.Text = 'Run - Non-Stack PNG Sequence' | |
self.button3.Location = Point(125, 75) | |
self.button3.Width = 200 | |
self.button3.Click += self.CaptureNonStackPNG | |
self.button4 = Button() | |
self.button4.Text = 'Run - Stacked PNG Sequence' | |
self.button4.Location = Point(125, 113) | |
self.button4.Width = 200 | |
self.button4.Click += self.CaptureStackPNG | |
self.button5 = Button() | |
self.button5.Text = 'Run - Stacked FIT32 Sequence' | |
self.button5.Location = Point(125, 150) | |
self.button5.Width = 200 | |
self.button5.Click += self.CaptureStackFIT32 | |
self.AcceptButton = self.button1 | |
self.NoStackPNG_Button = self.button3 | |
self.StackPNG_Button = self.button4 | |
self.StackFIT32_Button = self.button5 | |
self.Controls.Add(self.label) | |
self.Controls.Add(self.label1) | |
self.Controls.Add(self.label2) | |
self.Controls.Add(self.textbox1) | |
self.Controls.Add(self.textbox2) | |
## self.Controls.Add(self.button1) ## Fix this | |
self.Controls.Add(self.button3) | |
self.Controls.Add(self.button4) | |
self.Controls.Add(self.button5) | |
def CaptureNonStackPNG(self, sender, event): | |
wait_sec = int(self.textbox1.Text) | |
acquire_count = int(self.textbox2.Text) | |
self.label.Text = "STATUS: Iterations = 0" | |
runMyCaptureNonStackPNG(acquire_count, wait_sec) | |
def CaptureStackPNG(self, sender, event): | |
wait_sec = int(self.textbox1.Text) | |
acquire_count = int(self.textbox2.Text) | |
self.label.Text = "STATUS: Iterations = 0" | |
runMyCaptureStackPNG(acquire_count, wait_sec) | |
def CaptureStackFIT32(self, sender, event): | |
wait_sec = int(self.textbox1.Text) | |
acquire_count = int(self.textbox2.Text) | |
self.label.Text = "STATUS: Iterations = 0" | |
runMyCaptureStackFIT32(acquire_count, wait_sec) | |
def stop_seq(self, sender, event): | |
self.label.Text = "STATUS: Sequence aborted" | |
form = SimpleTextBoxForm() | |
Application.Run(form) | |
## This gets run once when script envoked and creates "Run Seq" button | |
##SharpCap.AddCustomButton("Run StackPNG ", None, "Count=%d Delay=%d" % (ACQUIRE_CNT,ACQUIRE_WAIT_SEC), runMyCaptureStackPNG) | |
##SharpCap.AddCustomButton("Run StackFIT32 ", None, "Count=%d Delay=%d" % (ACQUIRE_CNT,ACQUIRE_WAIT_SEC), runMyCaptureFIT32) | |
##SharpCap.AddCustomButton("Run NonStackPNG", None, "Count=%d Delay=%d" % (ACQUIRE_CNT,ACQUIRE_WAIT_SEC), runMyCaptureNonStackPNG) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment