42 #include <visp/vpPlanarObjectDetector.h>
44 #if (VISP_HAVE_OPENCV_VERSION >= 0x020000) // Require opencv >= 2.0.0
46 #include <visp/vpImageConvert.h>
47 #include <visp/vpException.h>
48 #include <visp/vpImagePoint.h>
49 #include <visp/vpDisplay.h>
50 #include <visp/vpDisplayX.h>
51 #include <visp/vpColor.h>
52 #include <visp/vpImageTools.h>
83 load(_dataFile, _objectName);
120 std::vector < vpImagePoint > ptsx(nbpt);
121 std::vector < vpImagePoint > ptsy(nbpt);
122 for(
unsigned int i=0; i<nbpt; i++){
123 ptsx[i] = ptsy[i] = ip[i];
126 for(
unsigned int i=0; i<nbpt; i++){
127 for(
unsigned int j=0; j<nbpt-1; j++){
128 if(ptsx[j].get_j() > ptsx[j+1].get_j()){
129 double tmp = ptsx[j+1].
get_j();
130 ptsx[j+1].set_j(ptsx[j].get_j());
135 for(
unsigned int i=0; i<nbpt; i++){
136 for(
unsigned int j=0; j<nbpt-1; j++){
137 if(ptsy[j].get_i() > ptsy[j+1].get_i()){
138 double tmp = ptsy[j+1].get_i();
139 ptsy[j+1].set_i(ptsy[j].get_i());
188 unsigned int _height,
unsigned int _width)
251 for(
unsigned int i=0; i<refPts.size(); ++i){
255 for(
unsigned int i=0; i<curPts.size(); ++i){
260 if(curPts.size() < 4){
261 for (
unsigned int i = 0; i < 3; i += 1){
262 for (
unsigned int j = 0; j < 3; j += 1){
275 std::vector<unsigned char> mask;
276 H = cv::findHomography(cv::Mat(refPts), cv::Mat(curPts), mask, cv::RANSAC, 10);
280 const cv::Mat_<double>& H_tmp =
H;
282 for(
unsigned int i = 0; i < 4; i++ )
286 double w = 1./(H_tmp(2,0)*pt.x + H_tmp(2,1)*pt.y + H_tmp(2,2));
287 dst_corners[i] = cv::Point2f((
float)((H_tmp(0,0)*pt.x + H_tmp(0,1)*pt.y + H_tmp(0,2))*w),
288 (
float)((H_tmp(1,0)*pt.x + H_tmp(1,1)*pt.y + H_tmp(1,2))*w));
291 double* ptr = (
double*)H_tmp.data;
292 for(
unsigned int i=0; i<9; i++){
293 this->
homography[(
unsigned int)(i/3)][i%3] = *(ptr++);
304 for (
unsigned int i = 0; i < mask.size(); i += 1){
307 ip.
set_i(curPts[i].y);
308 ip.
set_j(curPts[i].x);
310 ip.
set_i(refPts[i].y);
311 ip.
set_j(refPts[i].x);
340 const vpImagePoint &iP,
const unsigned int height,
const unsigned int width)
344 vpTRACE(
"Bad size for the subimage");
346 "Bad size for the subimage"));
352 (
unsigned int)iP.
get_i(),
353 (
unsigned int)iP.
get_j(),
354 height, width, subImage);
378 (
unsigned int)rectangle.
getWidth()));
435 display(Icurrent, displayKpts);
484 std::vector<vpImagePoint>
487 std::vector <vpImagePoint> corners;
491 corners.push_back(ip);
507 ip.y = (float)_modelROI.y;
508 ip.x = (
float)_modelROI.x;
511 ip.y = (float)(_modelROI.y+_modelROI.height);
512 ip.x = (float)_modelROI.x;
515 ip.y = (float)(_modelROI.y+_modelROI.height);
516 ip.x = (float)(_modelROI.x+_modelROI.width);
519 ip.y = (float)_modelROI.y;
520 ip.x = (
float)(_modelROI.x+_modelROI.width);
void set_j(const double j)
void initialiseRefCorners(const cv::Rect &_modelROI)
unsigned int getWidth() const
virtual unsigned int matchPoint(const vpImage< unsigned char > &I)
void computeRoi(vpImagePoint *ip, const unsigned int nbpt)
void getMatchedPoints(const unsigned int _index, vpImagePoint &_referencePoint, vpImagePoint &_currentPoint)
void set_i(const double i)
std::vector< cv::Point2f > ref_corners
The corners in the reference image.
void load(const std::string &dataFilename, const std::string &objName)
Load the Fern classifier.
error that can be emited by ViSP classes.
void getReferencePoint(const unsigned int _i, vpImagePoint &_imPoint)
cv::Rect modelROI
The ROI for the reference image.
const std::vector< cv::Point2f > & getRefPt() const
static const vpColor green
vpImagePoint getTopLeft() const
cv::Mat H
Computed homography in the OpenCV format.
bool matchPoint(const vpImage< unsigned char > &I)
virtual unsigned int buildReference(const vpImage< unsigned char > &I)
std::vector< cv::Point2f > dst_corners
The estimated new coordinates of the corners (reprojected using the homography).
void display(vpImage< unsigned char > &I, bool displayKpts=false)
vpFernClassifier fern
Fern Classifier used to match the points between a reference image and the current image...
std::vector< vpImagePoint > currentImagePoints
Vector of the image point in the current image that match after the deletion of the outliers with the...
vpHomography homography
Computed homography in the ViSP format.
virtual void displayCross(const vpImagePoint &ip, unsigned int size, const vpColor &color, unsigned int thickness=1)=0
unsigned int buildReference(const vpImage< unsigned char > &I)
const std::vector< cv::Point2f > & getCurPt() const
void record(const std::string &_objectName, const std::string &_dataFile)
record the Ferns classifier in the text file
bool isCorrect
Flag to indicate wether the last computed homography is correct or not.
cv::Rect getModelROI() const
void recordDetector(const std::string &objectName, const std::string &dataFile)
Record the Ferns classifier in the text file.
unsigned int minNbMatching
Minimal number of point to after the ransac needed to suppose that the homography has been correctly ...
unsigned int getHeight() const
void set_uv(const double u, const double v)
Defines a rectangle in the plane.
std::vector< vpImagePoint > getDetectedCorners() const
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
void load(const std::string &_dataFile, const std::string &)
load the Fern classifier
std::vector< vpImagePoint > refImagePoints
Vector of the image point in the reference image that match after the deletion of the outliers with t...
virtual ~vpPlanarObjectDetector()