1
0
mirror of https://github.com/opencv/opencv.git synced 2026-07-30 15:53:03 +04:00
Files
opencv/apps/opencv_stitching_tool/opencv_stitching/camera_estimator.py
T
Lukas-Alexander Weber fa5c7a9e75 Merge pull request #21020 from lukasalexanderweber:squash
Created Stitching Tool based on stitching_detailed.py
2021-11-08 11:54:06 +00:00

28 lines
906 B
Python

from collections import OrderedDict
import cv2 as cv
import numpy as np
from .stitching_error import StitchingError
class CameraEstimator:
CAMERA_ESTIMATOR_CHOICES = OrderedDict()
CAMERA_ESTIMATOR_CHOICES['homography'] = cv.detail_HomographyBasedEstimator
CAMERA_ESTIMATOR_CHOICES['affine'] = cv.detail_AffineBasedEstimator
DEFAULT_CAMERA_ESTIMATOR = list(CAMERA_ESTIMATOR_CHOICES.keys())[0]
def __init__(self, estimator=DEFAULT_CAMERA_ESTIMATOR, **kwargs):
self.estimator = CameraEstimator.CAMERA_ESTIMATOR_CHOICES[estimator](
**kwargs
)
def estimate(self, features, pairwise_matches):
b, cameras = self.estimator.apply(features, pairwise_matches, None)
if not b:
raise StitchingError("Homography estimation failed.")
for cam in cameras:
cam.R = cam.R.astype(np.float32)
return cameras