Script to take images for focus stacking

Discussions on extending SharpCap using the built in Python scripting functionality
Post Reply
Xplode85
Posts: 8
Joined: Wed Sep 04, 2019 10:40 am

Script to take images for focus stacking

#1

Post by Xplode85 »

I'm working on a project where i want to find micro meteorites and take images of them, to do that i want to use Sharpcap with a ZWO camera and motorfocuser i have here.
Testing it manually it works great, but i want to do it automatically, would someone be willing to help me write a script for this?
I just need to be able to set auto/manual exposure/gain and move the focuser in 1 direction, take 1 image, move focuser, take image etc.

Here's what i gotten together so far from looking at scripts others have written, it moves the focuser, saves an image, but i don't know how to make it cycle through it a set amount of times.
copy/pasting focusing/imaging several times the focuser doesn't move more than once and the image are are saved over the first.

Code: Select all

import time

focus_steps = 150
settle_time = 2

pos_2 = SharpCap.Focusers.SelectedFocuser.Position
pos_1 = pos_2 - focus_steps
pos_3 = pos_2 + focus_steps

SharpCap.SelectedCamera.Controls.OutputFormat.Value = "PNG files (*.png)"
SharpCap.SelectedCamera.Controls.Exposure.Automatic = True
SharpCap.Focusers.SelectedFocuser.Connected = True
pos_2 = SharpCap.Focusers.SelectedFocuser.Position
pos_1 = pos_2 - focus_steps
pos_3 = pos_2 + focus_steps

SharpCap.Focusers.SelectedFocuser.Move(pos_3)
time.sleep(settle_time)

Name="D:\Test\capture" + str(i) + ".png"
SharpCap.SelectedCamera.CaptureSingleFrameTo(Name)
Here's one of my images so far by doing this process manually. The FOV is around 3x2.5mm
2021-02-10-17.19.34 ZS PMax small.jpg
2021-02-10-17.19.34 ZS PMax small.jpg (682.21 KiB) Viewed 2172 times
User avatar
admin
Site Admin
Posts: 13173
Joined: Sat Feb 11, 2017 3:52 pm
Location: Vale of the White Horse, UK
Contact:

Re: Script to take images for focus stacking

#2

Post by admin »

Hi,

maybe have a look at the new sequener feature in SharpCap 3.3 beta - viewtopic.php?f=38&t=3109

This gives an easier to use way of automating SharpCap that should be able to do what you want.

cheers,

Robin
Xplode85
Posts: 8
Joined: Wed Sep 04, 2019 10:40 am

Re: Script to take images for focus stacking

#3

Post by Xplode85 »

Thanks for your fast reply!
I'm already up and running with the sequencer, probably got like 75% of how it want it to work!
Xplode85
Posts: 8
Joined: Wed Sep 04, 2019 10:40 am

Re: Script to take images for focus stacking

#4

Post by Xplode85 »

I did find a small problem, i can't find a way to make it save all the files in the same folder (i guess it's a new "sequence for every capture), if i change the filename template so it doesn't include time it will just save over the last file.

EDIT: Fixed it by adding frametime in the filename :D
Xplode85
Posts: 8
Joined: Wed Sep 04, 2019 10:40 am

Re: Script to take images for focus stacking

#5

Post by Xplode85 »

Got it working very nicely in the end, i also threw so live stacking in there to improve SNR.

Here's the result after stacking 60 focus shifted images with 50 exposures each. (t's a regular rock, not a micrometeorite)
2021-02-11-01.29.13 ZS DMap-2.jpg
2021-02-11-01.29.13 ZS DMap-2.jpg (569.73 KiB) Viewed 2154 times
User avatar
admin
Site Admin
Posts: 13173
Joined: Sat Feb 11, 2017 3:52 pm
Location: Vale of the White Horse, UK
Contact:

Re: Script to take images for focus stacking

#6

Post by admin »

Hi,

good to hear that you got it working (and an awesome photo there too). I think people use this technique for cellular microscopy too.

cheers,

Robin
Post Reply