From: Vladislav Vinogradov Date: Mon, 3 Feb 2014 08:35:24 +0000 (+0400) Subject: turn on CUDA part of stitching module on Android for non-dynamic build X-Git-Tag: accepted/tizen/6.0/unified/20201030.111113~1314^2~628^2~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=a138e5a6a585e9dfc686d76b9769adeff02672b3;p=platform%2Fupstream%2Fopencv.git turn on CUDA part of stitching module on Android for non-dynamic build --- diff --git a/modules/stitching/CMakeLists.txt b/modules/stitching/CMakeLists.txt index 6e9a35b..fc8b2fc 100644 --- a/modules/stitching/CMakeLists.txt +++ b/modules/stitching/CMakeLists.txt @@ -1,6 +1,7 @@ set(the_description "Images stitching") -if (ENABLE_DYNAMIC_CUDA) +if(ENABLE_DYNAMIC_CUDA) + add_definitions(-DDYNAMIC_CUDA_SUPPORT) ocv_define_module(stitching opencv_imgproc opencv_features2d opencv_calib3d opencv_objdetect OPTIONAL opencv_nonfree) else() ocv_define_module(stitching opencv_imgproc opencv_features2d opencv_calib3d opencv_objdetect OPTIONAL opencv_gpu opencv_nonfree) -endif() \ No newline at end of file +endif() diff --git a/modules/stitching/include/opencv2/stitching/detail/matchers.hpp b/modules/stitching/include/opencv2/stitching/detail/matchers.hpp index 36f80f4..af7439f 100644 --- a/modules/stitching/include/opencv2/stitching/detail/matchers.hpp +++ b/modules/stitching/include/opencv2/stitching/detail/matchers.hpp @@ -44,11 +44,12 @@ #define __OPENCV_STITCHING_MATCHERS_HPP__ #include "opencv2/core/core.hpp" +#include "opencv2/core/gpumat.hpp" #include "opencv2/features2d/features2d.hpp" #include "opencv2/opencv_modules.hpp" -#if defined(HAVE_OPENCV_NONFREE) && defined(HAVE_OPENCV_GPU) && !defined(ANDROID) +#if defined(HAVE_OPENCV_NONFREE) #include "opencv2/nonfree/gpu.hpp" #endif @@ -104,7 +105,7 @@ private: }; -#if defined(HAVE_OPENCV_NONFREE) && defined(HAVE_OPENCV_GPU) && !defined(ANDROID) +#if defined(HAVE_OPENCV_NONFREE) class CV_EXPORTS SurfFeaturesFinderGpu : public FeaturesFinder { public: diff --git a/modules/stitching/include/opencv2/stitching/detail/seam_finders.hpp b/modules/stitching/include/opencv2/stitching/detail/seam_finders.hpp index 9301dc5..5034c80 100644 --- a/modules/stitching/include/opencv2/stitching/detail/seam_finders.hpp +++ b/modules/stitching/include/opencv2/stitching/detail/seam_finders.hpp @@ -45,7 +45,7 @@ #include #include "opencv2/core/core.hpp" -#include "opencv2/opencv_modules.hpp" +#include "opencv2/core/gpumat.hpp" namespace cv { namespace detail { @@ -227,7 +227,6 @@ private: }; -#if defined(HAVE_OPENCV_GPU) && !defined(ANDROID) class CV_EXPORTS GraphCutSeamFinderGpu : public GraphCutSeamFinderBase, public PairwiseSeamFinder { public: @@ -251,7 +250,6 @@ private: float terminal_cost_; float bad_region_penalty_; }; -#endif } // namespace detail } // namespace cv diff --git a/modules/stitching/include/opencv2/stitching/detail/warpers.hpp b/modules/stitching/include/opencv2/stitching/detail/warpers.hpp index d44bfe6..60d5e54 100644 --- a/modules/stitching/include/opencv2/stitching/detail/warpers.hpp +++ b/modules/stitching/include/opencv2/stitching/detail/warpers.hpp @@ -44,11 +44,8 @@ #define __OPENCV_STITCHING_WARPERS_HPP__ #include "opencv2/core/core.hpp" +#include "opencv2/core/gpumat.hpp" #include "opencv2/imgproc/imgproc.hpp" -#include "opencv2/opencv_modules.hpp" -#if defined(HAVE_OPENCV_GPU) && !defined(ANDROID) -# include "opencv2/gpu/gpu.hpp" -#endif namespace cv { namespace detail { @@ -331,7 +328,6 @@ public: }; -#if defined(HAVE_OPENCV_GPU) && !defined(ANDROID) class CV_EXPORTS PlaneWarperGpu : public PlaneWarper { public: @@ -448,7 +444,6 @@ public: private: gpu::GpuMat d_xmap_, d_ymap_, d_src_, d_dst_; }; -#endif struct SphericalPortraitProjector : ProjectorBase diff --git a/modules/stitching/include/opencv2/stitching/warpers.hpp b/modules/stitching/include/opencv2/stitching/warpers.hpp index 87efa7e..11e012f 100644 --- a/modules/stitching/include/opencv2/stitching/warpers.hpp +++ b/modules/stitching/include/opencv2/stitching/warpers.hpp @@ -145,7 +145,6 @@ public: -#if defined(HAVE_OPENCV_GPU) && !defined(ANDROID) class PlaneWarperGpu: public WarperCreator { public: @@ -165,7 +164,6 @@ class SphericalWarperGpu: public WarperCreator public: Ptr create(float scale) const { return new detail::SphericalWarperGpu(scale); } }; -#endif } // namespace cv diff --git a/modules/stitching/src/blenders.cpp b/modules/stitching/src/blenders.cpp index fb3c0d6..316263e 100644 --- a/modules/stitching/src/blenders.cpp +++ b/modules/stitching/src/blenders.cpp @@ -189,7 +189,7 @@ Rect FeatherBlender::createWeightMaps(const vector &masks, const vector &pyr) void createLaplacePyrGpu(const Mat &img, int num_levels, vector &pyr) { -#if defined(HAVE_OPENCV_GPU) && !defined(ANDROID) +#if defined(HAVE_OPENCV_GPU) && !defined(DYNAMIC_CUDA_SUPPORT) pyr.resize(num_levels + 1); vector gpu_pyr(num_levels + 1); @@ -512,6 +512,7 @@ void createLaplacePyrGpu(const Mat &img, int num_levels, vector &pyr) (void)img; (void)num_levels; (void)pyr; + CV_Error(CV_StsNotImplemented, "CUDA optimization is unavailable"); #endif } @@ -531,7 +532,7 @@ void restoreImageFromLaplacePyr(vector &pyr) void restoreImageFromLaplacePyrGpu(vector &pyr) { -#if defined(HAVE_OPENCV_GPU) && !defined(ANDROID) +#if defined(HAVE_OPENCV_GPU) && !defined(DYNAMIC_CUDA_SUPPORT) if (pyr.empty()) return; @@ -549,6 +550,7 @@ void restoreImageFromLaplacePyrGpu(vector &pyr) gpu_pyr[0].download(pyr[0]); #else (void)pyr; + CV_Error(CV_StsNotImplemented, "CUDA optimization is unavailable"); #endif } diff --git a/modules/stitching/src/matchers.cpp b/modules/stitching/src/matchers.cpp index d862062..ac29d7c 100644 --- a/modules/stitching/src/matchers.cpp +++ b/modules/stitching/src/matchers.cpp @@ -45,10 +45,7 @@ using namespace std; using namespace cv; using namespace cv::detail; - -#if defined(HAVE_OPENCV_GPU) && !defined(ANDROID) using namespace cv::gpu; -#endif #ifdef HAVE_OPENCV_NONFREE #include "opencv2/nonfree/nonfree.hpp" @@ -129,7 +126,7 @@ private: float match_conf_; }; -#if defined(HAVE_OPENCV_GPU) && !defined(ANDROID) +#if defined(HAVE_OPENCV_GPU) && !defined(DYNAMIC_CUDA_SUPPORT) class GpuMatcher : public FeaturesMatcher { public: @@ -204,7 +201,7 @@ void CpuMatcher::match(const ImageFeatures &features1, const ImageFeatures &feat LOG("1->2 & 2->1 matches: " << matches_info.matches.size() << endl); } -#if defined(HAVE_OPENCV_GPU) && !defined(ANDROID) +#if defined(HAVE_OPENCV_GPU) && !defined(DYNAMIC_CUDA_SUPPORT) void GpuMatcher::match(const ImageFeatures &features1, const ImageFeatures &features2, MatchesInfo& matches_info) { matches_info.matches.clear(); @@ -432,7 +429,7 @@ void OrbFeaturesFinder::find(const Mat &image, ImageFeatures &features) } } -#if defined(HAVE_OPENCV_NONFREE) && defined(HAVE_OPENCV_GPU) && !defined(ANDROID) +#if defined(HAVE_OPENCV_NONFREE) && defined(HAVE_OPENCV_GPU) && !defined(DYNAMIC_CUDA_SUPPORT) SurfFeaturesFinderGpu::SurfFeaturesFinderGpu(double hess_thresh, int num_octaves, int num_layers, int num_octaves_descr, int num_layers_descr) { @@ -478,6 +475,29 @@ void SurfFeaturesFinderGpu::collectGarbage() keypoints_.release(); descriptors_.release(); } +#elif defined(HAVE_OPENCV_NONFREE) +SurfFeaturesFinderGpu::SurfFeaturesFinderGpu(double hess_thresh, int num_octaves, int num_layers, + int num_octaves_descr, int num_layers_descr) +{ + (void)hess_thresh; + (void)num_octaves; + (void)num_layers; + (void)num_octaves_descr; + (void)num_layers_descr; + CV_Error(CV_StsNotImplemented, "CUDA optimization is unavailable"); +} + + +void SurfFeaturesFinderGpu::find(const Mat &image, ImageFeatures &features) +{ + (void)image; + (void)features; + CV_Error(CV_StsNotImplemented, "CUDA optimization is unavailable"); +} + +void SurfFeaturesFinderGpu::collectGarbage() +{ +} #endif @@ -533,7 +553,7 @@ void FeaturesMatcher::operator ()(const vector &features, vector< BestOf2NearestMatcher::BestOf2NearestMatcher(bool try_use_gpu, float match_conf, int num_matches_thresh1, int num_matches_thresh2) { -#if defined(HAVE_OPENCV_GPU) && !defined(ANDROID) +#if defined(HAVE_OPENCV_GPU) && !defined(DYNAMIC_CUDA_SUPPORT) if (try_use_gpu && getCudaEnabledDeviceCount() > 0) impl_ = new GpuMatcher(match_conf); else diff --git a/modules/stitching/src/precomp.hpp b/modules/stitching/src/precomp.hpp index 54b6721..699f19c 100644 --- a/modules/stitching/src/precomp.hpp +++ b/modules/stitching/src/precomp.hpp @@ -68,7 +68,7 @@ #include "opencv2/imgproc/imgproc.hpp" #include "opencv2/features2d/features2d.hpp" #include "opencv2/calib3d/calib3d.hpp" -#if defined(HAVE_OPENCV_GPU) && !defined(ANDROID) +#if defined(HAVE_OPENCV_GPU) && !defined(DYNAMIC_CUDA_SUPPORT) #include "opencv2/gpu/gpu.hpp" #ifdef HAVE_OPENCV_NONFREE diff --git a/modules/stitching/src/seam_finders.cpp b/modules/stitching/src/seam_finders.cpp index a198c1e..234f204 100644 --- a/modules/stitching/src/seam_finders.cpp +++ b/modules/stitching/src/seam_finders.cpp @@ -1318,7 +1318,7 @@ void GraphCutSeamFinder::find(const vector &src, const vector &corne } -#if defined(HAVE_OPENCV_GPU) && !defined(ANDROID) +#if defined(HAVE_OPENCV_GPU) && !defined(DYNAMIC_CUDA_SUPPORT) void GraphCutSeamFinderGpu::find(const vector &src, const vector &corners, vector &masks) { @@ -1642,6 +1642,62 @@ void GraphCutSeamFinderGpu::setGraphWeightsColorGrad( } } } +#else +void GraphCutSeamFinderGpu::find(const vector &src, const vector &corners, + vector &masks) +{ + (void)src; + (void)corners; + (void)masks; + CV_Error(CV_StsNotImplemented, "CUDA optimization is unavailable"); +} + + +void GraphCutSeamFinderGpu::findInPair(size_t first, size_t second, Rect roi) +{ + (void)first; + (void)second; + (void)roi; + CV_Error(CV_StsNotImplemented, "CUDA optimization is unavailable"); +} + + +void GraphCutSeamFinderGpu::setGraphWeightsColor(const Mat &img1, const Mat &img2, const Mat &mask1, const Mat &mask2, + Mat &terminals, Mat &leftT, Mat &rightT, Mat &top, Mat &bottom) +{ + (void)img1; + (void)img2; + (void)mask1; + (void)mask2; + (void)terminals; + (void)leftT; + (void)rightT; + (void)top; + (void)bottom; + CV_Error(CV_StsNotImplemented, "CUDA optimization is unavailable"); +} + + +void GraphCutSeamFinderGpu::setGraphWeightsColorGrad( + const Mat &img1, const Mat &img2, const Mat &dx1, const Mat &dx2, + const Mat &dy1, const Mat &dy2, const Mat &mask1, const Mat &mask2, + Mat &terminals, Mat &leftT, Mat &rightT, Mat &top, Mat &bottom) +{ + (void)img1; + (void)img2; + (void)dx1; + (void)dx2; + (void)dy1; + (void)dy2; + (void)mask1; + (void)mask2; + (void)terminals; + (void)leftT; + (void)rightT; + (void)top; + (void)bottom; + CV_Error(CV_StsNotImplemented, "CUDA optimization is unavailable"); +} #endif } // namespace detail diff --git a/modules/stitching/src/stitcher.cpp b/modules/stitching/src/stitcher.cpp index 4a36ab0..83ea609 100644 --- a/modules/stitching/src/stitcher.cpp +++ b/modules/stitching/src/stitcher.cpp @@ -58,7 +58,7 @@ Stitcher Stitcher::createDefault(bool try_use_gpu) stitcher.setFeaturesMatcher(new detail::BestOf2NearestMatcher(try_use_gpu)); stitcher.setBundleAdjuster(new detail::BundleAdjusterRay()); -#if defined(HAVE_OPENCV_GPU) && !defined(ANDROID) +#if defined(HAVE_OPENCV_GPU) && !defined(DYNAMIC_CUDA_SUPPORT) if (try_use_gpu && gpu::getCudaEnabledDeviceCount() > 0) { #if defined(HAVE_OPENCV_NONFREE) diff --git a/modules/stitching/src/warpers.cpp b/modules/stitching/src/warpers.cpp index 9358319..3b1d9c2 100644 --- a/modules/stitching/src/warpers.cpp +++ b/modules/stitching/src/warpers.cpp @@ -212,7 +212,7 @@ void SphericalWarper::detectResultRoi(Size src_size, Point &dst_tl, Point &dst_b } -#if defined(HAVE_OPENCV_GPU) && !defined(ANDROID) +#if defined(HAVE_OPENCV_GPU) && !defined(DYNAMIC_CUDA_SUPPORT) Rect PlaneWarperGpu::buildMaps(Size src_size, const Mat &K, const Mat &R, gpu::GpuMat &xmap, gpu::GpuMat &ymap) { return buildMaps(src_size, K, R, Mat::zeros(3, 1, CV_32F), xmap, ymap); @@ -294,6 +294,96 @@ Point CylindricalWarperGpu::warp(const gpu::GpuMat &src, const Mat &K, const Mat gpu::remap(src, dst, d_xmap_, d_ymap_, interp_mode, border_mode); return dst_roi.tl(); } +#else +Rect PlaneWarperGpu::buildMaps(Size src_size, const Mat &K, const Mat &R, gpu::GpuMat &xmap, gpu::GpuMat &ymap) +{ + return buildMaps(src_size, K, R, Mat::zeros(3, 1, CV_32F), xmap, ymap); +} + +Rect PlaneWarperGpu::buildMaps(Size src_size, const Mat &K, const Mat &R, const Mat &T, gpu::GpuMat &xmap, gpu::GpuMat &ymap) +{ + (void)src_size; + (void)K; + (void)R; + (void)T; + (void)xmap; + (void)ymap; + CV_Error(CV_StsNotImplemented, "CUDA optimization is unavailable"); + return Rect(); +} + +Point PlaneWarperGpu::warp(const gpu::GpuMat &src, const Mat &K, const Mat &R, int interp_mode, int border_mode, + gpu::GpuMat &dst) +{ + return warp(src, K, R, Mat::zeros(3, 1, CV_32F), interp_mode, border_mode, dst); +} + + +Point PlaneWarperGpu::warp(const gpu::GpuMat &src, const Mat &K, const Mat &R, const Mat &T, int interp_mode, int border_mode, + gpu::GpuMat &dst) +{ + (void)src; + (void)K; + (void)R; + (void)T; + (void)interp_mode; + (void)border_mode; + (void)dst; + CV_Error(CV_StsNotImplemented, "CUDA optimization is unavailable"); + return Point(); +} + + +Rect SphericalWarperGpu::buildMaps(Size src_size, const Mat &K, const Mat &R, gpu::GpuMat &xmap, gpu::GpuMat &ymap) +{ + (void)src_size; + (void)K; + (void)R; + (void)xmap; + (void)ymap; + CV_Error(CV_StsNotImplemented, "CUDA optimization is unavailable"); + return Rect(); +} + + +Point SphericalWarperGpu::warp(const gpu::GpuMat &src, const Mat &K, const Mat &R, int interp_mode, int border_mode, + gpu::GpuMat &dst) +{ + (void)src; + (void)K; + (void)R; + (void)interp_mode; + (void)border_mode; + (void)dst; + CV_Error(CV_StsNotImplemented, "CUDA optimization is unavailable"); + return Point(); +} + + +Rect CylindricalWarperGpu::buildMaps(Size src_size, const Mat &K, const Mat &R, gpu::GpuMat &xmap, gpu::GpuMat &ymap) +{ + (void)src_size; + (void)K; + (void)R; + (void)xmap; + (void)ymap; + CV_Error(CV_StsNotImplemented, "CUDA optimization is unavailable"); + return Rect(); +} + + +Point CylindricalWarperGpu::warp(const gpu::GpuMat &src, const Mat &K, const Mat &R, int interp_mode, int border_mode, + gpu::GpuMat &dst) +{ + (void)src; + (void)K; + (void)R; + (void)interp_mode; + (void)border_mode; + (void)dst; + CV_Error(CV_StsNotImplemented, "CUDA optimization is unavailable"); + return Point(); +} #endif void SphericalPortraitWarper::detectResultRoi(Size src_size, Point &dst_tl, Point &dst_br)