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;
262 if (!isTrackedLine) {
263 isTrackedLineWithVisibility =
false;
267 unsigned int ind = 0;
268 isTrackedLineWithVisibility =
false;
271 isTrackedLineWithVisibility =
true;
287 for (
unsigned int i = 0; i <
meline.size(); i++)
311 for (
unsigned int i = 0; i <
meline.size(); i++) {
331 std::vector<std::pair<vpPoint, vpPoint> > linesLst;
339 if (linesLst.size() == 0) {
354 while (theta > M_PI) {
357 while (theta < -M_PI) {
361 if (theta < -M_PI / 2.0)
362 theta = -theta - 3 * M_PI / 2.0;
364 theta = M_PI / 2.0 - theta;
366 for (
unsigned int i = 0; i < linesLst.size(); i++) {
369 linesLst[i].first.project();
370 linesLst[i].second.project();
375 vpMbtMeLine *melinePt =
new vpMbtMeLine;
376 melinePt->setMask(*mask);
379 melinePt->setInitRange(0);
383 melinePt->jmin = (int)ip1.
get_j() - marge;
384 melinePt->jmax = (int)ip2.
get_j() + marge;
386 melinePt->jmin = (int)ip2.
get_j() - marge;
387 melinePt->jmax = (int)ip1.
get_j() + marge;
390 melinePt->imin = (int)ip1.
get_i() - marge;
391 melinePt->imax = (int)ip2.
get_i() + marge;
393 melinePt->imin = (int)ip2.
get_i() - marge;
394 melinePt->imax = (int)ip1.
get_i() + marge;
398 melinePt->initTracking(I, ip1, ip2, rho, theta, doNotTrack);
399 meline.push_back(melinePt);
400 nbFeature.push_back((
unsigned int)melinePt->getMeList().size());
427 for (
size_t i = 0; i <
meline.size(); i++) {
433 for (
size_t i = 0; i <
meline.size(); i++) {
466 std::vector<std::pair<vpPoint, vpPoint> > linesLst;
474 if (linesLst.size() !=
meline.size() || linesLst.size() == 0) {
475 for (
size_t i = 0; i <
meline.size(); i++) {
490 for (
size_t j = 0; j <
meline.size(); j++) {
506 while (theta > M_PI) {
509 while (theta < -M_PI) {
513 if (theta < -M_PI / 2.0)
514 theta = -theta - 3 * M_PI / 2.0;
516 theta = M_PI / 2.0 - theta;
519 for (
unsigned int i = 0; i < linesLst.size(); i++) {
522 linesLst[i].first.project();
523 linesLst[i].second.project();
544 meline[i]->updateParameters(I, ip1, ip2, rho, theta);
549 for (
size_t j = 0; j <
meline.size(); j++) {
562 for (
size_t i = 0; i <
meline.size(); i++) {
588 for (
size_t i = 0; i <
meline.size(); i++) {
616 bool displayFullModel)
618 std::vector<std::vector<double> > models =
621 for (
size_t i = 0; i < models.size(); i++) {
641 bool displayFullModel)
643 std::vector<std::vector<double> > models =
646 for (
size_t i = 0; i < models.size(); i++) {
669 for (
size_t i = 0; i <
meline.size(); i++) {
678 for (
size_t i = 0; i <
meline.size(); i++) {
691 std::vector<std::vector<double> > features;
693 for (
size_t i = 0; i <
meline.size(); i++) {
694 vpMbtMeLine *me_l =
meline[i];
696 for (std::list<vpMeSite>::const_iterator it = me_l->getMeList().begin(); it != me_l->getMeList().end(); ++it) {
698 #if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
699 std::vector<double> params = {0,
702 std::vector<double> params;
706 params.push_back(
static_cast<double>(p_me_l.
getState()));
708 features.push_back(params);
730 bool displayFullModel)
732 std::vector<std::vector<double> > models;
734 if ((
isvisible && isTrackedLine) || displayFullModel) {
753 std::vector<std::pair<vpPoint, vpPoint> > linesLst;
760 for (
unsigned int i = 0; i < linesLst.size(); i++) {
761 linesLst[i].first.project();
762 linesLst[i].second.project();
767 #if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
768 std::vector<double> params = {0,
771 std::vector<double> params;
773 params.push_back(ip1.
get_i());
774 params.push_back(ip1.
get_j());
775 params.push_back(ip2.
get_i());
776 params.push_back(ip2.
get_j());
778 models.push_back(params);
795 for (
size_t i = 0; i <
meline.size(); i++) {
798 std::list<vpMeSite> &me_site_list =
meline[i]->getMeList();
799 me_site_list.clear();
819 double rho = featureline.
getRho();
820 double theta = featureline.
getTheta();
822 double co = cos(theta);
823 double si = sin(theta);
825 double mx = 1.0 / cam.
get_px();
826 double my = 1.0 / cam.
get_py();
836 for (
size_t i = 0; i <
meline.size(); i++) {
837 for (std::list<vpMeSite>::const_iterator it =
meline[i]->getMeList().begin();
838 it !=
meline[i]->getMeList().end(); ++it) {
845 alpha_ = x * si - y * co;
848 double *Ltheta = H[1];
850 for (
unsigned int k = 0; k < 6; k++) {
851 L[j][k] = (Lrho[k] + alpha_ * Ltheta[k]);
853 error[j] = rho - (x * co + y * si);
861 for (
size_t i = 0; i <
meline.size(); i++) {
862 for (std::list<vpMeSite>::const_iterator it =
meline[i]->getMeList().begin();
863 it !=
meline[i]->getMeList().end(); ++it) {
864 for (
unsigned int k = 0; k < 6; k++) {
891 for (
size_t i = 0; i <
meline.size(); i++) {
892 for (std::list<vpMeSite>::const_iterator it =
meline[i]->getMeList().begin(); it !=
meline[i]->getMeList().end();
897 if (i_ < 0 || j_ < 0) {
901 if (((
unsigned int)i_ > (I.
getHeight() - threshold)) || (
unsigned int)i_ < threshold ||
902 ((
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.