Commit 2d96430a authored by biagio montesano's avatar biagio montesano

Added possibility to return float descriptors

parent 044b227d
Tracking API
============
.. highlight:: cpp
Long-term optical tracking API
------------------------------
Long-term optical tracking is one of most important issue for many computer vision applications in real world scenario.
The development in this area is very fragmented and this API is an unique interface useful for plug several algorithms and compare them.
This algorithms start from a bounding box of the target and with their internal representation they avoid the drift during the tracking.
These long-term trackers are able to evaluate online the quality of the location of the target in the new frame, without ground truth.
There are three main components: the TrackerSampler, the TrackerFeatureSet and the TrackerModel. The first component is the object that computes the patches over the frame based on the last target location.
The TrackerFeatureSet is the class that manages the Features, is possible plug many kind of these (HAAR, HOG, LBP, Feature2D, etc).
The last component is the internal representation of the target, it is the appearence model. It stores all state candidates and compute the trajectory (the most likely target states). The class TrackerTargetState represents a possible state of the target.
The TrackerSampler and the TrackerFeatureSet are the visual representation of the target, instead the TrackerModel is the statistical model.
UML design:
-----------
**Tracker diagram**
.. image:: pics/Trackerline.png
:width: 80%
:alt: Tracker diagram
:align: center
......@@ -165,10 +165,10 @@ class CV_EXPORTS_W BinaryDescriptor : public Algorithm
/* requires descriptors computation (only one image) */
CV_WRAP
void compute( const Mat& image, CV_OUT CV_IN_OUT std::vector<KeyLine>& keylines, CV_OUT Mat& descriptors ) const;
void compute( const Mat& image, CV_OUT CV_IN_OUT std::vector<KeyLine>& keylines, CV_OUT Mat& descriptors, bool returnFloatDescr=false ) const;
/* requires descriptors computation (more than one image) */
void compute( const std::vector<Mat>& images, std::vector<std::vector<KeyLine> >& keylines, std::vector<Mat>& descriptors ) const;
void compute( const std::vector<Mat>& images, std::vector<std::vector<KeyLine> >& keylines, std::vector<Mat>& descriptors, bool returnFloatDescr=false ) const;
/*return descriptor size */
int descriptorSize() const;
......@@ -185,14 +185,14 @@ class CV_EXPORTS_W BinaryDescriptor : public Algorithm
/* definition of operator () */
CV_WRAP_AS(detectAndCompute)
virtual void operator()( InputArray image, InputArray mask, CV_OUT std::vector<KeyLine>& keylines, OutputArray descriptors,
bool useProvidedKeyLines = false ) const;
bool useProvidedKeyLines = false, bool returnFloatDescr=false ) const;
protected:
/* implementation of line detection */
virtual void detectImpl( const Mat& imageSrc, std::vector<KeyLine>& keylines, const Mat& mask = Mat() ) const;
/* implementation of descriptors' computation */
virtual void computeImpl( const Mat& imageSrc, std::vector<KeyLine>& keylines, Mat& descriptors ) const;
virtual void computeImpl( const Mat& imageSrc, std::vector<KeyLine>& keylines, Mat& descriptors, bool returnFloatDescr ) const;
/* function inherited from Algorithm */
AlgorithmInfo* info() const;
......
......@@ -99,7 +99,7 @@ int main( int argc, char** argv )
for ( size_t i = 0; i < lines.size(); i++ )
{
KeyLine kl = lines[i];
if( kl.octave == 0 )
if( kl.octave == 0 /*&& kl.response >0.08*/)
{
/* get a random color */
int R = ( rand() % (int) ( 255 + 1 ) );
......
......@@ -189,7 +189,7 @@ BinaryDescriptor::BinaryDescriptor( const BinaryDescriptor::Params &parameters )
/* definition of operator () */
void BinaryDescriptor::operator()( InputArray image, InputArray mask, CV_OUT std::vector<KeyLine>& keylines, OutputArray descriptors,
bool useProvidedKeyLines ) const
bool useProvidedKeyLines, bool returnFloatDescr ) const
{
/* create some matrix objects */
......@@ -210,7 +210,7 @@ void BinaryDescriptor::operator()( InputArray image, InputArray mask, CV_OUT std
detectImpl( imageMat, keylines, maskMat );
/* compute descriptors */
computeImpl( imageMat, keylines, descrMat );
computeImpl( imageMat, keylines, descrMat, returnFloatDescr );
}
BinaryDescriptor::~BinaryDescriptor()
......@@ -481,7 +481,6 @@ void BinaryDescriptor::detectImpl( const Mat& imageSrc, std::vector<KeyLine>& ke
}
/* delete undesired KeyLines, according to input mask */
std::cout << "Mask size " << mask.rows << " " << mask.cols << std::endl;
if( !mask.empty() )
{
for ( size_t keyCounter = 0; keyCounter < keylines.size(); keyCounter++ )
......@@ -495,20 +494,22 @@ void BinaryDescriptor::detectImpl( const Mat& imageSrc, std::vector<KeyLine>& ke
}
/* requires descriptors computation (only one image) */
void BinaryDescriptor::compute( const Mat& image, CV_OUT CV_IN_OUT std::vector<KeyLine>& keylines, CV_OUT Mat& descriptors ) const
void BinaryDescriptor::compute( const Mat& image, CV_OUT CV_IN_OUT std::vector<KeyLine>& keylines, CV_OUT Mat& descriptors,
bool returnFloatDescr ) const
{
computeImpl( image, keylines, descriptors );
computeImpl( image, keylines, descriptors, returnFloatDescr );
}
/* requires descriptors computation (more than one image) */
void BinaryDescriptor::compute( const std::vector<Mat>& images, std::vector<std::vector<KeyLine> >& keylines, std::vector<Mat>& descriptors ) const
void BinaryDescriptor::compute( const std::vector<Mat>& images, std::vector<std::vector<KeyLine> >& keylines, std::vector<Mat>& descriptors,
bool returnFloatDescr ) const
{
for ( size_t i = 0; i < images.size(); i++ )
computeImpl( images[i], keylines[i], descriptors[i] );
computeImpl( images[i], keylines[i], descriptors[i], returnFloatDescr );
}
/* implementation of descriptors computation */
void BinaryDescriptor::computeImpl( const Mat& imageSrc, std::vector<KeyLine>& keylines, Mat& descriptors ) const
void BinaryDescriptor::computeImpl( const Mat& imageSrc, std::vector<KeyLine>& keylines, Mat& descriptors, bool returnFloatDescr ) const
{
/* convert input image to gray scale */
cv::Mat image;
......@@ -616,9 +617,6 @@ void BinaryDescriptor::computeImpl( const Mat& imageSrc, std::vector<KeyLine>& k
/* compute LBD descriptors */
bn->computeLBD( sl );
/* resize output matrix */
descriptors = cv::Mat( keylines.size(), 32, CV_8UC1 );
/* fill output matrix with descriptors */
for ( size_t k = 0; k < sl.size(); k++ )
{
......@@ -628,18 +626,42 @@ void BinaryDescriptor::computeImpl( const Mat& imageSrc, std::vector<KeyLine>& k
int lineOctave = ( sl[k][lineC] ).octaveCount;
int originalIndex = correspondences.find( std::pair<int, int>( k, lineOctave ) )->second;
/* get a pointer to correspondent row in output matrix */
uchar* pointerToRow = descriptors.ptr( originalIndex );
if( !returnFloatDescr )
{
/* resize output matrix */
descriptors = cv::Mat( keylines.size(), 32, CV_8UC1 );
/* get a pointer to correspondent row in output matrix */
uchar* pointerToRow = descriptors.ptr( originalIndex );
/* get LBD data */
float* desVec = sl[k][lineC].descriptor.data();
/* get LBD data */
float* desVec = sl[k][lineC].descriptor.data();
/* fill current row with binary descriptor */
for ( int comb = 0; comb < 32; comb++ )
{
*pointerToRow = bn->binaryConversion( &desVec[8 * combinations[comb][0]], &desVec[8 * combinations[comb][1]] );
pointerToRow++;
}
}
/* fill current row with binary descriptor */
for ( int comb = 0; comb < 32; comb++ )
else
{
*pointerToRow = bn->binaryConversion( &desVec[8 * combinations[comb][0]], &desVec[8 * combinations[comb][1]] );
/* resize output matrix */
descriptors = cv::Mat( keylines.size(), NUM_OF_BANDS * 8, CV_32FC1 );
pointerToRow++;
/* get a pointer to correspondent row in output matrix */
uchar* pointerToRow = descriptors.ptr( originalIndex );
/* get LBD data */
std::vector<float> desVec = sl[k][lineC].descriptor;
for ( size_t count = 0; count < desVec.size(); count++ )
{
*pointerToRow = desVec[count];
pointerToRow++;
}
}
}
......@@ -653,6 +675,7 @@ int BinaryDescriptor::OctaveKeyLines( ScaleLines &keyLines )
/* final number of extracted lines */
unsigned int numOfFinalLine = 0;
std::vector<float> prec, w_idth, nfa;
for ( size_t scaleCounter = 0; scaleCounter < octaveImages.size(); scaleCounter++ )
{
......@@ -660,13 +683,13 @@ int BinaryDescriptor::OctaveKeyLines( ScaleLines &keyLines )
cv::Mat currentScaledImage = octaveImages[scaleCounter];
/* create an LSD detector and store a pointer to it */
cv::Ptr<cv::LineSegmentDetector> ls = cv::createLineSegmentDetector( cv::LSD_REFINE_ADV );
cv::Ptr<cv::LineSegmentDetector> ls = cv::createLineSegmentDetector( cv::LSD_REFINE_ADV, 0.8, 0.6, 2.0, 22.5 );
/* prepare a vector to host extracted segments */
std::vector<cv::Vec4i> lines_std;
/* use detector to extract segments */
ls->detect( currentScaledImage, lines_std );
ls->detect( currentScaledImage, lines_std, w_idth, prec/*, nfa*/ );
/* store lines extracted from current image */
extractedLines.push_back( lines_std );
......@@ -676,6 +699,17 @@ int BinaryDescriptor::OctaveKeyLines( ScaleLines &keyLines )
}
Mat appoggio = octaveImages[0].clone();
cvtColor(appoggio, appoggio, COLOR_GRAY2BGR);
for(size_t t = 0; t<extractedLines[0].size(); t++)
{
Vec4i v = extractedLines[0][t];
line(appoggio, Point(v[0], v[1]), Point(v[2], v[3]), Scalar(255, 0, 0), 3);
std::cout<< std::endl << prec[t] << " " << w_idth[t] /*<< " " << nfa[t]*/ << std::endl;
imshow("M", appoggio);
//waitKey();
}
/* prepare a vector to store octave information associated to extracted lines */
std::vector<OctaveLine> octaveLines( numOfFinalLine );
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment