Forked from pzwang/CaptureSeq_ALL_V10-pwang.py
Last active
December 27, 2016 08:18
-
-
Save CC58/292d97a0181f89f67a41013a60e8adfc to your computer and use it in GitHub Desktop.
cleaned up version of SharpCap capture script
This file contains 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.1 for SharpCap v2.9 only | |
## Capture series of pics at specified intervals for specificed count | |
## o Non-Stack PNG - capture time lapse of clouds, or capture using camera on-board stacking | |
## o Stacked PNG - capture time lapse of comets to make a movie (use free VirtualDub) | |
## o Stacked FIT32 - capture progressively longer stacks of an object (use free Fitswork4) | |
## 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') ## needed to create window | |
from System.Drawing import Point, Font, FontStyle | |
# 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): | |
global g_MyExit | |
g_MyExit = 0 | |
global cnt | |
cnt = 0 | |
for cnt in range(0, acquire_count): | |
##self.label4.Text = "Status: Count = %d " % cnt | |
try: | |
SharpCap.Transforms.SelectedTransform.FrameTransform.Reset() ## clear stacking count | |
except: | |
pass | |
print "Waiting...." | |
for sec in range(0, wait_sec): ## cut into 1sec intervals to shorten lockup of other threads | |
runDelayMSec(100) ## wait 100 * 10ms = 1000ms | |
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 PNG 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 | |
## | |
## 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): | |
global g_MyExit | |
g_MyExit = 0 | |
cnt = 0 | |
for cnt in range(0, acquire_count): | |
try: | |
SharpCap.Transforms.SelectedTransform.FrameTransform.Reset() ## clear stacking count | |
except: | |
g_MyExit = 1 | |
print "Waiting...." | |
for sec in range(0, wait_sec): ## cut into 1sec intervals to shorten lockup of other threads | |
runDelayMSec(100) ## wait 100 * 10ms = 1000ms | |
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 PNG 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 | |
## | |
## 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): | |
global g_MyExit | |
g_MyExit = 0 | |
try: | |
SharpCap.Transforms.SelectedTransform.FrameTransform.Reset() ## clear stacking count | |
except: | |
g_MyExit = 1 | |
cnt = 0 | |
for cnt in range(0, acquire_count): | |
print "Waiting...." | |
for sec in range(0, wait_sec): ## cut into 1sec intervals to shorten lockup of other threads | |
runDelayMSec(100) ## wait 100 * 10ms = 1000ms | |
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) | |
def runMyExit(): | |
global g_MyExit | |
g_MyExit = 1 | |
def runDelayMSec(milli): | |
for msec in range(0, milli): ## cut into 10ms increments - Wait for one second | |
Thread.Sleep(10) ## wait 10ms | |
Application.DoEvents() ## free bandwidth for other threads, prevents SharpCap lockup | |
class SimpleTextBoxForm(Form): | |
def __init__(self): | |
##self.Parent = SharpCap.MainWindow.Handle | |
self.Text = "SharpCap Scripts" | |
self.Width = 270 | |
self.Height = 270 | |
X = SharpCap.MainWindow.Location.X + SharpCap.MainWindow.Width * .75 | |
Y = SharpCap.MainWindow.Location.Y + 105 ## + SharpCap.MainWindow.Height/2 | |
self.StartPosition = FormStartPosition.Manual | |
self.Location = Point(X,Y) | |
self.TopMost = True ## TopMost, Top, TopLevel | |
self.label3 = Label() | |
self.label3.Text = "Time Lapse Capture Scripts v1.1" | |
self.label3.Font = Font("Arial", 9, FontStyle.Bold) | |
self.label3.Location = Point(20, 5) | |
self.label3.Height = 25 | |
self.label3.Width = 250 | |
self.label1 = Label() | |
self.label1.Text = "Seconds" | |
self.label1.Location = Point(5, 30) | |
self.label1.Height = 20 | |
self.label1.Width = 50 | |
self.label2 = Label() | |
self.label2.Text = "Count" | |
self.label2.Location = Point(5, 105) | |
self.label2.Height = 20 | |
self.label2.Width = 50 | |
self.label5 = Label() | |
self.label5.Text = "Cloud movie" | |
self.label5.Location = Point(185, 55) | |
self.label5.Height = 20 | |
self.label5.Width = 100 | |
self.label6 = Label() | |
self.label6.Text = "Comet movie" | |
self.label6.Location = Point(185, 93) | |
self.label6.Height = 20 | |
self.label6.Width = 100 | |
self.label7 = Label() | |
self.label7.Text = "DSOs" | |
self.label7.Location = Point(185, 130) | |
self.label7.Height = 20 | |
self.label7.Width = 50 | |
self.textbox1 = TextBox() | |
self.textbox1.Text = "5" ## seconds | |
self.textbox1.Location = Point(5, 50) | |
self.textbox1.Width = 40 | |
self.textbox2 = TextBox() | |
self.textbox2.Text = "10" ## count | |
self.textbox2.Location = Point(5, 125) | |
self.textbox2.Width = 40 | |
self.button1 = Button() | |
self.button1.Text = 'Stop Capture' | |
self.button1.Location = Point(60, 190) | |
self.button1.Width = 120 | |
self.button1.Click += self.CaptureStop | |
self.button3 = Button() | |
self.button3.Text = 'Run- Non-Stack PNG' | |
self.button3.Location = Point(60, 50) | |
self.button3.Width = 120 | |
self.button3.Click += self.CaptureNonStackPNG | |
self.button4 = Button() | |
self.button4.Text = 'Run- Stacked PNG' | |
self.button4.Location = Point(60, 88) | |
self.button4.Width = 120 | |
self.button4.Click += self.CaptureStackPNG | |
self.button5 = Button() | |
self.button5.Text = 'Run- Stacked FIT32' | |
self.button5.Location = Point(60, 125) | |
self.button5.Width = 120 | |
self.button5.Click += self.CaptureStackFIT32 | |
self.label4 = Label() | |
self.label4.Text = "Status: Idle " | |
##self.label4.Text = "Status: Count = %d " % cnt | |
self.label4.Location = Point(60, 165) | |
self.label4.Height = 25 | |
self.label4.Width = 250 | |
self.Controls.Add(self.label1) | |
self.Controls.Add(self.label2) | |
self.Controls.Add(self.label3) | |
self.Controls.Add(self.label4) | |
self.Controls.Add(self.label5) | |
self.Controls.Add(self.label6) | |
self.Controls.Add(self.label7) | |
self.Controls.Add(self.textbox1) | |
self.Controls.Add(self.textbox2) | |
self.Controls.Add(self.button1) | |
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.label4.Text = "Status: Running- NonStacked PNG" | |
self.button1.Visible = True | |
runMyCaptureNonStackPNG(acquire_count, wait_sec) | |
self.label4.Text = "Status: STOPPED " | |
def CaptureStackPNG(self, sender, event): | |
wait_sec = int(self.textbox1.Text) | |
acquire_count = int(self.textbox2.Text) | |
self.label4.Text = "Status: Running- Stacked PNG " | |
runMyCaptureStackPNG(acquire_count, wait_sec) | |
self.label4.Text = "Status: STOPPED " | |
def CaptureStackFIT32(self, sender, event): | |
wait_sec = int(self.textbox1.Text) | |
acquire_count = int(self.textbox2.Text) | |
self.label4.Text = "Status: Running- Stacked FIT32 " | |
runMyCaptureStackFIT32(acquire_count, wait_sec) | |
self.label4.Text = "Status: STOPPED " | |
def CaptureStop(self, sender, event): | |
global g_MyExit | |
g_MyExit = 1 | |
self.label4.Text = "Status: STOPPED " | |
## This gets run once when script envoked | |
form = SimpleTextBoxForm() | |
Application.Run(form) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment