72#include <visp3/imgproc/vpImgproc.h>
76#if defined(VISP_BUILD_DEPRECATED_FUNCTIONS) && defined(ENABLE_VISP_NAMESPACE)
77using namespace VISP_NAMESPACE_NAME;
80bool fromTo(
const vpImagePoint &from,
const vpImagePoint &to,
vpDirection &direction);
81bool crossesEastBorder(
const vpImage<int> &I,
bool checked[8],
const vpImagePoint &point);
83void followBorder(vpImage<int> &I,
const vpImagePoint &ij, vpImagePoint &i2j2,
vpContour *border,
int nbd);
87void drawContours(vpImage<unsigned char> &I,
const std::vector<std::vector<vpImagePoint> > &contours,
unsigned char grayValue);
88void drawContours(vpImage<vpRGBa> &I,
const std::vector<std::vector<vpImagePoint> > &contours,
const vpColor &color);
98 if (std::fabs(from.
get_i() - to.
get_i()) < std::numeric_limits<double>::epsilon()) {
107 if (std::fabs(from.
get_j() - to.
get_j()) < std::numeric_limits<double>::epsilon()) {
118 if (std::fabs(from.
get_j() - to.
get_j()) < std::numeric_limits<double>::epsilon()) {
139 bool b = checked[
static_cast<int>(direction.
m_direction)];
141 if ((point.
get_i() < 0) || (point.
get_j() < 0)) {
145 unsigned int i =
static_cast<unsigned int>(point.
get_i());
146 unsigned int j =
static_cast<unsigned int>(point.
get_j());
148 return (I[i][j] != 0) && ((
static_cast<unsigned int>(point.
get_j()) == (I.getWidth() - 1)) || b);
155 unsigned int i =
static_cast<unsigned int>(point.
get_i());
156 unsigned int j =
static_cast<unsigned int>(point.
get_j());
161 else if (I[i][j] == 1) {
170 if (!
fromTo(ij, i2j2, dir)) {
178 bool activepixel_ij_neg =
true;
182 if ((activePixel.
get_i() >= 0) && (activePixel.
get_j() >= 0)) {
184 activepixel_ij_neg =
false;
192 if ((i1j1.
get_i() < 0) || (i1j1.
get_j() < 0)) {
200 const int sizeChecked = 8;
201 bool checked[sizeChecked] = {
false,
false,
false,
false,
false,
false,
false,
false };
203 bool i4j4_eq_ij_and_i3j3_eq_i1j1 =
false;
204 while (i4j4_eq_ij_and_i3j3_eq_i1j1 ==
false) {
205 if (!
fromTo(i3j3, i2j2, dir)) {
213 for (
int cpt = 0; cpt < sizeChecked; ++cpt) {
214 checked[cpt] =
false;
217 bool i4j4_ij_neg =
true;
218 while (
true && i4j4_ij_neg) {
219 i4j4 = trace.
active(I, i3j3);
220 if ((i4j4.
get_i() >= 0) && (i4j4.
get_j() >= 0)) {
225 checked[
static_cast<int>(trace.
m_direction)] =
true;
232 if ((i4j4 == ij) && (i3j3 == i1j1)) {
234 i4j4_eq_ij_and_i3j3_eq_i1j1 =
true;
247 return ((I[i][j] == 1) && ((j == 0) || (I[i][j - 1] == 0)));
252 return ((I[i][j] >= 1) && ((j == (I.getWidth() - 1)) || (I[i][j + 1] == 0)));
257 if ((level > 0) && (level < std::numeric_limits<int>::max())) {
262 contour_list.
m_children.push_back(contour_node);
265 std::vector<vpContour *>::const_iterator root_m_children_end = root.
m_children.end();
266 for (std::vector<vpContour *>::const_iterator it = root.
m_children.begin(); it != root_m_children_end; ++it) {
273 if (I.getSize() == 0) {
277 std::vector<std::vector<vpImagePoint> >::const_iterator contours_end = contours.end();
278 for (std::vector<std::vector<vpImagePoint> >::const_iterator it1 = contours.begin(); it1 != contours_end; ++it1) {
279 std::vector<vpImagePoint>::const_iterator it1_end = it1->end();
280 for (std::vector<vpImagePoint>::const_iterator it2 = it1->begin(); it2 != it1_end; ++it2) {
281 unsigned int i =
static_cast<unsigned int>(it2->get_i());
282 unsigned int j =
static_cast<unsigned int>(it2->get_j());
290 if (I.getSize() == 0) {
294 std::vector<std::vector<vpImagePoint> >::const_iterator contours_end = contours.end();
295 for (std::vector<std::vector<vpImagePoint> >::const_iterator it1 = contours.begin(); it1 != contours_end; ++it1) {
296 std::vector<vpImagePoint>::const_iterator it1_end = it1->end();
297 for (std::vector<vpImagePoint>::const_iterator it2 = it1->begin(); it2 != it1_end; ++it2) {
298 unsigned int i =
static_cast<unsigned int>(it2->get_i());
299 unsigned int j =
static_cast<unsigned int>(it2->get_j());
300 I[i][j] =
vpRGBa(color.R, color.G, color.B);
308 if (I_original.
getSize() == 0) {
318 unsigned int i_height = I.getHeight();
319 unsigned int i_width = I.getWidth();
320 unsigned int i_original_width = I_original.
getWidth();
322 for (
unsigned int i = 0; i < i_height; ++i) {
323 if ((i == 0) || (i == (i_height - 1))) {
324 memset(I.bitmap, 0,
sizeof(
int) * i_width);
328 for (
unsigned int j = 0; j < i_original_width; ++j) {
329 I[i][j + 1] = I_original[i - 1][j];
331 I[i][i_width - 1] = 0;
345 std::map<int, vpContour *> borderMap;
346 borderMap[lnbd] = root;
348 for (
unsigned int i = 0; i < i_height; ++i) {
351 for (
unsigned int j = 0; j < i_width; ++j) {
357 if (isOuter || isHole) {
367 borderPrime = borderMap[lnbd];
391 borderPrime = borderMap[lnbd];
421 contourPts.push_back(border->
m_points);
424 borderMap[nbd] = border;
428 if ((fji != 0) && (fji != 1)) {
429 lnbd = std::abs(fji);
438 std::vector<vpContour *>::iterator contours_m_children_end = contours.
m_children.end();
439 for (std::vector<vpContour *>::iterator it = contours.
m_children.begin(); it != contours_m_children_end; ++it) {
440 (*it)->m_parent =
nullptr;
441 if (*it !=
nullptr) {
452 std::vector<vpContour *>::iterator root_m_children_end = root->
m_children.end();
453 for (std::vector<vpContour *>::const_iterator it = root->
m_children.begin(); it != root_m_children_end; ++it) {
455 std::vector<vpContour *> children_copy = (*it)->m_children;
457 (*it)->m_children.clear();
461 (*it)->m_children = children_copy;
463 size_t contours_m_children_size = contours.
m_children.size();
464 for (
size_t i = 0; i < contours_m_children_size; ++i) {
467 contourPts.push_back((*it)->m_points);
474 std::vector<vpContour *>::iterator contours_m_children_end = contours.
m_children.end();
475 for (std::vector<vpContour *>::iterator it = contours.
m_children.begin(); it != contours_m_children_end; ++it) {
476 (*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
unsigned int getHeight() const
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)