Set up your telescope, press start, and go to sleep. The Jetson takes hundreds of photos of the moon or planets, scores each one for sharpness, throws away the blurry frames, and stacks the best ones into a stunning final image — overnight, automatically.
What you will learn
- What image stacking is and why it makes photos sharper
- How to measure sharpness using the Laplacian variance method
- How to control a telescope mount via INDI protocol
- How to detect clouds and pause imaging automatically
- How to stack images using AutoStakkert via command line
Step 1 — Run the night sky imaging session
cd ~/tutorials/07-sky-imaging
python3 sky_imager.py --target moon --photos 500 --interval 2 --output ~/captures/moon_session_1
Step 2 — How sharpness scoring works
import cv2
def sharpness_score(image):
"""Higher score = sharper image"""
grey = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
return cv2.Laplacian(grey, cv2.CV_64F).var()
def keep_best(images, top_percent=0.2):
"""Keep the sharpest top 20% of frames"""
scored = [(sharpness_score(img), img) for img in images]
scored.sort(key=lambda x: x[0], reverse=True)
cutoff = int(len(scored) * top_percent)
return [img for _, img in scored[:cutoff]]
Step 3 — Detect clouds automatically
def sky_is_clear(frame):
"""Returns True if sky is dark enough for imaging"""
grey = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
avg_brightness = grey.mean()
return avg_brightness < 60 # dark sky threshold
# In your imaging loop:
while imaging:
frame = camera.capture()
if not sky_is_clear(frame):
print("Clouds detected — waiting 5 minutes...")
time.sleep(300)
continue
# take photo and score it...
Step 4 — Stack the best frames
# AutoStakkert3 is pre-installed — stack via command line
python3 stack_frames.py --input ~/captures/moon_session_1/best/ --output ~/captures/moon_session_1/stacked_moon.png