Permalink
Browse files

support for OpenCV built without opencv-gpu module

  • Loading branch information...
1 parent 4551bbd commit 0799cf455c71767b86f67c4fb3f395b77b73dd75 @royshil committed Jan 30, 2013
@@ -8,6 +8,8 @@
#include "GPUSURFFeatureMatcher.h"
+#ifdef HAVE_OPENCV_GPU
+
#include "FindCameraMatrices.h"
#include <opencv2/features2d/features2d.hpp>
#include <opencv2/highgui/highgui.hpp>
@@ -102,4 +104,6 @@ void GPUSURFFeatureMatcher::MatchFeatures(int idx_i, int idx_j, vector<DMatch>*
CV_PROFILE("match",matcher.match( descriptors_1, descriptors_2, *matches );)
}
}
-}
+}
+
+#endif
@@ -7,6 +7,9 @@
*/
#include "IFeatureMatcher.h"
+#include <opencv2/opencv_modules.hpp>
+
+#ifdef HAVE_OPENCV_GPU
#include <opencv2/gpu/gpu.hpp>
class GPUSURFFeatureMatcher : public IFeatureMatcher {
@@ -28,4 +31,18 @@ class GPUSURFFeatureMatcher : public IFeatureMatcher {
void MatchFeatures(int idx_i, int idx_j, std::vector<cv::DMatch>* matches = NULL);
std::vector<cv::KeyPoint> GetImagePoints(int idx) { return imgpts[idx]; }
-};
+};
+#else
+//empty impl.
+class GPUSURFFeatureMatcher : public IFeatureMatcher {
+public:
+ GPUSURFFeatureMatcher(std::vector<cv::Mat>& imgs,
+ std::vector<std::vector<cv::KeyPoint> >& imgpts) {}
+
+ void MatchFeatures(int idx_i, int idx_j, std::vector<cv::DMatch>* matches = NULL) {}
+
+ std::vector<cv::KeyPoint> GetImagePoints(int idx) { return std::vector<cv::KeyPoint>(); }
+
+};
+
+#endif
@@ -13,7 +13,9 @@
using namespace std;
+#ifdef HAVE_OPENCV_GPU
#include <opencv2/gpu/gpu.hpp>
+#endif
#include <opencv2/calib3d/calib3d.hpp>
bool sort_by_first(pair<int,pair<int,int> > a, pair<int,pair<int,int> > b) { return a.first < b.first; }
@@ -210,6 +212,7 @@ bool MultiCameraPnP::FindPoseEstimation(
CV_PROFILE("solvePnPRansac",cv::solvePnPRansac(ppcloud, imgPoints, K, distortion_coeff, rvec, t, true, 1000, 0.006 * maxVal, 0.25 * (double)(imgPoints.size()), inliers, CV_EPNP);)
//CV_PROFILE("solvePnP",cv::solvePnP(ppcloud, imgPoints, K, distortion_coeff, rvec, t, true, CV_EPNP);)
} else {
+#ifdef HAVE_OPENCV_GPU
//use GPU ransac
//make sure datatstructures are cv::gpu compatible
cv::Mat ppcloud_m(ppcloud); ppcloud_m = ppcloud_m.t();
@@ -220,6 +223,7 @@ bool MultiCameraPnP::FindPoseEstimation(
rvec_.convertTo(rvec,CV_64FC1);
t_.convertTo(t,CV_64FC1);
+#endif
}
vector<cv::Point2f> projected3D;
@@ -10,7 +10,9 @@
#include "OFFeatureMatcher.h"
#include <opencv2/video/video.hpp>
#include <opencv2/imgproc/imgproc.hpp>
+#ifdef HAVE_OPENCV_GPU
#include <opencv2/gpu/gpu.hpp>
+#endif
#include <opencv2/flann/flann.hpp>
#ifdef __SFM__DEBUG__
@@ -55,6 +57,7 @@ void OFFeatureMatcher::MatchFeatures(int idx_i, int idx_j, vector<DMatch>* match
vector<uchar> vstatus(i_pts.size()); vector<float> verror(i_pts.size());
+#ifdef HAVE_OPENCV_GPU
if(use_gpu) {
gpu::GpuMat gpu_prevImg,gpu_nextImg,gpu_prevPts,gpu_nextPts,gpu_status,gpu_error;
gpu_prevImg.upload(prevgray);
@@ -73,7 +76,9 @@ void OFFeatureMatcher::MatchFeatures(int idx_i, int idx_j, vector<DMatch>* match
gpu_error.download(verror_mat);
Mat(vstatus_mat.t()).copyTo(Mat(vstatus));
Mat(verror_mat.t()).copyTo(Mat(verror));
- } else {
+ } else
+#endif
+ {
CV_PROFILE("OpticalFlow",calcOpticalFlowPyrLK(prevgray, gray, i_pts, j_pts, vstatus, verror);)
}
View
@@ -16,7 +16,9 @@
using namespace std;
+#ifdef HAVE_OPENCV_GPU
#include <opencv2/gpu/gpu.hpp>
+#endif
class VisualizerListener : public SfMUpdateListener {
public:
@@ -85,10 +87,14 @@ int main(int argc, char** argv) {
else
distance->use_rich_features = (strcmp(argv[2], "RICH") == 0);
+#ifdef HAVE_OPENCV_GPU
if(argc < 4)
distance->use_gpu = (cv::gpu::getCudaEnabledDeviceCount() > 0);
else
distance->use_gpu = (strcmp(argv[3], "GPU") == 0);
+#else
+ distance->use_gpu = false;
+#endif
cv::Ptr<VisualizerListener> visualizerListener = new VisualizerListener; //with ref-count
distance->attach(visualizerListener);

0 comments on commit 0799cf4

Please sign in to comment.