40#include <visp3/core/vpImageTools.h>
44#ifdef ENABLE_VISP_NAMESPACE
47 std::cout <<
"Test vpImageTools::binarise() with different data types." << std::endl;
50 std::vector<unsigned char> uchar_array(width * height);
51 std::vector<double> double_array(width * height);
52 std::vector<vpRGBa> rgba_array(width * height);
56 rgba_array[
i] =
vpRGBa(i, i, i, i);
63 std::cout <<
"I:" << std::endl;
64 for (
unsigned int i = 0;
i < I.getHeight();
i++) {
65 for (
unsigned int j = 0;
j < I.getWidth();
j++) {
66 std::cout << static_cast<unsigned>(I[i][j]) <<
" ";
68 std::cout << std::endl;
71 std::cout <<
"\nI_double:" << std::endl;
72 for (
unsigned int i = 0;
i < I_double.getHeight();
i++) {
73 for (
unsigned int j = 0;
j < I_double.getWidth();
j++) {
74 std::cout << I_double[
i][
j] <<
" ";
76 std::cout << std::endl;
79 std::cout <<
"\nI_rgba:" << std::endl;
80 for (
unsigned int i = 0;
i < I_rgba.getHeight();
i++) {
81 for (
unsigned int j = 0;
j < I_rgba.getWidth();
j++) {
82 std::cout << static_cast<unsigned>(I_rgba[i][j].R) <<
" ; " <<
static_cast<unsigned>(I_rgba[
i][
j].G) <<
" ; "
83 <<
static_cast<unsigned>(I_rgba[i][j].B) <<
" ; " <<
static_cast<unsigned int>(I_rgba[
i][
j].A)
86 std::cout << std::endl;
94 std::cout <<
"\nI binarise:" << std::endl;
95 for (
unsigned int i = 0;
i < I.getHeight();
i++) {
96 for (
unsigned int j = 0;
j < I.getWidth();
j++) {
97 std::cout << static_cast<unsigned>(I[i][j]) <<
" ";
99 std::cout << std::endl;
102 std::cout <<
"\nI_double binarise:" << std::endl;
103 for (
unsigned int i = 0;
i < I_double.getHeight();
i++) {
104 for (
unsigned int j = 0;
j < I_double.getWidth();
j++) {
105 std::cout << I_double[
i][
j] <<
" ";
107 std::cout << std::endl;
110 std::cout <<
"\nI_rgba binarise:" << std::endl;
111 for (
unsigned int i = 0;
i < I_rgba.getHeight();
i++) {
112 for (
unsigned int j = 0;
j < I_rgba.getWidth();
j++) {
113 std::cout << static_cast<unsigned>(I_rgba[i][j].R) <<
" ; " <<
static_cast<unsigned>(I_rgba[
i][
j].G) <<
" ; "
114 <<
static_cast<unsigned>(I_rgba[i][j].B) <<
" ; " <<
static_cast<unsigned>(I_rgba[
i][
j].A) << std::endl;
116 std::cout << std::endl;
122 std::vector<unsigned char> uchar_array1(width * height);
123 std::vector<unsigned char> uchar_array2(width * height);
124 for (
unsigned int i = 0;
i < 256;
i++) {
125 uchar_array1[
i] = (
unsigned char)i;
126 uchar_array2[
i] = (
unsigned char)i;
132 unsigned char threshold1 = 50, threshold2 = 200;
133 unsigned char value1 = 4, value2 = 127, value3 = 250;
137 for (
unsigned int i = 0;
i <
height;
i++) {
138 for (
unsigned int j = 0;
j <
width;
j++) {
139 if (I_uchar1[i][j] != I_uchar2[i][j]) {
140 std::cerr <<
"Results are different between iterate and LUT methods !" << std::endl;
149 std::vector<unsigned char> uchar_array_perf_lut(width * height);
150 std::vector<unsigned char> uchar_array_perf_iterate(width * height);
152 uchar_array_perf_lut[
i] = (
unsigned char)i;
153 uchar_array_perf_iterate[
i] = (
unsigned char)i;
159 unsigned int nbIterations = 100;
162 for (
unsigned int cpt = 0; cpt < nbIterations; cpt++) {
166 std::cout <<
"Iterate: " << chrono.
getDurationMs() <<
" ms for " << nbIterations <<
" iterations." << std::endl;
169 for (
unsigned int cpt = 0; cpt < nbIterations; cpt++) {
173 std::cout <<
"LUT: " << chrono.
getDurationMs() <<
" ms for " << nbIterations <<
" iterations." << std::endl;
175 std::cout <<
"\ntestImageBinarise ok !" << std::endl;
void start(bool reset=true)
Definition of the vpImage class member functions.