#include <visp3/core/vpImageTools.h>
int main()
{
#ifdef ENABLE_VISP_NAMESPACE
#endif
std::cout << "Test vpImageTools::binarise() with different data types." << std::endl;
unsigned int width = 5, height = 4;
std::vector<unsigned char> uchar_array(width * height);
std::vector<double> double_array(width * height);
std::vector<vpRGBa> rgba_array(width * height);
for (unsigned char i = 0; i < width * height; i++) {
uchar_array[i] = i;
double_array[i] = i;
rgba_array[i] =
vpRGBa(i, i, i, i);
}
std::cout << "I:" << std::endl;
for (
unsigned int i = 0; i < I.
getHeight(); i++) {
for (
unsigned int j = 0; j < I.
getWidth(); j++) {
std::cout << static_cast<unsigned>(I[i][j]) << " ";
}
std::cout << std::endl;
}
std::cout << "\nI_double:" << std::endl;
for (
unsigned int i = 0; i < I_double.
getHeight(); i++) {
for (
unsigned int j = 0; j < I_double.
getWidth(); j++) {
std::cout << I_double[i][j] << " ";
}
std::cout << std::endl;
}
std::cout << "\nI_rgba:" << std::endl;
for (
unsigned int i = 0; i < I_rgba.
getHeight(); i++) {
for (
unsigned int j = 0; j < I_rgba.
getWidth(); j++) {
std::cout << static_cast<unsigned>(I_rgba[i][j].R) << " ; " << static_cast<unsigned>(I_rgba[i][j].G) << " ; "
<< static_cast<unsigned>(I_rgba[i][j].B) << " ; " << static_cast<unsigned int>(I_rgba[i][j].A)
<< std::endl;
}
std::cout << std::endl;
}
(unsigned char)255);
std::cout << "\nI binarise:" << std::endl;
for (
unsigned int i = 0; i < I.
getHeight(); i++) {
for (
unsigned int j = 0; j < I.
getWidth(); j++) {
std::cout << static_cast<unsigned>(I[i][j]) << " ";
}
std::cout << std::endl;
}
std::cout << "\nI_double binarise:" << std::endl;
for (
unsigned int i = 0; i < I_double.
getHeight(); i++) {
for (
unsigned int j = 0; j < I_double.
getWidth(); j++) {
std::cout << I_double[i][j] << " ";
}
std::cout << std::endl;
}
std::cout << "\nI_rgba binarise:" << std::endl;
for (
unsigned int i = 0; i < I_rgba.
getHeight(); i++) {
for (
unsigned int j = 0; j < I_rgba.
getWidth(); j++) {
std::cout << static_cast<unsigned>(I_rgba[i][j].R) << " ; " << static_cast<unsigned>(I_rgba[i][j].G) << " ; "
<< static_cast<unsigned>(I_rgba[i][j].B) << " ; " << static_cast<unsigned>(I_rgba[i][j].A) << std::endl;
}
std::cout << std::endl;
}
width = 32;
height = 8;
std::vector<unsigned char> uchar_array1(width * height);
std::vector<unsigned char> uchar_array2(width * height);
for (unsigned int i = 0; i < 256; i++) {
uchar_array1[i] = (unsigned char)i;
uchar_array2[i] = (unsigned char)i;
}
unsigned char threshold1 = 50, threshold2 = 200;
unsigned char value1 = 4, value2 = 127, value3 = 250;
for (unsigned int i = 0; i < height; i++) {
for (unsigned int j = 0; j < width; j++) {
if (I_uchar1[i][j] != I_uchar2[i][j]) {
std::cerr << "Results are different between iterate and LUT methods !" << std::endl;
return EXIT_FAILURE;
}
}
}
width = 640;
height = 480;
std::vector<unsigned char> uchar_array_perf_lut(width * height);
std::vector<unsigned char> uchar_array_perf_iterate(width * height);
for (unsigned int i = 0; i < width * height; i++) {
uchar_array_perf_lut[i] = (unsigned char)i;
uchar_array_perf_iterate[i] = (unsigned char)i;
}
unsigned int nbIterations = 100;
for (unsigned int cpt = 0; cpt < nbIterations; cpt++) {
}
std::cout <<
"Iterate: " << chrono.
getDurationMs() <<
" ms for " << nbIterations <<
" iterations." << std::endl;
for (unsigned int cpt = 0; cpt < nbIterations; cpt++) {
}
std::cout <<
"LUT: " << chrono.
getDurationMs() <<
" ms for " << nbIterations <<
" iterations." << std::endl;
std::cout << "\ntestImageBinarise ok !" << std::endl;
return EXIT_SUCCESS;
}
void start(bool reset=true)
unsigned int getWidth() const
unsigned int getHeight() const