diff --git a/modules/python/src2/cv2.cpp b/modules/python/src2/cv2.cpp index b491761005..59a4c67bc5 100644 --- a/modules/python/src2/cv2.cpp +++ b/modules/python/src2/cv2.cpp @@ -114,6 +114,7 @@ typedef SimpleBlobDetector::Params SimpleBlobDetector_Params; typedef cvflann::flann_distance_t cvflann_flann_distance_t; typedef cvflann::flann_algorithm_t cvflann_flann_algorithm_t; +typedef Stitcher::Status Status; static PyObject* failmsgp(const char *fmt, ...) { @@ -444,6 +445,12 @@ PyObject* pyopencv_from(const bool& value) return PyBool_FromLong(value); } +template<> +PyObject* pyopencv_from(const Status& value) +{ + return PyInt_FromLong(value); +} + template<> bool pyopencv_to(PyObject* obj, bool& value, const char* name) { diff --git a/modules/stitching/include/opencv2/stitching.hpp b/modules/stitching/include/opencv2/stitching.hpp index b647c0fe2c..15e9479e29 100644 --- a/modules/stitching/include/opencv2/stitching.hpp +++ b/modules/stitching/include/opencv2/stitching.hpp @@ -55,7 +55,7 @@ namespace cv { -class CV_EXPORTS Stitcher +class CV_EXPORTS_W Stitcher { public: enum { ORIG_RESOL = -1 }; @@ -67,23 +67,24 @@ public: ERR_CAMERA_PARAMS_ADJUST_FAIL = 3 }; + // Stitcher() {} // Creates stitcher with default parameters static Stitcher createDefault(bool try_use_gpu = false); - double registrationResol() const { return registr_resol_; } - void setRegistrationResol(double resol_mpx) { registr_resol_ = resol_mpx; } + CV_WRAP double registrationResol() const { return registr_resol_; } + CV_WRAP void setRegistrationResol(double resol_mpx) { registr_resol_ = resol_mpx; } - double seamEstimationResol() const { return seam_est_resol_; } - void setSeamEstimationResol(double resol_mpx) { seam_est_resol_ = resol_mpx; } + CV_WRAP double seamEstimationResol() const { return seam_est_resol_; } + CV_WRAP void setSeamEstimationResol(double resol_mpx) { seam_est_resol_ = resol_mpx; } - double compositingResol() const { return compose_resol_; } - void setCompositingResol(double resol_mpx) { compose_resol_ = resol_mpx; } + CV_WRAP double compositingResol() const { return compose_resol_; } + CV_WRAP void setCompositingResol(double resol_mpx) { compose_resol_ = resol_mpx; } - double panoConfidenceThresh() const { return conf_thresh_; } - void setPanoConfidenceThresh(double conf_thresh) { conf_thresh_ = conf_thresh; } + CV_WRAP double panoConfidenceThresh() const { return conf_thresh_; } + CV_WRAP void setPanoConfidenceThresh(double conf_thresh) { conf_thresh_ = conf_thresh; } - bool waveCorrection() const { return do_wave_correct_; } - void setWaveCorrection(bool flag) { do_wave_correct_ = flag; } + CV_WRAP bool waveCorrection() const { return do_wave_correct_; } + CV_WRAP void setWaveCorrection(bool flag) { do_wave_correct_ = flag; } detail::WaveCorrectKind waveCorrectKind() const { return wave_correct_kind_; } void setWaveCorrectKind(detail::WaveCorrectKind kind) { wave_correct_kind_ = kind; } @@ -127,21 +128,21 @@ public: const Ptr blender() const { return blender_; } void setBlender(Ptr b) { blender_ = b; } - Status estimateTransform(InputArrayOfArrays images); + CV_WRAP Status estimateTransform(InputArrayOfArrays images); Status estimateTransform(InputArrayOfArrays images, const std::vector > &rois); - Status composePanorama(OutputArray pano); + CV_WRAP Status composePanorama(OutputArray pano); Status composePanorama(InputArrayOfArrays images, OutputArray pano); - Status stitch(InputArrayOfArrays images, OutputArray pano); + CV_WRAP Status stitch(InputArrayOfArrays images, OutputArray pano); Status stitch(InputArrayOfArrays images, const std::vector > &rois, OutputArray pano); std::vector component() const { return indices_; } std::vector cameras() const { return cameras_; } - double workScale() const { return work_scale_; } + CV_WRAP double workScale() const { return work_scale_; } private: - Stitcher() {} + //Stitcher() {} Status matchImages(); Status estimateCameraParams(); @@ -175,6 +176,8 @@ private: double warped_image_scale_; }; +CV_EXPORTS_W Ptr createStitcher(bool try_use_gpu = false); + } // namespace cv #endif // __OPENCV_STITCHING_STITCHER_HPP__ diff --git a/modules/stitching/src/stitcher.cpp b/modules/stitching/src/stitcher.cpp index f3bbe38c32..43efbd3880 100644 --- a/modules/stitching/src/stitcher.cpp +++ b/modules/stitching/src/stitcher.cpp @@ -531,4 +531,45 @@ Stitcher::Status Stitcher::estimateCameraParams() return OK; } + +Ptr createStitcher(bool try_use_gpu) +{ + Ptr stitcher = makePtr(); + stitcher->setRegistrationResol(0.6); + stitcher->setSeamEstimationResol(0.1); + stitcher->setCompositingResol(Stitcher::ORIG_RESOL); + stitcher->setPanoConfidenceThresh(1); + stitcher->setWaveCorrection(true); + stitcher->setWaveCorrectKind(detail::WAVE_CORRECT_HORIZ); + stitcher->setFeaturesMatcher(makePtr(try_use_gpu)); + stitcher->setBundleAdjuster(makePtr()); + + #ifdef HAVE_OPENCV_CUDA + if (try_use_gpu && cuda::getCudaEnabledDeviceCount() > 0) + { + #ifdef HAVE_OPENCV_NONFREE + stitcher->setFeaturesFinder(makePtr()); + #else + stitcher->setFeaturesFinder(makePtr()); + #endif + stitcher->setWarper(makePtr()); + stitcher->setSeamFinder(makePtr()); + } + else + #endif + { + #ifdef HAVE_OPENCV_NONFREE + stitcher->setFeaturesFinder(makePtr()); + #else + stitcher->setFeaturesFinder(makePtr()); + #endif + stitcher->setWarper(makePtr()); + stitcher->setSeamFinder(makePtr(detail::GraphCutSeamFinderBase::COST_COLOR)); + } + + stitcher->setExposureCompensator(makePtr()); + stitcher->setBlender(makePtr(try_use_gpu)); + + return stitcher; +} } // namespace cv