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))
45 #if defined(__APPLE__) && defined(__MACH__) // Apple OSX and iOS (Darwin)
46 # include <TargetConditionals.h>
54 : c0Mo(), p1Ext(), p2Ext(), cylinder(), circle1(), circle2(),
55 initPoints(), initPoints3D(), curPoints(), curPointsInd(),
56 nbPointsCur(0), nbPointsInit(0), minNbPoint(4), enoughPoints(false),
57 cam(), isTrackedKltCylinder(true), listIndicesCylinderBBox(), hiddenface(NULL), useScanLine(false)
115 initPoints = std::map<int, vpImagePoint>();
116 initPoints3D = std::map<int, vpPoint>();
117 curPoints = std::map<int, vpImagePoint>();
118 curPointsInd = std::map<int, int>();
120 for (
unsigned int i = 0; i < static_cast<unsigned int>(_tracker.
getNbFeatures()); i ++){
123 _tracker.
getFeature((
int)i,
id, x_tmp, y_tmp);
129 if((
unsigned int)y_tmp < hiddenface->getMbScanLineRenderer().getPrimitiveIDs().getHeight() &&
130 (
unsigned int)x_tmp < hiddenface->getMbScanLineRenderer().getPrimitiveIDs().getWidth())
142 std::vector<vpImagePoint> roi;
159 double Z = computeZ(xm,ym);
164 curPointsInd[(int)
id] = (
int)i;
168 curPointsInd[id] = (int)i;
176 initPoints3D[(int)
id] = p;
178 initPoints3D[id] = p;
185 if(nbPointsCur >= minNbPoint) enoughPoints =
true;
186 else enoughPoints =
false;
204 curPoints = std::map<int, vpImagePoint>();
205 curPointsInd = std::map<int, int>();
207 for (
unsigned int i = 0; i < static_cast<unsigned int>(_tracker.
getNbFeatures()); i++){
209 if(isTrackedFeature((
int)
id)){
211 curPoints[(int)
id] =
vpImagePoint(static_cast<double>(y),
static_cast<double>(x));
212 curPointsInd[(int)
id] = (
int)i;
214 curPoints[id] =
vpImagePoint(static_cast<double>(y),static_cast<double>(x));
215 curPointsInd[id] = (int)i;
221 if(nbPointsCur >= minNbPoint) enoughPoints =
true;
222 else enoughPoints =
false;
237 std::map<int, vpImagePoint> tmp;
238 std::map<int, int> tmp2;
239 unsigned int nbSupp = 0;
243 std::map<int, vpImagePoint>::const_iterator iter = curPoints.begin();
244 for( ; iter != curPoints.end(); iter++){
245 if(_w[k] > threshold_outlier && _w[k+1] > threshold_outlier){
247 tmp[iter->first] =
vpImagePoint(iter->second.get_i(), iter->second.get_j());
248 tmp2[iter->first] = curPointsInd[iter->first];
253 initPoints.erase(iter->first);
260 curPoints = std::map<int, vpImagePoint>();
261 curPointsInd = std::map<int, int>();
265 if(nbPointsCur >= minNbPoint) enoughPoints =
true;
266 else enoughPoints =
false;
284 unsigned int index_ = 0;
288 std::map<int, vpImagePoint>::const_iterator iter = curPoints.begin();
289 for( ; iter != curPoints.end(); iter++){
291 double i_cur(iter->second.get_i()), j_cur(iter->second.get_j());
293 double x_cur(0), y_cur(0);
300 double x0_transform(p0.
get_x()), y0_transform(p0.
get_y()) ;
302 double Z = computeZ(x_cur, y_cur);
304 if(
vpMath::isNaN(Z) || Z < std::numeric_limits<double>::epsilon()){
315 _J[2*index_+1][0] = 0;
316 _J[2*index_+1][1] = 0;
317 _J[2*index_+1][2] = 0;
318 _J[2*index_+1][3] = 0;
319 _J[2*index_+1][4] = 0;
320 _J[2*index_+1][5] = 0;
322 _R[2*index_] = (x0_transform - x_cur);
323 _R[2*index_+1] = (y0_transform - y_cur);
330 _J[2*index_][0] = - invZ;
332 _J[2*index_][2] = x_cur * invZ;
333 _J[2*index_][3] = x_cur * y_cur;
334 _J[2*index_][4] = -(1+x_cur*x_cur);
335 _J[2*index_][5] = y_cur;
337 _J[2*index_+1][0] = 0;
338 _J[2*index_+1][1] = - invZ;
339 _J[2*index_+1][2] = y_cur * invZ;
340 _J[2*index_+1][3] = (1+y_cur*y_cur);
341 _J[2*index_+1][4] = - y_cur * x_cur;
342 _J[2*index_+1][5] = - x_cur;
344 _R[2*index_] = (x0_transform - x_cur);
345 _R[2*index_+1] = (y0_transform - y_cur);
359 vpMbtDistanceKltCylinder::isTrackedFeature(
const int _id)
361 std::map<int, vpImagePoint>::iterator iter = initPoints.find(_id);
362 if(iter != initPoints.end())
378 #
if (VISP_HAVE_OPENCV_VERSION >= 0x020408)
383 unsigned char nb,
unsigned int shiftBorder)
385 #if (VISP_HAVE_OPENCV_VERSION >= 0x020408)
386 int width = mask.cols;
387 int height = mask.rows;
389 int width = mask->width;
390 int height = mask->height;
398 int i_min, i_max, j_min, j_max;
399 std::vector<vpImagePoint> roi;
417 double shiftBorder_d = (double) shiftBorder;
418 #if (VISP_HAVE_OPENCV_VERSION >= 0x020408)
419 for(
int i=i_min; i< i_max; i++){
420 double i_d = (double) i;
421 for(
int j=j_min; j< j_max; j++){
422 double j_d = (double) j;
423 if(shiftBorder != 0){
429 mask.at<
unsigned char>(i,j) = nb;
434 mask.at<
unsigned char>(i,j) = nb;
440 unsigned char* ptrData = (
unsigned char*)mask->imageData + i_min*mask->widthStep+j_min;
441 for(
int i=i_min; i< i_max; i++){
442 double i_d = (double) i;
443 for(
int j=j_min; j< j_max; j++){
444 double j_d = (double) j;
445 if(shiftBorder != 0){
466 ptrData += mask->widthStep - j_max + j_min;
481 std::map<int, vpImagePoint>::const_iterator iter = curPoints.begin();
482 for( ; iter != curPoints.end(); iter++){
485 iP.
set_i(static_cast<double>(iter->second.get_i()));
486 iP.
set_j(static_cast<double>(iter->second.get_j()));
493 sprintf(ide,
"%ld", static_cast<long int>(
id));
506 std::map<int, vpImagePoint>::const_iterator iter = curPoints.begin();
507 for( ; iter != curPoints.end(); iter++){
510 iP.
set_i(static_cast<double>(iter->second.get_i()));
511 iP.
set_j(static_cast<double>(iter->second.get_j()));
518 sprintf(ide,
"%ld", static_cast<long int>(
id));
525 const vpColor col,
const unsigned int thickness,
const bool )
537 catch(...){std::cout<<
"Problem projection circle 1";}
541 catch(...){std::cout<<
"Problem projection circle 2";}
553 double i11,i12,i21,i22,j11,j12,j21,j22;
576 const vpColor col,
const unsigned int thickness,
const bool )
588 catch(...){std::cout<<
"Problem projection circle 1";}
592 catch(...){std::cout<<
"Problem projection circle 2";}
604 double i11,i12,i21,i22,j11,j12,j21,j22;
631 vpMbtDistanceKltCylinder::computeZ(
const double &x,
const double &y)
641 #elif !defined(VISP_BUILD_SHARED_LIBS)
643 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 computeZ(const double x, const double y) const
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, const PointInPolygonMethod &method=PnPolyRayCasting) const
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)
Generic class defining intrinsic camera parameters.
double get_oZ() const
Get the point Z coordinate in the object frame.
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.
static void displayCross(const vpImage< unsigned char > &I, const vpImagePoint &ip, unsigned int size, const vpColor &color, unsigned int thickness=1)
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. Thus to enable this ...
void getFeature(const int &index, long &id, float &x, float &y) const
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 ...
static void displayLine(const vpImage< unsigned char > &I, const vpImagePoint &ip1, const vpImagePoint &ip2, const vpColor &color, unsigned int thickness=1)
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()