Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@ jobs:
boost-date-time
boost-exception
boost-filesystem
boost-foreach
boost-iterator
boost-lexical-cast
boost-math[legacy]
Expand Down
1 change: 0 additions & 1 deletion doc/sphinx/source/install/install.rst
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,6 @@ To install the dependencies:
boost-container
boost-date-time
boost-exception
boost-foreach
boost-filesystem
boost-iterator
boost-lexical-cast
Expand Down
8 changes: 2 additions & 6 deletions src/cctag/Identification.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
#include <boost/accumulators/statistics/median.hpp>
#include <boost/accumulators/statistics/variance.hpp>
#include <boost/assert.hpp>
#include <boost/foreach.hpp>

#include <cmath>
#include <mutex>
Expand All @@ -48,151 +47,148 @@
* @param[in] minIdentProba minimal probability to considered a cctag as correctly identified
* @return true if the cctag has been correctly identified, false otherwise
*/
bool orazioDistanceRobust(
std::vector<std::list<float> > & vScore,
const RadiusRatioBank & rrBank,
const std::vector<cctag::ImageCut> & cuts,
float minIdentProba)
{
BOOST_ASSERT( cuts.size() > 0 );

using namespace cctag::numerical;
using namespace boost::accumulators;

using MapT = std::map<float, MarkerID>;

if ( cuts.empty() )
{
return false;
}
#ifdef GRIFF_DEBUG
if( rrBank.size() == 0 )
{
return false;
}
#endif // GRIFF_DEBUG

const size_t cut_count = cuts.size();
static std::mutex vscore_mutex;

tbb::parallel_for(size_t(0), cut_count, [&](size_t i) {
const cctag::ImageCut& cut = cuts[i];
if ( !cut.outOfBounds() )
{
MapT sortedId; // 6-nearest neighbours along with their affectation probability
const std::size_t sizeIds = 6;
IdSet idSet;
idSet.reserve(sizeIds);

// imgSig contains the rectified 1D signal.
//boost::numeric::ublas::vector<float> imgSig( cuts.front().imgSignal().size() );
const std::vector<float> & imgSig = cut.imgSignal();

// compute some statitics
accumulator_set< float, features< /*tag::median,*/ tag::variance > > acc;
// Put the image signal into the accumulator
acc = std::for_each( imgSig.begin()+30, imgSig.end(), acc ); // todo@Lilian +30

// Mean
const float medianSig = boost::accumulators::mean( acc );

// or median
//const float medianSig = computeMedian( imgSig );

const float varSig = boost::accumulators::variance( acc );

accumulator_set< float, features< tag::mean > > accInf;
accumulator_set< float, features< tag::mean > > accSup;

bool doAccumulate = false;
for(float i : imgSig)
{
if ( (!doAccumulate) && ( i < medianSig ) )
doAccumulate = true;

if (doAccumulate)
{
if ( i < medianSig )
accInf( i );
else
accSup( i );
}
}
const float muw = boost::accumulators::mean( accSup );
const float mub = boost::accumulators::mean( accInf );

// Find the nearest ID in rrBank
const float stepX = (cut.endSig() - cut.beginSig()) / ( imgSig.size() - 1.f );

// vector of 1 or -1 values
std::vector<float> digit( imgSig.size() );

#ifdef GRIFF_DEBUG
assert( rrBank.size() > 0 );
#endif // GRIFF_DEBUG
// Loop over imgSig values, compute and sum the difference between
// imgSig and digit (i.e. generated profile)
for( std::size_t idc = 0; idc < rrBank.size(); ++idc )
{
// Compute the idc-th profile from the radius ratio
// todo@Lilian: to be pre-computed
float x = cut.beginSig();
for(float & i : digit)
{
std::ssize_t ldum = 0;
for(float j : rrBank[idc])
{
if( 1.f / j <= x )
{
++ldum;
}
}
// set odd value to -1 and even value to 1
i = - ( ldum % 2 ) * 2 + 1;

x += stepX;
}

// compute distance to profile
float distance = 0;
for( std::size_t i = 0 ; i < imgSig.size() ; ++i )
{
distance += dis( imgSig[i], digit[i], mub, muw, varSig );
}
const float v = std::exp( -distance ); // todo: remove the exp()
sortedId[v] = idc;
}

#ifdef GRIFF_DEBUG
assert( sortedId.size() > 0 );
#endif // GRIFF_DEBUG
int k = 0;
BOOST_REVERSE_FOREACH( const MapT::const_iterator::value_type & v, sortedId )
for( auto riter = sortedId.crbegin(); riter != sortedId.crend(); ++riter )
{
if( k >= sizeIds ) break;
std::pair< MarkerID, float > markerId;
markerId.first = v.second;
markerId.second = v.first;
idSet.push_back(markerId);
idSet.emplace_back(riter->second, riter->first);
++k;
}

#ifdef GRIFF_DEBUG
assert( idSet.size() > 0 );
MarkerID _debug_m = idSet.front().first;
assert( _debug_m > 0 );
assert( vScore.size() > _debug_m );
#endif // GRIFF_DEBUG

{
std::lock_guard<std::mutex> lock(vscore_mutex);
vScore[idSet.front().first].push_back(idSet.front().second);
}
}
});
return true;
}

Check notice on line 191 in src/cctag/Identification.cpp

View check run for this annotation

codefactor.io / CodeFactor

src/cctag/Identification.cpp#L50-L191

Complex Method
void createRectifiedCutImage(const std::vector<ImageCut> & vCuts, cv::Mat & output)
{
output = cv::Mat(vCuts.size(), vCuts.front().imgSignal().size(), CV_8UC1);
Expand Down