76 #include <visp3/imgproc/vpImgproc.h> 86 if (std::fabs(from.
get_i() - to.
get_i()) < std::numeric_limits<double>::epsilon()) {
88 direction.m_direction = EAST;
90 direction.m_direction = WEST;
93 if (std::fabs(from.
get_j() - to.
get_j()) < std::numeric_limits<double>::epsilon()) {
94 direction.m_direction = SOUTH;
96 direction.m_direction = SOUTH_EAST;
98 direction.m_direction = SOUTH_WEST;
101 if (std::fabs(from.
get_j() - to.
get_j()) < std::numeric_limits<double>::epsilon()) {
102 direction.m_direction = NORTH;
104 direction.m_direction = NORTH_EAST;
106 direction.m_direction = NORTH_WEST;
115 vpDirection direction;
120 bool b = checked[(int)direction.m_direction];
126 unsigned int i = (
unsigned int)point.
get_i();
127 unsigned int j = (
unsigned int)point.
get_j();
129 return I[i][j] != 0 && ((
unsigned int)point.
get_j() == I.
getWidth() - 1 || b);
136 unsigned int i = (
unsigned int)point.
get_i();
137 unsigned int j = (
unsigned int)point.
get_j();
139 if (crossesEastBorder(I, checked, point)) {
141 }
else if (I[i][j] == 1) {
150 if (!fromTo(ij, i2j2, dir)) {
154 vpDirection trace = dir.clockwise();
158 while (trace.m_direction != dir.m_direction) {
161 if (activePixel.
get_i() >= 0 && activePixel.
get_j() >= 0) {
166 trace = trace.clockwise();
169 if (i1j1.get_i() < 0 || i1j1.get_j() < 0) {
177 bool checked[8] = {
false,
false,
false,
false,
false,
false,
false,
false};
180 if (!fromTo(i3j3, i2j2, dir)) {
184 trace = dir.counterClockwise();
188 for (
int cpt = 0; cpt < 8; cpt++) {
189 checked[cpt] =
false;
193 i4j4 = trace.active(I, i3j3);
194 if (i4j4.get_i() >= 0 && i4j4.get_j() >= 0) {
198 checked[(int)trace.m_direction] =
true;
199 trace = trace.counterClockwise();
202 addContourPoint(I, border, i3j3, checked, nbd);
204 if (i4j4 == ij && i3j3 == i1j1) {
215 bool isOuterBorderStart(
const vpImage<int> &I,
unsigned int i,
unsigned int j)
217 return (I[i][j] == 1 && (j == 0 || I[i][j - 1] == 0));
220 bool isHoleBorderStart(
const vpImage<int> &I,
unsigned int i,
unsigned int j)
222 return (I[i][j] >= 1 && (j == I.
getWidth() - 1 || I[i][j + 1] == 0));
232 contour_list.
m_children.push_back(contour_node);
235 for (std::vector<vp::vpContour *>::const_iterator it = root.
m_children.begin(); it != root.
m_children.end(); ++it) {
236 getContoursList(**it, level + 1, contour_list);
251 unsigned char grayValue)
257 for (std::vector<std::vector<vpImagePoint> >::const_iterator it1 = contours.begin(); it1 != contours.end(); ++it1) {
258 for (std::vector<vpImagePoint>::const_iterator it2 = it1->begin(); it2 != it1->end(); ++it2) {
259 unsigned int i = (
unsigned int)it2->get_i();
260 unsigned int j = (
unsigned int)it2->get_j();
281 for (std::vector<std::vector<vpImagePoint> >::const_iterator it1 = contours.begin(); it1 != contours.end(); ++it1) {
282 for (std::vector<vpImagePoint>::const_iterator it2 = it1->begin(); it2 != it1->end(); ++it2) {
283 unsigned int i = (
unsigned int)it2->get_i();
284 unsigned int j = (
unsigned int)it2->get_j();
285 I[i][j] =
vpRGBa(color.
R, color.
G, color.
B);
303 if (I_original.
getSize() == 0) {
312 for (
unsigned int i = 0; i < I.
getHeight(); i++) {
317 for (
unsigned int j = 0; j < I_original.
getWidth(); j++) {
318 I[i][j + 1] = I_original[i - 1][j];
334 std::map<int, vpContour *> borderMap;
335 borderMap[lnbd] = root;
337 for (
unsigned int i = 0; i < I.
getHeight(); i++) {
340 for (
unsigned int j = 0; j < I.
getWidth(); j++) {
343 bool isOuter = isOuterBorderStart(I, i, j);
344 bool isHole = isHoleBorderStart(I, i, j);
346 if (isOuter || isHole) {
356 borderPrime = borderMap[lnbd];
379 borderPrime = borderMap[lnbd];
399 followBorder(I, ij, from, border, nbd);
409 contourPts.push_back(border->
m_points);
412 borderMap[nbd] = border;
416 if (fji != 0 && fji != 1) {
417 lnbd = std::abs(fji);
426 for (std::vector<vpContour *>::iterator it = contours.
m_children.begin(); it != contours.
m_children.end(); ++it) {
439 for (std::vector<vpContour *>::const_iterator it = root->
m_children.begin(); it != root->
m_children.end(); ++it) {
441 std::vector<vpContour *> children_copy = (*it)->m_children;
443 (*it)->m_children.clear();
447 (*it)->m_children = children_copy;
449 for (
size_t i = 0; i < contours.
m_children.size(); i++) {
452 contourPts.push_back((*it)->m_points);
455 getContoursList(*root, 0, contours);
458 for (std::vector<vpContour *>::iterator it = contours.
m_children.begin(); it != contours.
m_children.end(); ++it) {
459 (*it)->m_parent = &contours;
unsigned int getWidth() const
unsigned char B
Blue component.
Type * bitmap
points toward the bitmap
Class to define colors available for display functionnalities.
std::vector< vpImagePoint > m_points
error that can be emited by ViSP classes.
std::vector< vpContour * > m_children
unsigned char G
Green component.
VISP_EXPORT void findContours(const vpImage< unsigned char > &I_original, vpContour &contours, std::vector< std::vector< vpImagePoint > > &contourPts, const vpContourRetrievalType &retrievalMode=vp::CONTOUR_RETR_TREE)
unsigned int getSize() const
vpContourType m_contourType
VISP_EXPORT void drawContours(vpImage< unsigned char > &I, const std::vector< std::vector< vpImagePoint > > &contours, unsigned char grayValue=255)
void set_j(const double jj)
void setParent(vpContour *parent)
unsigned char R
Red component.
unsigned int getHeight() const
Class that defines a 2D point in an image. This class is useful for image processing and stores only ...
Definition of the vpImage class member functions.