1 #include <visp3/gui/vpDisplayOpenCV.h>
3 #include <visp3/vision/vpHomography.h>
4 #include <visp3/vision/vpKeyPoint.h>
5 #include <visp3/core/vpPixelMeterConversion.h>
6 #include <visp3/io/vpVideoReader.h>
8 int main(
int argc,
const char **argv)
10 #if (VISP_HAVE_OPENCV_VERSION >= 0x020101)
15 method = atoi(argv[1]);
18 std::cout <<
"Uses Ransac to estimate the homography" << std::endl;
20 std::cout <<
"Uses a robust scheme to estimate the homography" << std::endl;
29 const std::string detectorName =
"ORB";
30 const std::string extractorName =
"ORB";
32 const std::string matcherName =
"BruteForce-Hamming";
34 vpKeyPoint keypoint(detectorName, extractorName, matcherName, filterType);
35 keypoint.buildReference(I);
48 corner_ref[0].
set_ij(115, 64);
49 corner_ref[1].
set_ij( 83, 253);
50 corner_ref[2].
set_ij(282, 307);
51 corner_ref[3].
set_ij(330, 72);
54 for (
unsigned int i=0; i<4; i++) {
66 while ( ! reader.
end() )
74 unsigned int nbMatch = keypoint.matchPoint(I);
75 std::cout <<
"Nb matches: " << nbMatch << std::endl;
78 std::vector<vpImagePoint> iPref(nbMatch), iPcur(nbMatch);
80 std::vector<double> mPref_x(nbMatch), mPref_y(nbMatch);
81 std::vector<double> mPcur_x(nbMatch), mPcur_y(nbMatch);
82 std::vector<bool> inliers(nbMatch);
85 for (
unsigned int i = 0; i < nbMatch; i++) {
86 keypoint.getMatchedPoints(i, iPref[i], iPcur[i]);
98 (
unsigned int)(mPref_x.size()*0.25), 2.0/cam.
get_px(),
true);
104 std::cout <<
"Cannot compute homography from matches..." << std::endl;
111 for (
int i=0; i< 4; i++) {
118 for (
int i=0; i< 4; i++) {
120 corner_cur[i] + offset,
121 corner_cur[(i+1)%4] + offset,
127 for (
unsigned int i = 0; i < nbMatch; i++) {
128 if(inliers[i] ==
true)
143 (void)argc; (void)argv;
static vpImagePoint project(const vpCameraParameters &cam, const vpHomography &bHa, const vpImagePoint &iPa)
unsigned int getWidth() const
Class that enables to manipulate easily a video file or a sequence of images. As it inherits from the...
static void convertPoint(const vpCameraParameters &cam, const double &u, const double &v, double &x, double &y)
Point coordinates conversion from pixel coordinates to normalized coordinates in meter...
static const vpColor green
static void flush(const vpImage< unsigned char > &I)
Implementation of an homography and operations on homographies.
static void display(const vpImage< unsigned char > &I)
The vpDisplayOpenCV allows to display image using the opencv library.
virtual void displayCross(const vpImagePoint &ip, unsigned int size, const vpColor &color, unsigned int thickness=1)=0
Generic class defining intrinsic camera parameters.
static bool ransac(const std::vector< double > &xb, const std::vector< double > &yb, const std::vector< double > &xa, const std::vector< double > &ya, vpHomography &aHb, std::vector< bool > &inliers, double &residual, unsigned int nbInliersConsensus, double threshold, bool normalization=true)
void acquire(vpImage< vpRGBa > &I)
void resize(const unsigned int h, const unsigned int w)
set the size of the image without initializing it.
void setFileName(const char *filename)
static void robust(const std::vector< double > &xb, const std::vector< double > &yb, const std::vector< double > &xa, const std::vector< double > &ya, vpHomography &aHb, std::vector< bool > &inlier, double &residual, double weights_threshold=0.4, unsigned int niter=4, bool normalization=true)
Class that allows keypoints detection (and descriptors extraction) and matching thanks to OpenCV libr...
void insert(const vpImage< Type > &src, const vpImagePoint topLeft)
unsigned int getHeight() const
virtual bool getClick(bool blocking=true)=0
Class that defines a 2D point in an image. This class is useful for image processing and stores only ...
virtual void displayLine(const vpImagePoint &ip1, const vpImagePoint &ip2, const vpColor &color, unsigned int thickness=1)=0
static const vpColor white
void set_ij(const double ii, const double jj)
static const vpColor blue