38 #include <visp3/mbt/vpMbtDistanceKltCylinder.h>
39 #include <visp3/mbt/vpMbtDistanceKltPoints.h>
40 #include <visp3/core/vpPolygon.h>
43 #if defined(VISP_HAVE_MODULE_KLT) && (defined(VISP_HAVE_OPENCV) && (VISP_HAVE_OPENCV_VERSION >= 0x020100))
50 : c0Mo(), p1Ext(), p2Ext(), cylinder(), circle1(), circle2(),
51 initPoints(), initPoints3D(), curPoints(), curPointsInd(),
52 nbPointsCur(0), nbPointsInit(0), minNbPoint(4), enoughPoints(false),
53 cam(), isTrackedKltCylinder(true), listIndicesCylinderBBox(), hiddenface(NULL), useScanLine(false)
111 initPoints = std::map<int, vpImagePoint>();
112 initPoints3D = std::map<int, vpPoint>();
113 curPoints = std::map<int, vpImagePoint>();
114 curPointsInd = std::map<int, int>();
116 for (
unsigned int i = 0; i < static_cast<unsigned int>(_tracker.
getNbFeatures()); i ++){
119 _tracker.
getFeature((
int)i,
id, x_tmp, y_tmp);
125 if((
unsigned int)y_tmp < hiddenface->getMbScanLineRenderer().getPrimitiveIDs().getHeight() &&
126 (
unsigned int)x_tmp < hiddenface->getMbScanLineRenderer().getPrimitiveIDs().getWidth())
138 std::vector<vpImagePoint> roi;
155 double Z = computeZ(xm,ym);
159 curPointsInd[id] = (int)i;
166 initPoints3D[id] = p;
172 if(nbPointsCur >= minNbPoint) enoughPoints =
true;
173 else enoughPoints =
false;
191 curPoints = std::map<int, vpImagePoint>();
192 curPointsInd = std::map<int, int>();
194 for (
unsigned int i = 0; i < static_cast<unsigned int>(_tracker.
getNbFeatures()); i++){
196 if(isTrackedFeature(
id)){
197 curPoints[id] =
vpImagePoint(static_cast<double>(y),static_cast<double>(x));
198 curPointsInd[id] = (int)i;
203 if(nbPointsCur >= minNbPoint) enoughPoints =
true;
204 else enoughPoints =
false;
219 std::map<int, vpImagePoint> tmp;
220 std::map<int, int> tmp2;
221 unsigned int nbSupp = 0;
225 std::map<int, vpImagePoint>::const_iterator iter = curPoints.begin();
226 for( ; iter != curPoints.end(); iter++){
227 if(_w[k] > threshold_outlier && _w[k+1] > threshold_outlier){
229 tmp[iter->first] =
vpImagePoint(iter->second.get_i(), iter->second.get_j());
230 tmp2[iter->first] = curPointsInd[iter->first];
235 initPoints.erase(iter->first);
242 curPoints = std::map<int, vpImagePoint>();
243 curPointsInd = std::map<int, int>();
247 if(nbPointsCur >= minNbPoint) enoughPoints =
true;
248 else enoughPoints =
false;
266 unsigned int index_ = 0;
270 std::map<int, vpImagePoint>::const_iterator iter = curPoints.begin();
271 for( ; iter != curPoints.end(); iter++){
273 double i_cur(iter->second.get_i()), j_cur(iter->second.get_j());
275 double x_cur(0), y_cur(0);
282 double x0_transform(p0.
get_x()), y0_transform(p0.
get_y()) ;
284 double Z = computeZ(x_cur, y_cur);
286 if(
vpMath::isNaN(Z) || Z < std::numeric_limits<double>::epsilon()){
297 _J[2*index_+1][0] = 0;
298 _J[2*index_+1][1] = 0;
299 _J[2*index_+1][2] = 0;
300 _J[2*index_+1][3] = 0;
301 _J[2*index_+1][4] = 0;
302 _J[2*index_+1][5] = 0;
304 _R[2*index_] = (x0_transform - x_cur);
305 _R[2*index_+1] = (y0_transform - y_cur);
312 _J[2*index_][0] = - invZ;
314 _J[2*index_][2] = x_cur * invZ;
315 _J[2*index_][3] = x_cur * y_cur;
316 _J[2*index_][4] = -(1+x_cur*x_cur);
317 _J[2*index_][5] = y_cur;
319 _J[2*index_+1][0] = 0;
320 _J[2*index_+1][1] = - invZ;
321 _J[2*index_+1][2] = y_cur * invZ;
322 _J[2*index_+1][3] = (1+y_cur*y_cur);
323 _J[2*index_+1][4] = - y_cur * x_cur;
324 _J[2*index_+1][5] = - x_cur;
326 _R[2*index_] = (x0_transform - x_cur);
327 _R[2*index_+1] = (y0_transform - y_cur);
341 vpMbtDistanceKltCylinder::isTrackedFeature(
const int _id)
343 std::map<int, vpImagePoint>::iterator iter = initPoints.find(_id);
344 if(iter != initPoints.end())
360 #
if (VISP_HAVE_OPENCV_VERSION >= 0x020408)
365 unsigned char nb,
unsigned int shiftBorder)
367 #if (VISP_HAVE_OPENCV_VERSION >= 0x020408)
368 int width = mask.cols;
369 int height = mask.rows;
371 int width = mask->width;
372 int height = mask->height;
379 int i_min, i_max, j_min, j_max;
380 std::vector<vpImagePoint> roi;
398 double shiftBorder_d = (double) shiftBorder;
399 #if (VISP_HAVE_OPENCV_VERSION >= 0x020408)
400 for(
int i=i_min; i< i_max; i++){
401 double i_d = (double) i;
402 for(
int j=j_min; j< j_max; j++){
403 double j_d = (double) j;
404 if(shiftBorder != 0){
410 mask.at<
unsigned char>(i,j) = nb;
415 mask.at<
unsigned char>(i,j) = nb;
421 unsigned char* ptrData = (
unsigned char*)mask->imageData + i_min*mask->widthStep+j_min;
422 for(
int i=i_min; i< i_max; i++){
423 double i_d = (double) i;
424 for(
int j=j_min; j< j_max; j++){
425 double j_d = (double) j;
426 if(shiftBorder != 0){
447 ptrData += mask->widthStep - j_max + j_min;
462 std::map<int, vpImagePoint>::const_iterator iter = curPoints.begin();
463 for( ; iter != curPoints.end(); iter++){
466 iP.
set_i(static_cast<double>(iter->second.get_i()));
467 iP.
set_j(static_cast<double>(iter->second.get_j()));
474 sprintf(ide,
"%ld", static_cast<long int>(
id));
487 std::map<int, vpImagePoint>::const_iterator iter = curPoints.begin();
488 for( ; iter != curPoints.end(); iter++){
491 iP.
set_i(static_cast<double>(iter->second.get_i()));
492 iP.
set_j(static_cast<double>(iter->second.get_j()));
499 sprintf(ide,
"%ld", static_cast<long int>(
id));
506 const vpColor col,
const unsigned int thickness,
const bool )
518 catch(...){std::cout<<
"Problem projection circle 1";}
522 catch(...){std::cout<<
"Problem projection circle 2";}
534 double i11,i12,i21,i22,j11,j12,j21,j22;
557 const vpColor col,
const unsigned int thickness,
const bool )
569 catch(...){std::cout<<
"Problem projection circle 1";}
573 catch(...){std::cout<<
"Problem projection circle 2";}
585 double i11,i12,i21,i22,j11,j12,j21,j22;
612 vpMbtDistanceKltCylinder::computeZ(
const double &x,
const double &y)
614 double A = x*x + y*y + 1 - ((cylinder.
getA()*x+cylinder.
getB()*y+cylinder.
getC()) * (cylinder.
getA()*x+cylinder.
getB()*y+cylinder.
getC()));
615 double B = (x * cylinder.
getX() + y * cylinder.
getY() + cylinder.
getZ());
618 return (B - std::sqrt(B*B - A*C))/A;
620 #elif !defined(VISP_BUILD_SHARED_LIBS)
622 void dummy_vpMbtDistanceKltCylinder() {};
Implementation of a matrix and operations on matrices.
void displayPrimitive(const vpImage< unsigned char > &_I)
unsigned int computeNbDetectedCurrent(const vpKltOpencv &_tracker)
void removeOutliers(const vpColVector &weight, const double &threshold_outlier)
void changeFrame(const vpHomogeneousMatrix &cMo, vpColVector &cP)
perspective projection of the circle
Implementation of an homogeneous matrix and operations on such kind of matrices.
std::vector< int > listIndicesCylinderBBox
Pointer to the polygon that define a face.
static bool isNaN(const double value)
Class to define colors available for display functionnalities.
static void displayText(const vpImage< unsigned char > &I, const vpImagePoint &ip, const std::string &s, const vpColor &color)
double get_oY() const
Get the point Y coordinate in the object frame.
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...
void init(const vpKltOpencv &_tracker, const vpHomogeneousMatrix &cMo)
double get_y() const
Get the point y coordinate in the image plane.
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)
vpMbtDistanceKltCylinder()
void changeFrame(const vpHomogeneousMatrix &cMo, vpColVector &cP)
Class that defines what is a point.
bool isInside(const vpImagePoint &iP)
virtual ~vpMbtDistanceKltCylinder()
void set_i(const double ii)
void computeInteractionMatrixAndResidu(const vpHomogeneousMatrix &cMc0, vpColVector &_R, vpMatrix &_J)
static void computeIntersectionPoint(const vpCircle &circle, const vpCameraParameters &cam, const double &rho, const double &theta, double &i, double &j)
virtual void displayCross(const vpImagePoint &ip, unsigned int size, const vpColor &color, unsigned int thickness=1)=0
Generic class defining intrinsic camera parameters.
double get_oZ() const
Get the point Z coordinate in the object frame.
void getFeature(const int &index, int &id, float &x, float &y) const
double get_x() const
Get the point x coordinate in the image plane.
bool useScanLine
Use scanline rendering.
void buildFrom(const vpPoint &p1, const vpPoint &p2, const double &r)
vpMbHiddenFaces< vpMbtPolygon > * hiddenface
Pointer to the list of faces.
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)
static void convertLine(const vpCameraParameters &cam, const double &rho_m, const double &theta_m, double &rho_p, double &theta_p)
Line coordinates conversion (rho,theta).
void set_j(const double jj)
double get_oX() const
Get the point X coordinate in the object frame.
void setWorldCoordinates(const double oX, const double oY, const double oZ)
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.
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 setWorldCoordinates(const vpColVector &oP)
void updateMask(cv::Mat &mask, unsigned char _nb=255, unsigned int _shiftBorder=0)
void changeFrame(const vpHomogeneousMatrix &cMo, vpColVector &_cP)
void set_ij(const double ii, const double jj)
void setWorldCoordinates(const vpColVector &oP)
std::vector< PolygonType * > & getPolygon()