1 #include <visp3/core/vpConfig.h>
3 #include <visp3/gui/vpDisplayX.h>
4 #include <visp3/gui/vpDisplayGDI.h>
5 #include <visp3/gui/vpDisplayOpenCV.h>
6 #include <visp3/mbt/vpMbEdgeTracker.h>
7 #include <visp3/io/vpVideoReader.h>
8 #include <visp3/vision/vpKeyPoint.h>
9 #include <visp3/core/vpIoTools.h>
12 int main(
int argc,
char ** argv) {
13 #if defined(VISP_HAVE_OPENCV) && ((VISP_HAVE_OPENCV_VERSION >= 0x020400) || defined(VISP_HAVE_FFMPEG))
16 std::string videoname =
"teabox.mpg";
18 for (
int i=0; i<argc; i++) {
19 if (std::string(argv[i]) ==
"--name")
20 videoname = std::string(argv[i+1]);
21 else if (std::string(argv[i]) ==
"--help") {
22 std::cout <<
"\nUsage: " << argv[0] <<
" [--name <video name>] [--help]\n" << std::endl;
29 if(! parentname.empty())
30 objectname = parentname +
"/" + objectname;
32 std::cout <<
"Video name: " << videoname << std::endl;
33 std::cout <<
"Tracker requested config files: " << objectname
38 <<
"cao or wrl]" << std::endl;
39 std::cout <<
"Tracker optional config files: " << objectname <<
".[ppm]" << std::endl;
49 #if defined(VISP_HAVE_X11)
51 #elif defined(VISP_HAVE_GDI)
53 #elif defined(VISP_HAVE_OPENCV)
56 std::cout <<
"No image viewer is available..." << std::endl;
60 display.
init(I, 100, 100,
"Model-based edge tracker");
97 tracker.
initClick(I, objectname +
".init",
true);
102 std::string detectorName =
"FAST";
103 std::string extractorName =
"ORB";
104 std::string matcherName =
"BruteForce-Hamming";
105 std::string configurationFile =
"detection-config.xml";
107 #if (defined(VISP_HAVE_OPENCV_NONFREE) || defined(VISP_HAVE_OPENCV_XFEATURES2D))
108 detectorName =
"SIFT";
109 extractorName =
"SIFT";
110 matcherName =
"BruteForce";
111 configurationFile =
"detection-config-SIFT.xml";
120 #ifdef VISP_HAVE_XML2
133 std::vector<cv::KeyPoint> trainKeyPoints;
135 keypoint_learning.
detect(I, trainKeyPoints, elapsedTime);
139 std::vector<vpPolygon> polygons;
140 std::vector<std::vector<vpPoint> > roisPt;
141 std::pair<std::vector<vpPolygon>, std::vector<std::vector<vpPoint> > > pair = tracker.
getPolygonFaces(
false);
142 polygons = pair.first;
143 roisPt = pair.second;
145 std::vector<cv::Point3f> points3f;
160 for(std::vector<cv::KeyPoint>::const_iterator it = trainKeyPoints.begin(); it != trainKeyPoints.end(); ++it) {
172 #ifdef VISP_HAVE_XML2
194 bool click_done =
false;
203 if(keypoint_detection.
matchPoint(I, cam, cMo, error, elapsedTime)) {
224 #ifdef VISP_HAVE_XML2
227 #if defined(VISP_HAVE_COIN3D) && (COIN_MAJOR_VERSION == 3)
232 std::cout <<
"Catch an exception: " << e << std::endl;
237 std::cout <<
"Install OpenCV or ffmpeg and rebuild ViSP to use this example." << std::endl;
virtual void setDisplayFeatures(const bool displayF)
void setRansacIteration(const int nbIter)
void setMovingEdge(const vpMe &me)
void setUseRansacVVS(const bool ransacVVS)
static bool getClick(const vpImage< unsigned char > &I, bool blocking=true)
virtual unsigned int getClipping() const
virtual void setAngleDisappear(const double &a)
Implementation of an homogeneous matrix and operations on such kind of matrices.
void track(const vpImage< unsigned char > &I)
void setMaskNumber(const unsigned int &a)
void setRansacThreshold(const double threshold)
Display for windows using GDI (available on any windows 32 platform).
void setSampleStep(const double &s)
static void displayText(const vpImage< unsigned char > &I, const vpImagePoint &ip, const std::string &s, const vpColor &color)
void setNbTotalSample(const int &nb)
Use the X11 console to display images on unix-like OS. Thus to enable this class X11 should be instal...
Class that enables to manipulate easily a video file or a sequence of images. As it inherits from the...
static const vpColor none
error that can be emited by ViSP classes.
void init(vpImage< unsigned char > &I, int winx=-1, int winy=-1, const std::string &title="")
Make the complete tracking of an object by using its CAD model.
virtual void setPose(const vpImage< unsigned char > &I, const vpHomogeneousMatrix &cdMo)
virtual void setCameraParameters(const vpCameraParameters &camera)
void loadConfigFile(const std::string &configFile)
static void flush(const vpImage< unsigned char > &I)
void setMu1(const double &mu_1)
void initPersProjWithoutDistortion(const double px, const double py, const double u0, const double v0)
virtual void setNearClippingDistance(const double &dist)
virtual void setOgreVisibilityTest(const bool &v)
void setMatcher(const std::string &matcherName)
void open(vpImage< vpRGBa > &I)
static void compute3DForPointsInPolygons(const vpHomogeneousMatrix &cMo, const vpCameraParameters &cam, std::vector< cv::KeyPoint > &candidates, const std::vector< vpPolygon > &polygons, const std::vector< std::vector< vpPoint > > &roisPt, std::vector< cv::Point3f > &points, cv::Mat *descriptors=NULL)
void setMaskSize(const unsigned int &a)
static void display(const vpImage< unsigned char > &I)
The vpDisplayOpenCV allows to display image using the OpenCV library. Thus to enable this class OpenC...
virtual void getCameraParameters(vpCameraParameters &camera) const
Generic class defining intrinsic camera parameters.
void setDetector(const vpFeatureDetectorType &detectorType)
void acquire(vpImage< vpRGBa > &I)
unsigned int buildReference(const vpImage< unsigned char > &I)
virtual void setFarClippingDistance(const double &dist)
void setFileName(const char *filename)
virtual void setAngleAppear(const double &a)
virtual void initClick(const vpImage< unsigned char > &I, const std::string &initFile, const bool displayHelp=false)
static double rad(double deg)
unsigned int matchPoint(const vpImage< unsigned char > &I)
void setRansacConsensusPercentage(const double percentage)
static void displayFrame(const vpImage< unsigned char > &I, const vpHomogeneousMatrix &cMo, const vpCameraParameters &cam, double size, const vpColor &color=vpColor::none, unsigned int thickness=1, vpImagePoint offset=vpImagePoint(0, 0))
static void displayCross(const vpImage< unsigned char > &I, const vpImagePoint &ip, unsigned int size, const vpColor &color, unsigned int thickness=1)
void setMu2(const double &mu_2)
void loadLearningData(const std::string &filename, const bool binaryMode=false, const bool append=false)
virtual void loadModel(const char *modelFile, const bool verbose=false)
Class that allows keypoints detection (and descriptors extraction) and matching thanks to OpenCV libr...
void saveLearningData(const std::string &filename, const bool binaryMode=false, const bool saveTrainingImages=true)
virtual void getPose(vpHomogeneousMatrix &cMo_) const
void setThreshold(const double &t)
void display(const vpImage< unsigned char > &I, const vpHomogeneousMatrix &cMo, const vpCameraParameters &cam, const vpColor &col, const unsigned int thickness=1, const bool displayFullModel=false)
void setUseRansacConsensusPercentage(const bool usePercentage)
void loadConfigFile(const std::string &configFile)
void setFilterMatchingType(const vpFilterMatchingType &filterType)
void setRange(const unsigned int &r)
virtual void setClipping(const unsigned int &flags)
void setExtractor(const vpFeatureDescriptorType &extractorType)
void setMatchingRatioThreshold(const double ratio)
virtual std::pair< std::vector< vpPolygon >, std::vector< std::vector< vpPoint > > > getPolygonFaces(const bool orderPolygons=true, const bool useVisibility=true, const bool clipPolygon=false)
void detect(const vpImage< unsigned char > &I, std::vector< cv::KeyPoint > &keyPoints, const vpRect &rectangle=vpRect())