Automatically saving the livestack as a new frame is stacked

Discussions on extending SharpCap using the built in Python scripting functionality
Post Reply
clouzot
Posts: 5
Joined: Thu Aug 08, 2019 11:13 am

Automatically saving the livestack as a new frame is stacked

Post by clouzot » Thu Aug 08, 2019 11:20 am

Hi,

Sharpcap Pro user here (64-bit)

For demonstration purposes, I'd want to be able to automatically save the livestack ("as seen", possibly) as soon as a new frame gets captured and stacked.

The goal here would be to demonstrate how the stack evolves in time as new frames are added, via a small GIF or a "stop-motion" movie.

I know the livestack can already be saved every X minutes, but it's also reset at the same time.

I guess a way to achieve that would be to write a small Python script, but I could not find script examples that use the livestacking object. Would there be any pointers to such scripts I could modify and adapt to my needs?

Thanks!

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

Re: Automatically saving the livestack as a new frame is stacked

Post by admin » Thu Aug 08, 2019 3:38 pm

Hi,

This is the starting point that you need to save the image from the live stacking as seen.

Code: Select all

SharpCap.LiveStacking.SaveFrameAsSeen("f:\\file.png")
You can monitor the value of

Code: Select all

SharpCap.LiveStacking.StackedFrames
Every second or so to see if it is increased and then save if it has.

Cheers, Robin

clouzot
Posts: 5
Joined: Thu Aug 08, 2019 11:13 am

Re: Automatically saving the livestack as a new frame is stacked

Post by clouzot » Thu Aug 08, 2019 3:40 pm

Thank you Robin, I'll give it a go tonight!

clouzot
Posts: 5
Joined: Thu Aug 08, 2019 11:13 am

Re: Automatically saving the livestack as a new frame is stacked

Post by clouzot » Fri Aug 16, 2019 8:51 am

Here you go:

The script saves each iteration of the stack on the desktop, in a folder named "SharpcapStacks", using a subfolder named after the date and time.

It resets the stack when it is launched (a design choice), but you can disable that behavior by commenting out the SharpCap.LiveStacking.Reset() line.

If possible, I'll try and add a way to automagically create a GIF from the saved images.

Some debug lines are still present (commented out, especially the one that disturbs the observer with a beep each time a new image has been stacked). Please feel free to remove and modify as needed.

Code: Select all

# Script that saves the stack each time a new frame is stacked
# import winsound
import time
import datetime
from os.path import expanduser
home = expanduser("~")
fileTime = 'stack-{date:%Y-%m-%d_%H_%M_%S}'.format( date=datetime.datetime.now() )

SharpCap.LiveStacking.Reset() # reset the livestack

stackedFrames = SharpCap.LiveStacking.StackedFrames
pathName = home + "\\Desktop\\SharpcapStacks\\" + fileTime + "\\{}.png"

# loop indefinitely
while True:
	if SharpCap.LiveStacking.StackedFrames > stackedFrames:
		 stackedFrames = SharpCap.LiveStacking.StackedFrames
		 # winsound.Beep(500, 250)
		 stackFileName = pathName.format(stackedFrames) # add the number of stacked frames to the filename
		 # print stackFileName
		 SharpCap.LiveStacking.SaveFrameAsSeen(stackFileName) # save
	time.sleep(SharpCap.SelectedCamera.Controls.Exposure.Value/1000) # pause for the duration of the frame capture

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest