Difference between revisions of "Image Stitching for NVIDIA Jetson/User Guide/Homography estimation"

From RidgeRun Developer Connection
Jump to: navigation, search
(Dependencies)
Line 14: Line 14:
  
 
The above dependencies can be installed making use of a [https://docs.python.org/3/tutorial/venv.html Python virtual environment]. A virtual environment is useful to install Python packages without damaging some other environment in your machine. To create a new virtual environment, run the following command:
 
The above dependencies can be installed making use of a [https://docs.python.org/3/tutorial/venv.html Python virtual environment]. A virtual environment is useful to install Python packages without damaging some other environment in your machine. To create a new virtual environment, run the following command:
 +
 +
<syntaxhighlight lang=bash>
 +
python3.6 -m venv ENV-NAME
 +
</syntaxhighlight>
 +
 +
A new folder will be created with the name ''ENV-NAME''. To activate the virtual environment, run the following:
 +
 +
<syntaxhighlight lang=bash>
 +
source <ENV-NAME>/bin/activate
 +
</syntaxhighlight>
 +
 +
Source the virtual environment each time you want to use it. To install the packages in the virtual environment:
 +
 +
<syntaxhighlight lang=bash>
 +
pip install numpy
 +
pip install opencv-python
 +
</syntaxhighlight>
  
 
= Script estimation flow =
 
= Script estimation flow =

Revision as of 09:04, 29 July 2020



  Index Next: Getting Started/Building Image Stitching for NVIDIA Jetson



Nvidia-preferred-partner-badge-rgb-for-screen.png



The following page will introduce a way to estimate an initial homography matrix that can be used in the cudastitcher element. This method consists of a Python script that estimates the homography between two images. Download the homography_estimation.py script.

Dependencies

  • Python 3.6
  • OpenCV 4.0 or later.
  • Numpy

Installing the dependencies using a virtual environment

The above dependencies can be installed making use of a Python virtual environment. A virtual environment is useful to install Python packages without damaging some other environment in your machine. To create a new virtual environment, run the following command:

python3.6 -m venv ENV-NAME

A new folder will be created with the name ENV-NAME. To activate the virtual environment, run the following:

source <ENV-NAME>/bin/activate

Source the virtual environment each time you want to use it. To install the packages in the virtual environment:

pip install numpy
pip install opencv-python

Script estimation flow

The steps performed by the script are the following:

  1. Load the images.
  2. Remove the distortion of the images.
  3. Perform a preprocessing to the images removing the noise using a Gaussian filter.
  4. Extract the keypoint and the corresponding descriptors with the SIFT algorithm.
  5. Find the correspondences among the key points of the two images.
  6. With the resulting keypoints, estimate the homography.

Script usage

The script has two modes:

  • left_fixed: where the left image is fixed and the right image will be transformed by the homography.
  • right_fixed: where the right image is fixed and the left image will be transformed by the homograpy.

For both modes can be adjusted the sigma value of the Gaussian filter and the width size of the overlap between the two images. The following are the complete options of the script:

python homography_estimation.py --help
usage: homography_estimation.py [-h] {left_fixed,right_fixed} ...

Tool for use the prediction capabilities of the models in the Adversarial
Anomaly Detector.

positional arguments:
  {left_fixed,right_fixed}
    left_fixed          Estimation of homography between two images
    right_fixed         Estimation of homographies two images

optional arguments:
  -h, --help            show this help message and exit

Type "homography_estimation.py <command> -h" for more information.

Options for the left_fixed mode:

python homography_estimation.py left_fixed --help
usage: homography_estimation.py left_fixed [-h] [--targetImage TARGETIMAGE]
                                           [--originalImage ORIGINALIMAGE]
                                           [--overlap OVERLAP] [--sigma SIGMA]

Estimation of homography between two images

optional arguments:
  -h, --help            show this help message and exit
  --targetImage TARGETIMAGE
                        Path of the target image
  --originalImage ORIGINALIMAGE
                        Path of the original image
  --overlap OVERLAP     Overlap size
  --sigma SIGMA         Gaussian filter sigma

Options for the right_fixed mode:

python homography_estimation.py right_fixed --help
usage: homography_estimation.py right_fixed [-h] [--targetImage TARGETIMAGE]
                                            [--originalImage ORIGINALIMAGE]
                                            [--overlap OVERLAP]
                                            [--sigma SIGMA]

Estimation of homographies two images

optional arguments:
  -h, --help            show this help message and exit
  --targetImage TARGETIMAGE
                        Path of the target image
  --originalImage ORIGINALIMAGE
                        Path of the original image
  --overlap OVERLAP     Overlap size
  --sigma SIGMA         Gaussian filter sigma

Example

The following example will estimate the homography of two images, with the left one fixed:

python homography_estimation.py left_fixed --targetImage /home/lmurillo/Desktop/captures/cam0.png --originalImage /home/lmurillo/Desktop/captures/cam1.png --overlap 391 --sigma 1.6

The --targetImage options corresponds to the image that is fixed and the --originalImage corresponds to the image that will be transformed. The output will be something like this:

matches: 311
RC_HOMOGRAPHY= \"h00\":0.5677192548684104,\"h01\":-0.0002205787019542546, \"h02\":1512.3174240935518, \"h10\":-0.18102969502215555, \"h11\":1.00110250078885, \"h12\":-3.677240508288687, \"h20\":-0.0002231803407071444, \"h21\":1.611398763903541e-05, \"h22\":1

Also, the script will generate some images to evaluate the quality of the homography:

Preprocessed target image
Preprocessed original image
Keypoints matches
Result of the stitching with the estimated homography


  Index Next: Getting Started/Building Image Stitching for NVIDIA Jetson