39 #include <visp3/mbt/vpMbtDistanceKltPoints.h>
40 #include <visp3/core/vpPolygon.h>
42 #if defined(VISP_HAVE_MODULE_KLT) && (defined(VISP_HAVE_OPENCV) && (VISP_HAVE_OPENCV_VERSION >= 0x020100))
49 : H(), N(), N_cur(), invd0(1.), cRc0_0n(), initPoints(), curPoints(), curPointsInd(),
50 nbPointsCur(0), nbPointsInit(0), minNbPoint(4), enoughPoints(false), dt(1.), d0(1.),
51 cam(), isTrackedKltPoints(true), polygon(NULL), hiddenface(NULL), useScanLine(false)
53 initPoints = std::map<int, vpImagePoint>();
54 curPoints = std::map<int, vpImagePoint>();
55 curPointsInd = std::map<int, int>();
78 initPoints = std::map<int, vpImagePoint>();
79 curPoints = std::map<int, vpImagePoint>();
80 curPointsInd = std::map<int, int>();
81 std::vector<vpImagePoint> roi;
84 for (
unsigned int i = 0; i < static_cast<unsigned int>(_tracker.
getNbFeatures()); i ++){
93 if((
unsigned int)y_tmp < hiddenface->getMbScanLineRenderer().getPrimitiveIDs().getHeight() &&
94 (
unsigned int)x_tmp < hiddenface->getMbScanLineRenderer().getPrimitiveIDs().getWidth() &&
106 curPointsInd[id] = (int)i;
112 if(nbPointsCur >= minNbPoint) enoughPoints =
true;
113 else enoughPoints =
false;
119 N = plan.getNormal();
139 curPoints = std::map<int, vpImagePoint>();
140 curPointsInd = std::map<int, int>();
142 for (
unsigned int i = 0; i < static_cast<unsigned int>(_tracker.
getNbFeatures()); i++){
144 if(isTrackedFeature(
id)){
145 curPoints[id] =
vpImagePoint(static_cast<double>(y),static_cast<double>(x));
146 curPointsInd[id] = (int)i;
151 if(nbPointsCur >= minNbPoint) enoughPoints =
true;
152 else enoughPoints =
false;
170 unsigned int index_ = 0;
172 std::map<int, vpImagePoint>::const_iterator iter = curPoints.begin();
173 for( ; iter != curPoints.end(); iter++){
175 double i_cur(iter->second.get_i()), j_cur(iter->second.get_j());
177 double x_cur(0), y_cur(0);
184 double x0_transform, y0_transform ;
185 computeP_mu_t(x0, y0, x0_transform, y0_transform, H );
187 double invZ = compute_1_over_Z(x_cur, y_cur);
189 _J[2*index_][0] = - invZ;
191 _J[2*index_][2] = x_cur * invZ;
192 _J[2*index_][3] = x_cur * y_cur;
193 _J[2*index_][4] = -(1+x_cur*x_cur);
194 _J[2*index_][5] = y_cur;
196 _J[2*index_+1][0] = 0;
197 _J[2*index_+1][1] = - invZ;
198 _J[2*index_+1][2] = y_cur * invZ;
199 _J[2*index_+1][3] = (1+y_cur*y_cur);
200 _J[2*index_+1][4] = - y_cur * x_cur;
201 _J[2*index_+1][5] = - x_cur;
203 _R[2*index_] = (x0_transform - x_cur);
204 _R[2*index_+1] = (y0_transform - y_cur);
210 vpMbtDistanceKltPoints::compute_1_over_Z(
const double x,
const double y)
212 double num = cRc0_0n[0] * x + cRc0_0n[1] * y + cRc0_0n[2];
213 double den = -(d0 - dt);
230 vpMbtDistanceKltPoints::computeP_mu_t(
const double x_in,
const double y_in,
double& x_out,
double& y_out,
const vpMatrix& _cHc0)
232 double p_mu_t_2 = x_in * _cHc0[2][0] + y_in * _cHc0[2][1] + _cHc0[2][2];
234 if( fabs(p_mu_t_2) < std::numeric_limits<double>::epsilon()){
240 x_out = (x_in * _cHc0[0][0] + y_in * _cHc0[0][1] + _cHc0[0][2]) / p_mu_t_2;
241 y_out = (x_in * _cHc0[1][0] + y_in * _cHc0[1][1] + _cHc0[1][2]) / p_mu_t_2;
267 vpGEMM(ctransc0, N, -invd0, cRc0, 1.0, cHc0, VP_GEMM_B_T);
290 for (
unsigned int i = 0; i < 3; i += 1){
291 dt += ctransc0[i] * (N_cur[i]);
303 vpMbtDistanceKltPoints::isTrackedFeature(
const int _id)
313 std::map<int, vpImagePoint>::iterator iter = initPoints.find(_id);
314 if(iter != initPoints.end())
330 #
if (VISP_HAVE_OPENCV_VERSION >= 0x020408)
335 unsigned char nb,
unsigned int shiftBorder)
337 #if (VISP_HAVE_OPENCV_VERSION >= 0x020408)
338 int width = mask.cols;
339 int height = mask.rows;
341 int width = mask->width;
342 int height = mask->height;
345 int i_min, i_max, j_min, j_max;
346 std::vector<vpImagePoint> roi;
364 double shiftBorder_d = (double) shiftBorder;
365 #if (VISP_HAVE_OPENCV_VERSION >= 0x020408)
366 for(
int i=i_min; i< i_max; i++){
367 double i_d = (double) i;
368 for(
int j=j_min; j< j_max; j++){
369 double j_d = (double) j;
370 if(shiftBorder != 0){
376 mask.at<
unsigned char>(i,j) = nb;
381 mask.at<
unsigned char>(i,j) = nb;
387 unsigned char* ptrData = (
unsigned char*)mask->imageData + i_min*mask->widthStep+j_min;
388 for(
int i=i_min; i< i_max; i++){
389 double i_d = (double) i;
390 for(
int j=j_min; j< j_max; j++){
391 double j_d = (double) j;
392 if(shiftBorder != 0){
413 ptrData += mask->widthStep - j_max + j_min;
428 std::map<int, vpImagePoint> tmp;
429 std::map<int, int> tmp2;
430 unsigned int nbSupp = 0;
434 std::map<int, vpImagePoint>::const_iterator iter = curPoints.begin();
435 for( ; iter != curPoints.end(); iter++){
436 if(_w[k] > threshold_outlier && _w[k+1] > threshold_outlier){
438 tmp[iter->first] =
vpImagePoint(iter->second.get_i(), iter->second.get_j());
439 tmp2[iter->first] = curPointsInd[iter->first];
444 initPoints.erase(iter->first);
451 curPoints = std::map<int, vpImagePoint>();
452 curPointsInd = std::map<int, int>();
456 if(nbPointsCur >= minNbPoint) enoughPoints =
true;
457 else enoughPoints =
false;
469 std::map<int, vpImagePoint>::const_iterator iter = curPoints.begin();
470 for( ; iter != curPoints.end(); iter++){
473 iP.
set_i(static_cast<double>(iter->second.get_i()));
474 iP.
set_j(static_cast<double>(iter->second.get_j()));
481 sprintf(ide,
"%ld", static_cast<long int>(
id));
494 std::map<int, vpImagePoint>::const_iterator iter = curPoints.begin();
495 for( ; iter != curPoints.end(); iter++){
498 iP.
set_i(static_cast<double>(iter->second.get_i()));
499 iP.
set_j(static_cast<double>(iter->second.get_j()));
506 sprintf(ide,
"%ld", static_cast<long int>(
id));
513 const vpColor col,
const unsigned int thickness,
const bool displayFullModel)
517 std::vector<std::pair<vpPoint,unsigned int> > roi;
520 for (
unsigned int j = 0; j < roi.size(); j += 1){
529 std::vector<std::pair<vpPoint, vpPoint> > linesLst;
534 linesLst.push_back(std::make_pair(roi[j].first,roi[(j+1)%roi.size()].first));
536 for(
unsigned int i = 0 ; i < linesLst.size() ; i++){
537 linesLst[i].first.project();
538 linesLst[i].second.project();
552 const vpColor col,
const unsigned int thickness,
const bool displayFullModel)
556 std::vector<std::pair<vpPoint,unsigned int> > roi;
559 for (
unsigned int j = 0; j < roi.size(); j += 1){
568 std::vector<std::pair<vpPoint, vpPoint> > linesLst;
573 linesLst.push_back(std::make_pair(roi[j].first,roi[(j+1)%roi.size()].first));
575 for(
unsigned int i = 0 ; i < linesLst.size() ; i++){
576 linesLst[i].first.project();
577 linesLst[i].second.project();
588 #elif !defined(VISP_BUILD_SHARED_LIBS)
590 void dummy_vpMbKltTracker() {};
Implementation of a matrix and operations on matrices.
void getRoiClipped(const vpCameraParameters &cam, std::vector< vpImagePoint > &roi)
void init(const vpKltOpencv &_tracker)
void removeOutliers(const vpColVector &weight, const double &threshold_outlier)
Implementation of an homogeneous matrix and operations on such kind of matrices.
static void convertPoint(const vpCameraParameters &cam, const double &x, const double &y, double &u, double &v)
Point coordinates conversion from normalized coordinates in meter to pixel coordinates ...
Class to define colors available for display functionnalities.
vpMbHiddenFaces< vpMbtPolygon > * hiddenface
Pointer to the list of faces.
static void displayText(const vpImage< unsigned char > &I, const vpImagePoint &ip, const std::string &s, const vpColor &color)
virtual ~vpMbtDistanceKltPoints()
error that can be emited by ViSP classes.
vpMbScanLine & getMbScanLineRenderer()
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 int round(const double x)
static void getMinMaxRoi(const std::vector< vpImagePoint > &roi, int &i_min, int &i_max, int &j_min, int &j_max)
Implementation of a rotation matrix and operations on such kind of matrices.
bool isInside(const vpImagePoint &iP)
unsigned int computeNbDetectedCurrent(const vpKltOpencv &_tracker)
Implementation of an homography and operations on homographies.
void set_i(const double ii)
vpColVector & normalize()
vpPoint & getPoint(const unsigned int _index)
void displayPrimitive(const vpImage< unsigned char > &_I)
virtual void displayCross(const vpImagePoint &ip, unsigned int size, const vpColor &color, unsigned int thickness=1)=0
void getPolygonClipped(std::vector< std::pair< vpPoint, unsigned int > > &poly)
Generic class defining intrinsic camera parameters.
void getFeature(const int &index, int &id, float &x, float &y) const
void extract(vpRotationMatrix &R) const
virtual bool isVisible(const vpHomogeneousMatrix &cMo, const double alpha, const bool &modulo=false, const vpCameraParameters &cam=vpCameraParameters(), const vpImage< unsigned char > &I=vpImage< unsigned char >())
void computeHomography(const vpHomogeneousMatrix &_cTc0, vpHomography &cHc0)
void set_j(const double jj)
void computeScanLineQuery(const vpPoint &a, const vpPoint &b, std::vector< std::pair< vpPoint, vpPoint > > &lines, const bool &displayResults=false)
Implementation of column vector and the associated operations.
Wrapper for the KLT (Kanade-Lucas-Tomasi) feature tracker implemented in OpenCV.
int getNbFeatures() const
Get the number of current features.
vpMbtPolygon * polygon
Pointer to the polygon that define a face.
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
This class defines the container for a plane geometrical structure.
Class that consider the case of a translation vector.
void computeInteractionMatrixAndResidu(vpColVector &_R, vpMatrix &_J)
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)
bool useScanLine
Use scanline rendering.
void updateMask(cv::Mat &mask, unsigned char _nb=255, unsigned int _shiftBorder=0)