#include <iostream>
#include <limits>
#include <visp3/core/vpConfig.h>
#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<bool useFullScale >
{
if ((hsv_computed.
H != hsv_truth.
H) ||
(hsv_computed.
S != hsv_truth.
S) ||
(hsv_computed.
V != hsv_truth.
V)) {
std::cout << "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;
}
template<typename Type, bool useFullScale >
{
std::cout << "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::cout << std::endl << "----- Testing single pixel HSV to HSV conversions -----" << std::endl;
isSuccess = isSuccess && test_hsv(hsvfucf,
vpHSV<float>(1., 1., 1.));
isSuccess = isSuccess && test_hsv(hsvfuct,
vpHSV<float>(1., 1., 1.));
isSuccess = isSuccess && test_hsv(hsvducf,
vpHSV<double>(1., 1., 1.));
isSuccess = isSuccess && test_hsv(hsvduct,
vpHSV<double>(1., 1., 1.));
std::cout << std::endl << "----- Testing vpImageConvert(HSV, HSV) conversions -----" << std::endl;
{
std::cout << std::endl << "\t UCHAR -> floating types" << std::endl;
bool localSuccess = vpHSVTests::areAlmostEqual(Ihff, "Ihff", Ihff_truth, "Ihff_truth");
if (!localSuccess) {
std::cerr << "vpImageConvert(HSV<uchar, false>, HSV<float>) failed!" << std::endl;
}
isSuccess = isSuccess && localSuccess;
localSuccess = vpHSVTests::areAlmostEqual(Ihft, "Ihft", Ihft_truth, "Ihft_truth");
if (!localSuccess) {
std::cerr << "vpImageConvert(HSV<uchar, true>, HSV<float>) failed!" << std::endl;
}
isSuccess = isSuccess && localSuccess;
localSuccess = vpHSVTests::areAlmostEqual(Ihdf, "Ihdf", Ihdf_truth, "Ihdf_truth");
if (!localSuccess) {
std::cerr << "vpImageConvert(HSV<uchar, false>, HSV<double>) failed!" << std::endl;
}
isSuccess = isSuccess && localSuccess;
localSuccess = vpHSVTests::areAlmostEqual(Ihdt, "Ihdt", Ihdt_truth, "Ihdt_truth");
if (!localSuccess) {
std::cerr << "vpImageConvert(HSV<uchar, true>, HSV<double>) failed!" << std::endl;
}
isSuccess = isSuccess && localSuccess;
}
{
std::cout << std::endl << "\t floating types -> UCHAR" << std::endl;
bool localSuccess = vpHSVTests::areAlmostEqual(Iucf, "Iucf", Iucf_truth, "Iucf_truth");
if (!localSuccess) {
std::cerr << "vpImageConvert(HSV<float>, HSV<uchar, false>) failed!" << std::endl;
}
isSuccess = isSuccess && localSuccess;
localSuccess = vpHSVTests::areAlmostEqual(Iuct, "Iuct", Iuct_truth, "Iuct_truth");
if (!localSuccess) {
std::cerr << "vpImageConvert(HSV<float>, HSV<uchar, true>) failed!" << std::endl;
}
isSuccess = isSuccess && localSuccess;
localSuccess = vpHSVTests::areAlmostEqual(Iucf, "Iucf", Iucf_truth, "Iucf_truth");
if (!localSuccess) {
std::cerr << "vpImageConvert(HSV<double>, HSV<uchar, false>) failed!" << std::endl;
}
isSuccess = isSuccess && localSuccess;
localSuccess = vpHSVTests::areAlmostEqual(Iuct, "Iuct", Iuct_truth, "Iuct_truth");
if (!localSuccess) {
std::cerr << "vpImageConvert(HSV<double>, HSV<uchar, true>) failed!" << std::endl;
}
isSuccess = isSuccess && localSuccess;
}
{
std::cout << std::endl << "\t floating types -> floating types" << std::endl;
bool localSuccess = vpHSVTests::areAlmostEqual(Idouble, "Idouble", Idouble_truth, "Idouble_truth");
if (!localSuccess) {
std::cerr << "vpImageConvert(HSV<float>, HSV<double>) failed!" << std::endl;
}
isSuccess = isSuccess && localSuccess;
localSuccess = vpHSVTests::areAlmostEqual(Ifloat, "Ifloat", Ifloat_truth, "Ifloat_truth");
if (!localSuccess) {
std::cerr << "vpImageConvert(HSV<double>, HSV<float>) 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)