• Stars
    star
    1,844
  • Rank 25,170 (Top 0.5 %)
  • Language
    C++
  • License
    MIT License
  • Created over 11 years ago
  • Updated about 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Automatic Panorama Stitching From Scratch

OpenPano

cmu0

Introduction

OpenPano is a panorama stitching program written in C++ from scratch (without any vision libraries). It mainly follows the routine described in the paper Automatic Panoramic Image Stitching using Invariant Features, which is also the one used by AutoStitch.

Build Status

Compile Dependencies:

  • gcc >= 4.7 (Or VS2015)
  • Eigen
  • FLANN (already included in the repository, slightly modified)
  • CImg (optional. already included in the repository)
  • libjpeg (optional if you only work with png files)
  • cmake or make

Eigen, CImg and FLANN are header-only, to simplify the compilation on different platforms. CImg and libjpeg are only used to read and write images, so you can easily get rid of them.

On ArchLinux, install dependencies by: sudo pacman -S gcc sed cmake make libjpeg eigen

On Ubuntu, install dependencies by: sudo apt install build-essential sed cmake libjpeg-dev libeigen3-dev

Compile:

Linux / OSX / WSL (bash on windows)

$ make -C src

or

$ mkdir build && cd build && cmake .. && make

The default clang on OSX doesn't contain openmp support. You may need gcc or different clang. See #16.

Windows

  • Install cmake, VS2015
  • Set environment variable Eigen3_DIR to {YOUR_EIGEN3_DIRECTORY}/eigen3/cmake.
  • Open Visual Studio Developer Command Prompt.
  • cd path/to/OpenPano
  • cmake .
  • Open the VS2015 project and compile the project
  • copy config.cfg to the directory containing image-stitching.exe
  • The author have never used Visual Studio and this windows build process may not work for you. Feel free to submit PR to improve the build process.

Options:

Three modes are available (set/unset the options in config.cfg):

  • cylinder mode. Requirements:

    • You stay at the same spot and only turn left (or right) when taking the images (as is usually done), no translations or other type of rotations allowed.
    • Images are taken with the same camera, with a known FOCAL_LENGTH set in config.
    • Images are given in the left-to-right order. (I might fix this in the future)
  • camera estimation mode. Requirements:

    • You stay at the same spot when taking the images, and can turn your camera left-right or up-down.
    • Don't use too few images.
    • It runs slower because it needs to perform pairwise matches.
  • translation mode. Simply stitch images together by affine transformation. Requirements:

    • Camera performs pure translation.
    • The images are roughly at the same depth.
    • Input images are ordered according to the translation movement.

Some options you may care:

  • FOCAL_LENGTH: focal length of your camera in 35mm equivalent. Only useful in cylinder mode.
  • ORDERED_INPUT: whether input images are ordered sequentially. has to be 1 in CYLINDER and TRANS mode.
  • CROP: whether to crop the final image to avoid irregular white border.

Other parameters are quality-related. The default values are generally good for images with more than 0.7 megapixels. If your images are too small and cannot produce satisfactory results, it might be better to resize your images rather than tune the parameters.

Run:

$ ./image-stitching <file1> <file2> ...

The output file is out.jpg. You can play with the example data to start with.

Before dealing with very large images (4 megapixels or more), it's better to resize them. (I might add this feature in the future)

In cylinder/translation mode, the input file names need to have the correct order.

Examples (All original data available for download):

Zijing Apartment in Tsinghua University: dorm

"Myselves": myself

Carnegie Mellon University from 38 images apple

Newell-Simon Hall in CMU (this one is hard because objects are closer): nsh

A full-view pano built from UAV images: uav

For more examples, see results.

Speed & Memory:

Tested on Intel Core i7-6700HQ, with ESTIMATE_CAMERA mode:

  • 11 ordered images of size 600x400: 3.2s.
  • 13 ordered images of size 1500x1112: 6s.
  • 38 unordered images of size 1300x867 (high vertical FOV): 51s.

Memory consumption is known to be huge with default libc allocator. Simply using a modern allocator (e.g. tcmalloc, jemalloc) can help a lot. Also, setting LAZY_READ to 1 can save memory at the cost of a minor slow down.

Peak memory in bytes (assume each input has the same w & h):

  • Without LAZY_READ option: max(finalw * finalh * 12, #photos * w * h * 12 + #photos * #matched_pairs * 96 + #keypoints * 520)
  • With LAZY_READ option: max(finalw * finalh * 16, #threads * w * h * 12, #photos * #matched_pairs * 96 + #keypoints * 520)

Algorithms

  • Features: SIFT
  • Transformation: use RANSAC to estimate a homography or affine transformation.
  • Optimization: focal estimation, bundle adjustment, and some straightening tricks.

For details, see my blog post.

Quality Guidelines

To get the best stitching quality:

  • While rotating the camera for different shots, try to keep the position of camera lens static.
  • Keep the exposure parameters unchanged.
  • Do not shoot on moving objects.
  • Objects far away will stitch better.
  • The algorithm doesn't work well with wide-angle cameras where images are distorted heavily. Camera parameters are needed to undistort the images.

TODOs

  • apply pairwise matching for translation mode as well
  • run bundle adjustment on sphere lens instead of perspective lens
  • improve feature detector and matching
  • use LAZY_READ & 1 byte image in both blender to reduce peak memory
  • clean up use of copies of ImageRef
  • faster gaussian blur kernel
  • port some hotspot (e.g. dist.cc) to neon
  • support read/write EXIF metadata to:
    • get focal length, distortion, etc
    • allow pano to be viewed on Facebook
  • python bindings

More Repositories

1

wechat-dump

Cracking encrypted wechat message history from android
Python
1,645
star
2

speaker-recognition

A Speaker Recognition System
C++
675
star
3

Adversarial-Face-Attack

Black-Box Adversarial Attack on Public Face Recognition Systems
Python
401
star
4

dash-docset-tensorflow

dash/zeal docset for TensorFlow 1 & 2
CSS
197
star
5

SoPaper

Automatically Search and Download Papers
Python
194
star
6

RAM-multiprocess-dataloader

Demystify RAM Usage in Multi-Process Data Loaders
Python
169
star
7

moco.tensorflow

A TensorFlow re-implementation of Momentum Contrast (MoCo): https://arxiv.org/abs/1911.05722
Python
161
star
8

cocoapi

Contains the "pycocotools" package on PyPI. Changes made to the official cocoapi about packaging.
Jupyter Notebook
123
star
9

GroupNorm-reproduce

An official collection of code in different frameworks that reproduces experiments in "Group Normalization"
Python
117
star
10

Ray-Tracing-Engine

A Photorealistic 3D Rendering Engine
C++
104
star
11

dotfiles

my dotfiles..
Python
58
star
12

dotvim

Over 1200+ lines of vimrc
Vim Script
43
star
13

Stereo-Pose-Machines

Stereo Pose Machines - Real Time 3D Pose Estimation
Python
43
star
14

vim-PinyinSearch

help vim search Chinese by Pinyin
Vim Script
39
star
15

FRN-on-common-ImageNet-baseline

Filter Response Normalization tested on better ImageNet baselines.
Python
35
star
16

dash-docset-matlab

Generate Dash Docset for Matlab
22
star
17

haDNN

Proof-of-Concept CNN in Halide
C++
21
star
18

hexo-tag-vimhighlight

Highlight code using vim in hexo
CoffeeScript
20
star
19

duxiu-downloader

Download e-books from duxiu.com
JavaScript
14
star
20

math

notes on math
TeX
8
star
21

dash-docset-jax

Create nice dash/zeal docset for JAX+Flax
Python
7
star
22

N-Body

Parallel N-Body Simulation Program
C++
5
star
23

dash-docset-torch

Dash/zeal docset for torch
Shell
5
star
24

ImageResizer

An Image Resizer using Seam Carving alogrithm.
C++
5
star
25

sigmod14contest

Code for ACM SIGMOD 2014 programming contest
C++
5
star
26

tensorflow-wheels

A repo to store custom tensorflow wheels in releases
5
star
27

Mandelbrot-Set

draw Mandelbrot set based on Xwindow. Use mpi / openmp / pthread to speed up
C++
3
star
28

vim-SugarCpp

support SugarCpp in vim.
Vim Script
2
star
29

sudoku

A sudoku solver using dancing links and algorithm X
C++
1
star
30

googlecli

Command Line Google Search
Python
1
star