Merge pull request #1811 from Nerei:fixed_some_build_errors
This commit is contained in:
commit
bb4bf7a1f9
@ -5,6 +5,7 @@
|
|||||||
#include "cascadeclassifier.h"
|
#include "cascadeclassifier.h"
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
using namespace cv;
|
||||||
|
|
||||||
CvHOGFeatureParams::CvHOGFeatureParams()
|
CvHOGFeatureParams::CvHOGFeatureParams()
|
||||||
{
|
{
|
||||||
|
@ -20,23 +20,23 @@ class CvHOGEvaluator : public CvFeatureEvaluator
|
|||||||
public:
|
public:
|
||||||
virtual ~CvHOGEvaluator() {}
|
virtual ~CvHOGEvaluator() {}
|
||||||
virtual void init(const CvFeatureParams *_featureParams,
|
virtual void init(const CvFeatureParams *_featureParams,
|
||||||
int _maxSampleCount, Size _winSize );
|
int _maxSampleCount, cv::Size _winSize );
|
||||||
virtual void setImage(const Mat& img, uchar clsLabel, int idx);
|
virtual void setImage(const cv::Mat& img, uchar clsLabel, int idx);
|
||||||
virtual float operator()(int varIdx, int sampleIdx) const;
|
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:
|
protected:
|
||||||
virtual void generateFeatures();
|
virtual void generateFeatures();
|
||||||
virtual void integralHistogram(const Mat &img, std::vector<Mat> &histogram, Mat &norm, int nbins) const;
|
virtual void integralHistogram(const cv::Mat &img, std::vector<cv::Mat> &histogram, cv::Mat &norm, int nbins) const;
|
||||||
class Feature
|
class Feature
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Feature();
|
Feature();
|
||||||
Feature( int offset, int x, int y, int cellW, int cellH );
|
Feature( int offset, int x, int y, int cellW, int cellH );
|
||||||
float calc( const std::vector<Mat> &_hists, const Mat &_normSum, size_t y, int featComponent ) const;
|
float calc( const std::vector<cv::Mat> &_hists, const cv::Mat &_normSum, size_t y, int featComponent ) const;
|
||||||
void write( FileStorage &fs ) const;
|
void write( cv::FileStorage &fs ) const;
|
||||||
void write( FileStorage &fs, int varIdx ) const;
|
void write( cv::FileStorage &fs, int varIdx ) const;
|
||||||
|
|
||||||
Rect rect[N_CELLS]; //cells
|
cv::Rect rect[N_CELLS]; //cells
|
||||||
|
|
||||||
struct
|
struct
|
||||||
{
|
{
|
||||||
@ -45,8 +45,8 @@ protected:
|
|||||||
};
|
};
|
||||||
std::vector<Feature> features;
|
std::vector<Feature> features;
|
||||||
|
|
||||||
Mat normSum; //for nomalization calculation (L1 or L2)
|
cv::Mat normSum; //for nomalization calculation (L1 or L2)
|
||||||
std::vector<Mat> hist;
|
std::vector<cv::Mat> hist;
|
||||||
};
|
};
|
||||||
|
|
||||||
inline float CvHOGEvaluator::operator()(int varIdx, int sampleIdx) const
|
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);
|
return features[featureIdx].calc( hist, normSum, sampleIdx, componentIdx);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline float CvHOGEvaluator::Feature::calc( const std::vector<Mat>& _hists, const Mat& _normSum, size_t y, int featComponent ) const
|
inline float CvHOGEvaluator::Feature::calc( const std::vector<cv::Mat>& _hists, const cv::Mat& _normSum, size_t y, int featComponent ) const
|
||||||
{
|
{
|
||||||
float normFactor;
|
float normFactor;
|
||||||
float res;
|
float res;
|
||||||
|
@ -1,4 +1,18 @@
|
|||||||
#include "opencv2/core.hpp"
|
#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 "boost.h"
|
||||||
#include "cascadeclassifier.h"
|
#include "cascadeclassifier.h"
|
||||||
|
@ -13,8 +13,8 @@ struct CvCascadeBoostParams : CvBoostParams
|
|||||||
CvCascadeBoostParams( int _boostType, float _minHitRate, float _maxFalseAlarm,
|
CvCascadeBoostParams( int _boostType, float _minHitRate, float _maxFalseAlarm,
|
||||||
double _weightTrimRate, int _maxDepth, int _maxWeakCount );
|
double _weightTrimRate, int _maxDepth, int _maxWeakCount );
|
||||||
virtual ~CvCascadeBoostParams() {}
|
virtual ~CvCascadeBoostParams() {}
|
||||||
void write( FileStorage &fs ) const;
|
void write( cv::FileStorage &fs ) const;
|
||||||
bool read( const FileNode &node );
|
bool read( const cv::FileNode &node );
|
||||||
virtual void printDefaults() const;
|
virtual void printDefaults() const;
|
||||||
virtual void printAttrs() const;
|
virtual void printAttrs() const;
|
||||||
virtual bool scanAttr( const std::string prmName, const std::string val);
|
virtual bool scanAttr( const std::string prmName, const std::string val);
|
||||||
@ -45,7 +45,7 @@ struct CvCascadeBoostTrainData : CvDTreeTrainData
|
|||||||
virtual void free_train_data();
|
virtual void free_train_data();
|
||||||
|
|
||||||
const CvFeatureEvaluator* featureEvaluator;
|
const CvFeatureEvaluator* featureEvaluator;
|
||||||
Mat valCache; // precalculated feature values (CV_32FC1)
|
cv::Mat valCache; // precalculated feature values (CV_32FC1)
|
||||||
CvMat _resp; // for casting
|
CvMat _resp; // for casting
|
||||||
int numPrecalcVal, numPrecalcIdx;
|
int numPrecalcVal, numPrecalcIdx;
|
||||||
};
|
};
|
||||||
@ -54,9 +54,9 @@ class CvCascadeBoostTree : public CvBoostTree
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
virtual CvDTreeNode* predict( int sampleIdx ) const;
|
virtual CvDTreeNode* predict( int sampleIdx ) const;
|
||||||
void write( FileStorage &fs, const Mat& featureMap );
|
void write( cv::FileStorage &fs, const cv::Mat& featureMap );
|
||||||
void read( const FileNode &node, CvBoost* _ensemble, CvDTreeTrainData* _data );
|
void read( const cv::FileNode &node, CvBoost* _ensemble, CvDTreeTrainData* _data );
|
||||||
void markFeaturesInMap( Mat& featureMap );
|
void markFeaturesInMap( cv::Mat& featureMap );
|
||||||
protected:
|
protected:
|
||||||
virtual void split_node_data( CvDTreeNode* n );
|
virtual void split_node_data( CvDTreeNode* n );
|
||||||
};
|
};
|
||||||
@ -70,10 +70,10 @@ public:
|
|||||||
virtual float predict( int sampleIdx, bool returnSum = false ) const;
|
virtual float predict( int sampleIdx, bool returnSum = false ) const;
|
||||||
|
|
||||||
float getThreshold() const { return threshold; }
|
float getThreshold() const { return threshold; }
|
||||||
void write( FileStorage &fs, const Mat& featureMap ) const;
|
void write( cv::FileStorage &fs, const cv::Mat& featureMap ) const;
|
||||||
bool read( const FileNode &node, const CvFeatureEvaluator* _featureEvaluator,
|
bool read( const cv::FileNode &node, const CvFeatureEvaluator* _featureEvaluator,
|
||||||
const CvCascadeBoostParams& _params );
|
const CvCascadeBoostParams& _params );
|
||||||
void markUsedFeaturesInMap( Mat& featureMap );
|
void markUsedFeaturesInMap( cv::Mat& featureMap );
|
||||||
protected:
|
protected:
|
||||||
virtual bool set_params( const CvBoostParams& _params );
|
virtual bool set_params( const CvBoostParams& _params );
|
||||||
virtual void update_weights( CvBoostTree* tree );
|
virtual void update_weights( CvBoostTree* tree );
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
#include <queue>
|
#include <queue>
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
using namespace cv;
|
||||||
|
|
||||||
static const char* stageTypes[] = { CC_BOOST };
|
static const char* stageTypes[] = { CC_BOOST };
|
||||||
static const char* featureTypes[] = { CC_HAAR, CC_LBP, CC_HOG };
|
static const char* featureTypes[] = { CC_HAAR, CC_LBP, CC_HOG };
|
||||||
|
@ -72,8 +72,8 @@ public:
|
|||||||
|
|
||||||
CvCascadeParams();
|
CvCascadeParams();
|
||||||
CvCascadeParams( int _stageType, int _featureType );
|
CvCascadeParams( int _stageType, int _featureType );
|
||||||
void write( FileStorage &fs ) const;
|
void write( cv::FileStorage &fs ) const;
|
||||||
bool read( const FileNode &node );
|
bool read( const cv::FileNode &node );
|
||||||
|
|
||||||
void printDefaults() const;
|
void printDefaults() const;
|
||||||
void printAttrs() const;
|
void printAttrs() const;
|
||||||
@ -81,7 +81,7 @@ public:
|
|||||||
|
|
||||||
int stageType;
|
int stageType;
|
||||||
int featureType;
|
int featureType;
|
||||||
Size winSize;
|
cv::Size winSize;
|
||||||
};
|
};
|
||||||
|
|
||||||
class CvCascadeClassifier
|
class CvCascadeClassifier
|
||||||
@ -104,20 +104,20 @@ private:
|
|||||||
bool updateTrainingSet( double& acceptanceRatio );
|
bool updateTrainingSet( double& acceptanceRatio );
|
||||||
int fillPassedSamples( int first, int count, bool isPositive, int64& consumed );
|
int fillPassedSamples( int first, int count, bool isPositive, int64& consumed );
|
||||||
|
|
||||||
void writeParams( FileStorage &fs ) const;
|
void writeParams( cv::FileStorage &fs ) const;
|
||||||
void writeStages( FileStorage &fs, const Mat& featureMap ) const;
|
void writeStages( cv::FileStorage &fs, const cv::Mat& featureMap ) const;
|
||||||
void writeFeatures( FileStorage &fs, const Mat& featureMap ) const;
|
void writeFeatures( cv::FileStorage &fs, const cv::Mat& featureMap ) const;
|
||||||
bool readParams( const FileNode &node );
|
bool readParams( const cv::FileNode &node );
|
||||||
bool readStages( const FileNode &node );
|
bool readStages( const cv::FileNode &node );
|
||||||
|
|
||||||
void getUsedFeaturesIdxMap( Mat& featureMap );
|
void getUsedFeaturesIdxMap( cv::Mat& featureMap );
|
||||||
|
|
||||||
CvCascadeParams cascadeParams;
|
CvCascadeParams cascadeParams;
|
||||||
Ptr<CvFeatureParams> featureParams;
|
cv::Ptr<CvFeatureParams> featureParams;
|
||||||
Ptr<CvCascadeBoostParams> stageParams;
|
cv::Ptr<CvCascadeBoostParams> stageParams;
|
||||||
|
|
||||||
Ptr<CvFeatureEvaluator> featureEvaluator;
|
cv::Ptr<CvFeatureEvaluator> featureEvaluator;
|
||||||
std::vector< Ptr<CvCascadeBoost> > stageClassifiers;
|
std::vector< cv::Ptr<CvCascadeBoost> > stageClassifiers;
|
||||||
CvCascadeImageReader imgReader;
|
CvCascadeImageReader imgReader;
|
||||||
int numStages, curNumSamples;
|
int numStages, curNumSamples;
|
||||||
int numPos, numNeg;
|
int numPos, numNeg;
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
#include "cascadeclassifier.h"
|
#include "cascadeclassifier.h"
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
using namespace cv;
|
||||||
|
|
||||||
float calcNormFactor( const Mat& sum, const Mat& sqSum )
|
float calcNormFactor( const Mat& sum, const Mat& sqSum )
|
||||||
{
|
{
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
#include "cascadeclassifier.h"
|
#include "cascadeclassifier.h"
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
using namespace cv;
|
||||||
|
|
||||||
CvHaarFeatureParams::CvHaarFeatureParams() : mode(BASIC)
|
CvHaarFeatureParams::CvHaarFeatureParams() : mode(BASIC)
|
||||||
{
|
{
|
||||||
|
@ -18,8 +18,8 @@ public:
|
|||||||
CvHaarFeatureParams( int _mode );
|
CvHaarFeatureParams( int _mode );
|
||||||
|
|
||||||
virtual void init( const CvFeatureParams& fp );
|
virtual void init( const CvFeatureParams& fp );
|
||||||
virtual void write( FileStorage &fs ) const;
|
virtual void write( cv::FileStorage &fs ) const;
|
||||||
virtual bool read( const FileNode &node );
|
virtual bool read( const cv::FileNode &node );
|
||||||
|
|
||||||
virtual void printDefaults() const;
|
virtual void printDefaults() const;
|
||||||
virtual void printAttrs() const;
|
virtual void printAttrs() const;
|
||||||
@ -32,11 +32,11 @@ class CvHaarEvaluator : public CvFeatureEvaluator
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
virtual void init(const CvFeatureParams *_featureParams,
|
virtual void init(const CvFeatureParams *_featureParams,
|
||||||
int _maxSampleCount, Size _winSize );
|
int _maxSampleCount, cv::Size _winSize );
|
||||||
virtual void setImage(const Mat& img, uchar clsLabel, int idx);
|
virtual void setImage(const cv::Mat& img, uchar clsLabel, int idx);
|
||||||
virtual float operator()(int featureIdx, int sampleIdx) const;
|
virtual float operator()(int featureIdx, int sampleIdx) const;
|
||||||
virtual void writeFeatures( FileStorage &fs, const Mat& featureMap ) const;
|
virtual void writeFeatures( cv::FileStorage &fs, const cv::Mat& featureMap ) const;
|
||||||
void writeFeature( FileStorage &fs, int fi ) const; // for old file fornat
|
void writeFeature( cv::FileStorage &fs, int fi ) const; // for old file fornat
|
||||||
protected:
|
protected:
|
||||||
virtual void generateFeatures();
|
virtual void generateFeatures();
|
||||||
|
|
||||||
@ -48,13 +48,13 @@ protected:
|
|||||||
int x0, int y0, int w0, int h0, float wt0,
|
int x0, int y0, int w0, int h0, float wt0,
|
||||||
int x1, int y1, int w1, int h1, float wt1,
|
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 );
|
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;
|
float calc( const cv::Mat &sum, const cv::Mat &tilted, size_t y) const;
|
||||||
void write( FileStorage &fs ) const;
|
void write( cv::FileStorage &fs ) const;
|
||||||
|
|
||||||
bool tilted;
|
bool tilted;
|
||||||
struct
|
struct
|
||||||
{
|
{
|
||||||
Rect r;
|
cv::Rect r;
|
||||||
float weight;
|
float weight;
|
||||||
} rect[CV_HAAR_FEATURE_MAX];
|
} rect[CV_HAAR_FEATURE_MAX];
|
||||||
|
|
||||||
@ -65,9 +65,9 @@ protected:
|
|||||||
};
|
};
|
||||||
|
|
||||||
std::vector<Feature> features;
|
std::vector<Feature> features;
|
||||||
Mat sum; /* sum images (each row represents image) */
|
cv::Mat sum; /* sum images (each row represents image) */
|
||||||
Mat tilted; /* tilted sum images (each row represents image) */
|
cv::Mat tilted; /* tilted sum images (each row represents image) */
|
||||||
Mat normfactor; /* normalization factor */
|
cv::Mat normfactor; /* normalization factor */
|
||||||
};
|
};
|
||||||
|
|
||||||
inline float CvHaarEvaluator::operator()(int featureIdx, int sampleIdx) const
|
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);
|
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>((int)y) : _sum.ptr<int>((int)y);
|
const int* img = tilted ? _tilted.ptr<int>((int)y) : _sum.ptr<int>((int)y);
|
||||||
float ret = rect[0].weight * (img[fastRect[0].p0] - img[fastRect[0].p1] - img[fastRect[0].p2] + img[fastRect[0].p3] ) +
|
float ret = rect[0].weight * (img[fastRect[0].p0] - img[fastRect[0].p1] - img[fastRect[0].p2] + img[fastRect[0].p3] ) +
|
||||||
|
@ -8,6 +8,7 @@
|
|||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
using namespace cv;
|
||||||
|
|
||||||
bool CvCascadeImageReader::create( const string _posFilename, const string _negFilename, Size _winSize )
|
bool CvCascadeImageReader::create( const string _posFilename, const string _negFilename, Size _winSize )
|
||||||
{
|
{
|
||||||
|
@ -3,15 +3,15 @@
|
|||||||
|
|
||||||
#include "highgui.h"
|
#include "highgui.h"
|
||||||
|
|
||||||
using namespace cv;
|
|
||||||
|
|
||||||
class CvCascadeImageReader
|
class CvCascadeImageReader
|
||||||
{
|
{
|
||||||
public:
|
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(); }
|
void restart() { posReader.restart(); }
|
||||||
bool getNeg(Mat &_img) { return negReader.get( _img ); }
|
bool getNeg(cv::Mat &_img) { return negReader.get( _img ); }
|
||||||
bool getPos(Mat &_img) { return posReader.get( _img ); }
|
bool getPos(cv::Mat &_img) { return posReader.get( _img ); }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
class PosReader
|
class PosReader
|
||||||
@ -20,7 +20,7 @@ private:
|
|||||||
PosReader();
|
PosReader();
|
||||||
virtual ~PosReader();
|
virtual ~PosReader();
|
||||||
bool create( const std::string _filename );
|
bool create( const std::string _filename );
|
||||||
bool get( Mat &_img );
|
bool get( cv::Mat &_img );
|
||||||
void restart();
|
void restart();
|
||||||
|
|
||||||
short* vec;
|
short* vec;
|
||||||
@ -35,18 +35,18 @@ private:
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
NegReader();
|
NegReader();
|
||||||
bool create( const std::string _filename, Size _winSize );
|
bool create( const std::string _filename, cv::Size _winSize );
|
||||||
bool get( Mat& _img );
|
bool get( cv::Mat& _img );
|
||||||
bool nextImg();
|
bool nextImg();
|
||||||
|
|
||||||
Mat src, img;
|
cv::Mat src, img;
|
||||||
std::vector<std::string> imgFilenames;
|
std::vector<std::string> imgFilenames;
|
||||||
Point offset, point;
|
cv::Point offset, point;
|
||||||
float scale;
|
float scale;
|
||||||
float scaleFactor;
|
float scaleFactor;
|
||||||
float stepFactor;
|
float stepFactor;
|
||||||
size_t last, round;
|
size_t last, round;
|
||||||
Size winSize;
|
cv::Size winSize;
|
||||||
} negReader;
|
} negReader;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -4,6 +4,8 @@
|
|||||||
#include "lbpfeatures.h"
|
#include "lbpfeatures.h"
|
||||||
#include "cascadeclassifier.h"
|
#include "cascadeclassifier.h"
|
||||||
|
|
||||||
|
using namespace cv;
|
||||||
|
|
||||||
CvLBPFeatureParams::CvLBPFeatureParams()
|
CvLBPFeatureParams::CvLBPFeatureParams()
|
||||||
{
|
{
|
||||||
maxCatCount = 256;
|
maxCatCount = 256;
|
||||||
|
@ -15,11 +15,11 @@ class CvLBPEvaluator : public CvFeatureEvaluator
|
|||||||
public:
|
public:
|
||||||
virtual ~CvLBPEvaluator() {}
|
virtual ~CvLBPEvaluator() {}
|
||||||
virtual void init(const CvFeatureParams *_featureParams,
|
virtual void init(const CvFeatureParams *_featureParams,
|
||||||
int _maxSampleCount, Size _winSize );
|
int _maxSampleCount, cv::Size _winSize );
|
||||||
virtual void setImage(const Mat& img, uchar clsLabel, int idx);
|
virtual void setImage(const cv::Mat& img, uchar clsLabel, int idx);
|
||||||
virtual float operator()(int featureIdx, int sampleIdx) const
|
virtual float operator()(int featureIdx, int sampleIdx) const
|
||||||
{ return (float)features[featureIdx].calc( sum, sampleIdx); }
|
{ 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:
|
protected:
|
||||||
virtual void generateFeatures();
|
virtual void generateFeatures();
|
||||||
|
|
||||||
@ -28,18 +28,18 @@ protected:
|
|||||||
public:
|
public:
|
||||||
Feature();
|
Feature();
|
||||||
Feature( int offset, int x, int y, int _block_w, int _block_h );
|
Feature( int offset, int x, int y, int _block_w, int _block_h );
|
||||||
uchar calc( const Mat& _sum, size_t y ) const;
|
uchar calc( const cv::Mat& _sum, size_t y ) const;
|
||||||
void write( FileStorage &fs ) const;
|
void write( cv::FileStorage &fs ) const;
|
||||||
|
|
||||||
Rect rect;
|
cv::Rect rect;
|
||||||
int p[16];
|
int p[16];
|
||||||
};
|
};
|
||||||
std::vector<Feature> features;
|
std::vector<Feature> 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>((int)y);
|
const int* psum = _sum.ptr<int>((int)y);
|
||||||
int cval = psum[p[5]] - psum[p[6]] - psum[p[9]] + psum[p[10]];
|
int cval = psum[p[5]] - psum[p[6]] - psum[p[9]] + psum[p[10]];
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
#include "cascadeclassifier.h"
|
#include "cascadeclassifier.h"
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
using namespace cv;
|
||||||
|
|
||||||
int main( int argc, char* argv[] )
|
int main( int argc, char* argv[] )
|
||||||
{
|
{
|
||||||
|
@ -30,13 +30,13 @@
|
|||||||
(p3) = (rect).x + (rect).width - (rect).height \
|
(p3) = (rect).x + (rect).width - (rect).height \
|
||||||
+ (step) * ((rect).y + (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<class Feature>
|
template<class Feature>
|
||||||
void _writeFeatures( const std::vector<Feature> features, FileStorage &fs, const Mat& featureMap )
|
void _writeFeatures( const std::vector<Feature> features, cv::FileStorage &fs, const cv::Mat& featureMap )
|
||||||
{
|
{
|
||||||
fs << FEATURES << "[";
|
fs << FEATURES << "[";
|
||||||
const Mat_<int>& featureMap_ = (const Mat_<int>&)featureMap;
|
const cv::Mat_<int>& featureMap_ = (const cv::Mat_<int>&)featureMap;
|
||||||
for ( int fi = 0; fi < featureMap.cols; fi++ )
|
for ( int fi = 0; fi < featureMap.cols; fi++ )
|
||||||
if ( featureMap_(0, fi) >= 0 )
|
if ( featureMap_(0, fi) >= 0 )
|
||||||
{
|
{
|
||||||
@ -53,8 +53,8 @@ public:
|
|||||||
CvParams();
|
CvParams();
|
||||||
virtual ~CvParams() {}
|
virtual ~CvParams() {}
|
||||||
// from|to file
|
// from|to file
|
||||||
virtual void write( FileStorage &fs ) const = 0;
|
virtual void write( cv::FileStorage &fs ) const = 0;
|
||||||
virtual bool read( const FileNode &node ) = 0;
|
virtual bool read( const cv::FileNode &node ) = 0;
|
||||||
// from|to screen
|
// from|to screen
|
||||||
virtual void printDefaults() const;
|
virtual void printDefaults() const;
|
||||||
virtual void printAttrs() const;
|
virtual void printAttrs() const;
|
||||||
@ -68,9 +68,9 @@ public:
|
|||||||
enum { HAAR = 0, LBP = 1, HOG = 2 };
|
enum { HAAR = 0, LBP = 1, HOG = 2 };
|
||||||
CvFeatureParams();
|
CvFeatureParams();
|
||||||
virtual void init( const CvFeatureParams& fp );
|
virtual void init( const CvFeatureParams& fp );
|
||||||
virtual void write( FileStorage &fs ) const;
|
virtual void write( cv::FileStorage &fs ) const;
|
||||||
virtual bool read( const FileNode &node );
|
virtual bool read( const cv::FileNode &node );
|
||||||
static Ptr<CvFeatureParams> create( int featureType );
|
static cv::Ptr<CvFeatureParams> create( int featureType );
|
||||||
int maxCatCount; // 0 in case of numerical features
|
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
|
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:
|
public:
|
||||||
virtual ~CvFeatureEvaluator() {}
|
virtual ~CvFeatureEvaluator() {}
|
||||||
virtual void init(const CvFeatureParams *_featureParams,
|
virtual void init(const CvFeatureParams *_featureParams,
|
||||||
int _maxSampleCount, Size _winSize );
|
int _maxSampleCount, cv::Size _winSize );
|
||||||
virtual void setImage(const Mat& img, uchar clsLabel, int idx);
|
virtual void setImage(const cv::Mat& img, uchar clsLabel, int idx);
|
||||||
virtual void writeFeatures( FileStorage &fs, const Mat& featureMap ) const = 0;
|
virtual void writeFeatures( cv::FileStorage &fs, const cv::Mat& featureMap ) const = 0;
|
||||||
virtual float operator()(int featureIdx, int sampleIdx) const = 0;
|
virtual float operator()(int featureIdx, int sampleIdx) const = 0;
|
||||||
static Ptr<CvFeatureEvaluator> create(int type);
|
static cv::Ptr<CvFeatureEvaluator> create(int type);
|
||||||
|
|
||||||
int getNumFeatures() const { return numFeatures; }
|
int getNumFeatures() const { return numFeatures; }
|
||||||
int getMaxCatCount() const { return featureParams->maxCatCount; }
|
int getMaxCatCount() const { return featureParams->maxCatCount; }
|
||||||
int getFeatureSize() const { return featureParams->featSize; }
|
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<float>(si, 0); }
|
float getCls(int si) const { return cls.at<float>(si, 0); }
|
||||||
protected:
|
protected:
|
||||||
virtual void generateFeatures() = 0;
|
virtual void generateFeatures() = 0;
|
||||||
|
|
||||||
int npos, nneg;
|
int npos, nneg;
|
||||||
int numFeatures;
|
int numFeatures;
|
||||||
Size winSize;
|
cv::Size winSize;
|
||||||
CvFeatureParams *featureParams;
|
CvFeatureParams *featureParams;
|
||||||
Mat cls;
|
cv::Mat cls;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -105,7 +105,9 @@ public:
|
|||||||
context(_context), depthGenerator(_depthGenerator), imageGenerator(_imageGenerator),
|
context(_context), depthGenerator(_depthGenerator), imageGenerator(_imageGenerator),
|
||||||
maxBufferSize(_maxBufferSize), isCircleBuffer(_isCircleBuffer), maxTimeDuration(_maxTimeDuration)
|
maxBufferSize(_maxBufferSize), isCircleBuffer(_isCircleBuffer), maxTimeDuration(_maxTimeDuration)
|
||||||
{
|
{
|
||||||
|
#ifdef HAVE_TBB
|
||||||
task = 0;
|
task = 0;
|
||||||
|
#endif
|
||||||
|
|
||||||
CV_Assert( depthGenerator.IsValid() );
|
CV_Assert( depthGenerator.IsValid() );
|
||||||
CV_Assert( imageGenerator.IsValid() );
|
CV_Assert( imageGenerator.IsValid() );
|
||||||
@ -150,7 +152,7 @@ public:
|
|||||||
task = new( tbb::task::allocate_root() ) TBBApproximateSynchronizerTask( *this );
|
task = new( tbb::task::allocate_root() ) TBBApproximateSynchronizerTask( *this );
|
||||||
tbb::task::enqueue(*task);
|
tbb::task::enqueue(*task);
|
||||||
#else
|
#else
|
||||||
task = new ApproximateSynchronizer( *this );
|
task->reset( new ApproximateSynchronizer( *this ) );
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -171,6 +173,9 @@ public:
|
|||||||
xn::ImageGenerator &imageGenerator;
|
xn::ImageGenerator &imageGenerator;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
ApproximateSyncGrabber(const ApproximateSyncGrabber&);
|
||||||
|
ApproximateSyncGrabber& operator=(const ApproximateSyncGrabber&);
|
||||||
|
|
||||||
int maxBufferSize;
|
int maxBufferSize;
|
||||||
bool isCircleBuffer;
|
bool isCircleBuffer;
|
||||||
int maxTimeDuration;
|
int maxTimeDuration;
|
||||||
@ -214,7 +219,7 @@ private:
|
|||||||
virtual bool grab( xn::DepthMetaData& depthMetaData,
|
virtual bool grab( xn::DepthMetaData& depthMetaData,
|
||||||
xn::ImageMetaData& imageMetaData )
|
xn::ImageMetaData& imageMetaData )
|
||||||
{
|
{
|
||||||
while(1)
|
for(;;)
|
||||||
{
|
{
|
||||||
if( !isDepthFilled )
|
if( !isDepthFilled )
|
||||||
isDepthFilled = popDepthMetaData(depth);
|
isDepthFilled = popDepthMetaData(depth);
|
||||||
@ -951,7 +956,7 @@ double CvCapture_OpenNI::getDepthGeneratorProperty( int propIdx )
|
|||||||
propValue = depthGenerator.GetAlternativeViewPointCap().IsViewPointAs(imageGenerator) ? 1.0 : 0.0;
|
propValue = depthGenerator.GetAlternativeViewPointCap().IsViewPointAs(imageGenerator) ? 1.0 : 0.0;
|
||||||
break;
|
break;
|
||||||
case CV_CAP_PROP_POS_MSEC :
|
case CV_CAP_PROP_POS_MSEC :
|
||||||
propValue = depthGenerator.GetTimestamp();
|
propValue = (double)depthGenerator.GetTimestamp();
|
||||||
break;
|
break;
|
||||||
case CV_CAP_PROP_POS_FRAMES :
|
case CV_CAP_PROP_POS_FRAMES :
|
||||||
propValue = depthGenerator.GetFrameID();
|
propValue = depthGenerator.GetFrameID();
|
||||||
@ -1039,7 +1044,7 @@ double CvCapture_OpenNI::getImageGeneratorProperty( int propIdx )
|
|||||||
propValue = mode.nFPS;
|
propValue = mode.nFPS;
|
||||||
break;
|
break;
|
||||||
case CV_CAP_PROP_POS_MSEC :
|
case CV_CAP_PROP_POS_MSEC :
|
||||||
propValue = imageGenerator.GetTimestamp();
|
propValue = (double)imageGenerator.GetTimestamp();
|
||||||
break;
|
break;
|
||||||
case CV_CAP_PROP_POS_FRAMES :
|
case CV_CAP_PROP_POS_FRAMES :
|
||||||
propValue = imageGenerator.GetFrameID();
|
propValue = imageGenerator.GetFrameID();
|
||||||
|
@ -43,9 +43,13 @@
|
|||||||
#include "precomp.hpp"
|
#include "precomp.hpp"
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
|
||||||
#ifndef INT32_MAX
|
#if defined _MSC_VER && _MSC_VER == 1500
|
||||||
#define __STDC_LIMIT_MACROS
|
typedef int int_fast32_t;
|
||||||
#include <stdint.h>
|
#else
|
||||||
|
#ifndef INT32_MAX
|
||||||
|
#define __STDC_LIMIT_MACROS
|
||||||
|
#include <stdint.h>
|
||||||
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
@ -40,9 +40,6 @@
|
|||||||
//M*/
|
//M*/
|
||||||
|
|
||||||
#include "test_precomp.hpp"
|
#include "test_precomp.hpp"
|
||||||
#include <string>
|
|
||||||
#include <algorithm>
|
|
||||||
#include <fstream>
|
|
||||||
|
|
||||||
using namespace cv;
|
using namespace cv;
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
@ -13,5 +13,9 @@
|
|||||||
#include "opencv2/ts.hpp"
|
#include "opencv2/ts.hpp"
|
||||||
#include "opencv2/photo.hpp"
|
#include "opencv2/photo.hpp"
|
||||||
#include "opencv2/highgui.hpp"
|
#include "opencv2/highgui.hpp"
|
||||||
|
#include <string>
|
||||||
|
#include <algorithm>
|
||||||
|
#include <fstream>
|
||||||
|
#include <ctime>
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -108,10 +108,9 @@ namespace cv
|
|||||||
void remove(const String &window_name);
|
void remove(const String &window_name);
|
||||||
|
|
||||||
static VizAccessor * instance_;
|
static VizAccessor * instance_;
|
||||||
static bool is_instantiated_;
|
|
||||||
|
|
||||||
struct VizAccessorImpl;
|
struct VizAccessorImpl;
|
||||||
static VizAccessorImpl * impl_;
|
VizAccessorImpl * impl_;
|
||||||
|
|
||||||
friend class Viz3d;
|
friend class Viz3d;
|
||||||
};
|
};
|
||||||
|
@ -57,7 +57,7 @@ namespace cv
|
|||||||
{
|
{
|
||||||
namespace viz
|
namespace viz
|
||||||
{
|
{
|
||||||
class CV_EXPORTS Color : public Scalar
|
class Color : public Scalar
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Color();
|
Color();
|
||||||
@ -169,8 +169,26 @@ namespace cv
|
|||||||
Vec2f principal_point_;
|
Vec2f principal_point_;
|
||||||
Vec2f focal_;
|
Vec2f focal_;
|
||||||
};
|
};
|
||||||
|
|
||||||
} /* namespace viz */
|
} /* namespace viz */
|
||||||
} /* namespace cv */
|
} /* 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
|
#endif
|
||||||
|
@ -47,9 +47,6 @@
|
|||||||
//M*/
|
//M*/
|
||||||
|
|
||||||
#include "precomp.hpp"
|
#include "precomp.hpp"
|
||||||
#include "interactor_style.h"
|
|
||||||
|
|
||||||
using namespace cv;
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
void cv::viz::InteractorStyle::Initialize()
|
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]);
|
FindPokedRenderer(Interactor->GetEventPosition()[0], Interactor->GetEventPosition()[1]);
|
||||||
wif_->SetInput(Interactor->GetRenderWindow());
|
wif_->SetInput(Interactor->GetRenderWindow());
|
||||||
wif_->Modified(); // Update the WindowToImageFilter
|
wif_->Modified(); // Update the WindowToImageFilter
|
||||||
snapshot_writer_->Modified();
|
snapshot_writer_->Modified();
|
||||||
snapshot_writer_->SetFileName(file.c_str());
|
snapshot_writer_->SetFileName(file.c_str());
|
||||||
snapshot_writer_->Write();
|
snapshot_writer_->Write();
|
||||||
@ -117,30 +114,19 @@ void cv::viz::InteractorStyle::OnChar()
|
|||||||
FindPokedRenderer(Interactor->GetEventPosition()[0], Interactor->GetEventPosition()[1]);
|
FindPokedRenderer(Interactor->GetEventPosition()[0], Interactor->GetEventPosition()[1]);
|
||||||
if (Interactor->GetKeyCode() >= '0' && Interactor->GetKeyCode() <= '9')
|
if (Interactor->GetKeyCode() >= '0' && Interactor->GetKeyCode() <= '9')
|
||||||
return;
|
return;
|
||||||
std::string key(Interactor->GetKeySym());
|
|
||||||
if (key.find("XF86ZoomIn") != std::string::npos)
|
String key(Interactor->GetKeySym());
|
||||||
|
if (key.find("XF86ZoomIn") != String::npos)
|
||||||
zoomIn();
|
zoomIn();
|
||||||
else if (key.find("XF86ZoomOut") != std::string::npos)
|
else if (key.find("XF86ZoomOut") != String::npos)
|
||||||
zoomOut();
|
zoomOut();
|
||||||
|
|
||||||
int keymod = false;
|
int keymod = false;
|
||||||
switch (modifier_)
|
switch (modifier_)
|
||||||
{
|
{
|
||||||
case KB_MOD_ALT:
|
case KB_MOD_ALT: keymod = Interactor->GetAltKey(); break;
|
||||||
{
|
case KB_MOD_CTRL: keymod = Interactor->GetControlKey(); break;
|
||||||
keymod = Interactor->GetAltKey();
|
case KB_MOD_SHIFT: keymod = Interactor->GetShiftKey(); break;
|
||||||
break;
|
|
||||||
}
|
|
||||||
case KB_MOD_CTRL:
|
|
||||||
{
|
|
||||||
keymod = Interactor->GetControlKey();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case KB_MOD_SHIFT:
|
|
||||||
{
|
|
||||||
keymod = Interactor->GetShiftKey();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (Interactor->GetKeyCode())
|
switch (Interactor->GetKeyCode())
|
||||||
@ -193,11 +179,15 @@ void cv::viz::InteractorStyle::registerKeyboardCallback(void (*callback)(const K
|
|||||||
keyboard_callback_cookie_ = cookie;
|
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
|
void
|
||||||
cv::viz::InteractorStyle::OnKeyDown()
|
cv::viz::InteractorStyle::OnKeyDown()
|
||||||
{
|
{
|
||||||
|
|
||||||
CV_Assert("Interactor style not initialized. Please call Initialize() before continuing" && init_);
|
CV_Assert("Interactor style not initialized. Please call Initialize() before continuing" && init_);
|
||||||
CV_Assert("No renderer given! Use SetRendererCollection() before continuing." && renderer_);
|
CV_Assert("No renderer given! Use SetRendererCollection() before continuing." && renderer_);
|
||||||
|
|
||||||
@ -216,9 +206,9 @@ cv::viz::InteractorStyle::OnKeyDown()
|
|||||||
|
|
||||||
|
|
||||||
// Get the status of special keys (Cltr+Alt+Shift)
|
// Get the status of special keys (Cltr+Alt+Shift)
|
||||||
bool shift = Interactor->GetShiftKey();
|
bool shift = getShiftKey();
|
||||||
bool ctrl = Interactor->GetControlKey();
|
bool ctrl = getControlKey();
|
||||||
bool alt = Interactor->GetAltKey();
|
bool alt = getAltKey();
|
||||||
|
|
||||||
bool keymod = false;
|
bool keymod = false;
|
||||||
switch (modifier_)
|
switch (modifier_)
|
||||||
@ -269,42 +259,40 @@ cv::viz::InteractorStyle::OnKeyDown()
|
|||||||
vtkSmartPointer<vtkActorCollection> ac = CurrentRenderer->GetActors();
|
vtkSmartPointer<vtkActorCollection> ac = CurrentRenderer->GetActors();
|
||||||
vtkCollectionSimpleIterator ait;
|
vtkCollectionSimpleIterator ait;
|
||||||
for (ac->InitTraversal(ait); vtkActor* actor = ac->GetNextActor(ait); )
|
for (ac->InitTraversal(ait); vtkActor* actor = ac->GetNextActor(ait); )
|
||||||
{
|
|
||||||
for (actor->InitPathTraversal(); vtkAssemblyPath* path = actor->GetNextPath(); )
|
for (actor->InitPathTraversal(); vtkAssemblyPath* path = actor->GetNextPath(); )
|
||||||
{
|
{
|
||||||
vtkActor* apart = reinterpret_cast <vtkActor*>(path->GetLastNode()->GetViewProp());
|
vtkActor* apart = reinterpret_cast <vtkActor*>(path->GetLastNode()->GetViewProp());
|
||||||
apart->GetProperty()->SetRepresentationToPoints();
|
apart->GetProperty()->SetRepresentationToPoints();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
// Save a PNG snapshot with the current screen
|
// Save a PNG snapshot with the current screen
|
||||||
case 'j': case 'J':
|
case 'j': case 'J':
|
||||||
{
|
{
|
||||||
char cam_fn[80], snapshot_fn[80];
|
unsigned int t = static_cast<unsigned int>(time(0));
|
||||||
unsigned t = static_cast<unsigned>(time(0));
|
String png_file = cv::format("screenshot-%d.png", t);
|
||||||
sprintf(snapshot_fn, "screenshot-%d.png" , t);
|
String cam_file = cv::format("screenshot-%d.cam", t);
|
||||||
saveScreenshot(snapshot_fn);
|
|
||||||
|
|
||||||
sprintf(cam_fn, "screenshot-%d.cam", t);
|
|
||||||
ofstream ofs_cam;
|
|
||||||
ofs_cam.open(cam_fn);
|
|
||||||
vtkSmartPointer<vtkCamera> cam = Interactor->GetRenderWindow()->GetRenderers()->GetFirstRenderer()->GetActiveCamera();
|
vtkSmartPointer<vtkCamera> cam = Interactor->GetRenderWindow()->GetRenderers()->GetFirstRenderer()->GetActiveCamera();
|
||||||
double clip[2], focal[3], pos[3], view[3];
|
Vec2d clip;
|
||||||
cam->GetClippingRange(clip);
|
Vec3d focal, pos, view;
|
||||||
cam->GetFocalPoint(focal);
|
cam->GetClippingRange(clip.val);
|
||||||
cam->GetPosition(pos);
|
cam->GetFocalPoint(focal.val);
|
||||||
cam->GetViewUp(view);
|
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();
|
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],
|
||||||
int *win_size = Interactor->GetRenderWindow()->GetSize();
|
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]);
|
||||||
ofs_cam << clip[0] << "," << clip[1] << "/" << focal[0] << "," << focal[1] << "," << focal[2] << "/" <<
|
|
||||||
pos[0] << "," << pos[1] << "," << pos[2] << "/" << view[0] << "," << view[1] << "," << view[2] << "/" <<
|
saveScreenshot(png_file);
|
||||||
cam->GetViewAngle() / 180.0 * CV_PI << "/" << win_size[0] << "," << win_size[1] << "/" << win_pos[0] << "," << win_pos[1]
|
ofstream ofs_cam(cam_file.c_str());
|
||||||
<< endl;
|
ofs_cam << data.c_str() << endl;
|
||||||
ofs_cam.close();
|
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;
|
break;
|
||||||
}
|
}
|
||||||
// display current camera settings/parameters
|
// display current camera settings/parameters
|
||||||
@ -349,7 +337,6 @@ cv::viz::InteractorStyle::OnKeyDown()
|
|||||||
vtkSmartPointer<vtkActorCollection> ac = CurrentRenderer->GetActors();
|
vtkSmartPointer<vtkActorCollection> ac = CurrentRenderer->GetActors();
|
||||||
vtkCollectionSimpleIterator ait;
|
vtkCollectionSimpleIterator ait;
|
||||||
for (ac->InitTraversal(ait); vtkActor* actor = ac->GetNextActor(ait); )
|
for (ac->InitTraversal(ait); vtkActor* actor = ac->GetNextActor(ait); )
|
||||||
{
|
|
||||||
for (actor->InitPathTraversal(); vtkAssemblyPath* path = actor->GetNextPath(); )
|
for (actor->InitPathTraversal(); vtkAssemblyPath* path = actor->GetNextPath(); )
|
||||||
{
|
{
|
||||||
vtkActor* apart = reinterpret_cast <vtkActor*>(path->GetLastNode()->GetViewProp());
|
vtkActor* apart = reinterpret_cast <vtkActor*>(path->GetLastNode()->GetViewProp());
|
||||||
@ -357,7 +344,6 @@ cv::viz::InteractorStyle::OnKeyDown()
|
|||||||
if (psize < 63.0f)
|
if (psize < 63.0f)
|
||||||
apart->GetProperty()->SetPointSize(psize + 1.0f);
|
apart->GetProperty()->SetPointSize(psize + 1.0f);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -370,7 +356,6 @@ cv::viz::InteractorStyle::OnKeyDown()
|
|||||||
vtkSmartPointer<vtkActorCollection> ac = CurrentRenderer->GetActors();
|
vtkSmartPointer<vtkActorCollection> ac = CurrentRenderer->GetActors();
|
||||||
vtkCollectionSimpleIterator ait;
|
vtkCollectionSimpleIterator ait;
|
||||||
for (ac->InitTraversal(ait); vtkActor* actor = ac->GetNextActor(ait); )
|
for (ac->InitTraversal(ait); vtkActor* actor = ac->GetNextActor(ait); )
|
||||||
{
|
|
||||||
for (actor->InitPathTraversal(); vtkAssemblyPath* path = actor->GetNextPath(); )
|
for (actor->InitPathTraversal(); vtkAssemblyPath* path = actor->GetNextPath(); )
|
||||||
{
|
{
|
||||||
vtkActor* apart = static_cast<vtkActor*>(path->GetLastNode()->GetViewProp());
|
vtkActor* apart = static_cast<vtkActor*>(path->GetLastNode()->GetViewProp());
|
||||||
@ -378,7 +363,6 @@ cv::viz::InteractorStyle::OnKeyDown()
|
|||||||
if (psize > 1.0f)
|
if (psize > 1.0f)
|
||||||
apart->GetProperty()->SetPointSize(psize - 1.0f);
|
apart->GetProperty()->SetPointSize(psize - 1.0f);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -455,9 +439,7 @@ cv::viz::InteractorStyle::OnKeyDown()
|
|||||||
case 'o': case 'O':
|
case 'o': case 'O':
|
||||||
{
|
{
|
||||||
vtkSmartPointer<vtkCamera> cam = CurrentRenderer->GetActiveCamera();
|
vtkSmartPointer<vtkCamera> cam = CurrentRenderer->GetActiveCamera();
|
||||||
int flag = cam->GetParallelProjection();
|
cam->SetParallelProjection(!cam->GetParallelProjection());
|
||||||
cam->SetParallelProjection(!flag);
|
|
||||||
|
|
||||||
CurrentRenderer->SetActiveCamera(cam);
|
CurrentRenderer->SetActiveCamera(cam);
|
||||||
CurrentRenderer->Render();
|
CurrentRenderer->Render();
|
||||||
break;
|
break;
|
||||||
@ -494,18 +476,14 @@ cv::viz::InteractorStyle::OnKeyDown()
|
|||||||
// if a valid transformation was found, use it otherwise fall back to default view point.
|
// if a valid transformation was found, use it otherwise fall back to default view point.
|
||||||
if (found_transformation)
|
if (found_transformation)
|
||||||
{
|
{
|
||||||
vtkProp3D * actor = vtkProp3D::SafeDownCast(it->second);
|
const vtkMatrix4x4* m = vtkProp3D::SafeDownCast(it->second)->GetUserMatrix();
|
||||||
cam->SetPosition(actor->GetUserMatrix()->GetElement(0, 3),
|
|
||||||
actor->GetUserMatrix()->GetElement(1, 3),
|
|
||||||
actor->GetUserMatrix()->GetElement(2, 3));
|
|
||||||
|
|
||||||
cam->SetFocalPoint(actor->GetUserMatrix()->GetElement(0, 3) - actor->GetUserMatrix()->GetElement(0, 2),
|
cam->SetFocalPoint(m->GetElement(0, 3) - m->GetElement(0, 2),
|
||||||
actor->GetUserMatrix()->GetElement(1, 3) - actor->GetUserMatrix()->GetElement(1, 2),
|
m->GetElement(1, 3) - m->GetElement(1, 2),
|
||||||
actor->GetUserMatrix()->GetElement(2, 3) - actor->GetUserMatrix()->GetElement(2, 2));
|
m->GetElement(2, 3) - m->GetElement(2, 2));
|
||||||
|
|
||||||
cam->SetViewUp(actor->GetUserMatrix()->GetElement(0, 1),
|
cam->SetViewUp (m->GetElement(0, 1), m->GetElement(1, 1), m->GetElement(2, 1));
|
||||||
actor->GetUserMatrix()->GetElement(1, 1),
|
cam->SetPosition(m->GetElement(0, 3), m->GetElement(1, 3), m->GetElement(2, 3));
|
||||||
actor->GetUserMatrix()->GetElement(2, 1));
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -538,7 +516,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
|
// Check if there is a keyboard callback registered
|
||||||
if (keyboardCallback_)
|
if (keyboardCallback_)
|
||||||
keyboardCallback_(event, keyboard_callback_cookie_);
|
keyboardCallback_(event, keyboard_callback_cookie_);
|
||||||
@ -550,7 +528,7 @@ cv::viz::InteractorStyle::OnKeyDown()
|
|||||||
//////////////////////////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
void cv::viz::InteractorStyle::OnKeyUp()
|
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
|
// Check if there is a keyboard callback registered
|
||||||
if (keyboardCallback_)
|
if (keyboardCallback_)
|
||||||
keyboardCallback_(event, keyboard_callback_cookie_);
|
keyboardCallback_(event, keyboard_callback_cookie_);
|
||||||
@ -562,7 +540,7 @@ void cv::viz::InteractorStyle::OnKeyUp()
|
|||||||
void cv::viz::InteractorStyle::OnMouseMove()
|
void cv::viz::InteractorStyle::OnMouseMove()
|
||||||
{
|
{
|
||||||
Vec2i p(Interactor->GetEventPosition());
|
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_)
|
if (mouseCallback_)
|
||||||
mouseCallback_(event, mouse_callback_cookie_);
|
mouseCallback_(event, mouse_callback_cookie_);
|
||||||
Superclass::OnMouseMove();
|
Superclass::OnMouseMove();
|
||||||
@ -573,7 +551,7 @@ void cv::viz::InteractorStyle::OnLeftButtonDown()
|
|||||||
{
|
{
|
||||||
Vec2i p(Interactor->GetEventPosition());
|
Vec2i p(Interactor->GetEventPosition());
|
||||||
MouseEvent::Type type = (Interactor->GetRepeatCount() == 0) ? MouseEvent::MouseButtonPress : MouseEvent::MouseDblClick;
|
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_)
|
if (mouseCallback_)
|
||||||
mouseCallback_(event, mouse_callback_cookie_);
|
mouseCallback_(event, mouse_callback_cookie_);
|
||||||
Superclass::OnLeftButtonDown();
|
Superclass::OnLeftButtonDown();
|
||||||
@ -583,7 +561,7 @@ void cv::viz::InteractorStyle::OnLeftButtonDown()
|
|||||||
void cv::viz::InteractorStyle::OnLeftButtonUp()
|
void cv::viz::InteractorStyle::OnLeftButtonUp()
|
||||||
{
|
{
|
||||||
Vec2i p(Interactor->GetEventPosition());
|
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_)
|
if (mouseCallback_)
|
||||||
mouseCallback_(event, mouse_callback_cookie_);
|
mouseCallback_(event, mouse_callback_cookie_);
|
||||||
Superclass::OnLeftButtonUp();
|
Superclass::OnLeftButtonUp();
|
||||||
@ -595,7 +573,7 @@ void cv::viz::InteractorStyle::OnMiddleButtonDown()
|
|||||||
Vec2i p(Interactor->GetEventPosition());
|
Vec2i p(Interactor->GetEventPosition());
|
||||||
|
|
||||||
MouseEvent::Type type = (Interactor->GetRepeatCount() == 0) ? MouseEvent::MouseButtonPress : MouseEvent::MouseDblClick;
|
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_)
|
if (mouseCallback_)
|
||||||
mouseCallback_(event, mouse_callback_cookie_);
|
mouseCallback_(event, mouse_callback_cookie_);
|
||||||
Superclass::OnMiddleButtonDown();
|
Superclass::OnMiddleButtonDown();
|
||||||
@ -605,7 +583,7 @@ void cv::viz::InteractorStyle::OnMiddleButtonDown()
|
|||||||
void cv::viz::InteractorStyle::OnMiddleButtonUp()
|
void cv::viz::InteractorStyle::OnMiddleButtonUp()
|
||||||
{
|
{
|
||||||
Vec2i p(Interactor->GetEventPosition());
|
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_)
|
if (mouseCallback_)
|
||||||
mouseCallback_(event, mouse_callback_cookie_);
|
mouseCallback_(event, mouse_callback_cookie_);
|
||||||
Superclass::OnMiddleButtonUp();
|
Superclass::OnMiddleButtonUp();
|
||||||
@ -617,7 +595,7 @@ void cv::viz::InteractorStyle::OnRightButtonDown()
|
|||||||
Vec2i p(Interactor->GetEventPosition());
|
Vec2i p(Interactor->GetEventPosition());
|
||||||
|
|
||||||
MouseEvent::Type type = (Interactor->GetRepeatCount() == 0) ? MouseEvent::MouseButtonPress : MouseEvent::MouseDblClick;
|
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_)
|
if (mouseCallback_)
|
||||||
mouseCallback_(event, mouse_callback_cookie_);
|
mouseCallback_(event, mouse_callback_cookie_);
|
||||||
Superclass::OnRightButtonDown();
|
Superclass::OnRightButtonDown();
|
||||||
@ -627,7 +605,7 @@ void cv::viz::InteractorStyle::OnRightButtonDown()
|
|||||||
void cv::viz::InteractorStyle::OnRightButtonUp()
|
void cv::viz::InteractorStyle::OnRightButtonUp()
|
||||||
{
|
{
|
||||||
Vec2i p(Interactor->GetEventPosition());
|
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_)
|
if (mouseCallback_)
|
||||||
mouseCallback_(event, mouse_callback_cookie_);
|
mouseCallback_(event, mouse_callback_cookie_);
|
||||||
Superclass::OnRightButtonUp();
|
Superclass::OnRightButtonUp();
|
||||||
@ -637,7 +615,7 @@ void cv::viz::InteractorStyle::OnRightButtonUp()
|
|||||||
void cv::viz::InteractorStyle::OnMouseWheelForward()
|
void cv::viz::InteractorStyle::OnMouseWheelForward()
|
||||||
{
|
{
|
||||||
Vec2i p(Interactor->GetEventPosition());
|
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 a mouse callback registered, call it!
|
||||||
if (mouseCallback_)
|
if (mouseCallback_)
|
||||||
mouseCallback_(event, mouse_callback_cookie_);
|
mouseCallback_(event, mouse_callback_cookie_);
|
||||||
@ -669,7 +647,7 @@ void cv::viz::InteractorStyle::OnMouseWheelForward()
|
|||||||
void cv::viz::InteractorStyle::OnMouseWheelBackward()
|
void cv::viz::InteractorStyle::OnMouseWheelBackward()
|
||||||
{
|
{
|
||||||
Vec2i p(Interactor->GetEventPosition());
|
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 a mouse callback registered, call it!
|
||||||
if (mouseCallback_)
|
if (mouseCallback_)
|
||||||
mouseCallback_(event, mouse_callback_cookie_);
|
mouseCallback_(event, mouse_callback_cookie_);
|
||||||
@ -707,11 +685,8 @@ void cv::viz::InteractorStyle::OnTimer()
|
|||||||
Interactor->Render();
|
Interactor->Render();
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace cv
|
namespace cv { namespace viz
|
||||||
{
|
{
|
||||||
namespace viz
|
//Standard VTK macro for *New()
|
||||||
{
|
vtkStandardNewMacro(InteractorStyle)
|
||||||
//Standard VTK macro for *New()
|
}}
|
||||||
vtkStandardNewMacro(InteractorStyle)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@ -49,8 +49,6 @@
|
|||||||
#ifndef __OPENCV_VIZ_INTERACTOR_STYLE_H__
|
#ifndef __OPENCV_VIZ_INTERACTOR_STYLE_H__
|
||||||
#define __OPENCV_VIZ_INTERACTOR_STYLE_H__
|
#define __OPENCV_VIZ_INTERACTOR_STYLE_H__
|
||||||
|
|
||||||
#include <opencv2/viz/types.hpp>
|
|
||||||
|
|
||||||
namespace cv
|
namespace cv
|
||||||
{
|
{
|
||||||
namespace viz
|
namespace viz
|
||||||
@ -59,16 +57,9 @@ namespace cv
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
enum KeyboardModifier
|
enum KeyboardModifier { KB_MOD_ALT, KB_MOD_CTRL, KB_MOD_SHIFT };
|
||||||
{
|
|
||||||
KB_MOD_ALT,
|
|
||||||
KB_MOD_CTRL,
|
|
||||||
KB_MOD_SHIFT
|
|
||||||
};
|
|
||||||
|
|
||||||
static InteractorStyle *New();
|
static InteractorStyle *New();
|
||||||
|
|
||||||
InteractorStyle() {}
|
|
||||||
virtual ~InteractorStyle() {}
|
virtual ~InteractorStyle() {}
|
||||||
|
|
||||||
// this macro defines Superclass, the isA functionality and the safe downcast method
|
// this macro defines Superclass, the isA functionality and the safe downcast method
|
||||||
@ -77,32 +68,24 @@ namespace cv
|
|||||||
/** \brief Initialization routine. Must be called before anything else. */
|
/** \brief Initialization routine. Must be called before anything else. */
|
||||||
virtual void Initialize();
|
virtual void Initialize();
|
||||||
|
|
||||||
inline void setWidgetActorMap(const Ptr<WidgetActorMap>& actors) { widget_actor_map_ = actors; }
|
void setWidgetActorMap(const Ptr<WidgetActorMap>& actors) { widget_actor_map_ = actors; }
|
||||||
void setRenderer(vtkSmartPointer<vtkRenderer>& ren) { renderer_ = ren; }
|
void setRenderer(vtkSmartPointer<vtkRenderer>& ren) { renderer_ = ren; }
|
||||||
void registerMouseCallback(void (*callback)(const MouseEvent&, void*), void* cookie = 0);
|
void registerMouseCallback(void (*callback)(const MouseEvent&, void*), void* cookie = 0);
|
||||||
void registerKeyboardCallback(void (*callback)(const KeyboardEvent&, 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.*/
|
/** \brief Change the default keyboard modified from ALT to a different special key.*/
|
||||||
inline void setKeyboardModifier(const KeyboardModifier &modifier) { modifier_ = modifier; }
|
inline void setKeyboardModifier(const KeyboardModifier &modifier) { modifier_ = modifier; }
|
||||||
|
|
||||||
protected:
|
private:
|
||||||
/** \brief Set to true after initialization is complete. */
|
/** \brief Set to true after initialization is complete. */
|
||||||
bool init_;
|
bool init_;
|
||||||
|
|
||||||
/** \brief Collection of vtkRenderers stored internally. */
|
|
||||||
vtkSmartPointer<vtkRenderer> renderer_;
|
vtkSmartPointer<vtkRenderer> renderer_;
|
||||||
|
Ptr<WidgetActorMap> widget_actor_map_;
|
||||||
|
|
||||||
/** \brief Actor map stored internally. */
|
|
||||||
cv::Ptr<WidgetActorMap> widget_actor_map_;
|
|
||||||
|
|
||||||
/** \brief The current window width/height. */
|
|
||||||
Vec2i win_size_;
|
Vec2i win_size_;
|
||||||
|
|
||||||
/** \brief The current window position x/y. */
|
|
||||||
Vec2i win_pos_;
|
Vec2i win_pos_;
|
||||||
|
|
||||||
/** \brief The maximum resizeable window width/height. */
|
|
||||||
Vec2i max_win_size_;
|
Vec2i max_win_size_;
|
||||||
|
|
||||||
/** \brief A PNG writer for screenshot captures. */
|
/** \brief A PNG writer for screenshot captures. */
|
||||||
@ -145,6 +128,10 @@ namespace cv
|
|||||||
|
|
||||||
void (*mouseCallback_)(const MouseEvent&, void*);
|
void (*mouseCallback_)(const MouseEvent&, void*);
|
||||||
void *mouse_callback_cookie_;
|
void *mouse_callback_cookie_;
|
||||||
|
|
||||||
|
bool getAltKey();
|
||||||
|
bool getControlKey();
|
||||||
|
bool getShiftKey();
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -126,6 +126,9 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <opencv2/core.hpp>
|
#include <opencv2/core.hpp>
|
||||||
|
#include <opencv2/viz.hpp>
|
||||||
|
#include <opencv2/viz/widget_accessor.hpp>
|
||||||
|
#include <opencv2/core/utility.hpp>
|
||||||
|
|
||||||
namespace cv
|
namespace cv
|
||||||
{
|
{
|
||||||
@ -135,6 +138,7 @@ namespace cv
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#include "interactor_style.h"
|
||||||
#include "viz3d_impl.hpp"
|
#include "viz3d_impl.hpp"
|
||||||
|
|
||||||
namespace cv
|
namespace cv
|
||||||
@ -146,8 +150,5 @@ namespace cv
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#include <opencv2/viz.hpp>
|
|
||||||
#include <opencv2/viz/types.hpp>
|
|
||||||
#include "opencv2/viz/widget_accessor.hpp"
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -48,26 +48,6 @@
|
|||||||
|
|
||||||
#include "precomp.hpp"
|
#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
|
/// cv::viz::KeyboardEvent
|
||||||
|
|
||||||
|
@ -50,18 +50,9 @@
|
|||||||
|
|
||||||
cv::Affine3f cv::viz::makeTransformToGlobal(const Vec3f& axis_x, const Vec3f& axis_y, const Vec3f& axis_z, const Vec3f& origin)
|
cv::Affine3f cv::viz::makeTransformToGlobal(const Vec3f& axis_x, const Vec3f& axis_y, const Vec3f& axis_z, const Vec3f& origin)
|
||||||
{
|
{
|
||||||
Affine3f::Mat3 R;
|
Affine3f::Mat3 R(axis_x[0], axis_y[0], axis_z[0],
|
||||||
R.val[0] = axis_x.val[0];
|
axis_x[1], axis_y[1], axis_z[1],
|
||||||
R.val[3] = axis_x.val[1];
|
axis_x[2], axis_y[2], axis_z[2]);
|
||||||
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];
|
|
||||||
|
|
||||||
return Affine3f(R, origin);
|
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 u = normalize(y_dir.cross(n));
|
||||||
Vec3f v = n.cross(u);
|
Vec3f v = n.cross(u);
|
||||||
|
|
||||||
Matx44f pose_mat = Matx44f::zeros();
|
return makeTransformToGlobal(u, v, n, position);
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
vtkSmartPointer<vtkMatrix4x4> cv::viz::convertToVtkMatrix(const cv::Matx44f &m)
|
vtkSmartPointer<vtkMatrix4x4> cv::viz::convertToVtkMatrix(const cv::Matx44f &m)
|
||||||
@ -109,36 +85,31 @@ cv::Matx44f cv::viz::convertToMatx(const vtkSmartPointer<vtkMatrix4x4>& vtk_matr
|
|||||||
return m;
|
return m;
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace cv
|
namespace cv { namespace viz
|
||||||
{
|
{
|
||||||
namespace viz
|
template<typename _Tp> Vec<_Tp, 3>* vtkpoints_data(vtkSmartPointer<vtkPoints>& points);
|
||||||
|
|
||||||
|
template<> Vec3f* vtkpoints_data<float>(vtkSmartPointer<vtkPoints>& points)
|
||||||
{
|
{
|
||||||
template<typename _Tp> Vec<_Tp, 3>* vtkpoints_data(vtkSmartPointer<vtkPoints>& points);
|
CV_Assert(points->GetDataType() == VTK_FLOAT);
|
||||||
|
vtkDataArray *data = points->GetData();
|
||||||
template<> Vec3f* vtkpoints_data<float>(vtkSmartPointer<vtkPoints>& points)
|
float *pointer = static_cast<vtkFloatArray*>(data)->GetPointer(0);
|
||||||
{
|
return reinterpret_cast<Vec3f*>(pointer);
|
||||||
CV_Assert(points->GetDataType() == VTK_FLOAT);
|
|
||||||
vtkDataArray *data = points->GetData();
|
|
||||||
float *pointer = static_cast<vtkFloatArray*>(data)->GetPointer(0);
|
|
||||||
return reinterpret_cast<Vec3f*>(pointer);
|
|
||||||
}
|
|
||||||
|
|
||||||
template<> Vec3d* vtkpoints_data<double>(vtkSmartPointer<vtkPoints>& points)
|
|
||||||
{
|
|
||||||
CV_Assert(points->GetDataType() == VTK_DOUBLE);
|
|
||||||
vtkDataArray *data = points->GetData();
|
|
||||||
double *pointer = static_cast<vtkDoubleArray*>(data)->GetPointer(0);
|
|
||||||
return reinterpret_cast<Vec3d*>(pointer);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
template<> Vec3d* vtkpoints_data<double>(vtkSmartPointer<vtkPoints>& points)
|
||||||
|
{
|
||||||
|
CV_Assert(points->GetDataType() == VTK_DOUBLE);
|
||||||
|
vtkDataArray *data = points->GetData();
|
||||||
|
double *pointer = static_cast<vtkDoubleArray*>(data)->GetPointer(0);
|
||||||
|
return reinterpret_cast<Vec3d*>(pointer);
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
/// Viz accessor implementation
|
/// Viz accessor implementation
|
||||||
|
|
||||||
cv::viz::VizAccessor * cv::viz::VizAccessor::instance_ = 0;
|
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
|
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() { impl_ = new cv::viz::VizAccessor::VizAccessorImpl;}
|
||||||
|
cv::viz::VizAccessor::~VizAccessor() { delete impl_; }
|
||||||
cv::viz::VizAccessor::~VizAccessor()
|
|
||||||
{
|
|
||||||
if(impl_)
|
|
||||||
{
|
|
||||||
delete impl_;
|
|
||||||
impl_ = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
cv::viz::VizAccessor & cv::viz::VizAccessor::getInstance()
|
cv::viz::VizAccessor & cv::viz::VizAccessor::getInstance()
|
||||||
{
|
{
|
||||||
if (!is_instantiated_)
|
if (!instance_)
|
||||||
{
|
|
||||||
instance_ = new VizAccessor();
|
instance_ = new VizAccessor();
|
||||||
is_instantiated_ = true;
|
|
||||||
}
|
|
||||||
return *instance_;
|
return *instance_;
|
||||||
}
|
}
|
||||||
|
|
||||||
void cv::viz::VizAccessor::release()
|
void cv::viz::VizAccessor::release()
|
||||||
{
|
{
|
||||||
if (is_instantiated_)
|
if (instance_)
|
||||||
{
|
{
|
||||||
delete instance_;
|
delete instance_;
|
||||||
instance_ = 0;
|
instance_ = 0;
|
||||||
is_instantiated_ = false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -183,18 +143,15 @@ cv::viz::Viz3d cv::viz::VizAccessor::get(const String & window_name)
|
|||||||
generateWindowName(window_name, name);
|
generateWindowName(window_name, name);
|
||||||
|
|
||||||
VizMap::iterator vm_itr = impl_->viz_map.find(name);
|
VizMap::iterator vm_itr = impl_->viz_map.find(name);
|
||||||
bool exists = vm_itr != impl_->viz_map.end();
|
return vm_itr != impl_->viz_map.end() ? vm_itr->second : Viz3d(window_name);
|
||||||
if (exists) return vm_itr->second;
|
|
||||||
else return Viz3d(window_name);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void cv::viz::VizAccessor::add(Viz3d window)
|
void cv::viz::VizAccessor::add(Viz3d window)
|
||||||
{
|
{
|
||||||
String window_name = window.getWindowName();
|
String window_name = window.getWindowName();
|
||||||
VizMap::iterator vm_itr = impl_->viz_map.find(window_name);
|
VizMap::iterator vm_itr = impl_->viz_map.find(window_name);
|
||||||
bool exists = vm_itr != impl_->viz_map.end();
|
if (vm_itr == impl_->viz_map.end())
|
||||||
if (exists) return ;
|
impl_->viz_map.insert(VizPair(window_name, window));
|
||||||
impl_->viz_map.insert(VizPair(window_name, window));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void cv::viz::VizAccessor::remove(const String &window_name)
|
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);
|
generateWindowName(window_name, name);
|
||||||
|
|
||||||
VizMap::iterator vm_itr = impl_->viz_map.find(name);
|
VizMap::iterator vm_itr = impl_->viz_map.find(name);
|
||||||
bool exists = vm_itr != impl_->viz_map.end();
|
if (vm_itr != impl_->viz_map.end())
|
||||||
if (!exists) return ;
|
impl_->viz_map.erase(vm_itr);
|
||||||
impl_->viz_map.erase(vm_itr);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void cv::viz::VizAccessor::generateWindowName(const String &window_name, String &output)
|
void cv::viz::VizAccessor::generateWindowName(const String &window_name, String &output)
|
||||||
{
|
{
|
||||||
output = "Viz";
|
output = "Viz";
|
||||||
// Already is Viz
|
// Already is Viz
|
||||||
if (window_name == output) return;
|
if (window_name == output)
|
||||||
|
return;
|
||||||
|
|
||||||
String prefixed = output + " - ";
|
String prefixed = output + " - ";
|
||||||
if (window_name.substr(0, prefixed.length()) == prefixed) output = window_name; // Already has "Viz - "
|
if (window_name.substr(0, prefixed.length()) == prefixed)
|
||||||
else if (window_name.substr(0, output.length()) == output) output = prefixed + window_name; // Doesn't have prefix
|
output = window_name; // Already has "Viz - "
|
||||||
else output = (window_name == "" ? output : prefixed + window_name);
|
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)
|
cv::viz::Viz3d cv::viz::get(const String &window_name)
|
||||||
|
@ -46,8 +46,7 @@
|
|||||||
//
|
//
|
||||||
//M*/
|
//M*/
|
||||||
|
|
||||||
#include <opencv2/viz/viz3d.hpp>
|
#include "precomp.hpp"
|
||||||
#include "viz3d_impl.hpp"
|
|
||||||
|
|
||||||
cv::viz::Viz3d::Viz3d(const String& window_name) : impl_(0) { create(window_name); }
|
cv::viz::Viz3d::Viz3d(const String& window_name) : impl_(0) { create(window_name); }
|
||||||
|
|
||||||
|
@ -47,10 +47,6 @@
|
|||||||
//M*/
|
//M*/
|
||||||
|
|
||||||
#include "precomp.hpp"
|
#include "precomp.hpp"
|
||||||
#include "viz3d_impl.hpp"
|
|
||||||
#include "opencv2/core/utility.hpp"
|
|
||||||
|
|
||||||
#include <vtkRenderWindowInteractor.h>
|
|
||||||
|
|
||||||
#if 1 || !defined __APPLE__
|
#if 1 || !defined __APPLE__
|
||||||
vtkRenderWindowInteractor* vtkRenderWindowInteractorFixNew()
|
vtkRenderWindowInteractor* vtkRenderWindowInteractorFixNew()
|
||||||
@ -61,9 +57,7 @@ vtkRenderWindowInteractor* vtkRenderWindowInteractorFixNew()
|
|||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
cv::viz::Viz3d::VizImpl::VizImpl(const String &name)
|
cv::viz::Viz3d::VizImpl::VizImpl(const String &name)
|
||||||
: style_(vtkSmartPointer<cv::viz::InteractorStyle>::New())
|
: style_(vtkSmartPointer<cv::viz::InteractorStyle>::New()) , widget_actor_map_(new WidgetActorMap), s_lastDone_(0.0)
|
||||||
, widget_actor_map_(new WidgetActorMap)
|
|
||||||
, s_lastDone_(0.0)
|
|
||||||
{
|
{
|
||||||
renderer_ = vtkSmartPointer<vtkRenderer>::New();
|
renderer_ = vtkSmartPointer<vtkRenderer>::New();
|
||||||
|
|
||||||
@ -128,7 +122,8 @@ cv::viz::Viz3d::VizImpl::~VizImpl()
|
|||||||
{
|
{
|
||||||
if (interactor_)
|
if (interactor_)
|
||||||
interactor_->DestroyTimer(timer_id_);
|
interactor_->DestroyTimer(timer_id_);
|
||||||
if (renderer_) renderer_->Clear();
|
if (renderer_)
|
||||||
|
renderer_->Clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
@ -395,7 +390,7 @@ cv::viz::Camera cv::viz::Viz3d::VizImpl::getCamera() const
|
|||||||
|
|
||||||
Size window_size(renderer_->GetRenderWindow()->GetSize()[0],
|
Size window_size(renderer_->GetRenderWindow()->GetSize()[0],
|
||||||
renderer_->GetRenderWindow()->GetSize()[1]);
|
renderer_->GetRenderWindow()->GetSize()[1]);
|
||||||
double aspect_ratio = static_cast<double>(window_size.width) / static_cast<double>(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));
|
Matx44f proj_matrix = convertToMatx(active_camera.GetProjectionTransformMatrix(aspect_ratio, -1.0f, 1.0f));
|
||||||
Camera camera(proj_matrix, window_size);
|
Camera camera(proj_matrix, window_size);
|
||||||
|
@ -49,9 +49,6 @@
|
|||||||
#ifndef __OPENCV_VIZ_VIZ3D_IMPL_HPP__
|
#ifndef __OPENCV_VIZ_VIZ3D_IMPL_HPP__
|
||||||
#define __OPENCV_VIZ_VIZ3D_IMPL_HPP__
|
#define __OPENCV_VIZ_VIZ3D_IMPL_HPP__
|
||||||
|
|
||||||
#include <opencv2/viz.hpp>
|
|
||||||
#include "interactor_style.h"
|
|
||||||
|
|
||||||
struct cv::viz::Viz3d::VizImpl
|
struct cv::viz::Viz3d::VizImpl
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@ -127,10 +124,7 @@ private:
|
|||||||
|
|
||||||
struct ExitMainLoopTimerCallback : public vtkCommand
|
struct ExitMainLoopTimerCallback : public vtkCommand
|
||||||
{
|
{
|
||||||
static ExitMainLoopTimerCallback* New()
|
static ExitMainLoopTimerCallback* New() { return new ExitMainLoopTimerCallback; }
|
||||||
{
|
|
||||||
return new ExitMainLoopTimerCallback;
|
|
||||||
}
|
|
||||||
virtual void Execute(vtkObject* vtkNotUsed(caller), unsigned long event_id, void* call_data)
|
virtual void Execute(vtkObject* vtkNotUsed(caller), unsigned long event_id, void* call_data)
|
||||||
{
|
{
|
||||||
if (event_id != vtkCommand::TimerEvent)
|
if (event_id != vtkCommand::TimerEvent)
|
||||||
@ -149,10 +143,7 @@ private:
|
|||||||
|
|
||||||
struct ExitCallback : public vtkCommand
|
struct ExitCallback : public vtkCommand
|
||||||
{
|
{
|
||||||
static ExitCallback* New()
|
static ExitCallback* New() { return new ExitCallback; }
|
||||||
{
|
|
||||||
return new ExitCallback;
|
|
||||||
}
|
|
||||||
virtual void Execute(vtkObject*, unsigned long event_id, void*)
|
virtual void Execute(vtkObject*, unsigned long event_id, void*)
|
||||||
{
|
{
|
||||||
if (event_id == vtkCommand::ExitEvent)
|
if (event_id == vtkCommand::ExitEvent)
|
||||||
@ -191,21 +182,7 @@ private:
|
|||||||
|
|
||||||
bool removeActorFromRenderer(const vtkSmartPointer<vtkProp> &actor);
|
bool removeActorFromRenderer(const vtkSmartPointer<vtkProp> &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<vtkDataSet> &data, vtkSmartPointer<vtkLODActor> &actor, bool use_scalars = true);
|
void createActorFromVTKDataSet(const vtkSmartPointer<vtkDataSet> &data, vtkSmartPointer<vtkLODActor> &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<vtkIdTypeArray> &cells, vtkSmartPointer<vtkIdTypeArray> &initcells, vtkIdType nr_points);
|
void updateCells(vtkSmartPointer<vtkIdTypeArray> &cells, vtkSmartPointer<vtkIdTypeArray> &initcells, vtkIdType nr_points);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -60,6 +60,8 @@
|
|||||||
#include "opencv2/ts.hpp"
|
#include "opencv2/ts.hpp"
|
||||||
#include <opencv2/core.hpp>
|
#include <opencv2/core.hpp>
|
||||||
#include <opencv2/imgproc.hpp>
|
#include <opencv2/imgproc.hpp>
|
||||||
|
#include <opencv2/highgui.hpp>
|
||||||
|
#include <opencv2/viz.hpp>
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
86
modules/viz/test/test_tutorial3.cpp
Normal file
86
modules/viz/test/test_tutorial3.cpp
Normal file
@ -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<cv::Point3f>();
|
||||||
|
//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, DISABLED_tutorial3_global_view)
|
||||||
|
{
|
||||||
|
tutorial3(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(Viz_viz3d, DISABLED_tutorial3_camera_view)
|
||||||
|
{
|
||||||
|
tutorial3(true);
|
||||||
|
}
|
@ -40,13 +40,11 @@
|
|||||||
//
|
//
|
||||||
//M*/
|
//M*/
|
||||||
#include "test_precomp.hpp"
|
#include "test_precomp.hpp"
|
||||||
#include <opencv2/viz.hpp>
|
|
||||||
#include <opencv2/highgui.hpp>
|
|
||||||
#include <string>
|
|
||||||
|
|
||||||
using namespace cv;
|
using namespace cv;
|
||||||
|
|
||||||
cv::Mat cvcloud_load()
|
static cv::Mat cvcloud_load()
|
||||||
{
|
{
|
||||||
cv::Mat cloud(1, 20000, CV_32FC3);
|
cv::Mat cloud(1, 20000, CV_32FC3);
|
||||||
std::ifstream ifs("/Users/nerei/cloud_dragon.ply");
|
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");
|
cv::viz::Viz3d viz("abc");
|
||||||
|
|
||||||
@ -98,19 +96,18 @@ TEST(Viz_viz3d, accuracy)
|
|||||||
cv::viz::WMesh bunny_widget(bunny_mesh);
|
cv::viz::WMesh bunny_widget(bunny_mesh);
|
||||||
bunny_widget.setColor(cv::viz::Color::cyan());
|
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);
|
cam_coordinates = cv::viz::WCameraPosition(0.2);
|
||||||
|
|
||||||
viz.showWidget("bunny", bunny_widget);
|
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_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.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.f,0.f,0.f), Point3f(0.f,0.f,0.f), Point3f(0.f,1.f,0.f)));
|
||||||
|
|
||||||
std::vector<Affine3f> cam_path;
|
std::vector<Affine3f> cam_path;
|
||||||
|
|
||||||
for (int i = 0, j = 0; i <= 360; ++i, j+=5)
|
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)),
|
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)));
|
||||||
Point3f(0.0,0.0,0.0), Point3f(0.0,1.0,0.0)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int path_counter = 0;
|
int path_counter = 0;
|
||||||
@ -133,7 +130,7 @@ TEST(Viz_viz3d, accuracy)
|
|||||||
colors[col] = Mat::zeros(img.rows/downSample, 1, CV_8UC3);
|
colors[col] = Mat::zeros(img.rows/downSample, 1, CV_8UC3);
|
||||||
for (int row = 0; row < row_max; ++row)
|
for (int row = 0; row < row_max; ++row)
|
||||||
{
|
{
|
||||||
clouds[col].at<Vec3f>(row) = Vec3f(downSample * float(col) / img.cols, 1.0-(downSample * float(row) / img.rows), 0.0);
|
clouds[col].at<Vec3f>(row) = Vec3f(downSample * float(col) / img.cols, 1.f-(downSample * float(row) / img.rows), 0.f);
|
||||||
colors[col].at<Vec3b>(row) = img.at<Vec3b>(row*downSample,col*downSample);
|
colors[col].at<Vec3b>(row) = img.at<Vec3b>(row*downSample,col*downSample);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -174,9 +171,11 @@ TEST(Viz_viz3d, accuracy)
|
|||||||
{
|
{
|
||||||
std::stringstream strstrm;
|
std::stringstream strstrm;
|
||||||
strstrm << "cloud_" << i;
|
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;
|
angle += 10;
|
||||||
viz.spinOnce(42, true);
|
viz.spinOnce(42, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
volatile void* a = (void*)&cvcloud_load; (void)a; //fixing warnings
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user