1 #include <visp3/core/vpConfig.h> 3 #include <visp3/core/vpIoTools.h> 4 #include <visp3/gui/vpDisplayGDI.h> 5 #include <visp3/gui/vpDisplayOpenCV.h> 6 #include <visp3/gui/vpDisplayX.h> 7 #include <visp3/io/vpVideoReader.h> 8 #include <visp3/mbt/vpMbGenericTracker.h> 9 #include <visp3/vision/vpKeyPoint.h> 11 int main(
int argc,
char **argv)
13 #if (VISP_HAVE_OPENCV_VERSION >= 0x020400) 16 std::string videoname =
"teabox.mp4";
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" || std::string(argv[i]) ==
"-h") {
22 std::cout <<
"\nUsage: " << argv[0] <<
" [--name <video name>] [--help] [-h]\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 <<
".[init," 35 <<
"cao or wrl]" << std::endl;
36 std::cout <<
"Tracker optional config files: " << objectname <<
".[ppm]" << std::endl;
46 #if defined(VISP_HAVE_X11) 48 #elif defined(VISP_HAVE_GDI) 50 #elif defined(VISP_HAVE_OPENCV) 53 std::cout <<
"No image viewer is available..." << std::endl;
57 display.
init(I, 100, 100,
"Model-based edge tracker");
62 tracker.loadConfigFile(objectname +
".xml");
63 tracker.getCameraParameters(cam);
76 tracker.setMovingEdge(me);
78 tracker.setCameraParameters(cam);
81 tracker.setNearClippingDistance(0.1);
82 tracker.setFarClippingDistance(100.0);
86 tracker.setOgreVisibilityTest(
false);
88 tracker.loadModel(objectname +
".cao");
90 tracker.loadModel(objectname +
".wrl");
91 tracker.setDisplayFeatures(
true);
92 tracker.initClick(I, objectname +
".init",
true);
97 #if (defined(VISP_HAVE_OPENCV_NONFREE) || defined(VISP_HAVE_OPENCV_XFEATURES2D)) || \ 98 (VISP_HAVE_OPENCV_VERSION >= 0x030411 && CV_MAJOR_VERSION < 4) || (VISP_HAVE_OPENCV_VERSION >= 0x040400) 99 std::string detectorName =
"SIFT";
100 std::string extractorName =
"SIFT";
101 std::string matcherName =
"BruteForce";
102 std::string configurationFile =
"detection-config-SIFT.xml";
104 std::string detectorName =
"FAST";
105 std::string extractorName =
"ORB";
106 std::string matcherName =
"BruteForce-Hamming";
107 std::string configurationFile =
"detection-config.xml";
127 std::vector<cv::KeyPoint> trainKeyPoints;
129 keypoint_learning.
detect(I, trainKeyPoints, elapsedTime);
133 std::vector<vpPolygon> polygons;
134 std::vector<std::vector<vpPoint> > roisPt;
135 std::pair<std::vector<vpPolygon>, std::vector<std::vector<vpPoint> > > pair = tracker.getPolygonFaces(
false);
136 polygons = pair.first;
137 roisPt = pair.second;
139 std::vector<cv::Point3f> points3f;
140 tracker.getPose(cMo);
154 for (std::vector<cv::KeyPoint>::const_iterator it = trainKeyPoints.begin(); it != trainKeyPoints.end(); ++it) {
186 bool click_done =
false;
195 if (keypoint_detection.
matchPoint(I, cam, cMo, error, elapsedTime)) {
199 tracker.setPose(I, cMo);
217 std::cout <<
"Catch an exception: " << e << std::endl;
222 std::cout <<
"Install OpenCV and rebuild ViSP to use this example." << std::endl;
void loadLearningData(const std::string &filename, bool binaryMode=false, bool append=false)
static bool getClick(const vpImage< unsigned char > &I, bool blocking=true)
void setUseRansacConsensusPercentage(bool usePercentage)
void setRansacIteration(int nbIter)
Implementation of an homogeneous matrix and operations on such kind of matrices.
void setMaskNumber(const unsigned int &a)
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="")
Real-time 6D object pose tracking using its CAD model.
static void flush(const vpImage< unsigned char > &I)
void setMu1(const double &mu_1)
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...
Generic class defining intrinsic camera parameters.
void setDetector(const vpFeatureDetectorType &detectorType)
void acquire(vpImage< vpRGBa > &I)
unsigned int buildReference(const vpImage< unsigned char > &I)
void setRansacConsensusPercentage(double percentage)
void setMatchingRatioThreshold(double ratio)
void saveLearningData(const std::string &filename, bool binaryMode=false, bool saveTrainingImages=true)
static double rad(double deg)
void initPersProjWithoutDistortion(double px, double py, double u0, double v0)
unsigned int matchPoint(const vpImage< unsigned char > &I)
void setUseRansacVVS(bool ransacVVS)
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)
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, const vpImagePoint &offset=vpImagePoint(0, 0))
Class that allows keypoints detection (and descriptors extraction) and matching thanks to OpenCV libr...
void setThreshold(const double &t)
void setFileName(const std::string &filename)
void setRansacThreshold(double threshold)
void loadConfigFile(const std::string &configFile)
void setFilterMatchingType(const vpFilterMatchingType &filterType)
void setRange(const unsigned int &r)
void setExtractor(const vpFeatureDescriptorType &extractorType)
void detect(const vpImage< unsigned char > &I, std::vector< cv::KeyPoint > &keyPoints, const vpRect &rectangle=vpRect())