Stabilising/deshaking webcam timelapse footage

1,534 views
Skip to first unread message

Bruno Postle

unread,
Jun 25, 2018, 3:01:23 PM6/25/18
to Hugin ptx
I recently needed to convert a series of webcam images to video, but the
camera wobbles around in the wind, so I needed to stabilise them first.
Also the camera is at a funny angle, and I wanted to use Hugin to level
the scene.

The solution is to use align_image_stack to align the photos to an
anchor image, but align_image_stack can't cope with thousands of photos,
so it needs some help.

The attached perl script uses a Hugin project file as a template to
fix lens distortion, straighten, and define a crop for the output. It
also uses the photo defined in the project as a reference, so all the
images in the sequence are fitted to this image.

Here's a short clip showing the result is pretty solid (except during
the bit where the entire scene is covered in fog):
https://youtu.be/N80QkvfnjhQ

--
Bruno
nona-deshake

Alister Ling

unread,
Feb 3, 2020, 5:23:18 PM2/3/20
to hugin and other free panoramic software
THANK YOU !!  This works really well - I was worried that control points would include moving objects (Moon/Venus), but I don't see any evidence of that. My problem was that during the time-lapse, my tripod very gradually shifted. When I stacked the 500+ images, they were not aligned. 
Here is my Windows implementation of Bruno's nona-deshake using ActiveState Perl on Windows:
With much appreciation,
Alister.
P.S. I can now go back a decade and save a few other projects!

Aleksandr Spiridonov

unread,
Jul 5, 2021, 10:37:43 AM7/5/21
to hugin and other free panoramic software
I'm a Hugin and panotools newbie. I came across this thread while researching image alignment. Would this approach work to align multiple equirectangular images, or more specifically, I would be more interested in getting horizontal offsets between a particular image and the reference image. My use case is automatically aligning 360 panoramas that are taken on a periodic basis. The reason I'm mostly interested in determining the offset is because I can align the images in the pano viewer by mapping the pixel offsets to yaw offsets.

Thanks,
Alek

Bruno Postle

unread,
Jul 5, 2021, 12:08:00 PM7/5/21
to hugin and other free panoramic software
This should be possible with some extra steps.

The nona-deshake.pl script uses align_image_stack to align the photos.
This is more robust with sequences taken during different lighting
conditions, but I don't expect it to work with 360 degree images. So
you would need to extract a rectilinear image for each frame, align
these rectilinear frames, but modify the script to assemble the
aligned sequence from the original 360 degree images.

Just offsetting 360 degree images sideways is equivalent to a yaw
transform, this would be ok as long as there is no roll and pitch
variation. If so you only need to modify the script to print the yaw
angle for each source photo, and calculate the pixel offset from that.

--
Bruno

On Mon, 5 Jul 2021 at 15:37, Aleksandr Spiridonov <sash...@gmail.com> wrote:
>
> I'm a Hugin and panotools newbie. I came across this thread while researching image alignment. Would this approach work to align multiple equirectangular images, or more specifically, I would be more interested in getting horizontal offsets between a particular image and the reference image. My use case is automatically aligning 360 panoramas that are taken on a periodic basis. The reason I'm mostly interested in determining the offset is because I can align the images in the pano viewer by mapping the pixel offsets to yaw offsets.
>

Tommy Hughes

unread,
Oct 6, 2022, 6:33:38 AM10/6/22
to hugin and other free panoramic software

Is it possible to convert this to using tif rather than jpg? I did try modifying it myself, but, so far, it doesn't run.
Thanks.

Bruno Postle

unread,
Oct 7, 2022, 1:25:24 PM10/7/22
to hugi...@googlegroups.com
ffmpeg can split a video into TIFF frames, just change the output
format to webcam%08d.tif or similar.

If you want nona-deshake to render to TIFF instead of JPEG, then you
should change "$prefix%08d.jpg" on line 51 to "$prefix%08d.tif" and
'JPEG' on line 88 to 'TIFF'.

--
Bruno

David W. Jones

unread,
Oct 8, 2022, 2:06:20 AM10/8/22
to hugin-ptx
On 10/7/22 07:25, Bruno Postle wrote:
> ffmpeg can split a video into TIFF frames, just change the output
> format to webcam%08d.tif or similar.
>
> If you want nona-deshake to render to TIFF instead of JPEG, then you
> should change "$prefix%08d.jpg" on line 51 to "$prefix%08d.tif" and
> 'JPEG' on line 88 to 'TIFF'.

Hey, Bruno!

I have only had to do something like this once, years ago. But reading
your post made me think, "You know, this is something I could do to my
next handheld video."

Thanks!


--
David W. Jones
gnome...@gmail.com
wandering the landscape of god
http://dancingtreefrog.com
My password is the last 8 digits of π.

Tommy Hughes

unread,
Oct 8, 2022, 4:17:12 AM10/8/22
to hugin and other free panoramic software
Hi Bruno, I already have tiffs, and I have tried altering every line with jpg and changing it to tiff, but the script doesn't run. Do the tiff filenames need to be in a specific format to work? Is that the webcam%08d?  Mine are name LRT_00001.tif, currently.

Thanks

Bruno Postle

unread,
Oct 8, 2022, 5:54:19 AM10/8/22
to hugi...@googlegroups.com
I just did a test and you don't need to modify nona-deshake to use
TIFF input files.

I created a set of images called: temp00000001.tif, temp00000002.tif etc...

I created a Hugin project using just one of these images, set the crop
and output projection, saved as template.pto

Ran nona-deshake:

nona-deshake -o out template.pto temp*.tif

Note that this produces JPEG intermediate files called
out00000001.jpg, out00000002.jpg, etc.. If you don't want JPEG here
then you *do* need to modify nona-deshake.

ffmpeg needs an input file:

for FILE in out*.jpg; do echo "file '$FILE'" >> frames.txt; done

This produces a frames.txt file that looks like this:

file 'out00000001.jpg'
file 'out00000002.jpg'
file 'out00000003.jpg'
[etc..]

Then I joined these JPEGs into a video like so:

ffmpeg -f concat -i frames.txt output.mp4

--
Bruno

Tommy Hughes

unread,
Oct 8, 2022, 12:17:10 PM10/8/22
to hugin and other free panoramic software
Thanks Bruno, I must have just been calling the script wrong. It works with jpg, now I will try with tif.

Rich MacDonald

unread,
Oct 9, 2022, 3:07:16 PM10/9/22
to hugin and other free panoramic software
Very interesting idea. Perhaps worth mentioning there is an excellent tool for stabilizing video itself.
DaVinci Resolve is a gold standard and has a free option.

Another tool from a few years back but still functionality is deshaker using virtualdub.

tristan

unread,
Jan 17, 2023, 11:56:24 AM1/17/23
to hugin and other free panoramic software
Hi...

I use a Mac.
Perl was installed on the mac.
Is there a command used in the mac?

Thank you.

2018년 6월 26일 화요일 오전 4시 1분 23초 UTC+9에 bruno...@gmail.com님이 작성:
Reply all
Reply to author
Forward
0 new messages