71 #include <visp3/imgproc/vpImgproc.h>
75 #if defined(VISP_BUILD_DEPRECATED_FUNCTIONS) && defined(ENABLE_VISP_NAMESPACE)
85 if (std::fabs(from.
get_i() - to.
get_i()) < std::numeric_limits<double>::epsilon()) {
94 if (std::fabs(from.
get_j() - to.
get_j()) < std::numeric_limits<double>::epsilon()) {
105 if (std::fabs(from.
get_j() - to.
get_j()) < std::numeric_limits<double>::epsilon()) {
126 bool b = checked[
static_cast<int>(direction.
m_direction)];
128 if ((point.
get_i() < 0) || (point.
get_j() < 0)) {
132 unsigned int i =
static_cast<unsigned int>(point.
get_i());
133 unsigned int j =
static_cast<unsigned int>(point.
get_j());
135 return (I[i][j] != 0) && ((
static_cast<unsigned int>(point.
get_j()) == (I.
getWidth() - 1)) || b);
142 unsigned int i =
static_cast<unsigned int>(point.
get_i());
143 unsigned int j =
static_cast<unsigned int>(point.
get_j());
148 else if (I[i][j] == 1) {
157 if (!
fromTo(ij, i2j2, dir)) {
165 bool activepixel_ij_neg =
true;
169 if ((activePixel.
get_i() >= 0) && (activePixel.
get_j() >= 0)) {
171 activepixel_ij_neg =
false;
179 if ((i1j1.
get_i() < 0) || (i1j1.
get_j() < 0)) {
187 const int sizeChecked = 8;
188 bool checked[sizeChecked] = {
false,
false,
false,
false,
false,
false,
false,
false };
190 bool i4j4_eq_ij_and_i3j3_eq_i1j1 =
false;
191 while (i4j4_eq_ij_and_i3j3_eq_i1j1 ==
false) {
192 if (!
fromTo(i3j3, i2j2, dir)) {
200 for (
int cpt = 0; cpt < sizeChecked; ++cpt) {
201 checked[cpt] =
false;
204 bool i4j4_ij_neg =
true;
205 while (
true && i4j4_ij_neg) {
206 i4j4 = trace.
active(I, i3j3);
207 if ((i4j4.
get_i() >= 0) && (i4j4.
get_j() >= 0)) {
212 checked[
static_cast<int>(trace.
m_direction)] =
true;
219 if ((i4j4 == ij) && (i3j3 == i1j1)) {
221 i4j4_eq_ij_and_i3j3_eq_i1j1 =
true;
234 return ((I[i][j] == 1) && ((j == 0) || (I[i][j - 1] == 0)));
239 return ((I[i][j] >= 1) && ((j == (I.
getWidth() - 1)) || (I[i][j + 1] == 0)));
244 if ((level > 0) && (level < std::numeric_limits<int>::max())) {
249 contour_list.
m_children.push_back(contour_node);
252 std::vector<vpContour *>::const_iterator root_m_children_end = root.
m_children.end();
253 for (std::vector<vpContour *>::const_iterator it = root.
m_children.begin(); it != root_m_children_end; ++it) {
264 std::vector<std::vector<vpImagePoint> >::const_iterator contours_end = contours.end();
265 for (std::vector<std::vector<vpImagePoint> >::const_iterator it1 = contours.begin(); it1 != contours_end; ++it1) {
266 std::vector<vpImagePoint>::const_iterator it1_end = it1->end();
267 for (std::vector<vpImagePoint>::const_iterator it2 = it1->begin(); it2 != it1_end; ++it2) {
268 unsigned int i =
static_cast<unsigned int>(it2->get_i());
269 unsigned int j =
static_cast<unsigned int>(it2->get_j());
281 std::vector<std::vector<vpImagePoint> >::const_iterator contours_end = contours.end();
282 for (std::vector<std::vector<vpImagePoint> >::const_iterator it1 = contours.begin(); it1 != contours_end; ++it1) {
283 std::vector<vpImagePoint>::const_iterator it1_end = it1->end();
284 for (std::vector<vpImagePoint>::const_iterator it2 = it1->begin(); it2 != it1_end; ++it2) {
285 unsigned int i =
static_cast<unsigned int>(it2->get_i());
286 unsigned int j =
static_cast<unsigned int>(it2->get_j());
287 I[i][j] =
vpRGBa(color.
R, color.
G, color.
B);
295 if (I_original.
getSize() == 0) {
306 unsigned int i_width = I.
getWidth();
307 unsigned int i_original_width = I_original.
getWidth();
309 for (
unsigned int i = 0; i < i_height; ++i) {
310 if ((i == 0) || (i == (i_height - 1))) {
311 memset(I.
bitmap, 0,
sizeof(
int) * i_width);
315 for (
unsigned int j = 0; j < i_original_width; ++j) {
316 I[i][j + 1] = I_original[i - 1][j];
318 I[i][i_width - 1] = 0;
332 std::map<int, vpContour *> borderMap;
333 borderMap[lnbd] = root;
335 for (
unsigned int i = 0; i < i_height; ++i) {
338 for (
unsigned int j = 0; j < i_width; ++j) {
344 if (isOuter || isHole) {
354 borderPrime = borderMap[lnbd];
378 borderPrime = borderMap[lnbd];
408 contourPts.push_back(border->
m_points);
411 borderMap[nbd] = border;
415 if ((fji != 0) && (fji != 1)) {
416 lnbd = std::abs(fji);
425 std::vector<vpContour *>::iterator contours_m_children_end = contours.
m_children.end();
426 for (std::vector<vpContour *>::iterator it = contours.
m_children.begin(); it != contours_m_children_end; ++it) {
427 (*it)->m_parent =
nullptr;
428 if (*it !=
nullptr) {
439 std::vector<vpContour *>::iterator root_m_children_end = root->
m_children.end();
440 for (std::vector<vpContour *>::const_iterator it = root->
m_children.begin(); it != root_m_children_end; ++it) {
442 std::vector<vpContour *> children_copy = (*it)->m_children;
444 (*it)->m_children.clear();
448 (*it)->m_children = children_copy;
450 size_t contours_m_children_size = contours.
m_children.size();
451 for (
size_t i = 0; i < contours_m_children_size; ++i) {
454 contourPts.push_back((*it)->m_points);
461 std::vector<vpContour *>::iterator contours_m_children_end = contours.
m_children.end();
462 for (std::vector<vpContour *>::iterator it = contours.
m_children.begin(); it != contours_m_children_end; ++it) {
463 (*it)->m_parent = &contours;
VISP_NAMESPACE_ADDRESSING vpImagePoint active(const VISP_NAMESPACE_ADDRESSING vpImage< int > &I, const VISP_NAMESPACE_ADDRESSING vpImagePoint &point)
vpDirection counterClockwise()
vpDirectionType m_direction
Direction.
Class to define RGB colors available for display functionalities.
error that can be emitted by ViSP classes.
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.
unsigned int getWidth() const
unsigned int getSize() const
Type * bitmap
points toward the bitmap
unsigned int getHeight() const
unsigned char B
Blue component.
unsigned char R
Red component.
unsigned char G
Green component.
VISP_EXPORT void findContours(const VISP_NAMESPACE_ADDRESSING vpImage< unsigned char > &I_original, vpContour &contours, std::vector< std::vector< VISP_NAMESPACE_ADDRESSING vpImagePoint > > &contourPts, const vpContourRetrievalType &retrievalMode=CONTOUR_RETR_TREE)
VISP_EXPORT void drawContours(VISP_NAMESPACE_ADDRESSING vpImage< unsigned char > &I, const std::vector< std::vector< VISP_NAMESPACE_ADDRESSING vpImagePoint > > &contours, unsigned char grayValue=255)
void followBorder(vpImage< int > &I, const vpImagePoint &ij, vpImagePoint &i2j2, vpContour *border, int nbd)
bool fromTo(const vpImagePoint &from, const vpImagePoint &to, vpDirection &direction)
bool crossesEastBorder(const vpImage< int > &I, bool checked[8], const vpImagePoint &point)
bool isOuterBorderStart(const vpImage< int > &I, unsigned int i, unsigned int j)
void addContourPoint(vpImage< int > &I, vpContour *border, const vpImagePoint &point, bool checked[8], int nbd)
@ SOUTH_EAST
South-East direction.
@ SOUTH_WEST
South-West direction.
@ NORTH_EAST
North-East direction.
@ NORTH_WEST
North-West direction.
void getContoursList(const vpContour &root, int level, vpContour &contour_list)
bool isHoleBorderStart(const vpImage< int > &I, unsigned int i, unsigned int j)
std::vector< vpContour * > m_children
Children contour.
std::vector< VISP_NAMESPACE_ADDRESSING vpImagePoint > m_points
Vector of points belonging to the contour.
vpContourType m_contourType
Contour type.
vpContour * m_parent
Parent contour.
void setParent(vpContour *parent)