#include <iostream>
#include <limits>
#include <visp3/core/vpImage.h>
#include <visp3/core/vpImageConvert.h>
#include <visp3/core/vpRGBa.h>
#include <visp3/core/vpHSV.h>
#include "hsvUtils.h"
#if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
#ifdef ENABLE_VISP_NAMESPACE
#endif
#ifndef DOXYGEN_SHOULD_SKIP_THIS
template<typename Type, bool useFullScale >
{
std::cout << static_cast<int>(rgb_truth.
R) <<
","
<<
static_cast<int>(rgb_truth.
G) <<
","
<<
static_cast<int>(rgb_truth.
B) <<
"): Expected hsv value: ("
<<
static_cast<int>(hsv_truth.
H) <<
","
<<
static_cast<int>(hsv_truth.
S) <<
","
<<
static_cast<int>(hsv_truth.
V) <<
") converted value: ("
<<
static_cast<int>(hsv_computed.
H) <<
","
<<
static_cast<int>(hsv_computed.
S) <<
","
<<
static_cast<int>(hsv_computed.
V) <<
")" << std::endl;
return false;
}
return true;
}
#endif
int main()
{
bool isSuccess = true;
std::vector< vpColVector > rgb_truth;
double h_max;
bool h_full;
size_t size = rgb_truth.size();
for (size_t test = 0; test < 2; ++test) {
if (test == 0) {
h_max = 255;
h_full = true;
}
else {
h_full = false;
}
std::vector< vpColVector > hsv_truth;
hsv_truth.emplace_back(std::vector<double>({ 0., 0., 0. }));
hsv_truth.emplace_back(std::vector<double>({ 0., 0., 255. }));
hsv_truth.emplace_back(std::vector<double>({ 0., 255., 255. }));
hsv_truth.emplace_back(std::vector<double>({ h_max * 120. / 360., 255., 255. }));
hsv_truth.emplace_back(std::vector<double>({ h_max * 240. / 360., 255., 255. }));
hsv_truth.emplace_back(std::vector<double>({ h_max * 60. / 360., 255., 255. }));
hsv_truth.emplace_back(std::vector<double>({ h_max * 180. / 360., 255., 255. }));
hsv_truth.emplace_back(std::vector<double>({ h_max * 300. / 360., 255., 255. }));
hsv_truth.emplace_back(std::vector<double>({ 0., 0., 128. }));
hsv_truth.emplace_back(std::vector<double>({ h_max * 60. / 360., 255., 128. }));
hsv_truth.emplace_back(std::vector<double>({ 0., 255., 128. }));
hsv_truth.emplace_back(std::vector<double>({ h_max * 120. / 360., 255., 128. }));
hsv_truth.emplace_back(std::vector<double>({ h_max * 180. / 360., 255., 128. }));
hsv_truth.emplace_back(std::vector<double>({ h_max * 240. / 360., 255., 128. }));
hsv_truth.emplace_back(std::vector<double>({ h_max * 300. / 360., 255., 128. }));
std::cout << std::endl << "----- Test rgba -> hsv (unsigned char) conversion with h full scale: " << (h_full ? "yes" : "no") << " -----" << std::endl;
for (unsigned int id = 0; id < size; ++id) {
if (h_full) {
hsv.buildFrom(rgba);
}
else {
hsv.buildFrom(rgba);
}
}
if (h_full) {
std::cout << std::endl << "----- Test rgb -> hsv (double) conversion -----" << std::endl;
for (unsigned int id = 0; id < size; ++id) {
for (unsigned char c = 0; c < vpHSV<double>::nbChannels; ++c) {
hsv_truth[id][c] = hsv_truth[id][c] / 255.;
}
isSuccess = isSuccess && test_hsv(hsv, rgba,
vpHSV<double>(hsv_truth[
id]));
}
}
}
std::cout << std::endl << "----- Testing vpImageConvert::convert(vpImage<vpRGBa>, vpImage<vpHSV>) conversions -----" << std::endl;
bool localSuccess = vpHSVTests::areAlmostEqual(Ihsvucf, "Ihsvucf", Ihsvucf_truth, "Ihsvucf_truth", 1.0);
if (!localSuccess) {
std::cerr << "vpImageConvert(rgba, hsv<uchar, false>) failed!" << std::endl;
}
isSuccess = isSuccess && localSuccess;
localSuccess = vpHSVTests::areAlmostEqual(Ihsvuct, "Ihsvuct", Ihsvuct_truth, "Ihsvuct_truth", 1.0);
if (!localSuccess) {
std::cerr << "vpImageConvert(rgba, hsv<uchar, true>) failed!" << std::endl;
}
isSuccess = isSuccess && localSuccess;
localSuccess = vpHSVTests::areAlmostEqual(Ihsvd, "Ihsvd", Ihsvd_truth, "Ihsvd_truth");
if (!localSuccess) {
std::cerr << "vpImageConvert(rgba, hsv<double>) failed!" << std::endl;
}
isSuccess = isSuccess && localSuccess;
if (isSuccess) {
std::cout << "All tests were successful !" << std::endl;
return EXIT_SUCCESS;
}
std::cerr << "ERROR: Something went wrong !" << std::endl;
return EXIT_FAILURE;
}
#else
int main()
{
std::cout << "vpHSV class is not available, please use CXX 11 standard" << std::endl;
return EXIT_SUCCESS;
}
#endif
Class implementing the HSV pixel format.
static constexpr unsigned char maxHueUsingLimitedRange
Maximum value of the Hue channel when using unsigned char and the limited range.
static void convert(const vpImage< unsigned char > &src, vpImage< vpRGBa > &dest)
Definition of the vpImage class member functions.
static bool equal(double x, double y, double threshold=0.001)
unsigned char B
Blue component.
unsigned char R
Red component.
unsigned char G
Green component.