Skip to content

DSLR Image Capture With No Download

FormerLurker edited this page Feb 22, 2020 · 2 revisions

Note: These instructions are in beta. Please notify me with any issues or corrections, or just to say things worked for you.

Before Using This Guide

This guide assumes you have read and performed all of the steps in the Configuring an External Camera tutorial. If you have not done so, complete the guide at least up to and including step 4.

Prevent Image Download and Rendering - OctoPi instructions

These instructions assume you are running OctoPi, but the instructions for other types of Linux installations would be very similar.

It is possible to prevent Octolapse from downloading the images from your camera to your server entirely. Unfortunately this means that you will have to render your timelapse manually, and you won't get any snapshot previews within the Octolapse tab. However, if you want to render your videos manually from images stored on your camera's SD card, this is the guide for you!

Step 1 - Create Camera Initialization Script

First we have to add a new script, which we'll call our 'Camera Initialization Script'. This script will tell your camera to save all images to the SD card instead of to internal memory. IMPORTANT NOTE - Some cameras do NOT support configuration via GPhoto2. We will run some tests during this tutorial to see if things are working properly.

I put my script in /home/pi/scripts by navigating to the following directory:

cd /home/pi/scripts

Determine the appropriate capturetarget setting

The config options vary by camera and by the gphoto2 version. You can run the following command to see what options for capturetarget are available on your camera:

gphoto2 --get-config capturetarget

Here's what my camera reports after running this command:

Label: Capture Target
Readonly: 0
Type: RADIO
Current: Memory card
Choice: 0 Internal RAM
Choice: 1 Memory card
END

If your options aren't the same as mine (Memory card = 1) you will have to adjust the initialize-camera-save-to-sd.sh script accordingly.

Next, create a new script file with the nano editor like so:

nano initialize-camera-save-to-sd.sh

This will open the nano editor. Copy the following script and paste it into the nano editor by pressing the right mouse key.

IMPORTANT NOTE: The very first line #!/bin/sh is important, and must be included.

#!/bin/sh
# Camera Initialization Script
# Sets the capture target to the SD card
# Written by: [email protected]

# Put the arguments sent by Octolapse into variables for easy use
CAMERA_NAME=$1
# Set camera to save images to flash memory
# IMPORTANT:  The capturetarget setting may vary.  Run 'gphoto2 --get-config capturetarget' to determine the appropriate setting
gphoto2 --set-config capturetarget=1

IMPORTANT NOTE: Make ABSOLUTELY SURE that you have used the proper capturetarget settings we determined from the previous step. If this is wrong images will not be saved to your SD or internal memory! Now we need to save the script. Press ctrl + o and then Enter to save. Then press ctrl + x to exit.

Now we need to add execute permission to the script with the following command

chmod +x initialize-camera-save-to-sd.sh

Step 2 - Create trigger snapshot script

Next, we will need to create a new script to take the actual snapshot. Again, we need to create a new file with the nano editor like so:

nano trigger-snapshot.sh

Again, this will open the nano editor. Copy the following script and paste it into the nano editor by pressing the right mouse key.

IMPORTANT NOTE: The very first line #!/bin/sh is important, and must be included.

#!/bin/sh
# Camera Capture Script - Leave on Camera, Don't download
# Requires a camera initialization script with the following command:  gphoto2 --capture-image --set-config capturetarget=1
# Written by: [email protected]
# Put the arguments sent by Octolapse into variables for easy use
SNAPSHOT_NUMBER=$1
DELAY_SECONDS=$2
DATA_DIRECTORY=$3
SNAPSHOT_DIRECTORY=$4
SNAPSHOT_FILENAME=$5
SNAPSHOT_FULL_PATH=$6

# trigger the camera and exit immediately
gphoto2 --trigger-capture

Now we need to save the script. Press ctrl + o and then Enter to save. Then press ctrl + x to exit.

We need to add execute permissions to this script as well like so:

chmod +x trigger-snapshot.sh

Step 3 - Test Camera Scripts

Finally, we can test our scripts by entering in the following commands:

/home/pi/scripts/initialize-camera-save-to-sd.sh

This command should complete without returning any messages. If you see this error message:

*** Error: No camera found. ***

please see the troubleshooting section at the bottom of this guide.

Next, enter the following commands to test image capture:

/home/pi/scripts/trigger-snapshot.sh

This command should complete without returning any messages, and your camera should snap a picture. Unplug your camera from the USB cable and make sure the test image was captured.

Note: Not all cameras support the 'trigger-snapshot' command unfortunately. On my camera, the Nikon D5200, 'trigger-capture' returns after the snapshot is taken but before it is saved to SD. Some cameras return BEFORE the image is taken. In this case you may need to make some changes to trigger-snapshot.sh. Specifically you'll need to add a sleep 1 command right after gphoto2 --trigger-capture, which would look like this:

#!/bin/sh
# Camera Capture Script - Leave on Camera, Don't download
# Requires a camera initialization script with the following command:  gphoto2 --capture-image --set-config capturetarget=1
# Written by: [email protected]
# Put the arguments sent by Octolapse into variables for easy use
SNAPSHOT_NUMBER=$1
DELAY_SECONDS=$2
DATA_DIRECTORY=$3
SNAPSHOT_DIRECTORY=$4
SNAPSHOT_FILENAME=$5
SNAPSHOT_FULL_PATH=$6

# trigger the camera and exit immediately
gphoto2 --trigger-capture

# Wait for 1 second, you may need to adjust this value.  You want the lowest possible value
# that gives you a stable timelapse.
sleep 1  

That will cause the script to wait for 1 second before exiting, giving your camera time to take a snapshot. You will have to experiment to determine how long to sleep. You want to use the smallest possible value. For example, if you determine that one half of a second is adequate, you can change your script to sleep 0.5, or if one second isn't enough you could increase it to two seconds like this: sleep 2

Step 4 - Configure Octolapse

We're almost done! Open OctoPrint and edit your current camera settings via the Octolapse tab.

First, ensure that the camera profile is enabled by checking the 'enabled' checkbox at the top.

Second, make sure the 'Camera Type' drop down box at the top of the page from 'Webcam' to 'External Camera - Script'

Next, type in the following for the 'Snapshot Acquire Script' setting:

/home/pi/scripts/trigger-snapshot.sh

Set the 'Snapshot Delay' setting to 0. This will reduce the total snapshot time since it is unlikely that you will need a delay before attempting to take a snapshot when using a DSLR.

Set the 'Snapshot Timeout' to 10000 (10 seconds). This can be reduced later, but it's useful for testing.

Now move to the 'Custom Camera Scripts' section and set the 'Before Print Start Script' to the following:

/home/pi/scripts/initialize-camera-save-to-sd.sh

Make sure all of the other custom script fields are empty (Before Snapshot Script, After Snapshot Script, Before Render Script, After Render Script).

Save your camera profile changes.

Optionally you can edit your rendering settings and uncheck the 'Timelapse Generation' option. This will prevent a rendering error message from showing up after your prints complete (no images found), but other than that there are no downsides to just skipping this step. I have forgotten to re-enable timelapse generation when switching from my DSLR profile to my webcam profile, which is more irritating than an error message, so I personally would leave the rendering profile alone. In the future I plan to add an option to the camera profile to skip the rendering process.

Step 5 - Test Print

That should be it as far as configuration goes! Now run a short test print. Change your 'debug profile' within Octolapse to Test Print - Full Diagnostic. This option will cause a diagnostic lot to be recorded. Additionally, test mode will prevent your printer from heating up (bed and extruder) and will strip off all extrusion commands, so you won't waste any time or plastic. I strongly recommend you unload your filament, though, just in case there is a bug or glitch in the test mode code.

Octolapse should now run as usual, but should acquire an image from your DSLR instead of the usual webcam, and it will not download any images to your server. It should take substantially less time to acquire images now that the images aren't being downloaded. You should hear your camera snapping away during the snapshot phase. When the test print is completed, check your DSLR to make sure the snapshots are located within the camera's SD card.

Troubleshooting

I will improve this troubleshooting tutorial soon. For now if you have problems, please see this issue and add your comments and questions there. Be sure to include any terminal output and your camera profile settings from step 4. Please note any deviations from the above instructions or anything else you feel is relevant. Before creating an issue please re-read the guide to make sure nothing obvious is wrong, look through Octolapse Issues page and check the gphoto2 website and issues on the gphoto2 github page. It's possible that workarounds already exist!

Windows Installation

The instructions for this are coming soon!

Clone this wiki locally