#include <visp3/core/vpImageTools.h>
int main()
{
std::cout << "Test vpImageTools::binarise() with different data types." << std::endl;
unsigned int width = 5, height = 4;
unsigned char *uchar_array = new unsigned char[width*height];
double *double_array = new double[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;
}
vpImageTools::binarise(I, (
unsigned char) 5, (
unsigned char) 12, (
unsigned char) 0, (
unsigned char) 127, (
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;
unsigned char *uchar_array1 = new unsigned char[width*height];
unsigned char *uchar_array2 = new unsigned char[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 -1;
}
}
}
width = 640;
height = 480;
unsigned char *uchar_array_perf_lut = new unsigned char[width*height];
unsigned char *uchar_array_perf_iterate = new unsigned char[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: " << t1 << " ms for " << nbIterations << " iterations." << std::endl;
for(unsigned int cpt = 0; cpt < nbIterations; cpt++) {
}
std::cout << "LUT: " << t2 << " ms for " << nbIterations << " iterations." << std::endl;
std::cout << "\ntestImageBinarise ok !" << std::endl;
return 0;
}