PrusaConnect Timelapse "Plugin" (Early-beta release!)
 
Notifications
Clear all

Do you like this method? Poll is created on Dec 01, 2023

  
  
  

PrusaConnect Timelapse "Plugin" (Early-beta release!)  

  RSS
Fortnite Gamer
(@fortnite-gamer)
New Member
PrusaConnect Timelapse "Plugin" (Early-beta release!)

Prusa Connect Timelapse Creator

This Python script automates the process of creating a timelapse video from images downloaded from Prusa Connect. It performs the following steps:

Automated Clicking: The script simulates mouse clicks at a specified screen position. This can be used to trigger the downloading of images from Prusa Connect.

Image Organization: The script moves the downloaded images from the Downloads folder to a specified folder. It only moves images that have a filename starting with a specified prefix.

Timelapse Creation: The script creates a timelapse video from the moved images. The video is saved with a filename based on the common prefix of the image filenames.

Usage:

Specify the coordinates of the point to click in the x, y variables.Specify the number of clicks and the interval between clicks in the num_clicks and interval variables.

Call:

move_images_with_prefix

with the path to your Downloads folder, the path to the folder where you want to move the images, and the common prefix of the image filenames.

Call:

create_timelapse

with the path to the folder containing the images and the desired frames per second for the timelapse video.Dependencies

This script requires the pyautogui, opencv-python, os, and shutil Python libraries. You can install them using pip:

pip install pyautogui opencv-python 

Disclaimer: This script interacts with the screen and file system. Please use it responsibly and ensure that it does not interfere with your normal computer usage. Always test the script in a controlled environment before running it unattended.

Examples of Usage:

Nasa Fabric Timelapse

IMPORTANT NOTE: To get the correct X, Y position of the "download snapshot" button do this:

  1. Install the pyautogui library: If you haven’t already, you’ll need to install the pyautogui library. You can do this by opening your command prompt or terminal and typing the following command:
    pip install pyautogui
  2. Import the pyautogui library: In the Python shell, type the following command and press enter:

    import pyautogui
  3. Display the mouse position: Now, you can display the real-time position of your mouse cursor by typing the following command and pressing enter:
    pyautogui.displayMousePosition()

Best Answer by Fortnite Gamer:

VERSION 0.2 IS OUT NOW!

Changelog:

  • Added Security Feautres
  • Added Auto-Creation of Dependent Folders
  • Added Inputs so there is NO NEED TO EDIT CODE! HOORAY👌👌👌✔✔✔! 

 

 

New Usage AND FULL TUTORIAL:

 

 

Step 1:

Login to your Prusa connect account, and set it in a split screen on the left or right.

Next, navigate to your camera page, and ensure you are scrolled ALL THE WAY UP!

Step 2: Getting the X,Y Coords of your download button

In the future(V0.4), both of the scripts I will turn into a .exe, but for now it is manual:

Open Command Prompt, then cd into your python311 scripts folder, RUN:

pip install pyautogui

Then, in your shell, run:

import pyautogui

Then type:

pyautogui.displayMousePosition()

Hover over your download snapshot button, and note down the coords.

INPUT THEM INTO THE SCRIPT!

Step 3: Running the script

Now, for the last step, simply run the script, preferably try to run it right after the camera updates.

SUPER IMPORTANT NOTE: If your camera settings are set to update every 30 seconds(Won't work as well for timelapse), set them to 10 or, update the interval variable.

Hope this helps everyone! Have a good day, and post any of your issues in the replies! 

PS: I was in a hurry to get this published in time before the moderators in the Czech Republic(Czechia) wake up in order to gain the most traction to this post, if I made any critical errors, please lmk.

import pyautogui
import time
import os
import shutil
import cv2

# specify coordinates of the point to click
x, y = 1140, 1099

# specify number of clicks and interval between clicks
num_clicks = int(int(input(r'How long is your print?(Format in seconds long please!)'))/10)
us=input('What is your computer username? (To check the one to use, go to your downloads folder, copy the address and check what name is after C:\\)')
print(num_clicks)
interval = 10  # seconds

for _ in range(num_clicks):
    pyautogui.click(x, y)
    print(f'Click {_}/{num_clicks}')
    time.sleep(interval)

def delete_and_move_images_with_prefix(source_folder, destination_folder, prefix):
    # Create the destination folder if it doesn't exist
    os.makedirs(destination_folder, exist_ok=True)

    # Delete all files in the destination folder
    for filename in os.listdir(destination_folder):
        file_path = os.path.join(destination_folder, filename)
        try:
            if os.path.isfile(file_path) or os.path.islink(file_path):
                os.unlink(file_path)
            elif os.path.isdir(file_path):
                shutil.rmtree(file_path)
        except Exception as e:
            print('Failed to delete %s. Reason: %s' % (file_path, e))

    # Get a list of all files in the source folder
    files = os.listdir(source_folder)

    # Filter the list for files that start with the prefix and end with .jpg
    images = [f for f in files if f.startswith(prefix) and f.endswith('.jpg')]

    # Sort the images by their creation time (most recent first)
    images.sort(key=lambda img: os.path.getctime(os.path.join(source_folder, img)), reverse=True)

    # Move the images to the destination folder
    for image in images:
        shutil.move(os.path.join(source_folder, image), os.path.join(destination_folder, image))

# Usage
delete_and_move_images_with_prefix(fr'C:\\Users\\{us}\\Downloads', fr'C:\\Users\\{us}\\AppData\\Local\\Programs\\Python\\Python311\\SnapShots', 'snapshot-PrusaConnect Webcam-')

def create_timelapse(input_folder, output_folder, fps):
    images = [img for img in os.listdir(input_folder) if img.endswith(".jpg")]

    # Check if there are any images in the folder
    if not images:
        print("No images found in the folder.")
        return

    # Determine the common prefix of the image filenames
    common_prefix = os.path.commonprefix(images)
       
    # Use the common prefix as the output filename, or default to 'output.avi' if there's no common prefix
    output_file = f"{common_prefix or 'output'}(TimeLapse).avi"

    # Create the output folder if it doesn't exist
    os.makedirs(output_folder, exist_ok=True)

    # Full path to the output file
    output_path = os.path.join(output_folder, output_file)

    frame = cv2.imread(os.path.join(input_folder, images[0]))
    height, width, layers = frame.shape

    video = cv2.VideoWriter(output_path, cv2.VideoWriter_fourcc(*'DIVX'), fps, (width,height))

    for image in images:
        video.write(cv2.imread(os.path.join(input_folder, image)))

    cv2.destroyAllWindows()
    video.release()

# Usage
create_timelapse(fr'C:\\Users\\{us}\\AppData\\Local\\Programs\\Python\\Python311\\SnapShots', fr'C:\\Users\\{us}\\AppData\\Local\\Programs\\Python\\Python311\\TimeLapser', 60)
Posted : 01/12/2023 12:08 am
Fortnite Gamer
(@fortnite-gamer)
New Member
Topic starter answered:
This Setup Works amazing for me:

This post was modified 3 months ago by Fortnite Gamer
Posted : 01/12/2023 12:11 am
Fortnite Gamer
(@fortnite-gamer)
New Member
Topic starter answered:
RE:

VERSION 0.2 IS OUT NOW!

Changelog:

  • Added Security Feautres
  • Added Auto-Creation of Dependent Folders
  • Added Inputs so there is NO NEED TO EDIT CODE! HOORAY👌👌👌✔✔✔! 

 

 

New Usage AND FULL TUTORIAL:

 

 

Step 1:

Login to your Prusa connect account, and set it in a split screen on the left or right.

Next, navigate to your camera page, and ensure you are scrolled ALL THE WAY UP!

Step 2: Getting the X,Y Coords of your download button

In the future(V0.4), both of the scripts I will turn into a .exe, but for now it is manual:

Open Command Prompt, then cd into your python311 scripts folder, RUN:

pip install pyautogui

Then, in your shell, run:

import pyautogui

Then type:

pyautogui.displayMousePosition()

Hover over your download snapshot button, and note down the coords.

INPUT THEM INTO THE SCRIPT!

Step 3: Running the script

Now, for the last step, simply run the script, preferably try to run it right after the camera updates.

SUPER IMPORTANT NOTE: If your camera settings are set to update every 30 seconds(Won't work as well for timelapse), set them to 10 or, update the interval variable.

Hope this helps everyone! Have a good day, and post any of your issues in the replies! 

PS: I was in a hurry to get this published in time before the moderators in the Czech Republic(Czechia) wake up in order to gain the most traction to this post, if I made any critical errors, please lmk.

import pyautogui
import time
import os
import shutil
import cv2

# specify coordinates of the point to click
x, y = 1140, 1099

# specify number of clicks and interval between clicks
num_clicks = int(int(input(r'How long is your print?(Format in seconds long please!)'))/10)
us=input('What is your computer username? (To check the one to use, go to your downloads folder, copy the address and check what name is after C:\\)')
print(num_clicks)
interval = 10  # seconds

for _ in range(num_clicks):
    pyautogui.click(x, y)
    print(f'Click {_}/{num_clicks}')
    time.sleep(interval)

def delete_and_move_images_with_prefix(source_folder, destination_folder, prefix):
    # Create the destination folder if it doesn't exist
    os.makedirs(destination_folder, exist_ok=True)

    # Delete all files in the destination folder
    for filename in os.listdir(destination_folder):
        file_path = os.path.join(destination_folder, filename)
        try:
            if os.path.isfile(file_path) or os.path.islink(file_path):
                os.unlink(file_path)
            elif os.path.isdir(file_path):
                shutil.rmtree(file_path)
        except Exception as e:
            print('Failed to delete %s. Reason: %s' % (file_path, e))

    # Get a list of all files in the source folder
    files = os.listdir(source_folder)

    # Filter the list for files that start with the prefix and end with .jpg
    images = [f for f in files if f.startswith(prefix) and f.endswith('.jpg')]

    # Sort the images by their creation time (most recent first)
    images.sort(key=lambda img: os.path.getctime(os.path.join(source_folder, img)), reverse=True)

    # Move the images to the destination folder
    for image in images:
        shutil.move(os.path.join(source_folder, image), os.path.join(destination_folder, image))

# Usage
delete_and_move_images_with_prefix(fr'C:\\Users\\{us}\\Downloads', fr'C:\\Users\\{us}\\AppData\\Local\\Programs\\Python\\Python311\\SnapShots', 'snapshot-PrusaConnect Webcam-')

def create_timelapse(input_folder, output_folder, fps):
    images = [img for img in os.listdir(input_folder) if img.endswith(".jpg")]

    # Check if there are any images in the folder
    if not images:
        print("No images found in the folder.")
        return

    # Determine the common prefix of the image filenames
    common_prefix = os.path.commonprefix(images)
       
    # Use the common prefix as the output filename, or default to 'output.avi' if there's no common prefix
    output_file = f"{common_prefix or 'output'}(TimeLapse).avi"

    # Create the output folder if it doesn't exist
    os.makedirs(output_folder, exist_ok=True)

    # Full path to the output file
    output_path = os.path.join(output_folder, output_file)

    frame = cv2.imread(os.path.join(input_folder, images[0]))
    height, width, layers = frame.shape

    video = cv2.VideoWriter(output_path, cv2.VideoWriter_fourcc(*'DIVX'), fps, (width,height))

    for image in images:
        video.write(cv2.imread(os.path.join(input_folder, image)))

    cv2.destroyAllWindows()
    video.release()

# Usage
create_timelapse(fr'C:\\Users\\{us}\\AppData\\Local\\Programs\\Python\\Python311\\SnapShots', fr'C:\\Users\\{us}\\AppData\\Local\\Programs\\Python\\Python311\\TimeLapser', 60)
This post was modified 3 months ago 2 times by Fortnite Gamer
Posted : 01/12/2023 6:10 am
Ckobar
(@ckobar)
Trusted Member
RE: PrusaConnect Timelapse "Plugin" (Early-beta release!)

i'm sorry, that's way to complicated to me. And, if my understanding is right, i have to have a PC running while printing.

Posted : 06/12/2023 10:43 am
Share: