38 #include <visp3/core/vpConfig.h>
46 #include <visp3/core/vpMeterPixelConversion.h>
47 #include <visp3/core/vpPlane.h>
48 #include <visp3/mbt/vpMbtDistanceLine.h>
49 #include <visp3/visual_features/vpFeatureBuilder.h>
59 : name(), index(0), cam(), me(nullptr), isTrackedLine(true), isTrackedLineWithVisibility(true), wmean(1), featureline(),
60 poly(), useScanLine(false), meline(), line(nullptr), p1(nullptr), p2(nullptr), L(), error(), nbFeature(), nbFeatureTotal(0),
61 Reinit(false), hiddenface(nullptr), Lindex_polygon(), Lindex_polygon_tracked(), isvisible(false)
72 for (
unsigned int i = 0; i <
meline.size(); i++)
125 double norm = sqrt(A * A + B * B + C * C);
126 plane.
setA(A / norm);
127 plane.
setB(B / norm);
128 plane.
setC(C / norm);
129 plane.
setD(D / norm);
149 buildPlane(P1, P2, P3, plane1);
150 buildPlane(P1, P2, P4, plane2);
166 if (
line ==
nullptr) {
188 if (std::fabs((V1 - V2).sumSquare()) > std::numeric_limits<double>::epsilon()) {
190 V3[0] = double(rand_gen.
next() % 1000) / 100;
191 V3[1] = double(rand_gen.
next() % 1000) / 100;
192 V3[2] = double(rand_gen.
next() % 1000) / 100;
199 vpPoint P3(V3[0], V3[1], V3[2]);
200 vpPoint P4(V4[0], V4[1], V4[2]);
204 vpPoint P3(V1[0], V1[1], V1[2]);
205 vpPoint P4(V2[0], V2[1], V2[2]);
230 unsigned int ind = 0;
238 isTrackedLine =
false;
241 isTrackedLine =
true;
245 if (!isTrackedLine) {
246 isTrackedLineWithVisibility =
false;
259 if (!isTrackedLine) {
260 isTrackedLineWithVisibility =
false;
264 unsigned int ind = 0;
265 isTrackedLineWithVisibility =
false;
268 isTrackedLineWithVisibility =
true;
284 for (
unsigned int i = 0; i <
meline.size(); i++)
285 if (
meline[i] !=
nullptr) {
308 for (
unsigned int i = 0; i <
meline.size(); i++) {
328 std::vector<std::pair<vpPoint, vpPoint> > linesLst;
337 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;
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;
394 melinePt->imin = (int)ip2.
get_i() - marge;
395 melinePt->imax = (int)ip1.
get_i() + marge;
399 melinePt->initTracking(I, ip1, ip2, rho, theta, doNotTrack);
400 meline.push_back(melinePt);
401 nbFeature.push_back((
unsigned int)melinePt->getMeList().size());
430 for (
size_t i = 0; i <
meline.size(); i++) {
437 for (
size_t i = 0; i <
meline.size(); i++) {
470 std::vector<std::pair<vpPoint, vpPoint> > linesLst;
479 if (linesLst.size() !=
meline.size() || linesLst.size() == 0) {
480 for (
size_t i = 0; i <
meline.size(); i++) {
497 for (
size_t j = 0; j <
meline.size(); j++) {
513 while (theta > M_PI) {
516 while (theta < -M_PI) {
520 if (theta < -M_PI / 2.0)
521 theta = -theta - 3 * M_PI / 2.0;
523 theta = M_PI / 2.0 - theta;
526 for (
unsigned int i = 0; i < linesLst.size(); i++) {
529 linesLst[i].first.project();
530 linesLst[i].second.project();
553 meline[i]->updateParameters(I, ip1, ip2, rho, theta);
559 for (
size_t j = 0; j <
meline.size(); j++) {
573 for (
size_t i = 0; i <
meline.size(); i++) {
599 for (
size_t i = 0; i <
meline.size(); i++) {
627 bool displayFullModel)
629 std::vector<std::vector<double> > models =
632 for (
size_t i = 0; i < models.size(); i++) {
652 bool displayFullModel)
654 std::vector<std::vector<double> > models =
657 for (
size_t i = 0; i < models.size(); i++) {
680 for (
size_t i = 0; i <
meline.size(); i++) {
681 if (
meline[i] !=
nullptr) {
689 for (
size_t i = 0; i <
meline.size(); i++) {
690 if (
meline[i] !=
nullptr) {
702 std::vector<std::vector<double> > features;
704 for (
size_t i = 0; i <
meline.size(); i++) {
705 vpMbtMeLine *me_l =
meline[i];
706 if (me_l !=
nullptr) {
707 for (std::list<vpMeSite>::const_iterator it = me_l->getMeList().begin(); it != me_l->getMeList().end(); ++it) {
709 #if (VISP_CXX_STANDARD > VISP_CXX_STANDARD_98)
710 std::vector<double> params = { 0,
713 static_cast<double>(p_me_l.
getState()) };
715 std::vector<double> params;
719 params.push_back(
static_cast<double>(p_me_l.
getState()));
722 features.push_back(params);
744 bool displayFullModel)
746 std::vector<std::vector<double> > models;
748 if ((
isvisible && isTrackedLine) || displayFullModel) {
767 std::vector<std::pair<vpPoint, vpPoint> > linesLst;
775 for (
unsigned int i = 0; i < linesLst.size(); i++) {
776 linesLst[i].first.project();
777 linesLst[i].second.project();
782 #if (VISP_CXX_STANDARD > VISP_CXX_STANDARD_98)
783 std::vector<double> params = { 0,
789 std::vector<double> params;
791 params.push_back(ip1.
get_i());
792 params.push_back(ip1.
get_j());
793 params.push_back(ip2.
get_i());
794 params.push_back(ip2.
get_j());
797 models.push_back(params);
815 for (
size_t i = 0; i <
meline.size(); i++) {
818 std::list<vpMeSite> &me_site_list =
meline[i]->getMeList();
819 me_site_list.clear();
839 double rho = featureline.
getRho();
840 double theta = featureline.
getTheta();
842 double co = cos(theta);
843 double si = sin(theta);
845 double mx = 1.0 / cam.
get_px();
846 double my = 1.0 / cam.
get_py();
856 for (
size_t i = 0; i <
meline.size(); i++) {
857 for (std::list<vpMeSite>::const_iterator it =
meline[i]->getMeList().begin();
858 it !=
meline[i]->getMeList().end(); ++it) {
865 alpha_ = x * si - y * co;
868 double *Ltheta = H[1];
870 for (
unsigned int k = 0; k < 6; k++) {
871 L[j][k] = (Lrho[k] + alpha_ * Ltheta[k]);
873 error[j] = rho - (x * co + y * si);
882 for (
size_t i = 0; i <
meline.size(); i++) {
883 for (std::list<vpMeSite>::const_iterator it =
meline[i]->getMeList().begin();
884 it !=
meline[i]->getMeList().end(); ++it) {
885 for (
unsigned int k = 0; k < 6; k++) {
912 for (
size_t i = 0; i <
meline.size(); i++) {
913 for (std::list<vpMeSite>::const_iterator it =
meline[i]->getMeList().begin(); it !=
meline[i]->getMeList().end();
918 if (i_ < 0 || j_ < 0) {
922 if (((
unsigned int)i_ >(I.
getHeight() - threshold)) || (
unsigned int)i_ < threshold ||
923 ((
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 functionalities.
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 vpImagePoint &t)
vpMatrix interaction(unsigned int select=FEATURE_ALL) VP_OVERRIDE
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 projection() VP_OVERRIDE
void changeFrame(const vpHomogeneousMatrix &cMo, vpColVector &cP) const VP_OVERRIDE
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.
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)
bool initMovingEdge(const vpImage< unsigned char > &I, const vpHomogeneousMatrix &cMo, bool doNotTrack, const vpImage< bool > *mask=nullptr)
std::vector< std::vector< double > > getModelForDisplay(unsigned int width, unsigned int height, const vpHomogeneousMatrix &cMo, const vpCameraParameters &cam, bool displayFullModel=false)
virtual ~vpMbtDistanceLine()
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 reinitMovingEdge(const vpImage< unsigned char > &I, const vpHomogeneousMatrix &cMo, const vpImage< bool > *mask=nullptr)
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 VP_OVERRIDE
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.