40 #include <visp3/core/vpConfig.h>
48 #include <visp3/core/vpMeterPixelConversion.h>
49 #include <visp3/core/vpPlane.h>
50 #include <visp3/mbt/vpMbtDistanceLine.h>
51 #include <visp3/visual_features/vpFeatureBuilder.h>
60 : name(), index(0), cam(), me(NULL), isTrackedLine(true), isTrackedLineWithVisibility(true), wmean(1), featureline(),
61 poly(), useScanLine(false), meline(), line(NULL), p1(NULL), p2(NULL), L(), error(), nbFeature(), nbFeatureTotal(0),
62 Reinit(false), hiddenface(NULL), Lindex_polygon(), Lindex_polygon_tracked(), isvisible(false)
75 for (
unsigned int i = 0; i <
meline.size(); i++)
128 double norm = sqrt(A * A + B * B + C * C);
129 plane.
setA(A / norm);
130 plane.
setB(B / norm);
131 plane.
setC(C / norm);
132 plane.
setD(D / norm);
152 buildPlane(P1, P2, P3, plane1);
153 buildPlane(P1, P2, P4, plane2);
191 if (std::fabs((V1 - V2).sumSquare()) > std::numeric_limits<double>::epsilon()) {
193 V3[0] = double(rand_gen.
next() % 1000) / 100;
194 V3[1] = double(rand_gen.
next() % 1000) / 100;
195 V3[2] = double(rand_gen.
next() % 1000) / 100;
202 vpPoint P3(V3[0], V3[1], V3[2]);
203 vpPoint P4(V4[0], V4[1], V4[2]);
206 vpPoint P3(V1[0], V1[1], V1[2]);
207 vpPoint P4(V2[0], V2[1], V2[2]);
232 unsigned int ind = 0;
240 isTrackedLine =
false;
243 isTrackedLine =
true;
247 if (!isTrackedLine) {
248 isTrackedLineWithVisibility =
false;
261 if (!isTrackedLine) {
262 isTrackedLineWithVisibility =
false;
266 unsigned int ind = 0;
267 isTrackedLineWithVisibility =
false;
270 isTrackedLineWithVisibility =
true;
286 for (
unsigned int i = 0; i <
meline.size(); i++)
310 for (
unsigned int i = 0; i <
meline.size(); i++) {
330 std::vector<std::pair<vpPoint, vpPoint> > linesLst;
338 if (linesLst.size() == 0) {
353 while (theta > M_PI) {
356 while (theta < -M_PI) {
360 if (theta < -M_PI / 2.0)
361 theta = -theta - 3 * M_PI / 2.0;
363 theta = M_PI / 2.0 - theta;
365 for (
unsigned int i = 0; i < linesLst.size(); i++) {
368 linesLst[i].first.project();
369 linesLst[i].second.project();
374 vpMbtMeLine *melinePt =
new vpMbtMeLine;
375 melinePt->setMask(*mask);
378 melinePt->setInitRange(0);
382 melinePt->jmin = (int)ip1.
get_j() - marge;
383 melinePt->jmax = (int)ip2.
get_j() + marge;
385 melinePt->jmin = (int)ip2.
get_j() - marge;
386 melinePt->jmax = (int)ip1.
get_j() + marge;
389 melinePt->imin = (int)ip1.
get_i() - marge;
390 melinePt->imax = (int)ip2.
get_i() + marge;
392 melinePt->imin = (int)ip2.
get_i() - marge;
393 melinePt->imax = (int)ip1.
get_i() + marge;
397 melinePt->initTracking(I, ip1, ip2, rho, theta, doNotTrack);
398 meline.push_back(melinePt);
399 nbFeature.push_back((
unsigned int)melinePt->getMeList().size());
426 for (
size_t i = 0; i <
meline.size(); i++) {
432 for (
size_t i = 0; i <
meline.size(); i++) {
465 std::vector<std::pair<vpPoint, vpPoint> > linesLst;
473 if (linesLst.size() !=
meline.size() || linesLst.size() == 0) {
474 for (
size_t i = 0; i <
meline.size(); i++) {
489 for (
size_t j = 0; j <
meline.size(); j++) {
505 while (theta > M_PI) {
508 while (theta < -M_PI) {
512 if (theta < -M_PI / 2.0)
513 theta = -theta - 3 * M_PI / 2.0;
515 theta = M_PI / 2.0 - theta;
518 for (
unsigned int i = 0; i < linesLst.size(); i++) {
521 linesLst[i].first.project();
522 linesLst[i].second.project();
543 meline[i]->updateParameters(I, ip1, ip2, rho, theta);
548 for (
size_t j = 0; j <
meline.size(); j++) {
561 for (
size_t i = 0; i <
meline.size(); i++) {
587 for (
size_t i = 0; i <
meline.size(); i++) {
615 bool displayFullModel)
617 std::vector<std::vector<double> > models =
620 for (
size_t i = 0; i < models.size(); i++) {
640 bool displayFullModel)
642 std::vector<std::vector<double> > models =
645 for (
size_t i = 0; i < models.size(); i++) {
668 for (
size_t i = 0; i <
meline.size(); i++) {
677 for (
size_t i = 0; i <
meline.size(); i++) {
690 std::vector<std::vector<double> > features;
692 for (
size_t i = 0; i <
meline.size(); i++) {
693 vpMbtMeLine *me_l =
meline[i];
695 for (std::list<vpMeSite>::const_iterator it = me_l->getMeList().begin(); it != me_l->getMeList().end(); ++it) {
697 #if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
698 std::vector<double> params = {0,
701 std::vector<double> params;
705 params.push_back(
static_cast<double>(p_me_l.
getState()));
707 features.push_back(params);
729 bool displayFullModel)
731 std::vector<std::vector<double> > models;
733 if ((
isvisible && isTrackedLine) || displayFullModel) {
752 std::vector<std::pair<vpPoint, vpPoint> > linesLst;
759 for (
unsigned int i = 0; i < linesLst.size(); i++) {
760 linesLst[i].first.project();
761 linesLst[i].second.project();
766 #if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
767 std::vector<double> params = {0,
770 std::vector<double> params;
772 params.push_back(ip1.
get_i());
773 params.push_back(ip1.
get_j());
774 params.push_back(ip2.
get_i());
775 params.push_back(ip2.
get_j());
777 models.push_back(params);
794 for (
size_t i = 0; i <
meline.size(); i++) {
797 std::list<vpMeSite> &me_site_list =
meline[i]->getMeList();
798 me_site_list.clear();
818 double rho = featureline.
getRho();
819 double theta = featureline.
getTheta();
821 double co = cos(theta);
822 double si = sin(theta);
824 double mx = 1.0 / cam.
get_px();
825 double my = 1.0 / cam.
get_py();
835 for (
size_t i = 0; i <
meline.size(); i++) {
836 for (std::list<vpMeSite>::const_iterator it =
meline[i]->getMeList().begin();
837 it !=
meline[i]->getMeList().end(); ++it) {
844 alpha_ = x * si - y * co;
847 double *Ltheta = H[1];
849 for (
unsigned int k = 0; k < 6; k++) {
850 L[j][k] = (Lrho[k] + alpha_ * Ltheta[k]);
852 error[j] = rho - (x * co + y * si);
860 for (
size_t i = 0; i <
meline.size(); i++) {
861 for (std::list<vpMeSite>::const_iterator it =
meline[i]->getMeList().begin();
862 it !=
meline[i]->getMeList().end(); ++it) {
863 for (
unsigned int k = 0; k < 6; k++) {
890 for (
size_t i = 0; i <
meline.size(); i++) {
891 for (std::list<vpMeSite>::const_iterator it =
meline[i]->getMeList().begin(); it !=
meline[i]->getMeList().end();
896 if (i_ < 0 || j_ < 0) {
900 if (((
unsigned int)i_ > (I.
getHeight() - threshold)) || (
unsigned int)i_ < threshold ||
901 ((
unsigned int)j_ > (I.
getWidth() - threshold)) || (
unsigned int)j_ < threshold) {
void resize(unsigned int nrows, unsigned int ncols, bool flagNullify=true, bool recopy_=true)
Generic class defining intrinsic camera parameters.
void computeFov(const unsigned int &w, const unsigned int &h)
Implementation of column vector and the associated operations.
static vpColVector cross(const vpColVector &a, const vpColVector &b)
void resize(unsigned int i, bool flagNullify=true)
Class to define RGB colors available for display functionnalities.
static void displayLine(const vpImage< unsigned char > &I, const vpImagePoint &ip1, const vpImagePoint &ip2, const vpColor &color, unsigned int thickness=1, bool segment=true)
static void create(vpFeaturePoint &s, const vpCameraParameters &cam, const vpDot &d)
vpMatrix interaction(unsigned int select=FEATURE_ALL)
Implementation of an homogeneous matrix and operations on such kind of matrices.
Class that defines a 2D point in an image. This class is useful for image processing and stores only ...
unsigned int getWidth() const
unsigned int getHeight() const
Class that defines a 3D line in the object frame and allows forward projection of the line in the cam...
void changeFrame(const vpHomogeneousMatrix &cMo, vpColVector &cP) const
Implementation of a matrix and operations on matrices.
void computeScanLineQuery(const vpPoint &a, const vpPoint &b, std::vector< std::pair< vpPoint, vpPoint > > &lines, const bool &displayResults=false)
void setMovingEdge(vpMe *Me)
std::vector< unsigned int > nbFeature
The number of moving edges.
void displayMovingEdges(const vpImage< unsigned char > &I)
std::vector< bool > Lindex_polygon_tracked
void updateMovingEdge(const vpImage< unsigned char > &I, const vpHomogeneousMatrix &cMo)
bool isvisible
Indicates if the line is visible or not.
void computeInteractionMatrixError(const vpHomogeneousMatrix &cMo)
vpPoint * p2
The second extremity.
vpLine * line
The 3D line.
void initInteractionMatrixError()
void display(const vpImage< unsigned char > &I, const vpHomogeneousMatrix &cMo, const vpCameraParameters &cam, const vpColor &col, unsigned int thickness=1, bool displayFullModel=false)
std::list< int > Lindex_polygon
Index of the faces which contain the line.
bool initMovingEdge(const vpImage< unsigned char > &I, const vpHomogeneousMatrix &cMo, bool doNotTrack, const vpImage< bool > *mask=NULL)
void buildFrom(vpPoint &_p1, vpPoint &_p2, vpUniRand &rand_gen)
unsigned int nbFeatureTotal
The number of moving edges.
bool Reinit
Indicates if the line has to be reinitialized.
std::string getName() const
vpColVector error
The error vector.
vpMbHiddenFaces< vpMbtPolygon > * hiddenface
Pointer to the list of faces.
bool closeToImageBorder(const vpImage< unsigned char > &I, const unsigned int threshold)
std::vector< std::vector< double > > getModelForDisplay(unsigned int width, unsigned int height, const vpHomogeneousMatrix &cMo, const vpCameraParameters &cam, bool displayFullModel=false)
virtual ~vpMbtDistanceLine()
void reinitMovingEdge(const vpImage< unsigned char > &I, const vpHomogeneousMatrix &cMo, const vpImage< bool > *mask=NULL)
std::vector< std::vector< double > > getFeaturesForDisplay()
bool useScanLine
Use scanline rendering.
vpPoint * p1
The first extremity.
std::vector< vpMbtMeLine * > meline
The moving edge container.
vpMatrix L
The interaction matrix.
void setTracked(const std::string &name, const bool &track)
void addPolygon(const int &index)
void trackMovingEdge(const vpImage< unsigned char > &I)
Performs search in a given direction(normal) for a given distance(pixels) for a given 'site'....
vpMeSiteState getState() const
double get_ifloat() const
double get_jfloat() const
static void convertLine(const vpCameraParameters &cam, const double &rho_m, const double &theta_m, double &rho_p, double &theta_p)
static void convertPoint(const vpCameraParameters &cam, const double &x, const double &y, double &u, double &v)
This class defines the container for a plane geometrical structure.
Class that defines a 3D point in the object frame and allows forward projection of a 3D point in the ...
double get_oX() const
Get the point oX coordinate in the object frame.
double get_oZ() const
Get the point oZ coordinate in the object frame.
double get_oY() const
Get the point oY coordinate in the object frame.
void changeFrame(const vpHomogeneousMatrix &cMo, vpColVector &cP) const
vpPoint * p
corners in the object frame
void computePolygonClipped(const vpCameraParameters &cam=vpCameraParameters())
virtual void setNbPoint(unsigned int nb)
unsigned int getClipping() const
std::vector< std::pair< vpPoint, unsigned int > > polyClipped
Region of interest clipped.
void addPoint(unsigned int n, const vpPoint &P)
Class for generating random numbers with uniform probability density.