36 #include <visp3/core/vpConfig.h>
38 #if defined(VISP_HAVE_OPENCV) && defined(HAVE_OPENCV_IMGPROC)
39 #include <opencv2/imgproc/imgproc.hpp>
42 #include <visp3/tt/vpTemplateTrackerZone.h>
54 : Zone(), min_x(-1), min_y(-1), max_x(-1), max_y(-1)
109 std::vector<vpImagePoint> vip;
121 if (vip.size() > 1) {
127 if (vip.size() % 3 == 2)
130 else if (vip.size() % 3 == 0) {
167 if (vip.size() == 3) {
170 else if (vip.size() == 4) {
171 std::vector<vpImagePoint> vip_delaunay;
172 vip_delaunay.push_back(vip[0]);
173 vip_delaunay.push_back(vip[1]);
174 vip_delaunay.push_back(vip[2]);
175 vip_delaunay.push_back(vip[2]);
176 vip_delaunay.push_back(vip[3]);
177 vip_delaunay.push_back(vip[0]);
181 #if defined(VISP_HAVE_OPENCV) && defined(HAVE_OPENCV_IMGPROC)
184 for (
size_t i = 0; i < vip.size(); i++) {
185 cv::Point2f fp((
float)vip[i].get_u(), (
float)vip[i].get_v());
191 std::vector<cv::Vec6f> triangleList;
192 subdiv.getTriangleList(triangleList);
197 std::vector<vpImagePoint> vip_delaunay;
198 for (
size_t i = 0; i < triangleList.size(); i++) {
199 cv::Vec6f t = triangleList[i];
200 std::vector<vpImagePoint> p(3);
202 p[0].set_uv(t[0], t[1]);
203 p[1].set_uv(t[2], t[3]);
204 p[2].set_uv(t[4], t[5]);
206 if (p[0].inRectangle(rect) && p[1].inRectangle(rect) && p[2].inRectangle(rect)) {
207 vip_delaunay.push_back(p[0]);
208 vip_delaunay.push_back(p[1]);
209 vip_delaunay.push_back(p[2]);
221 for (
unsigned int i = 0; i < vip.size(); i += 3) {
270 std::vector<vpTemplateTrackerTriangle>::const_iterator Iterateurvecteur;
271 for (Iterateurvecteur =
Zone.begin(); Iterateurvecteur !=
Zone.end(); ++Iterateurvecteur) {
272 if (Iterateurvecteur->inTriangle(i, j))
286 std::vector<vpTemplateTrackerTriangle>::const_iterator Iterateurvecteur;
287 for (Iterateurvecteur =
Zone.begin(); Iterateurvecteur !=
Zone.end(); ++Iterateurvecteur) {
288 if (Iterateurvecteur->inTriangle(i, j))
304 std::vector<vpTemplateTrackerTriangle>::const_iterator Iterateurvecteur;
305 for (Iterateurvecteur =
Zone.begin(); Iterateurvecteur !=
Zone.end(); ++Iterateurvecteur) {
306 if (Iterateurvecteur->inTriangle(i, j)) {
325 std::vector<vpTemplateTrackerTriangle>::const_iterator Iterateurvecteur;
326 for (Iterateurvecteur =
Zone.begin(); Iterateurvecteur !=
Zone.end(); ++Iterateurvecteur) {
327 if (Iterateurvecteur->inTriangle(i, j)) {
448 std::vector<vpImagePoint> ip;
449 for (
unsigned int i = 0; i <
Zone.size(); i++) {
451 Zone[i].getCorners(ip);
465 std::vector<vpImagePoint> ip;
466 for (
unsigned int i = 0; i <
Zone.size(); i++) {
468 Zone[i].getCorners(ip);
492 for (
int i = 0; i < (int)I.
getHeight(); i++) {
493 for (
int j = 0; j < (int)I.
getWidth(); j++) {
495 I[i][j] = gray_level;
512 tempZone.
add(TtempDown);
550 double x_center = 0, y_center = 0;
551 for (
int j = 0; j < borne_x; j++)
552 for (
int i = 0; i < borne_y; i++)
563 x_center = x_center / cpt_pt;
564 y_center = y_center / cpt_pt;
566 center.
set_uv(x_center, y_center);
Class to define RGB colors available for display functionalities.
static const vpColor blue
static bool getClick(const vpImage< unsigned char > &I, bool blocking=true)
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 displayCross(const vpImage< unsigned char > &I, const vpImagePoint &ip, unsigned int size, const vpColor &color, unsigned int thickness=1)
static void flush(const vpImage< unsigned char > &I)
error that can be emitted by ViSP classes.
@ badValue
Used to indicate that a value is not in the allowed range.
@ functionNotImplementedError
Function not implemented.
@ divideByZeroError
Division by zero.
Class that defines a 2D point in an image. This class is useful for image processing and stores only ...
void set_uv(double u, double v)
unsigned int getWidth() const
unsigned int getHeight() const
Defines a rectangle in the plane.
void setBottomRight(const vpImagePoint &bottomRight)
void setTopLeft(const vpImagePoint &topLeft)
bool inTriangle(const vpImagePoint &ip) const
vpTemplateTrackerTriangle getPyramidDown() const
vpTemplateTrackerZone getPyramidDown() const
std::vector< vpTemplateTrackerTriangle > Zone
Vector of triangles that defines the zone.
int max_y
Bounding box parameter.
vpTemplateTrackerZone & operator=(const vpTemplateTrackerZone &z)
void initFromPoints(const vpImage< unsigned char > &I, const std::vector< vpImagePoint > &ip, bool delaunay=false)
bool inZone(const int &i, const int &j) const
void getTriangle(unsigned int i, vpTemplateTrackerTriangle &T) const
unsigned int getNbTriangle() const
void copy(const vpTemplateTrackerZone &z)
int max_x
Bounding box parameter.
void fillTriangle(vpImage< unsigned char > &I, unsigned int id, unsigned char gray_level)
vpRect getBoundingBox() const
void add(const vpTemplateTrackerTriangle &t)
vpImagePoint getCenter() const
void display(const vpImage< unsigned char > &I, const vpColor &col=vpColor::green, unsigned int thickness=3)
virtual ~vpTemplateTrackerZone()
int min_y
Bounding box parameter.
void initClick(const vpImage< unsigned char > &I, bool delaunay=false)
int min_x
Bounding box parameter.
VISP_EXPORT int wait(double t0, double t)