Gpu functionality in stitching module is excluded from Android build

This commit is contained in:
Andrey Kamaev 2011-09-07 08:59:39 +00:00
parent 95a3ffd0c5
commit 52184c8803
9 changed files with 85 additions and 33 deletions

View File

@ -28,12 +28,12 @@ endif()
add_subdirectory(video)
if(NOT (ANDROID OR IOS))
add_subdirectory(gpu)
endif()
if(NOT IOS)
add_subdirectory(traincascade)
add_subdirectory(haartraining)
endif()
if(NOT (ANDROID OR IOS))
add_subdirectory(gpu)
add_subdirectory(stitching)
endif()

View File

@ -1,2 +1,6 @@
include_directories("${OpenCV_SOURCE_DIR}/modules/imgproc/src") # For gcgraph.hpp
define_opencv_module(stitching opencv_core opencv_imgproc opencv_features2d opencv_calib3d opencv_gpu opencv_flann opencv_objdetect)
if(ANDROID)
define_opencv_module(stitching opencv_core opencv_imgproc opencv_features2d opencv_calib3d opencv_flann opencv_objdetect)
else()
define_opencv_module(stitching opencv_core opencv_imgproc opencv_features2d opencv_calib3d opencv_flann opencv_objdetect opencv_gpu)
endif()

View File

@ -44,7 +44,9 @@
#include "opencv2/core/core.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/gpu/gpu.hpp"
#ifndef ANDROID
# include "opencv2/gpu/gpu.hpp"
#endif
namespace cv {
namespace detail {
@ -118,7 +120,7 @@ protected:
void detectResultRoi(Point &dst_tl, Point &dst_br);
};
#ifndef ANDROID
class CV_EXPORTS PlaneWarperGpu : public PlaneWarper
{
public:
@ -129,6 +131,7 @@ public:
private:
gpu::GpuMat d_xmap_, d_ymap_, d_dst_, d_src_;
};
#endif
struct CV_EXPORTS SphericalProjector : ProjectorBase
@ -150,6 +153,7 @@ protected:
};
#ifndef ANDROID
class CV_EXPORTS SphericalWarperGpu : public SphericalWarper
{
public:
@ -160,6 +164,7 @@ public:
private:
gpu::GpuMat d_xmap_, d_ymap_, d_dst_, d_src_;
};
#endif
struct CV_EXPORTS CylindricalProjector : ProjectorBase
@ -183,6 +188,7 @@ protected:
};
#ifndef ANDROID
class CV_EXPORTS CylindricalWarperGpu : public CylindricalWarper
{
public:
@ -193,6 +199,7 @@ public:
private:
gpu::GpuMat d_xmap_, d_ymap_, d_dst_, d_src_;
};
#endif
} // namespace detail
} // namespace cv

View File

@ -158,7 +158,11 @@ void FeatherBlender::blend(Mat &dst, Mat &dst_mask)
MultiBandBlender::MultiBandBlender(int try_gpu, int num_bands)
{
setNumBands(num_bands);
#ifndef ANDROID
can_use_gpu_ = try_gpu && gpu::getCudaEnabledDeviceCount();
#else
can_use_gpu_ = false;
#endif
}
@ -342,9 +346,9 @@ void createLaplacePyr(const Mat &img, int num_levels, vector<Mat> &pyr)
}
}
void createLaplacePyrGpu(const Mat &img, int num_levels, vector<Mat> &pyr)
{
#ifndef ANDROID
pyr.resize(num_levels + 1);
vector<gpu::GpuMat> gpu_pyr(num_levels + 1);
@ -361,9 +365,9 @@ void createLaplacePyrGpu(const Mat &img, int num_levels, vector<Mat> &pyr)
}
pyr[num_levels] = gpu_pyr[num_levels];
#endif
}
void restoreImageFromLaplacePyr(vector<Mat> &pyr)
{
if (pyr.size() == 0)

View File

@ -43,7 +43,9 @@
#include "precomp.hpp"
using namespace std;
#ifndef ANDROID
using namespace cv::gpu;
#endif
namespace cv {
namespace detail {

View File

@ -45,7 +45,9 @@
using namespace std;
using namespace cv;
using namespace cv::detail;
#ifndef ANDROID
using namespace cv::gpu;
#endif
namespace {
@ -67,7 +69,7 @@ private:
Ptr<DescriptorExtractor> extractor_;
};
#ifndef ANDROID
class GpuSurfFeaturesFinder : public FeaturesFinder
{
public:
@ -97,6 +99,7 @@ private:
int num_octaves_, num_layers_;
int num_octaves_descr_, num_layers_descr_;
};
#endif
void CpuSurfFeaturesFinder::find(const Mat &image, ImageFeatures &features)
@ -108,7 +111,7 @@ void CpuSurfFeaturesFinder::find(const Mat &image, ImageFeatures &features)
extractor_->compute(gray_image, features.keypoints, features.descriptors);
}
#ifndef ANDROID
void GpuSurfFeaturesFinder::find(const Mat &image, ImageFeatures &features)
{
CV_Assert(image.depth() == CV_8U);
@ -141,6 +144,7 @@ void GpuSurfFeaturesFinder::releaseMemory()
keypoints_.release();
descriptors_.release();
}
#endif
//////////////////////////////////////////////////////////////////////////////
@ -220,7 +224,7 @@ private:
float match_conf_;
};
#ifndef ANDROID
class GpuMatcher : public FeaturesMatcher
{
public:
@ -235,6 +239,7 @@ private:
GpuMat train_idx_, distance_, all_dist_;
vector< vector<DMatch> > pair_matches;
};
#endif
void CpuMatcher::match(const ImageFeatures &features1, const ImageFeatures &features2, MatchesInfo& matches_info)
@ -274,7 +279,7 @@ void CpuMatcher::match(const ImageFeatures &features1, const ImageFeatures &feat
}
}
#ifndef ANDROID
void GpuMatcher::match(const ImageFeatures &features1, const ImageFeatures &features2, MatchesInfo& matches_info)
{
matches_info.matches.clear();
@ -330,6 +335,7 @@ void GpuMatcher::releaseMemory()
all_dist_.release();
vector< vector<DMatch> >().swap(pair_matches);
}
#endif
} // namespace
@ -348,9 +354,11 @@ void FeaturesFinder::operator ()(const Mat &image, ImageFeatures &features)
SurfFeaturesFinder::SurfFeaturesFinder(bool try_use_gpu, double hess_thresh, int num_octaves, int num_layers,
int num_octaves_descr, int num_layers_descr)
{
#ifndef ANDROID
if (try_use_gpu && getCudaEnabledDeviceCount() > 0)
impl_ = new GpuSurfFeaturesFinder(hess_thresh, num_octaves, num_layers, num_octaves_descr, num_layers_descr);
else
#endif
impl_ = new CpuSurfFeaturesFinder(hess_thresh, num_octaves, num_layers, num_octaves_descr, num_layers_descr);
}
@ -412,9 +420,11 @@ void FeaturesMatcher::operator ()(const vector<ImageFeatures> &features, vector<
BestOf2NearestMatcher::BestOf2NearestMatcher(bool try_use_gpu, float match_conf, int num_matches_thresh1, int num_matches_thresh2)
{
#ifndef ANDROID
if (try_use_gpu && getCudaEnabledDeviceCount() > 0)
impl_ = new GpuMatcher(match_conf);
else
#endif
impl_ = new CpuMatcher(match_conf);
is_thread_safe_ = impl_->isThreadSafe();

View File

@ -66,7 +66,9 @@
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/features2d/features2d.hpp"
#include "opencv2/calib3d/calib3d.hpp"
#include "opencv2/gpu/gpu.hpp"
#ifndef ANDROID
# include "opencv2/gpu/gpu.hpp"
#endif
#include "gcgraph.hpp"
#endif

View File

@ -49,13 +49,27 @@ namespace detail {
Ptr<Warper> Warper::createByCameraFocal(float focal, int type, bool try_gpu)
{
#ifndef ANDROID
bool can_use_gpu = try_gpu && gpu::getCudaEnabledDeviceCount();
if (type == PLANE)
return !can_use_gpu ? new PlaneWarper(focal) : new PlaneWarperGpu(focal);
if (type == CYLINDRICAL)
return !can_use_gpu ? new CylindricalWarper(focal) : new CylindricalWarperGpu(focal);
if (type == SPHERICAL)
return !can_use_gpu ? new SphericalWarper(focal) : new SphericalWarperGpu(focal);
if (can_use_gpu)
{
if (type == PLANE)
return new PlaneWarperGpu(focal);
if (type == CYLINDRICAL)
return new CylindricalWarperGpu(focal);
if (type == SPHERICAL)
return new SphericalWarperGpu(focal);
}
else
#endif
{
if (type == PLANE)
return new PlaneWarper(focal);
if (type == CYLINDRICAL)
return new CylindricalWarper(focal);
if (type == SPHERICAL)
return new SphericalWarper(focal);
}
CV_Error(CV_StsBadArg, "unsupported warping type");
return NULL;
}
@ -107,7 +121,7 @@ void PlaneWarper::detectResultRoi(Point &dst_tl, Point &dst_br)
dst_br.y = static_cast<int>(br_vf);
}
#ifndef ANDROID
Point PlaneWarperGpu::warp(const Mat &src, float focal, const Mat &R, Mat &dst, int interp_mode, int border_mode)
{
src_size_ = src.size();
@ -132,6 +146,7 @@ Point PlaneWarperGpu::warp(const Mat &src, float focal, const Mat &R, Mat &dst,
return dst_tl;
}
#endif
void SphericalWarper::detectResultRoi(Point &dst_tl, Point &dst_br)
@ -177,7 +192,7 @@ void SphericalWarper::detectResultRoi(Point &dst_tl, Point &dst_br)
dst_br.y = static_cast<int>(br_vf);
}
#ifndef ANDROID
Point SphericalWarperGpu::warp(const Mat &src, float focal, const Mat &R, Mat &dst,
int interp_mode, int border_mode)
{
@ -230,6 +245,7 @@ Point CylindricalWarperGpu::warp(const Mat &src, float focal, const Mat &R, Mat
return dst_tl;
}
#endif
} // namespace detail
} // namespace cv

View File

@ -19,8 +19,10 @@ if (BUILD_EXAMPLES)
"${CMAKE_SOURCE_DIR}/modules/legacy/include"
"${CMAKE_SOURCE_DIR}/modules/contrib/include"
"${CMAKE_SOURCE_DIR}/modules/stitching/include"
"${CMAKE_SOURCE_DIR}/modules/gpu/include"
)
)
if (NOT ANDROID)
include_directories("${CMAKE_SOURCE_DIR}/modules/gpu/include")
endif()
if(CMAKE_COMPILER_IS_GNUCXX)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-unused-function")
@ -37,19 +39,24 @@ if (BUILD_EXAMPLES)
PROJECT_LABEL "(EXAMPLE) ${name}")
add_dependencies(${the_target} opencv_core opencv_flann opencv_imgproc opencv_highgui
opencv_ml opencv_video opencv_objdetect opencv_features2d
opencv_calib3d opencv_legacy opencv_contrib opencv_stitching opencv_gpu)
opencv_calib3d opencv_legacy opencv_contrib opencv_stitching)
target_link_libraries(${the_target} ${OPENCV_LINKER_LIBS} opencv_core
opencv_flann opencv_imgproc opencv_highgui opencv_ml opencv_video opencv_objdetect
opencv_features2d opencv_calib3d opencv_legacy opencv_contrib opencv_stitching opencv_gpu)
if(ENABLE_SOLUTION_FOLDERS)
set_target_properties(${the_target} PROPERTIES FOLDER "samples//cpp")
endif()
opencv_features2d opencv_calib3d opencv_legacy opencv_contrib opencv_stitching)
if (NOT ANDROID)
target_link_libraries(${the_target} opencv_gpu)
add_dependencies(${the_target} opencv_gpu)
endif()
if(ENABLE_SOLUTION_FOLDERS)
set_target_properties(${the_target} PROPERTIES FOLDER "samples//cpp")
endif()
if(WIN32)
if (MSVC AND NOT BUILD_SHARED_LIBS)
set_target_properties(${the_target} PROPERTIES LINK_FLAGS "/NODEFAULTLIB:atlthunk.lib /NODEFAULTLIB:atlsd.lib /DEBUG")
endif()
if (MSVC AND NOT BUILD_SHARED_LIBS)
set_target_properties(${the_target} PROPERTIES LINK_FLAGS "/NODEFAULTLIB:atlthunk.lib /NODEFAULTLIB:atlsd.lib /DEBUG")
endif()
install(TARGETS ${the_target}
RUNTIME DESTINATION "samples/cpp" COMPONENT main)
endif()