Skip to content

Instantly share code, notes, and snippets.

@jrdi
Last active August 29, 2015 13:56
Show Gist options
  • Save jrdi/9328183 to your computer and use it in GitHub Desktop.
Save jrdi/9328183 to your computer and use it in GitHub Desktop.
#include "opencv2/core/core.hpp"
#include "itkObject.h"
#include "itkObjectFactory.h"
#include "BoostTestTargetConfig.h"
void CheckInputArrayChannels( cv::InputArray samples )
{
cv::Mat matrix = samples.getMat();
if( matrix.channels() != 1 )
{
itkGenericExceptionMacro( << "Channels error." );
}
}
BOOST_AUTO_TEST_CASE( cxInputArrayTest )
{
const unsigned int Dimension = 2;
typedef double CoordinateType;
// FAILS
{
typedef cv::Vec<CoordinateType, Dimension> SampleType;
typedef cv::Mat_<CoordinateType> SampleContainerType;
SampleType sample(2., 1.);
SampleContainerType samples;
samples.push_back( sample.t() );
BOOST_CHECK( samples.channels() == 1 );
BOOST_CHECK_NO_THROW( CheckInputArrayChannels( samples ) );
}
// FAILS
{
typedef cv::Matx<CoordinateType, 1, Dimension> SampleType;
typedef cv::Mat_<CoordinateType> SampleContainerType;
SampleType sample(2., 1.);
SampleContainerType samples;
samples.push_back( sample );
BOOST_CHECK( samples.channels() == 1 );
BOOST_CHECK_NO_THROW( CheckInputArrayChannels( samples ) );
}
// FAILS
{
typedef cv::Matx<CoordinateType, 1, Dimension> SampleType;
typedef std::vector<SampleType> SampleContainerType;
SampleType sample(2., 1.);
SampleContainerType samples;
samples.push_back( sample );
BOOST_CHECK_NO_THROW( CheckInputArrayChannels( samples ) );
}
// PASS
{
cv::Mat sample(1, 2, cv::DataType<CoordinateType>::type);
sample.at<CoordinateType>(0) = 2.;
sample.at<CoordinateType>(1) = 1.;
cv::Mat_<CoordinateType> samples;
samples.push_back( sample );
BOOST_CHECK( samples.channels() == 1 );
BOOST_CHECK_NO_THROW( CheckInputArrayChannels( samples ) );
}
// PASS
{
typedef cv::Matx<CoordinateType, 1, Dimension> SampleType;
typedef cv::Mat_<CoordinateType> SampleContainerType;
SampleType sample(2., 1.);
SampleContainerType samples;
samples.push_back( cv::Mat(sample) );
BOOST_CHECK( samples.channels() == 1 );
BOOST_CHECK_NO_THROW( CheckInputArrayChannels( samples ) );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment