From d275e29ea4b68606ccc5e79e1d4ae3fd6123709a Mon Sep 17 00:00:00 2001 From: Anatoly Baksheev Date: Tue, 15 Oct 2013 17:34:20 +0400 Subject: [PATCH 1/8] compilation & warnings --- modules/viz/test/test_viz3d.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/modules/viz/test/test_viz3d.cpp b/modules/viz/test/test_viz3d.cpp index ef21c9df75..eac0bd0496 100644 --- a/modules/viz/test/test_viz3d.cpp +++ b/modules/viz/test/test_viz3d.cpp @@ -109,8 +109,7 @@ TEST(Viz_viz3d, accuracy) for (int i = 0, j = 0; i <= 360; ++i, j+=5) { - cam_path.push_back(viz::makeCameraPose(Point3f(0.5*cos(double(i)*CV_PI/180.0), 0.5*sin(double(j)*CV_PI/180.0), 0.5*sin(double(i)*CV_PI/180.0)), - Point3f(0.0,0.0,0.0), Point3f(0.0,1.0,0.0))); + cam_path.push_back(viz::makeCameraPose(Vec3d(0.5*cos(double(i)*CV_PI/180.0), 0.5*sin(double(j)*CV_PI/180.0), 0.5*sin(double(i)*CV_PI/180.0)), Vec3f(0.f, 0.f, 0.f), Vec3f(0.f, 1.f, 0.f))); } int path_counter = 0; @@ -133,7 +132,7 @@ TEST(Viz_viz3d, accuracy) colors[col] = Mat::zeros(img.rows/downSample, 1, CV_8UC3); for (int row = 0; row < row_max; ++row) { - clouds[col].at(row) = Vec3f(downSample * float(col) / img.cols, 1.0-(downSample * float(row) / img.rows), 0.0); + clouds[col].at(row) = Vec3f(downSample * float(col) / img.cols, 1.f-(downSample * float(row) / img.rows), 0.f); colors[col].at(row) = img.at(row*downSample,col*downSample); } } @@ -174,7 +173,7 @@ TEST(Viz_viz3d, accuracy) { std::stringstream strstrm; strstrm << "cloud_" << i; - viz.setWidgetPose(strstrm.str(), Affine3f().translate(Vec3f(-0.5,0.0, -0.7 + 0.2*sin((angle+i*10)*CV_PI / 180.0)))); + viz.setWidgetPose(strstrm.str(), Affine3f().translate(Vec3f(-0.5f, 0.f, (float)(-0.7 + 0.2*sin((angle+i*10)*CV_PI / 180.0))))); } angle += 10; viz.spinOnce(42, true); From 0dad07047320a667bc7ba7f9529ff9d7066a35f7 Mon Sep 17 00:00:00 2001 From: Anatoly Baksheev Date: Sat, 16 Nov 2013 19:56:08 +0400 Subject: [PATCH 2/8] Fixed compilation errors: removed using namespace from hpp file. This led to pulling cv::ACCESS_MASK to global namespace where conflict with the same name in 'windows.h' --- apps/traincascade/HOGfeatures.cpp | 1 + apps/traincascade/HOGfeatures.h | 22 ++++++++--------- apps/traincascade/boost.cpp | 14 +++++++++++ apps/traincascade/boost.h | 18 +++++++------- apps/traincascade/cascadeclassifier.cpp | 1 + apps/traincascade/cascadeclassifier.h | 26 ++++++++++---------- apps/traincascade/features.cpp | 1 + apps/traincascade/haarfeatures.cpp | 1 + apps/traincascade/haarfeatures.h | 26 ++++++++++---------- apps/traincascade/imagestorage.cpp | 1 + apps/traincascade/imagestorage.h | 20 +++++++-------- apps/traincascade/lbpfeatures.cpp | 2 ++ apps/traincascade/lbpfeatures.h | 16 ++++++------ apps/traincascade/traincascade.cpp | 1 + apps/traincascade/traincascade_features.h | 30 +++++++++++------------ 15 files changed, 101 insertions(+), 79 deletions(-) diff --git a/apps/traincascade/HOGfeatures.cpp b/apps/traincascade/HOGfeatures.cpp index 132e2e62e9..e479777dfc 100644 --- a/apps/traincascade/HOGfeatures.cpp +++ b/apps/traincascade/HOGfeatures.cpp @@ -5,6 +5,7 @@ #include "cascadeclassifier.h" using namespace std; +using namespace cv; CvHOGFeatureParams::CvHOGFeatureParams() { diff --git a/apps/traincascade/HOGfeatures.h b/apps/traincascade/HOGfeatures.h index 329c6072ca..cdf758777d 100644 --- a/apps/traincascade/HOGfeatures.h +++ b/apps/traincascade/HOGfeatures.h @@ -20,23 +20,23 @@ class CvHOGEvaluator : public CvFeatureEvaluator public: virtual ~CvHOGEvaluator() {} virtual void init(const CvFeatureParams *_featureParams, - int _maxSampleCount, Size _winSize ); - virtual void setImage(const Mat& img, uchar clsLabel, int idx); + int _maxSampleCount, cv::Size _winSize ); + virtual void setImage(const cv::Mat& img, uchar clsLabel, int idx); virtual float operator()(int varIdx, int sampleIdx) const; - virtual void writeFeatures( FileStorage &fs, const Mat& featureMap ) const; + virtual void writeFeatures( cv::FileStorage &fs, const cv::Mat& featureMap ) const; protected: virtual void generateFeatures(); - virtual void integralHistogram(const Mat &img, std::vector &histogram, Mat &norm, int nbins) const; + virtual void integralHistogram(const cv::Mat &img, std::vector &histogram, cv::Mat &norm, int nbins) const; class Feature { public: Feature(); Feature( int offset, int x, int y, int cellW, int cellH ); - float calc( const std::vector &_hists, const Mat &_normSum, size_t y, int featComponent ) const; - void write( FileStorage &fs ) const; - void write( FileStorage &fs, int varIdx ) const; + float calc( const std::vector &_hists, const cv::Mat &_normSum, size_t y, int featComponent ) const; + void write( cv::FileStorage &fs ) const; + void write( cv::FileStorage &fs, int varIdx ) const; - Rect rect[N_CELLS]; //cells + cv::Rect rect[N_CELLS]; //cells struct { @@ -45,8 +45,8 @@ protected: }; std::vector features; - Mat normSum; //for nomalization calculation (L1 or L2) - std::vector hist; + cv::Mat normSum; //for nomalization calculation (L1 or L2) + std::vector hist; }; inline float CvHOGEvaluator::operator()(int varIdx, int sampleIdx) const @@ -57,7 +57,7 @@ inline float CvHOGEvaluator::operator()(int varIdx, int sampleIdx) const return features[featureIdx].calc( hist, normSum, sampleIdx, componentIdx); } -inline float CvHOGEvaluator::Feature::calc( const std::vector& _hists, const Mat& _normSum, size_t y, int featComponent ) const +inline float CvHOGEvaluator::Feature::calc( const std::vector& _hists, const cv::Mat& _normSum, size_t y, int featComponent ) const { float normFactor; float res; diff --git a/apps/traincascade/boost.cpp b/apps/traincascade/boost.cpp index 732704a4a2..5b244c8b3b 100644 --- a/apps/traincascade/boost.cpp +++ b/apps/traincascade/boost.cpp @@ -1,4 +1,18 @@ #include "opencv2/core.hpp" +#include "opencv2/core/utility.hpp" + +using cv::Size; +using cv::Mat; +using cv::Point; +using cv::FileStorage; +using cv::Rect; +using cv::Ptr; +using cv::FileNode; +using cv::Mat_; +using cv::Range; +using cv::FileNodeIterator; +using cv::ParallelLoopBody; + #include "boost.h" #include "cascadeclassifier.h" diff --git a/apps/traincascade/boost.h b/apps/traincascade/boost.h index 2a080484b5..0edf776a5b 100644 --- a/apps/traincascade/boost.h +++ b/apps/traincascade/boost.h @@ -13,8 +13,8 @@ struct CvCascadeBoostParams : CvBoostParams CvCascadeBoostParams( int _boostType, float _minHitRate, float _maxFalseAlarm, double _weightTrimRate, int _maxDepth, int _maxWeakCount ); virtual ~CvCascadeBoostParams() {} - void write( FileStorage &fs ) const; - bool read( const FileNode &node ); + void write( cv::FileStorage &fs ) const; + bool read( const cv::FileNode &node ); virtual void printDefaults() const; virtual void printAttrs() const; virtual bool scanAttr( const std::string prmName, const std::string val); @@ -45,7 +45,7 @@ struct CvCascadeBoostTrainData : CvDTreeTrainData virtual void free_train_data(); const CvFeatureEvaluator* featureEvaluator; - Mat valCache; // precalculated feature values (CV_32FC1) + cv::Mat valCache; // precalculated feature values (CV_32FC1) CvMat _resp; // for casting int numPrecalcVal, numPrecalcIdx; }; @@ -54,9 +54,9 @@ class CvCascadeBoostTree : public CvBoostTree { public: virtual CvDTreeNode* predict( int sampleIdx ) const; - void write( FileStorage &fs, const Mat& featureMap ); - void read( const FileNode &node, CvBoost* _ensemble, CvDTreeTrainData* _data ); - void markFeaturesInMap( Mat& featureMap ); + void write( cv::FileStorage &fs, const cv::Mat& featureMap ); + void read( const cv::FileNode &node, CvBoost* _ensemble, CvDTreeTrainData* _data ); + void markFeaturesInMap( cv::Mat& featureMap ); protected: virtual void split_node_data( CvDTreeNode* n ); }; @@ -70,10 +70,10 @@ public: virtual float predict( int sampleIdx, bool returnSum = false ) const; float getThreshold() const { return threshold; } - void write( FileStorage &fs, const Mat& featureMap ) const; - bool read( const FileNode &node, const CvFeatureEvaluator* _featureEvaluator, + void write( cv::FileStorage &fs, const cv::Mat& featureMap ) const; + bool read( const cv::FileNode &node, const CvFeatureEvaluator* _featureEvaluator, const CvCascadeBoostParams& _params ); - void markUsedFeaturesInMap( Mat& featureMap ); + void markUsedFeaturesInMap( cv::Mat& featureMap ); protected: virtual bool set_params( const CvBoostParams& _params ); virtual void update_weights( CvBoostTree* tree ); diff --git a/apps/traincascade/cascadeclassifier.cpp b/apps/traincascade/cascadeclassifier.cpp index 5c96b45f76..31bd1bee47 100644 --- a/apps/traincascade/cascadeclassifier.cpp +++ b/apps/traincascade/cascadeclassifier.cpp @@ -4,6 +4,7 @@ #include using namespace std; +using namespace cv; static const char* stageTypes[] = { CC_BOOST }; static const char* featureTypes[] = { CC_HAAR, CC_LBP, CC_HOG }; diff --git a/apps/traincascade/cascadeclassifier.h b/apps/traincascade/cascadeclassifier.h index 3eb50b5260..93be478b4e 100644 --- a/apps/traincascade/cascadeclassifier.h +++ b/apps/traincascade/cascadeclassifier.h @@ -72,8 +72,8 @@ public: CvCascadeParams(); CvCascadeParams( int _stageType, int _featureType ); - void write( FileStorage &fs ) const; - bool read( const FileNode &node ); + void write( cv::FileStorage &fs ) const; + bool read( const cv::FileNode &node ); void printDefaults() const; void printAttrs() const; @@ -81,7 +81,7 @@ public: int stageType; int featureType; - Size winSize; + cv::Size winSize; }; class CvCascadeClassifier @@ -104,20 +104,20 @@ private: bool updateTrainingSet( double& acceptanceRatio ); int fillPassedSamples( int first, int count, bool isPositive, int64& consumed ); - void writeParams( FileStorage &fs ) const; - void writeStages( FileStorage &fs, const Mat& featureMap ) const; - void writeFeatures( FileStorage &fs, const Mat& featureMap ) const; - bool readParams( const FileNode &node ); - bool readStages( const FileNode &node ); + void writeParams( cv::FileStorage &fs ) const; + void writeStages( cv::FileStorage &fs, const cv::Mat& featureMap ) const; + void writeFeatures( cv::FileStorage &fs, const cv::Mat& featureMap ) const; + bool readParams( const cv::FileNode &node ); + bool readStages( const cv::FileNode &node ); - void getUsedFeaturesIdxMap( Mat& featureMap ); + void getUsedFeaturesIdxMap( cv::Mat& featureMap ); CvCascadeParams cascadeParams; - Ptr featureParams; - Ptr stageParams; + cv::Ptr featureParams; + cv::Ptr stageParams; - Ptr featureEvaluator; - std::vector< Ptr > stageClassifiers; + cv::Ptr featureEvaluator; + std::vector< cv::Ptr > stageClassifiers; CvCascadeImageReader imgReader; int numStages, curNumSamples; int numPos, numNeg; diff --git a/apps/traincascade/features.cpp b/apps/traincascade/features.cpp index 7f0c0a7079..be0fe5f7fd 100644 --- a/apps/traincascade/features.cpp +++ b/apps/traincascade/features.cpp @@ -4,6 +4,7 @@ #include "cascadeclassifier.h" using namespace std; +using namespace cv; float calcNormFactor( const Mat& sum, const Mat& sqSum ) { diff --git a/apps/traincascade/haarfeatures.cpp b/apps/traincascade/haarfeatures.cpp index ceb730aafb..a58fb45c90 100644 --- a/apps/traincascade/haarfeatures.cpp +++ b/apps/traincascade/haarfeatures.cpp @@ -5,6 +5,7 @@ #include "cascadeclassifier.h" using namespace std; +using namespace cv; CvHaarFeatureParams::CvHaarFeatureParams() : mode(BASIC) { diff --git a/apps/traincascade/haarfeatures.h b/apps/traincascade/haarfeatures.h index 472822bb80..0894d098c3 100644 --- a/apps/traincascade/haarfeatures.h +++ b/apps/traincascade/haarfeatures.h @@ -18,8 +18,8 @@ public: CvHaarFeatureParams( int _mode ); virtual void init( const CvFeatureParams& fp ); - virtual void write( FileStorage &fs ) const; - virtual bool read( const FileNode &node ); + virtual void write( cv::FileStorage &fs ) const; + virtual bool read( const cv::FileNode &node ); virtual void printDefaults() const; virtual void printAttrs() const; @@ -32,11 +32,11 @@ class CvHaarEvaluator : public CvFeatureEvaluator { public: virtual void init(const CvFeatureParams *_featureParams, - int _maxSampleCount, Size _winSize ); - virtual void setImage(const Mat& img, uchar clsLabel, int idx); + int _maxSampleCount, cv::Size _winSize ); + virtual void setImage(const cv::Mat& img, uchar clsLabel, int idx); virtual float operator()(int featureIdx, int sampleIdx) const; - virtual void writeFeatures( FileStorage &fs, const Mat& featureMap ) const; - void writeFeature( FileStorage &fs, int fi ) const; // for old file fornat + virtual void writeFeatures( cv::FileStorage &fs, const cv::Mat& featureMap ) const; + void writeFeature( cv::FileStorage &fs, int fi ) const; // for old file fornat protected: virtual void generateFeatures(); @@ -48,13 +48,13 @@ protected: int x0, int y0, int w0, int h0, float wt0, int x1, int y1, int w1, int h1, float wt1, int x2 = 0, int y2 = 0, int w2 = 0, int h2 = 0, float wt2 = 0.0F ); - float calc( const Mat &sum, const Mat &tilted, size_t y) const; - void write( FileStorage &fs ) const; + float calc( const cv::Mat &sum, const cv::Mat &tilted, size_t y) const; + void write( cv::FileStorage &fs ) const; bool tilted; struct { - Rect r; + cv::Rect r; float weight; } rect[CV_HAAR_FEATURE_MAX]; @@ -65,9 +65,9 @@ protected: }; std::vector features; - Mat sum; /* sum images (each row represents image) */ - Mat tilted; /* tilted sum images (each row represents image) */ - Mat normfactor; /* normalization factor */ + cv::Mat sum; /* sum images (each row represents image) */ + cv::Mat tilted; /* tilted sum images (each row represents image) */ + cv::Mat normfactor; /* normalization factor */ }; inline float CvHaarEvaluator::operator()(int featureIdx, int sampleIdx) const @@ -76,7 +76,7 @@ inline float CvHaarEvaluator::operator()(int featureIdx, int sampleIdx) const return !nf ? 0.0f : (features[featureIdx].calc( sum, tilted, sampleIdx)/nf); } -inline float CvHaarEvaluator::Feature::calc( const Mat &_sum, const Mat &_tilted, size_t y) const +inline float CvHaarEvaluator::Feature::calc( const cv::Mat &_sum, const cv::Mat &_tilted, size_t y) const { const int* img = tilted ? _tilted.ptr((int)y) : _sum.ptr((int)y); float ret = rect[0].weight * (img[fastRect[0].p0] - img[fastRect[0].p1] - img[fastRect[0].p2] + img[fastRect[0].p3] ) + diff --git a/apps/traincascade/imagestorage.cpp b/apps/traincascade/imagestorage.cpp index a8426e074d..528f9c167d 100644 --- a/apps/traincascade/imagestorage.cpp +++ b/apps/traincascade/imagestorage.cpp @@ -8,6 +8,7 @@ #include using namespace std; +using namespace cv; bool CvCascadeImageReader::create( const string _posFilename, const string _negFilename, Size _winSize ) { diff --git a/apps/traincascade/imagestorage.h b/apps/traincascade/imagestorage.h index dd08e664de..fb68e25cb2 100644 --- a/apps/traincascade/imagestorage.h +++ b/apps/traincascade/imagestorage.h @@ -3,15 +3,15 @@ #include "highgui.h" -using namespace cv; + class CvCascadeImageReader { public: - bool create( const std::string _posFilename, const std::string _negFilename, Size _winSize ); + bool create( const std::string _posFilename, const std::string _negFilename, cv::Size _winSize ); void restart() { posReader.restart(); } - bool getNeg(Mat &_img) { return negReader.get( _img ); } - bool getPos(Mat &_img) { return posReader.get( _img ); } + bool getNeg(cv::Mat &_img) { return negReader.get( _img ); } + bool getPos(cv::Mat &_img) { return posReader.get( _img ); } private: class PosReader @@ -20,7 +20,7 @@ private: PosReader(); virtual ~PosReader(); bool create( const std::string _filename ); - bool get( Mat &_img ); + bool get( cv::Mat &_img ); void restart(); short* vec; @@ -35,18 +35,18 @@ private: { public: NegReader(); - bool create( const std::string _filename, Size _winSize ); - bool get( Mat& _img ); + bool create( const std::string _filename, cv::Size _winSize ); + bool get( cv::Mat& _img ); bool nextImg(); - Mat src, img; + cv::Mat src, img; std::vector imgFilenames; - Point offset, point; + cv::Point offset, point; float scale; float scaleFactor; float stepFactor; size_t last, round; - Size winSize; + cv::Size winSize; } negReader; }; diff --git a/apps/traincascade/lbpfeatures.cpp b/apps/traincascade/lbpfeatures.cpp index dd1659f9de..e99c6b2b7e 100644 --- a/apps/traincascade/lbpfeatures.cpp +++ b/apps/traincascade/lbpfeatures.cpp @@ -4,6 +4,8 @@ #include "lbpfeatures.h" #include "cascadeclassifier.h" +using namespace cv; + CvLBPFeatureParams::CvLBPFeatureParams() { maxCatCount = 256; diff --git a/apps/traincascade/lbpfeatures.h b/apps/traincascade/lbpfeatures.h index d4397c4427..3e36a5887a 100644 --- a/apps/traincascade/lbpfeatures.h +++ b/apps/traincascade/lbpfeatures.h @@ -15,11 +15,11 @@ class CvLBPEvaluator : public CvFeatureEvaluator public: virtual ~CvLBPEvaluator() {} virtual void init(const CvFeatureParams *_featureParams, - int _maxSampleCount, Size _winSize ); - virtual void setImage(const Mat& img, uchar clsLabel, int idx); + int _maxSampleCount, cv::Size _winSize ); + virtual void setImage(const cv::Mat& img, uchar clsLabel, int idx); virtual float operator()(int featureIdx, int sampleIdx) const { return (float)features[featureIdx].calc( sum, sampleIdx); } - virtual void writeFeatures( FileStorage &fs, const Mat& featureMap ) const; + virtual void writeFeatures( cv::FileStorage &fs, const cv::Mat& featureMap ) const; protected: virtual void generateFeatures(); @@ -28,18 +28,18 @@ protected: public: Feature(); Feature( int offset, int x, int y, int _block_w, int _block_h ); - uchar calc( const Mat& _sum, size_t y ) const; - void write( FileStorage &fs ) const; + uchar calc( const cv::Mat& _sum, size_t y ) const; + void write( cv::FileStorage &fs ) const; - Rect rect; + cv::Rect rect; int p[16]; }; std::vector features; - Mat sum; + cv::Mat sum; }; -inline uchar CvLBPEvaluator::Feature::calc(const Mat &_sum, size_t y) const +inline uchar CvLBPEvaluator::Feature::calc(const cv::Mat &_sum, size_t y) const { const int* psum = _sum.ptr((int)y); int cval = psum[p[5]] - psum[p[6]] - psum[p[9]] + psum[p[10]]; diff --git a/apps/traincascade/traincascade.cpp b/apps/traincascade/traincascade.cpp index a896c216c9..e6e16ba896 100644 --- a/apps/traincascade/traincascade.cpp +++ b/apps/traincascade/traincascade.cpp @@ -4,6 +4,7 @@ #include "cascadeclassifier.h" using namespace std; +using namespace cv; int main( int argc, char* argv[] ) { diff --git a/apps/traincascade/traincascade_features.h b/apps/traincascade/traincascade_features.h index dde0f1a7f8..dfba7a3d43 100644 --- a/apps/traincascade/traincascade_features.h +++ b/apps/traincascade/traincascade_features.h @@ -30,13 +30,13 @@ (p3) = (rect).x + (rect).width - (rect).height \ + (step) * ((rect).y + (rect).width + (rect).height); -float calcNormFactor( const Mat& sum, const Mat& sqSum ); +float calcNormFactor( const cv::Mat& sum, const cv::Mat& sqSum ); template -void _writeFeatures( const std::vector features, FileStorage &fs, const Mat& featureMap ) +void _writeFeatures( const std::vector features, cv::FileStorage &fs, const cv::Mat& featureMap ) { fs << FEATURES << "["; - const Mat_& featureMap_ = (const Mat_&)featureMap; + const cv::Mat_& featureMap_ = (const cv::Mat_&)featureMap; for ( int fi = 0; fi < featureMap.cols; fi++ ) if ( featureMap_(0, fi) >= 0 ) { @@ -53,8 +53,8 @@ public: CvParams(); virtual ~CvParams() {} // from|to file - virtual void write( FileStorage &fs ) const = 0; - virtual bool read( const FileNode &node ) = 0; + virtual void write( cv::FileStorage &fs ) const = 0; + virtual bool read( const cv::FileNode &node ) = 0; // from|to screen virtual void printDefaults() const; virtual void printAttrs() const; @@ -68,9 +68,9 @@ public: enum { HAAR = 0, LBP = 1, HOG = 2 }; CvFeatureParams(); virtual void init( const CvFeatureParams& fp ); - virtual void write( FileStorage &fs ) const; - virtual bool read( const FileNode &node ); - static Ptr create( int featureType ); + virtual void write( cv::FileStorage &fs ) const; + virtual bool read( const cv::FileNode &node ); + static cv::Ptr create( int featureType ); int maxCatCount; // 0 in case of numerical features int featSize; // 1 in case of simple features (HAAR, LBP) and N_BINS(9)*N_CELLS(4) in case of Dalal's HOG features }; @@ -80,25 +80,25 @@ class CvFeatureEvaluator public: virtual ~CvFeatureEvaluator() {} virtual void init(const CvFeatureParams *_featureParams, - int _maxSampleCount, Size _winSize ); - virtual void setImage(const Mat& img, uchar clsLabel, int idx); - virtual void writeFeatures( FileStorage &fs, const Mat& featureMap ) const = 0; + int _maxSampleCount, cv::Size _winSize ); + virtual void setImage(const cv::Mat& img, uchar clsLabel, int idx); + virtual void writeFeatures( cv::FileStorage &fs, const cv::Mat& featureMap ) const = 0; virtual float operator()(int featureIdx, int sampleIdx) const = 0; - static Ptr create(int type); + static cv::Ptr create(int type); int getNumFeatures() const { return numFeatures; } int getMaxCatCount() const { return featureParams->maxCatCount; } int getFeatureSize() const { return featureParams->featSize; } - const Mat& getCls() const { return cls; } + const cv::Mat& getCls() const { return cls; } float getCls(int si) const { return cls.at(si, 0); } protected: virtual void generateFeatures() = 0; int npos, nneg; int numFeatures; - Size winSize; + cv::Size winSize; CvFeatureParams *featureParams; - Mat cls; + cv::Mat cls; }; #endif From dfef42f94e1c56730c0dd47b275539ee639d1606 Mon Sep 17 00:00:00 2001 From: Anatoly Baksheev Date: Sat, 16 Nov 2013 20:56:42 +0400 Subject: [PATCH 3/8] Fixed Viz compilation: removed CV_EXPORTS from cv::viz::Color. The macro forced instantiation of all Matx constructors and triggered StaticAssert there. --- modules/viz/include/opencv2/viz/types.hpp | 22 ++++++++++++++++++++-- modules/viz/src/interactor_style.h | 2 +- modules/viz/src/types.cpp | 20 -------------------- 3 files changed, 21 insertions(+), 23 deletions(-) diff --git a/modules/viz/include/opencv2/viz/types.hpp b/modules/viz/include/opencv2/viz/types.hpp index 5a3667b828..3cccfa06fe 100644 --- a/modules/viz/include/opencv2/viz/types.hpp +++ b/modules/viz/include/opencv2/viz/types.hpp @@ -57,7 +57,7 @@ namespace cv { namespace viz { - class CV_EXPORTS Color : public Scalar + class Color : public Scalar { public: Color(); @@ -169,8 +169,26 @@ namespace cv Vec2f principal_point_; Vec2f focal_; }; - } /* namespace viz */ } /* namespace cv */ +////////////////////////////////////////////////////////////////////////////////////////////////////// +/// cv::viz::Color + +inline cv::viz::Color::Color() : Scalar(0, 0, 0) {} +inline cv::viz::Color::Color(double gray) : Scalar(gray, gray, gray) {} +inline cv::viz::Color::Color(double blue, double green, double red) : Scalar(blue, green, red) {} +inline cv::viz::Color::Color(const Scalar& color) : Scalar(color) {} + +inline cv::viz::Color cv::viz::Color::black() { return Color( 0, 0, 0); } +inline cv::viz::Color cv::viz::Color::green() { return Color( 0, 255, 0); } +inline cv::viz::Color cv::viz::Color::blue() { return Color(255, 0, 0); } +inline cv::viz::Color cv::viz::Color::cyan() { return Color(255, 255, 0); } +inline cv::viz::Color cv::viz::Color::red() { return Color( 0, 0, 255); } +inline cv::viz::Color cv::viz::Color::yellow() { return Color( 0, 255, 255); } +inline cv::viz::Color cv::viz::Color::magenta() { return Color(255, 0, 255); } +inline cv::viz::Color cv::viz::Color::white() { return Color(255, 255, 255); } +inline cv::viz::Color cv::viz::Color::gray() { return Color(128, 128, 128); } + + #endif diff --git a/modules/viz/src/interactor_style.h b/modules/viz/src/interactor_style.h index 7b80ee94b2..30d8529163 100644 --- a/modules/viz/src/interactor_style.h +++ b/modules/viz/src/interactor_style.h @@ -49,7 +49,7 @@ #ifndef __OPENCV_VIZ_INTERACTOR_STYLE_H__ #define __OPENCV_VIZ_INTERACTOR_STYLE_H__ -#include +#include "precomp.hpp" namespace cv { diff --git a/modules/viz/src/types.cpp b/modules/viz/src/types.cpp index 5528fbcfc2..861a783181 100644 --- a/modules/viz/src/types.cpp +++ b/modules/viz/src/types.cpp @@ -48,26 +48,6 @@ #include "precomp.hpp" -////////////////////////////////////////////////////////////////////////////////////////////////////// -/// cv::viz::Color - -cv::viz::Color::Color() : Scalar(0, 0, 0) {} -cv::viz::Color::Color(double gray) : Scalar(gray, gray, gray) {} -cv::viz::Color::Color(double blue, double green, double red) : Scalar(blue, green, red) {} -cv::viz::Color::Color(const Scalar& color) : Scalar(color) {} - -cv::viz::Color cv::viz::Color::black() { return Color( 0, 0, 0); } -cv::viz::Color cv::viz::Color::green() { return Color( 0, 255, 0); } -cv::viz::Color cv::viz::Color::blue() { return Color(255, 0, 0); } -cv::viz::Color cv::viz::Color::cyan() { return Color(255, 255, 0); } - -cv::viz::Color cv::viz::Color::red() { return Color( 0, 0, 255); } -cv::viz::Color cv::viz::Color::yellow() { return Color( 0, 255, 255); } -cv::viz::Color cv::viz::Color::magenta() { return Color(255, 0, 255); } -cv::viz::Color cv::viz::Color::white() { return Color(255, 255, 255); } - -cv::viz::Color cv::viz::Color::gray() { return Color(128, 128, 128); } - //////////////////////////////////////////////////////////////////// /// cv::viz::KeyboardEvent From 5c6248005a1573515ec3df399cb23f8105750463 Mon Sep 17 00:00:00 2001 From: Anatoly Baksheev Date: Sat, 16 Nov 2013 21:04:21 +0400 Subject: [PATCH 4/8] fixed warnings --- modules/highgui/src/cap_openni.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/modules/highgui/src/cap_openni.cpp b/modules/highgui/src/cap_openni.cpp index be5ed93ca2..db9a518df3 100644 --- a/modules/highgui/src/cap_openni.cpp +++ b/modules/highgui/src/cap_openni.cpp @@ -171,6 +171,9 @@ public: xn::ImageGenerator &imageGenerator; private: + ApproximateSyncGrabber(const ApproximateSyncGrabber&); + ApproximateSyncGrabber& operator=(const ApproximateSyncGrabber&); + int maxBufferSize; bool isCircleBuffer; int maxTimeDuration; @@ -214,7 +217,7 @@ private: virtual bool grab( xn::DepthMetaData& depthMetaData, xn::ImageMetaData& imageMetaData ) { - while(1) + for(;;) { if( !isDepthFilled ) isDepthFilled = popDepthMetaData(depth); @@ -951,7 +954,7 @@ double CvCapture_OpenNI::getDepthGeneratorProperty( int propIdx ) propValue = depthGenerator.GetAlternativeViewPointCap().IsViewPointAs(imageGenerator) ? 1.0 : 0.0; break; case CV_CAP_PROP_POS_MSEC : - propValue = depthGenerator.GetTimestamp(); + propValue = (double)depthGenerator.GetTimestamp(); break; case CV_CAP_PROP_POS_FRAMES : propValue = depthGenerator.GetFrameID(); @@ -1039,7 +1042,7 @@ double CvCapture_OpenNI::getImageGeneratorProperty( int propIdx ) propValue = mode.nFPS; break; case CV_CAP_PROP_POS_MSEC : - propValue = imageGenerator.GetTimestamp(); + propValue = (double)imageGenerator.GetTimestamp(); break; case CV_CAP_PROP_POS_FRAMES : propValue = imageGenerator.GetFrameID(); From d8600d3d13eefedf01863c836de81e39ccb42384 Mon Sep 17 00:00:00 2001 From: Anatoly Baksheev Date: Sat, 16 Nov 2013 21:27:03 +0400 Subject: [PATCH 5/8] fixed all Viz warnings moved some headers to precomp.hpp --- modules/highgui/src/cap_openni.cpp | 4 +++- modules/viz/src/interactor_style.cpp | 35 ++++++++++++++++------------ modules/viz/src/interactor_style.h | 6 +++-- modules/viz/src/precomp.hpp | 6 ++--- modules/viz/src/viz3d.cpp | 3 +-- modules/viz/src/viz3d_impl.cpp | 1 - modules/viz/src/viz3d_impl.hpp | 3 --- 7 files changed, 31 insertions(+), 27 deletions(-) diff --git a/modules/highgui/src/cap_openni.cpp b/modules/highgui/src/cap_openni.cpp index db9a518df3..22f7823bce 100644 --- a/modules/highgui/src/cap_openni.cpp +++ b/modules/highgui/src/cap_openni.cpp @@ -105,7 +105,9 @@ public: context(_context), depthGenerator(_depthGenerator), imageGenerator(_imageGenerator), maxBufferSize(_maxBufferSize), isCircleBuffer(_isCircleBuffer), maxTimeDuration(_maxTimeDuration) { +#ifdef HAVE_TBB task = 0; +#endif CV_Assert( depthGenerator.IsValid() ); CV_Assert( imageGenerator.IsValid() ); @@ -150,7 +152,7 @@ public: task = new( tbb::task::allocate_root() ) TBBApproximateSynchronizerTask( *this ); tbb::task::enqueue(*task); #else - task = new ApproximateSynchronizer( *this ); + task->reset( new ApproximateSynchronizer( *this ) ); #endif } diff --git a/modules/viz/src/interactor_style.cpp b/modules/viz/src/interactor_style.cpp index 8abc46880f..c740b248e3 100644 --- a/modules/viz/src/interactor_style.cpp +++ b/modules/viz/src/interactor_style.cpp @@ -47,7 +47,7 @@ //M*/ #include "precomp.hpp" -#include "interactor_style.h" + using namespace cv; @@ -193,6 +193,11 @@ void cv::viz::InteractorStyle::registerKeyboardCallback(void (*callback)(const K keyboard_callback_cookie_ = cookie; } +////////////////////////////////////////////////////////////////////////////////////////////// +bool cv::viz::InteractorStyle::getAltKey() { return Interactor->GetAltKey() != 0; } +bool cv::viz::InteractorStyle::getShiftKey() { return Interactor->GetShiftKey()!= 0; } +bool cv::viz::InteractorStyle::getControlKey() { return Interactor->GetControlKey()!= 0; } + ////////////////////////////////////////////////////////////////////////////////////////////// void cv::viz::InteractorStyle::OnKeyDown() @@ -216,9 +221,9 @@ cv::viz::InteractorStyle::OnKeyDown() // Get the status of special keys (Cltr+Alt+Shift) - bool shift = Interactor->GetShiftKey(); - bool ctrl = Interactor->GetControlKey(); - bool alt = Interactor->GetAltKey(); + bool shift = getShiftKey(); + bool ctrl = getControlKey(); + bool alt = getAltKey(); bool keymod = false; switch (modifier_) @@ -538,7 +543,7 @@ cv::viz::InteractorStyle::OnKeyDown() } } - KeyboardEvent event(true, Interactor->GetKeySym(), Interactor->GetKeyCode(), Interactor->GetAltKey(), Interactor->GetControlKey(), Interactor->GetShiftKey()); + KeyboardEvent event(true, Interactor->GetKeySym(), Interactor->GetKeyCode(), getAltKey(), getControlKey(), getShiftKey()); // Check if there is a keyboard callback registered if (keyboardCallback_) keyboardCallback_(event, keyboard_callback_cookie_); @@ -550,7 +555,7 @@ cv::viz::InteractorStyle::OnKeyDown() ////////////////////////////////////////////////////////////////////////////////////////////// void cv::viz::InteractorStyle::OnKeyUp() { - KeyboardEvent event(false, Interactor->GetKeySym(), Interactor->GetKeyCode(), Interactor->GetAltKey(), Interactor->GetControlKey(), Interactor->GetShiftKey()); + KeyboardEvent event(false, Interactor->GetKeySym(), Interactor->GetKeyCode(), getAltKey(), getControlKey(), getShiftKey()); // Check if there is a keyboard callback registered if (keyboardCallback_) keyboardCallback_(event, keyboard_callback_cookie_); @@ -562,7 +567,7 @@ void cv::viz::InteractorStyle::OnKeyUp() void cv::viz::InteractorStyle::OnMouseMove() { Vec2i p(Interactor->GetEventPosition()); - MouseEvent event(MouseEvent::MouseMove, MouseEvent::NoButton, p, Interactor->GetAltKey(), Interactor->GetControlKey(), Interactor->GetShiftKey()); + MouseEvent event(MouseEvent::MouseMove, MouseEvent::NoButton, p, getAltKey(), getControlKey(), getShiftKey()); if (mouseCallback_) mouseCallback_(event, mouse_callback_cookie_); Superclass::OnMouseMove(); @@ -573,7 +578,7 @@ void cv::viz::InteractorStyle::OnLeftButtonDown() { Vec2i p(Interactor->GetEventPosition()); MouseEvent::Type type = (Interactor->GetRepeatCount() == 0) ? MouseEvent::MouseButtonPress : MouseEvent::MouseDblClick; - MouseEvent event(type, MouseEvent::LeftButton, p, Interactor->GetAltKey(), Interactor->GetControlKey(), Interactor->GetShiftKey()); + MouseEvent event(type, MouseEvent::LeftButton, p, getAltKey(), getControlKey(), getShiftKey()); if (mouseCallback_) mouseCallback_(event, mouse_callback_cookie_); Superclass::OnLeftButtonDown(); @@ -583,7 +588,7 @@ void cv::viz::InteractorStyle::OnLeftButtonDown() void cv::viz::InteractorStyle::OnLeftButtonUp() { Vec2i p(Interactor->GetEventPosition()); - MouseEvent event(MouseEvent::MouseButtonRelease, MouseEvent::LeftButton, p, Interactor->GetAltKey(), Interactor->GetControlKey(), Interactor->GetShiftKey()); + MouseEvent event(MouseEvent::MouseButtonRelease, MouseEvent::LeftButton, p, getAltKey(), getControlKey(), getShiftKey()); if (mouseCallback_) mouseCallback_(event, mouse_callback_cookie_); Superclass::OnLeftButtonUp(); @@ -595,7 +600,7 @@ void cv::viz::InteractorStyle::OnMiddleButtonDown() Vec2i p(Interactor->GetEventPosition()); MouseEvent::Type type = (Interactor->GetRepeatCount() == 0) ? MouseEvent::MouseButtonPress : MouseEvent::MouseDblClick; - MouseEvent event(type, MouseEvent::MiddleButton, p, Interactor->GetAltKey(), Interactor->GetControlKey(), Interactor->GetShiftKey()); + MouseEvent event(type, MouseEvent::MiddleButton, p, getAltKey(), getControlKey(), getShiftKey()); if (mouseCallback_) mouseCallback_(event, mouse_callback_cookie_); Superclass::OnMiddleButtonDown(); @@ -605,7 +610,7 @@ void cv::viz::InteractorStyle::OnMiddleButtonDown() void cv::viz::InteractorStyle::OnMiddleButtonUp() { Vec2i p(Interactor->GetEventPosition()); - MouseEvent event(MouseEvent::MouseButtonRelease, MouseEvent::MiddleButton, p, Interactor->GetAltKey(), Interactor->GetControlKey(), Interactor->GetShiftKey()); + MouseEvent event(MouseEvent::MouseButtonRelease, MouseEvent::MiddleButton, p, getAltKey(), getControlKey(), getShiftKey()); if (mouseCallback_) mouseCallback_(event, mouse_callback_cookie_); Superclass::OnMiddleButtonUp(); @@ -617,7 +622,7 @@ void cv::viz::InteractorStyle::OnRightButtonDown() Vec2i p(Interactor->GetEventPosition()); MouseEvent::Type type = (Interactor->GetRepeatCount() == 0) ? MouseEvent::MouseButtonPress : MouseEvent::MouseDblClick; - MouseEvent event(type, MouseEvent::RightButton, p, Interactor->GetAltKey(), Interactor->GetControlKey(), Interactor->GetShiftKey()); + MouseEvent event(type, MouseEvent::RightButton, p, getAltKey(), getControlKey(), getShiftKey()); if (mouseCallback_) mouseCallback_(event, mouse_callback_cookie_); Superclass::OnRightButtonDown(); @@ -627,7 +632,7 @@ void cv::viz::InteractorStyle::OnRightButtonDown() void cv::viz::InteractorStyle::OnRightButtonUp() { Vec2i p(Interactor->GetEventPosition()); - MouseEvent event(MouseEvent::MouseButtonRelease, MouseEvent::RightButton, p, Interactor->GetAltKey(), Interactor->GetControlKey(), Interactor->GetShiftKey()); + MouseEvent event(MouseEvent::MouseButtonRelease, MouseEvent::RightButton, p, getAltKey(), getControlKey(), getShiftKey()); if (mouseCallback_) mouseCallback_(event, mouse_callback_cookie_); Superclass::OnRightButtonUp(); @@ -637,7 +642,7 @@ void cv::viz::InteractorStyle::OnRightButtonUp() void cv::viz::InteractorStyle::OnMouseWheelForward() { Vec2i p(Interactor->GetEventPosition()); - MouseEvent event(MouseEvent::MouseScrollUp, MouseEvent::VScroll, p, Interactor->GetAltKey(), Interactor->GetControlKey(), Interactor->GetShiftKey()); + MouseEvent event(MouseEvent::MouseScrollUp, MouseEvent::VScroll, p, getAltKey(), getControlKey(), getShiftKey()); // If a mouse callback registered, call it! if (mouseCallback_) mouseCallback_(event, mouse_callback_cookie_); @@ -669,7 +674,7 @@ void cv::viz::InteractorStyle::OnMouseWheelForward() void cv::viz::InteractorStyle::OnMouseWheelBackward() { Vec2i p(Interactor->GetEventPosition()); - MouseEvent event(MouseEvent::MouseScrollDown, MouseEvent::VScroll, p, Interactor->GetAltKey(), Interactor->GetControlKey(), Interactor->GetShiftKey()); + MouseEvent event(MouseEvent::MouseScrollDown, MouseEvent::VScroll, p, getAltKey(), getControlKey(), getShiftKey()); // If a mouse callback registered, call it! if (mouseCallback_) mouseCallback_(event, mouse_callback_cookie_); diff --git a/modules/viz/src/interactor_style.h b/modules/viz/src/interactor_style.h index 30d8529163..ed3f4dfbdd 100644 --- a/modules/viz/src/interactor_style.h +++ b/modules/viz/src/interactor_style.h @@ -49,8 +49,6 @@ #ifndef __OPENCV_VIZ_INTERACTOR_STYLE_H__ #define __OPENCV_VIZ_INTERACTOR_STYLE_H__ -#include "precomp.hpp" - namespace cv { namespace viz @@ -145,6 +143,10 @@ namespace cv void (*mouseCallback_)(const MouseEvent&, void*); void *mouse_callback_cookie_; + + bool getAltKey(); + bool getControlKey(); + bool getShiftKey(); }; } } diff --git a/modules/viz/src/precomp.hpp b/modules/viz/src/precomp.hpp index 5b889fdba3..beb7c5c048 100644 --- a/modules/viz/src/precomp.hpp +++ b/modules/viz/src/precomp.hpp @@ -126,6 +126,8 @@ #endif #include +#include +#include namespace cv { @@ -135,6 +137,7 @@ namespace cv } } +#include "interactor_style.h" #include "viz3d_impl.hpp" namespace cv @@ -146,8 +149,5 @@ namespace cv } } -#include -#include -#include "opencv2/viz/widget_accessor.hpp" #endif diff --git a/modules/viz/src/viz3d.cpp b/modules/viz/src/viz3d.cpp index f1714cf097..f5a0bc8895 100644 --- a/modules/viz/src/viz3d.cpp +++ b/modules/viz/src/viz3d.cpp @@ -46,8 +46,7 @@ // //M*/ -#include -#include "viz3d_impl.hpp" +#include "precomp.hpp" cv::viz::Viz3d::Viz3d(const String& window_name) : impl_(0) { create(window_name); } diff --git a/modules/viz/src/viz3d_impl.cpp b/modules/viz/src/viz3d_impl.cpp index 4ab0ddfdba..d014372428 100644 --- a/modules/viz/src/viz3d_impl.cpp +++ b/modules/viz/src/viz3d_impl.cpp @@ -47,7 +47,6 @@ //M*/ #include "precomp.hpp" -#include "viz3d_impl.hpp" #include "opencv2/core/utility.hpp" #include diff --git a/modules/viz/src/viz3d_impl.hpp b/modules/viz/src/viz3d_impl.hpp index e94b7361f9..50d642e714 100644 --- a/modules/viz/src/viz3d_impl.hpp +++ b/modules/viz/src/viz3d_impl.hpp @@ -49,9 +49,6 @@ #ifndef __OPENCV_VIZ_VIZ3D_IMPL_HPP__ #define __OPENCV_VIZ_VIZ3D_IMPL_HPP__ -#include -#include "interactor_style.h" - struct cv::viz::Viz3d::VizImpl { public: From e154bce2599e3af5248ed36392de39c3f5c6f665 Mon Sep 17 00:00:00 2001 From: Anatoly Baksheev Date: Sun, 17 Nov 2013 14:03:38 +0400 Subject: [PATCH 6/8] fixed compilation for vs2008 --- modules/objdetect/src/erfilter.cpp | 10 +++++++--- modules/photo/test/test_hdr.cpp | 3 --- modules/photo/test/test_precomp.hpp | 4 ++++ 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/modules/objdetect/src/erfilter.cpp b/modules/objdetect/src/erfilter.cpp index 7ab258a13d..52743afe99 100644 --- a/modules/objdetect/src/erfilter.cpp +++ b/modules/objdetect/src/erfilter.cpp @@ -43,9 +43,13 @@ #include "precomp.hpp" #include -#ifndef INT32_MAX -#define __STDC_LIMIT_MACROS -#include +#if defined _MSC_VER && _MSC_VER == 1500 + typedef int int_fast32_t; +#else + #ifndef INT32_MAX + #define __STDC_LIMIT_MACROS + #include + #endif #endif using namespace std; diff --git a/modules/photo/test/test_hdr.cpp b/modules/photo/test/test_hdr.cpp index d095c01cea..1d232b3ef7 100644 --- a/modules/photo/test/test_hdr.cpp +++ b/modules/photo/test/test_hdr.cpp @@ -40,9 +40,6 @@ //M*/ #include "test_precomp.hpp" -#include -#include -#include using namespace cv; using namespace std; diff --git a/modules/photo/test/test_precomp.hpp b/modules/photo/test/test_precomp.hpp index 5b22a1c755..336e5f8424 100644 --- a/modules/photo/test/test_precomp.hpp +++ b/modules/photo/test/test_precomp.hpp @@ -13,5 +13,9 @@ #include "opencv2/ts.hpp" #include "opencv2/photo.hpp" #include "opencv2/highgui.hpp" +#include +#include +#include +#include #endif From efcc341219872ae830a8c044f9e5dbd6c1afddb6 Mon Sep 17 00:00:00 2001 From: Anatoly Baksheev Date: Sun, 17 Nov 2013 15:18:15 +0400 Subject: [PATCH 7/8] added viz tutorial 3 test --- modules/viz/test/test_precomp.hpp | 2 + modules/viz/test/test_tutorial3.cpp | 86 +++++++++++++++++++++++++++++ modules/viz/test/test_viz3d.cpp | 10 ++-- 3 files changed, 93 insertions(+), 5 deletions(-) create mode 100644 modules/viz/test/test_tutorial3.cpp diff --git a/modules/viz/test/test_precomp.hpp b/modules/viz/test/test_precomp.hpp index 9ca98d7b83..9b98f206b1 100644 --- a/modules/viz/test/test_precomp.hpp +++ b/modules/viz/test/test_precomp.hpp @@ -60,6 +60,8 @@ #include "opencv2/ts.hpp" #include #include +#include +#include #include #include diff --git a/modules/viz/test/test_tutorial3.cpp b/modules/viz/test/test_tutorial3.cpp new file mode 100644 index 0000000000..27544a9a20 --- /dev/null +++ b/modules/viz/test/test_tutorial3.cpp @@ -0,0 +1,86 @@ +#include "test_precomp.hpp" + +using namespace cv; +using namespace std; + +/** + * @function cvcloud_load + * @brief load bunny.ply + */ +Mat cvcloud_load() +{ + Mat cloud(1, 20000, CV_32FC3); + ifstream ifs("d:/cloud_dragon.ply"); + + string str; + for(size_t i = 0; i < 12; ++i) + getline(ifs, str); + + Point3f* data = cloud.ptr(); + //float dummy1, dummy2; + for(size_t i = 0; i < 20000; ++i) + ifs >> data[i].x >> data[i].y >> data[i].z;// >> dummy1 >> dummy2; + + //cloud *= 5.0f; + return cloud; +} + +/** + * @function main + */ +void tutorial3(bool camera_pov) +{ + /// Create a window + viz::Viz3d myWindow("Coordinate Frame"); + + /// Add coordinate axes + myWindow.showWidget("Coordinate Widget", viz::WCoordinateSystem()); + + /// Let's assume camera has the following properties + Point3f cam_pos(3.0f,3.0f,3.0f), cam_focal_point(3.0f,3.0f,2.0f), cam_y_dir(-1.0f,0.0f,0.0f); + + /// We can get the pose of the cam using makeCameraPose + Affine3f cam_pose = viz::makeCameraPose(cam_pos, cam_focal_point, cam_y_dir); + + /// We can get the transformation matrix from camera coordinate system to global using + /// - makeTransformToGlobal. We need the axes of the camera + Affine3f transform = viz::makeTransformToGlobal(Vec3f(0.0f,-1.0f,0.0f), Vec3f(-1.0f,0.0f,0.0f), Vec3f(0.0f,0.0f,-1.0f), cam_pos); + + /// Create a cloud widget. + Mat bunny_cloud = cvcloud_load(); + viz::WCloud cloud_widget(bunny_cloud, viz::Color::green()); + + /// Pose of the widget in camera frame + Affine3f cloud_pose = Affine3f().translate(Vec3f(0.0f,0.0f,3.0f)); + /// Pose of the widget in global frame + Affine3f cloud_pose_global = transform * cloud_pose; + + /// Visualize camera frame + if (!camera_pov) + { + viz::WCameraPosition cpw(0.5); // Coordinate axes + viz::WCameraPosition cpw_frustum(Vec2f(0.889484, 0.523599)); // Camera frustum + myWindow.showWidget("CPW", cpw, cam_pose); + myWindow.showWidget("CPW_FRUSTUM", cpw_frustum, cam_pose); + } + + /// Visualize widget + myWindow.showWidget("bunny", cloud_widget, cloud_pose_global); + + /// Set the viewer pose to that of camera + if (camera_pov) + myWindow.setViewerPose(cam_pose); + + /// Start event loop. + myWindow.spin(); +} + +TEST(Viz_viz3d, tutorial3_global_view) +{ + tutorial3(false); +} + +TEST(Viz_viz3d, tutorial3_camera_view) +{ + tutorial3(true); +} diff --git a/modules/viz/test/test_viz3d.cpp b/modules/viz/test/test_viz3d.cpp index eac0bd0496..2acb5a3c3b 100644 --- a/modules/viz/test/test_viz3d.cpp +++ b/modules/viz/test/test_viz3d.cpp @@ -40,13 +40,11 @@ // //M*/ #include "test_precomp.hpp" -#include -#include -#include + using namespace cv; -cv::Mat cvcloud_load() +static cv::Mat cvcloud_load() { cv::Mat cloud(1, 20000, CV_32FC3); std::ifstream ifs("/Users/nerei/cloud_dragon.ply"); @@ -90,7 +88,7 @@ void keyboard_callback(const viz::KeyboardEvent & event, void * cookie) } } -TEST(Viz_viz3d, accuracy) +TEST(Viz_viz3d, develop) { cv::viz::Viz3d viz("abc"); @@ -178,4 +176,6 @@ TEST(Viz_viz3d, accuracy) angle += 10; viz.spinOnce(42, true); } + + volatile void* a = (void*)&cvcloud_load; (void)a; //fixing warnings } From 9e3a29701eee6055f0bcb36fae05a58b203bb919 Mon Sep 17 00:00:00 2001 From: Anatoly Baksheev Date: Sun, 17 Nov 2013 15:18:39 +0400 Subject: [PATCH 8/8] Viz code beautification --- modules/viz/include/opencv2/viz.hpp | 3 +- modules/viz/src/interactor_style.cpp | 108 +++++++++---------------- modules/viz/src/interactor_style.h | 25 ++---- modules/viz/src/precomp.hpp | 1 + modules/viz/src/viz.cpp | 116 +++++++++------------------ modules/viz/src/viz3d_impl.cpp | 12 +-- modules/viz/src/viz3d_impl.hpp | 24 +----- modules/viz/test/test_tutorial3.cpp | 4 +- modules/viz/test/test_viz3d.cpp | 8 +- 9 files changed, 96 insertions(+), 205 deletions(-) diff --git a/modules/viz/include/opencv2/viz.hpp b/modules/viz/include/opencv2/viz.hpp index f6dc882c30..5c2fe03d93 100644 --- a/modules/viz/include/opencv2/viz.hpp +++ b/modules/viz/include/opencv2/viz.hpp @@ -108,10 +108,9 @@ namespace cv void remove(const String &window_name); static VizAccessor * instance_; - static bool is_instantiated_; struct VizAccessorImpl; - static VizAccessorImpl * impl_; + VizAccessorImpl * impl_; friend class Viz3d; }; diff --git a/modules/viz/src/interactor_style.cpp b/modules/viz/src/interactor_style.cpp index c740b248e3..ccf188ded2 100644 --- a/modules/viz/src/interactor_style.cpp +++ b/modules/viz/src/interactor_style.cpp @@ -48,9 +48,6 @@ #include "precomp.hpp" - -using namespace cv; - ////////////////////////////////////////////////////////////////////////////////////////////// void cv::viz::InteractorStyle::Initialize() { @@ -78,11 +75,11 @@ void cv::viz::InteractorStyle::Initialize() } ////////////////////////////////////////////////////////////////////////////////////////////// -void cv::viz::InteractorStyle::saveScreenshot(const std::string &file) +void cv::viz::InteractorStyle::saveScreenshot(const String &file) { FindPokedRenderer(Interactor->GetEventPosition()[0], Interactor->GetEventPosition()[1]); wif_->SetInput(Interactor->GetRenderWindow()); - wif_->Modified(); // Update the WindowToImageFilter + wif_->Modified(); // Update the WindowToImageFilter snapshot_writer_->Modified(); snapshot_writer_->SetFileName(file.c_str()); snapshot_writer_->Write(); @@ -117,30 +114,19 @@ void cv::viz::InteractorStyle::OnChar() FindPokedRenderer(Interactor->GetEventPosition()[0], Interactor->GetEventPosition()[1]); if (Interactor->GetKeyCode() >= '0' && Interactor->GetKeyCode() <= '9') return; - std::string key(Interactor->GetKeySym()); - if (key.find("XF86ZoomIn") != std::string::npos) + + String key(Interactor->GetKeySym()); + if (key.find("XF86ZoomIn") != String::npos) zoomIn(); - else if (key.find("XF86ZoomOut") != std::string::npos) + else if (key.find("XF86ZoomOut") != String::npos) zoomOut(); int keymod = false; switch (modifier_) { - case KB_MOD_ALT: - { - keymod = Interactor->GetAltKey(); - break; - } - case KB_MOD_CTRL: - { - keymod = Interactor->GetControlKey(); - break; - } - case KB_MOD_SHIFT: - { - keymod = Interactor->GetShiftKey(); - break; - } + case KB_MOD_ALT: keymod = Interactor->GetAltKey(); break; + case KB_MOD_CTRL: keymod = Interactor->GetControlKey(); break; + case KB_MOD_SHIFT: keymod = Interactor->GetShiftKey(); break; } switch (Interactor->GetKeyCode()) @@ -202,7 +188,6 @@ bool cv::viz::InteractorStyle::getControlKey() { return Interactor->GetControlKe void cv::viz::InteractorStyle::OnKeyDown() { - CV_Assert("Interactor style not initialized. Please call Initialize() before continuing" && init_); CV_Assert("No renderer given! Use SetRendererCollection() before continuing." && renderer_); @@ -274,42 +259,40 @@ cv::viz::InteractorStyle::OnKeyDown() vtkSmartPointer ac = CurrentRenderer->GetActors(); vtkCollectionSimpleIterator ait; for (ac->InitTraversal(ait); vtkActor* actor = ac->GetNextActor(ait); ) - { for (actor->InitPathTraversal(); vtkAssemblyPath* path = actor->GetNextPath(); ) { vtkActor* apart = reinterpret_cast (path->GetLastNode()->GetViewProp()); apart->GetProperty()->SetRepresentationToPoints(); } - } break; } // Save a PNG snapshot with the current screen case 'j': case 'J': { - char cam_fn[80], snapshot_fn[80]; - unsigned t = static_cast(time(0)); - sprintf(snapshot_fn, "screenshot-%d.png" , t); - saveScreenshot(snapshot_fn); + unsigned int t = static_cast(time(0)); + String png_file = cv::format("screenshot-%d.png", t); + String cam_file = cv::format("screenshot-%d.cam", t); - sprintf(cam_fn, "screenshot-%d.cam", t); - ofstream ofs_cam; - ofs_cam.open(cam_fn); vtkSmartPointer cam = Interactor->GetRenderWindow()->GetRenderers()->GetFirstRenderer()->GetActiveCamera(); - double clip[2], focal[3], pos[3], view[3]; - cam->GetClippingRange(clip); - cam->GetFocalPoint(focal); - cam->GetPosition(pos); - cam->GetViewUp(view); + Vec2d clip; + Vec3d focal, pos, view; + cam->GetClippingRange(clip.val); + cam->GetFocalPoint(focal.val); + cam->GetPosition(pos.val); + cam->GetViewUp(view.val); + Vec2i win_pos(Interactor->GetRenderWindow()->GetPosition()); + Vec2i win_size(Interactor->GetRenderWindow()->GetSize()); + double angle = cam->GetViewAngle() / 180.0 * CV_PI; - int *win_pos = Interactor->GetRenderWindow()->GetPosition(); - int *win_size = Interactor->GetRenderWindow()->GetSize(); - ofs_cam << clip[0] << "," << clip[1] << "/" << focal[0] << "," << focal[1] << "," << focal[2] << "/" << - pos[0] << "," << pos[1] << "," << pos[2] << "/" << view[0] << "," << view[1] << "," << view[2] << "/" << - cam->GetViewAngle() / 180.0 * CV_PI << "/" << win_size[0] << "," << win_size[1] << "/" << win_pos[0] << "," << win_pos[1] - << endl; + String data = cv::format("%f,%f/%f,%f,%f/%f,%f,%f/%f,%f,%f/%f/%d,%d/%d,%d", clip[0],clip[1], focal[0],focal[1],focal[2], + pos[0],pos[1],pos[2], view[0],view[1], view[2], angle , win_size[0],win_size[1], win_pos[0], win_pos[1]); + + saveScreenshot(png_file); + ofstream ofs_cam(cam_file.c_str()); + ofs_cam << data.c_str() << endl; ofs_cam.close(); - std::cout << "Screenshot (" << snapshot_fn << ") and camera information (" << cam_fn << ") successfully captured." << std::endl; + cout << "Screenshot (" << png_file.c_str() << ") and camera information (" << cam_file.c_str() << ") successfully captured." << endl; break; } // display current camera settings/parameters @@ -354,7 +337,6 @@ cv::viz::InteractorStyle::OnKeyDown() vtkSmartPointer ac = CurrentRenderer->GetActors(); vtkCollectionSimpleIterator ait; for (ac->InitTraversal(ait); vtkActor* actor = ac->GetNextActor(ait); ) - { for (actor->InitPathTraversal(); vtkAssemblyPath* path = actor->GetNextPath(); ) { vtkActor* apart = reinterpret_cast (path->GetLastNode()->GetViewProp()); @@ -362,7 +344,6 @@ cv::viz::InteractorStyle::OnKeyDown() if (psize < 63.0f) apart->GetProperty()->SetPointSize(psize + 1.0f); } - } } break; } @@ -375,7 +356,6 @@ cv::viz::InteractorStyle::OnKeyDown() vtkSmartPointer ac = CurrentRenderer->GetActors(); vtkCollectionSimpleIterator ait; for (ac->InitTraversal(ait); vtkActor* actor = ac->GetNextActor(ait); ) - { for (actor->InitPathTraversal(); vtkAssemblyPath* path = actor->GetNextPath(); ) { vtkActor* apart = static_cast(path->GetLastNode()->GetViewProp()); @@ -383,7 +363,6 @@ cv::viz::InteractorStyle::OnKeyDown() if (psize > 1.0f) apart->GetProperty()->SetPointSize(psize - 1.0f); } - } } break; } @@ -460,9 +439,7 @@ cv::viz::InteractorStyle::OnKeyDown() case 'o': case 'O': { vtkSmartPointer cam = CurrentRenderer->GetActiveCamera(); - int flag = cam->GetParallelProjection(); - cam->SetParallelProjection(!flag); - + cam->SetParallelProjection(!cam->GetParallelProjection()); CurrentRenderer->SetActiveCamera(cam); CurrentRenderer->Render(); break; @@ -499,18 +476,14 @@ cv::viz::InteractorStyle::OnKeyDown() // if a valid transformation was found, use it otherwise fall back to default view point. if (found_transformation) { - vtkProp3D * actor = vtkProp3D::SafeDownCast(it->second); - cam->SetPosition(actor->GetUserMatrix()->GetElement(0, 3), - actor->GetUserMatrix()->GetElement(1, 3), - actor->GetUserMatrix()->GetElement(2, 3)); + const vtkMatrix4x4* m = vtkProp3D::SafeDownCast(it->second)->GetUserMatrix(); - cam->SetFocalPoint(actor->GetUserMatrix()->GetElement(0, 3) - actor->GetUserMatrix()->GetElement(0, 2), - actor->GetUserMatrix()->GetElement(1, 3) - actor->GetUserMatrix()->GetElement(1, 2), - actor->GetUserMatrix()->GetElement(2, 3) - actor->GetUserMatrix()->GetElement(2, 2)); + cam->SetFocalPoint(m->GetElement(0, 3) - m->GetElement(0, 2), + m->GetElement(1, 3) - m->GetElement(1, 2), + m->GetElement(2, 3) - m->GetElement(2, 2)); - cam->SetViewUp(actor->GetUserMatrix()->GetElement(0, 1), - actor->GetUserMatrix()->GetElement(1, 1), - actor->GetUserMatrix()->GetElement(2, 1)); + cam->SetViewUp (m->GetElement(0, 1), m->GetElement(1, 1), m->GetElement(2, 1)); + cam->SetPosition(m->GetElement(0, 3), m->GetElement(1, 3), m->GetElement(2, 3)); } else { @@ -712,11 +685,8 @@ void cv::viz::InteractorStyle::OnTimer() Interactor->Render(); } -namespace cv +namespace cv { namespace viz { - namespace viz - { - //Standard VTK macro for *New() - vtkStandardNewMacro(InteractorStyle) - } -} + //Standard VTK macro for *New() + vtkStandardNewMacro(InteractorStyle) +}} diff --git a/modules/viz/src/interactor_style.h b/modules/viz/src/interactor_style.h index ed3f4dfbdd..3af13fcc43 100644 --- a/modules/viz/src/interactor_style.h +++ b/modules/viz/src/interactor_style.h @@ -57,16 +57,9 @@ namespace cv { public: - enum KeyboardModifier - { - KB_MOD_ALT, - KB_MOD_CTRL, - KB_MOD_SHIFT - }; + enum KeyboardModifier { KB_MOD_ALT, KB_MOD_CTRL, KB_MOD_SHIFT }; static InteractorStyle *New(); - - InteractorStyle() {} virtual ~InteractorStyle() {} // this macro defines Superclass, the isA functionality and the safe downcast method @@ -75,32 +68,24 @@ namespace cv /** \brief Initialization routine. Must be called before anything else. */ virtual void Initialize(); - inline void setWidgetActorMap(const Ptr& actors) { widget_actor_map_ = actors; } + void setWidgetActorMap(const Ptr& actors) { widget_actor_map_ = actors; } void setRenderer(vtkSmartPointer& ren) { renderer_ = ren; } void registerMouseCallback(void (*callback)(const MouseEvent&, void*), void* cookie = 0); void registerKeyboardCallback(void (*callback)(const KeyboardEvent&, void*), void * cookie = 0); - void saveScreenshot(const std::string &file); + void saveScreenshot(const String &file); /** \brief Change the default keyboard modified from ALT to a different special key.*/ inline void setKeyboardModifier(const KeyboardModifier &modifier) { modifier_ = modifier; } - protected: + private: /** \brief Set to true after initialization is complete. */ bool init_; - /** \brief Collection of vtkRenderers stored internally. */ vtkSmartPointer renderer_; + Ptr widget_actor_map_; - /** \brief Actor map stored internally. */ - cv::Ptr widget_actor_map_; - - /** \brief The current window width/height. */ Vec2i win_size_; - - /** \brief The current window position x/y. */ Vec2i win_pos_; - - /** \brief The maximum resizeable window width/height. */ Vec2i max_win_size_; /** \brief A PNG writer for screenshot captures. */ diff --git a/modules/viz/src/precomp.hpp b/modules/viz/src/precomp.hpp index beb7c5c048..6df03e4f61 100644 --- a/modules/viz/src/precomp.hpp +++ b/modules/viz/src/precomp.hpp @@ -128,6 +128,7 @@ #include #include #include +#include namespace cv { diff --git a/modules/viz/src/viz.cpp b/modules/viz/src/viz.cpp index 2517d138a6..747c8de342 100644 --- a/modules/viz/src/viz.cpp +++ b/modules/viz/src/viz.cpp @@ -50,18 +50,9 @@ cv::Affine3f cv::viz::makeTransformToGlobal(const Vec3f& axis_x, const Vec3f& axis_y, const Vec3f& axis_z, const Vec3f& origin) { - Affine3f::Mat3 R; - R.val[0] = axis_x.val[0]; - R.val[3] = axis_x.val[1]; - R.val[6] = axis_x.val[2]; - - R.val[1] = axis_y.val[0]; - R.val[4] = axis_y.val[1]; - R.val[7] = axis_y.val[2]; - - R.val[2] = axis_z.val[0]; - R.val[5] = axis_z.val[1]; - R.val[8] = axis_z.val[2]; + Affine3f::Mat3 R(axis_x[0], axis_y[0], axis_z[0], + axis_x[1], axis_y[1], axis_z[1], + axis_x[2], axis_y[2], axis_z[2]); return Affine3f(R, origin); } @@ -73,22 +64,7 @@ cv::Affine3f cv::viz::makeCameraPose(const Vec3f& position, const Vec3f& focal_p Vec3f u = normalize(y_dir.cross(n)); Vec3f v = n.cross(u); - Matx44f pose_mat = Matx44f::zeros(); - pose_mat(0,0) = u[0]; - pose_mat(0,1) = u[1]; - pose_mat(0,2) = u[2]; - pose_mat(1,0) = v[0]; - pose_mat(1,1) = v[1]; - pose_mat(1,2) = v[2]; - pose_mat(2,0) = n[0]; - pose_mat(2,1) = n[1]; - pose_mat(2,2) = n[2]; - pose_mat(3,0) = position[0]; - pose_mat(3,1) = position[1]; - pose_mat(3,2) = position[2]; - pose_mat(3,3) = 1.0f; - pose_mat = pose_mat.t(); - return pose_mat; + return makeTransformToGlobal(u, v, n, position); } vtkSmartPointer cv::viz::convertToVtkMatrix(const cv::Matx44f &m) @@ -109,36 +85,31 @@ cv::Matx44f cv::viz::convertToMatx(const vtkSmartPointer& vtk_matr return m; } -namespace cv +namespace cv { namespace viz { - namespace viz + template Vec<_Tp, 3>* vtkpoints_data(vtkSmartPointer& points); + + template<> Vec3f* vtkpoints_data(vtkSmartPointer& points) { - template Vec<_Tp, 3>* vtkpoints_data(vtkSmartPointer& points); - - template<> Vec3f* vtkpoints_data(vtkSmartPointer& points) - { - CV_Assert(points->GetDataType() == VTK_FLOAT); - vtkDataArray *data = points->GetData(); - float *pointer = static_cast(data)->GetPointer(0); - return reinterpret_cast(pointer); - } - - template<> Vec3d* vtkpoints_data(vtkSmartPointer& points) - { - CV_Assert(points->GetDataType() == VTK_DOUBLE); - vtkDataArray *data = points->GetData(); - double *pointer = static_cast(data)->GetPointer(0); - return reinterpret_cast(pointer); - } + CV_Assert(points->GetDataType() == VTK_FLOAT); + vtkDataArray *data = points->GetData(); + float *pointer = static_cast(data)->GetPointer(0); + return reinterpret_cast(pointer); } -} + + template<> Vec3d* vtkpoints_data(vtkSmartPointer& points) + { + CV_Assert(points->GetDataType() == VTK_DOUBLE); + vtkDataArray *data = points->GetData(); + double *pointer = static_cast(data)->GetPointer(0); + return reinterpret_cast(pointer); + } +}} /////////////////////////////////////////////////////////////////////////////////////////////// /// Viz accessor implementation cv::viz::VizAccessor * cv::viz::VizAccessor::instance_ = 0; -bool cv::viz::VizAccessor::is_instantiated_ = false; -cv::viz::VizAccessor::VizAccessorImpl * cv::viz::VizAccessor::impl_ = 0; struct cv::viz::VizAccessor::VizAccessorImpl { @@ -146,33 +117,22 @@ struct cv::viz::VizAccessor::VizAccessorImpl }; cv::viz::VizAccessor::VizAccessor() { impl_ = new cv::viz::VizAccessor::VizAccessorImpl;} - -cv::viz::VizAccessor::~VizAccessor() -{ - if(impl_) - { - delete impl_; - impl_ = 0; - } -} +cv::viz::VizAccessor::~VizAccessor() { delete impl_; } cv::viz::VizAccessor & cv::viz::VizAccessor::getInstance() { - if (!is_instantiated_) - { + if (!instance_) instance_ = new VizAccessor(); - is_instantiated_ = true; - } + return *instance_; } void cv::viz::VizAccessor::release() { - if (is_instantiated_) + if (instance_) { delete instance_; instance_ = 0; - is_instantiated_ = false; } } @@ -183,18 +143,15 @@ cv::viz::Viz3d cv::viz::VizAccessor::get(const String & window_name) generateWindowName(window_name, name); VizMap::iterator vm_itr = impl_->viz_map.find(name); - bool exists = vm_itr != impl_->viz_map.end(); - if (exists) return vm_itr->second; - else return Viz3d(window_name); + return vm_itr != impl_->viz_map.end() ? vm_itr->second : Viz3d(window_name); } void cv::viz::VizAccessor::add(Viz3d window) { String window_name = window.getWindowName(); VizMap::iterator vm_itr = impl_->viz_map.find(window_name); - bool exists = vm_itr != impl_->viz_map.end(); - if (exists) return ; - impl_->viz_map.insert(VizPair(window_name, window)); + if (vm_itr == impl_->viz_map.end()) + impl_->viz_map.insert(VizPair(window_name, window)); } void cv::viz::VizAccessor::remove(const String &window_name) @@ -204,21 +161,24 @@ void cv::viz::VizAccessor::remove(const String &window_name) generateWindowName(window_name, name); VizMap::iterator vm_itr = impl_->viz_map.find(name); - bool exists = vm_itr != impl_->viz_map.end(); - if (!exists) return ; - impl_->viz_map.erase(vm_itr); + if (vm_itr != impl_->viz_map.end()) + impl_->viz_map.erase(vm_itr); } void cv::viz::VizAccessor::generateWindowName(const String &window_name, String &output) { output = "Viz"; // Already is Viz - if (window_name == output) return; + if (window_name == output) + return; String prefixed = output + " - "; - if (window_name.substr(0, prefixed.length()) == prefixed) output = window_name; // Already has "Viz - " - else if (window_name.substr(0, output.length()) == output) output = prefixed + window_name; // Doesn't have prefix - else output = (window_name == "" ? output : prefixed + window_name); + if (window_name.substr(0, prefixed.length()) == prefixed) + output = window_name; // Already has "Viz - " + else if (window_name.substr(0, output.length()) == output) + output = prefixed + window_name; // Doesn't have prefix + else + output = (window_name == "" ? output : prefixed + window_name); } cv::viz::Viz3d cv::viz::get(const String &window_name) diff --git a/modules/viz/src/viz3d_impl.cpp b/modules/viz/src/viz3d_impl.cpp index d014372428..ae8fc150c6 100644 --- a/modules/viz/src/viz3d_impl.cpp +++ b/modules/viz/src/viz3d_impl.cpp @@ -47,9 +47,6 @@ //M*/ #include "precomp.hpp" -#include "opencv2/core/utility.hpp" - -#include #if 1 || !defined __APPLE__ vtkRenderWindowInteractor* vtkRenderWindowInteractorFixNew() @@ -60,9 +57,7 @@ vtkRenderWindowInteractor* vtkRenderWindowInteractorFixNew() ///////////////////////////////////////////////////////////////////////////////////////////// cv::viz::Viz3d::VizImpl::VizImpl(const String &name) - : style_(vtkSmartPointer::New()) - , widget_actor_map_(new WidgetActorMap) - , s_lastDone_(0.0) + : style_(vtkSmartPointer::New()) , widget_actor_map_(new WidgetActorMap), s_lastDone_(0.0) { renderer_ = vtkSmartPointer::New(); @@ -127,7 +122,8 @@ cv::viz::Viz3d::VizImpl::~VizImpl() { if (interactor_) interactor_->DestroyTimer(timer_id_); - if (renderer_) renderer_->Clear(); + if (renderer_) + renderer_->Clear(); } ///////////////////////////////////////////////////////////////////////////////////////////// @@ -394,7 +390,7 @@ cv::viz::Camera cv::viz::Viz3d::VizImpl::getCamera() const Size window_size(renderer_->GetRenderWindow()->GetSize()[0], renderer_->GetRenderWindow()->GetSize()[1]); - double aspect_ratio = static_cast(window_size.width) / static_cast(window_size.height); + double aspect_ratio = window_size.width / (double)window_size.height; Matx44f proj_matrix = convertToMatx(active_camera.GetProjectionTransformMatrix(aspect_ratio, -1.0f, 1.0f)); Camera camera(proj_matrix, window_size); diff --git a/modules/viz/src/viz3d_impl.hpp b/modules/viz/src/viz3d_impl.hpp index 50d642e714..88f8424bf4 100644 --- a/modules/viz/src/viz3d_impl.hpp +++ b/modules/viz/src/viz3d_impl.hpp @@ -124,10 +124,7 @@ private: struct ExitMainLoopTimerCallback : public vtkCommand { - static ExitMainLoopTimerCallback* New() - { - return new ExitMainLoopTimerCallback; - } + static ExitMainLoopTimerCallback* New() { return new ExitMainLoopTimerCallback; } virtual void Execute(vtkObject* vtkNotUsed(caller), unsigned long event_id, void* call_data) { if (event_id != vtkCommand::TimerEvent) @@ -146,10 +143,7 @@ private: struct ExitCallback : public vtkCommand { - static ExitCallback* New() - { - return new ExitCallback; - } + static ExitCallback* New() { return new ExitCallback; } virtual void Execute(vtkObject*, unsigned long event_id, void*) { if (event_id == vtkCommand::ExitEvent) @@ -188,21 +182,7 @@ private: bool removeActorFromRenderer(const vtkSmartPointer &actor); - /** \brief Internal method. Creates a vtk actor from a vtk polydata object. - * \param[in] data the vtk polydata object to create an actor for - * \param[out] actor the resultant vtk actor object - * \param[in] use_scalars set scalar properties to the mapper if it exists in the data. Default: true. - */ void createActorFromVTKDataSet(const vtkSmartPointer &data, vtkSmartPointer &actor, bool use_scalars = true); - - /** \brief Updates a set of cells (vtkIdTypeArray) if the number of points in a cloud changes - * \param[out] cells the vtkIdTypeArray object (set of cells) to update - * \param[out] initcells a previously saved set of cells. If the number of points in the current cloud is - * higher than the number of cells in \a cells, and initcells contains enough data, then a copy from it - * will be made instead of regenerating the entire array. - * \param[in] nr_points the number of points in the new cloud. This dictates how many cells we need to - * generate - */ void updateCells(vtkSmartPointer &cells, vtkSmartPointer &initcells, vtkIdType nr_points); }; diff --git a/modules/viz/test/test_tutorial3.cpp b/modules/viz/test/test_tutorial3.cpp index 27544a9a20..6c63763dfd 100644 --- a/modules/viz/test/test_tutorial3.cpp +++ b/modules/viz/test/test_tutorial3.cpp @@ -75,12 +75,12 @@ void tutorial3(bool camera_pov) myWindow.spin(); } -TEST(Viz_viz3d, tutorial3_global_view) +TEST(Viz_viz3d, DISABLED_tutorial3_global_view) { tutorial3(false); } -TEST(Viz_viz3d, tutorial3_camera_view) +TEST(Viz_viz3d, DISABLED_tutorial3_camera_view) { tutorial3(true); } diff --git a/modules/viz/test/test_viz3d.cpp b/modules/viz/test/test_viz3d.cpp index 2acb5a3c3b..98811165ab 100644 --- a/modules/viz/test/test_viz3d.cpp +++ b/modules/viz/test/test_viz3d.cpp @@ -96,18 +96,18 @@ TEST(Viz_viz3d, develop) cv::viz::WMesh bunny_widget(bunny_mesh); bunny_widget.setColor(cv::viz::Color::cyan()); - cam_1 = cv::viz::WCameraPosition(cv::Vec2f(0.6, 0.4), 0.2, cv::viz::Color::green()); + cam_1 = cv::viz::WCameraPosition(cv::Vec2f(0.6f, 0.4f), 0.2, cv::viz::Color::green()); cam_coordinates = cv::viz::WCameraPosition(0.2); viz.showWidget("bunny", bunny_widget); - viz.showWidget("cam_1", cam_1, viz::makeCameraPose(Point3f(1.0,0.0,0.0), Point3f(0.0,0.0,0.0), Point3f(0.0,1.0,0.0))); - viz.showWidget("cam_coordinate", cam_coordinates, viz::makeCameraPose(Point3f(1.0,0.0,0.0), Point3f(0.0,0.0,0.0), Point3f(0.0,1.0,0.0))); + viz.showWidget("cam_1", cam_1, viz::makeCameraPose(Point3f(1.f,0.f,0.f), Point3f(0.f,0.f,0.f), Point3f(0.f,1.f,0.f))); + viz.showWidget("cam_coordinate", cam_coordinates, viz::makeCameraPose(Point3f(1.f,0.f,0.f), Point3f(0.f,0.f,0.f), Point3f(0.f,1.f,0.f))); std::vector cam_path; for (int i = 0, j = 0; i <= 360; ++i, j+=5) { - cam_path.push_back(viz::makeCameraPose(Vec3d(0.5*cos(double(i)*CV_PI/180.0), 0.5*sin(double(j)*CV_PI/180.0), 0.5*sin(double(i)*CV_PI/180.0)), Vec3f(0.f, 0.f, 0.f), Vec3f(0.f, 1.f, 0.f))); + cam_path.push_back(viz::makeCameraPose(Vec3d(0.5*cos(i*CV_PI/180.0), 0.5*sin(j*CV_PI/180.0), 0.5*sin(i*CV_PI/180.0)), Vec3f(0.f, 0.f, 0.f), Vec3f(0.f, 1.f, 0.f))); } int path_counter = 0;