diff --git a/modules/line_descriptor/doc/cameraman_lines2.png b/modules/line_descriptor/doc/cameraman_lines2.png new file mode 100644 index 000000000..01541766a Binary files /dev/null and b/modules/line_descriptor/doc/cameraman_lines2.png differ diff --git a/modules/line_descriptor/doc/pics/Trackerline.png b/modules/line_descriptor/doc/pics/Trackerline.png new file mode 100644 index 000000000..f5aa2bbd1 Binary files /dev/null and b/modules/line_descriptor/doc/pics/Trackerline.png differ diff --git a/modules/line_descriptor/doc/pics/cameraman_lines2.png b/modules/line_descriptor/doc/pics/cameraman_lines2.png new file mode 100644 index 000000000..01541766a Binary files /dev/null and b/modules/line_descriptor/doc/pics/cameraman_lines2.png differ diff --git a/modules/line_descriptor/doc/pics/match.png b/modules/line_descriptor/doc/pics/match.png new file mode 100644 index 000000000..c5d919b0a Binary files /dev/null and b/modules/line_descriptor/doc/pics/match.png differ diff --git a/modules/line_descriptor/doc/tutorial.rst b/modules/line_descriptor/doc/tutorial.rst new file mode 100644 index 000000000..7d2090ab7 --- /dev/null +++ b/modules/line_descriptor/doc/tutorial.rst @@ -0,0 +1,34 @@ +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 + + + diff --git a/modules/line_descriptor/include/opencv2/line_descriptor/descriptor.hpp b/modules/line_descriptor/include/opencv2/line_descriptor/descriptor.hpp index bd7155a83..6e98b76d3 100644 --- a/modules/line_descriptor/include/opencv2/line_descriptor/descriptor.hpp +++ b/modules/line_descriptor/include/opencv2/line_descriptor/descriptor.hpp @@ -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& keylines, CV_OUT Mat& descriptors ) const; + void compute( const Mat& image, CV_OUT CV_IN_OUT std::vector& keylines, CV_OUT Mat& descriptors, bool returnFloatDescr=false ) const; /* requires descriptors computation (more than one image) */ - void compute( const std::vector& images, std::vector >& keylines, std::vector& descriptors ) const; + void compute( const std::vector& images, std::vector >& keylines, std::vector& 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& 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& keylines, const Mat& mask = Mat() ) const; /* implementation of descriptors' computation */ - virtual void computeImpl( const Mat& imageSrc, std::vector& keylines, Mat& descriptors ) const; + virtual void computeImpl( const Mat& imageSrc, std::vector& keylines, Mat& descriptors, bool returnFloatDescr ) const; /* function inherited from Algorithm */ AlgorithmInfo* info() const; diff --git a/modules/line_descriptor/samples/lines_extraction.cpp b/modules/line_descriptor/samples/lines_extraction.cpp index bd9581697..3b473675a 100644 --- a/modules/line_descriptor/samples/lines_extraction.cpp +++ b/modules/line_descriptor/samples/lines_extraction.cpp @@ -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 ) ); diff --git a/modules/line_descriptor/src/binary_descriptor.cpp b/modules/line_descriptor/src/binary_descriptor.cpp index 19dfb0359..30102b337 100644 --- a/modules/line_descriptor/src/binary_descriptor.cpp +++ b/modules/line_descriptor/src/binary_descriptor.cpp @@ -189,7 +189,7 @@ BinaryDescriptor::BinaryDescriptor( const BinaryDescriptor::Params ¶meters ) /* definition of operator () */ void BinaryDescriptor::operator()( InputArray image, InputArray mask, CV_OUT std::vector& 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& 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& ke } /* requires descriptors computation (only one image) */ -void BinaryDescriptor::compute( const Mat& image, CV_OUT CV_IN_OUT std::vector& keylines, CV_OUT Mat& descriptors ) const +void BinaryDescriptor::compute( const Mat& image, CV_OUT CV_IN_OUT std::vector& 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& images, std::vector >& keylines, std::vector& descriptors ) const +void BinaryDescriptor::compute( const std::vector& images, std::vector >& keylines, std::vector& 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& keylines, Mat& descriptors ) const +void BinaryDescriptor::computeImpl( const Mat& imageSrc, std::vector& 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& 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& k int lineOctave = ( sl[k][lineC] ).octaveCount; int originalIndex = correspondences.find( std::pair( k, lineOctave ) )->second; - /* get a pointer to correspondent row in output matrix */ - uchar* pointerToRow = descriptors.ptr( originalIndex ); - - /* get LBD data */ - float* desVec = sl[k][lineC].descriptor.data(); - - /* fill current row with binary descriptor */ - for ( int comb = 0; comb < 32; comb++ ) + if( !returnFloatDescr ) { - *pointerToRow = bn->binaryConversion( &desVec[8 * combinations[comb][0]], &desVec[8 * combinations[comb][1]] ); + /* resize output matrix */ + descriptors = cv::Mat( keylines.size(), 32, CV_8UC1 ); - pointerToRow++; + /* get a pointer to correspondent row in output matrix */ + uchar* pointerToRow = descriptors.ptr( originalIndex ); + + /* 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++; + } + } + + else + { + /* resize output matrix */ + descriptors = cv::Mat( keylines.size(), NUM_OF_BANDS * 8, CV_32FC1 ); + + /* get a pointer to correspondent row in output matrix */ + uchar* pointerToRow = descriptors.ptr( originalIndex ); + + /* get LBD data */ + std::vector 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 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 ls = cv::createLineSegmentDetector( cv::LSD_REFINE_ADV ); + cv::Ptr ls = cv::createLineSegmentDetector( cv::LSD_REFINE_ADV, 0.8, 0.6, 2.0, 22.5 ); /* prepare a vector to host extracted segments */ std::vector 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 octaveLines( numOfFinalLine );