From ca0f70b23fb73818cbba6e79c93847b0fa8e90b0 Mon Sep 17 00:00:00 2001 From: biagio montesano Date: Wed, 6 Aug 2014 18:19:05 +0200 Subject: [PATCH] Corrected errors on matching --- .../opencv2/line_descriptor/descriptor.hpp | 25 +- .../samples/compute_descriptors.cpp | 8 +- modules/line_descriptor/samples/matching.cpp | 284 +++++++++++++++++- modules/line_descriptor/src/LSDDetector.cpp | 3 +- .../line_descriptor/src/binary_descriptor.cpp | 147 +++++++-- modules/line_descriptor/src/draw.cpp | 6 + .../line_descriptor/src/ed_line_detector.cpp | 4 +- 7 files changed, 431 insertions(+), 46 deletions(-) diff --git a/modules/line_descriptor/include/opencv2/line_descriptor/descriptor.hpp b/modules/line_descriptor/include/opencv2/line_descriptor/descriptor.hpp index a28f876ac..8c8860844 100644 --- a/modules/line_descriptor/include/opencv2/line_descriptor/descriptor.hpp +++ b/modules/line_descriptor/include/opencv2/line_descriptor/descriptor.hpp @@ -190,12 +190,14 @@ 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, bool returnFloatDescr = false ) const; + void compute( const Mat& image, CV_OUT CV_IN_OUT std::vector& keylines, CV_OUT Mat& descriptors, bool returnFloatDescr = false, + bool useDetectionData = false ) const; /* requires descriptors computation (more than one image) */ CV_WRAP void compute( const std::vector& images, std::vector >& keylines, std::vector& descriptors, bool returnFloatDescr = - false ) const; + false, + bool useDetectionData = false ) const; /* returns descriptor size */ CV_WRAP @@ -219,17 +221,24 @@ class CV_EXPORTS_W BinaryDescriptor : public Algorithm 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, bool returnFloatDescr ) const; + virtual void computeImpl( const Mat& imageSrc, std::vector& keylines, Mat& descriptors, bool returnFloatDescr, + bool useDetectionData ) const; /* function inherited from Algorithm */ AlgorithmInfo* info() const; private: + /* compute Gaussian pyramids */ + void computeGaussianPyramid( const Mat& image ); + + /* compute Sobel's derivatives */ + void computeSobel( const Mat& image ); + /* conversion of an LBD descriptor to its binary representation */ unsigned char binaryConversion( float* f1, float* f2 ); /* compute LBD descriptors using EDLine extractor */ - int computeLBD( ScaleLines &keyLines ); + int computeLBD( ScaleLines &keyLines, bool useDetectionData = false ); /* gathers lines in groups using EDLine extractor. Each group contains the same line, detected in different octaves */ @@ -251,7 +260,13 @@ class CV_EXPORTS_W BinaryDescriptor : public Algorithm *from the EDLineDetector class without extra computation cost. Another reason is that, if we use *a single EDLineDetector to detect lines in different octave of images, then we need to allocate and release *memory for gradient images (dxImg, dyImg, gImg) repeatedly for their varying size*/ - std::vector edLineVec_; + std::vector > edLineVec_; + + /* Sobel's derivatives */ + std::vector dxImg_vector, dyImg_vector; + + /* Gaussian pyramid */ + std::vector octaveImages; }; diff --git a/modules/line_descriptor/samples/compute_descriptors.cpp b/modules/line_descriptor/samples/compute_descriptors.cpp index c7a6249aa..0c7526734 100644 --- a/modules/line_descriptor/samples/compute_descriptors.cpp +++ b/modules/line_descriptor/samples/compute_descriptors.cpp @@ -104,17 +104,17 @@ int main( int argc, char** argv ) bd->detect( imageMat, keylines, mask ); /* select only lines from first octave */ - std::vector octave0; + /*std::vector octave0; for ( size_t i = 0; i < keylines.size(); i++ ) { if( keylines[i].octave == 0 ) octave0.push_back( keylines[i] ); - } + }*/ /* compute descriptors */ cv::Mat descriptors; - bd->compute( imageMat, octave0, descriptors, 1); - writeMat( descriptors, "bd_descriptors", 0 ); + bd->compute( imageMat, keylines, descriptors); + writeMat( descriptors, "bd_descriptors", 1 ); } diff --git a/modules/line_descriptor/samples/matching.cpp b/modules/line_descriptor/samples/matching.cpp index f6f4b7143..29a14ce35 100644 --- a/modules/line_descriptor/samples/matching.cpp +++ b/modules/line_descriptor/samples/matching.cpp @@ -63,6 +63,222 @@ static void help() } +inline void writeMat( cv::Mat m, std::string name, int n ) +{ + std::stringstream ss; + std::string s; + ss << n; + ss >> s; + std::string fileNameConf = name + s; + cv::FileStorage fsConf( fileNameConf, cv::FileStorage::WRITE ); + fsConf << "m" << m; + + fsConf.release(); +} + +inline void loadMat( cv::Mat& m, std::string name ) +{ + + cv::FileStorage fsConf( name, cv::FileStorage::READ ); + fsConf["m"] >> m; + + fsConf.release(); +} + +int binaryDist( const uchar * p_descriptor, const uchar * p_trained ) +{ + int count = 0; + for ( int i = 0; i < 32; i++ ) + { + uchar a = p_descriptor[i]; + uchar a1 = a & 1; + uchar a2 = a & 2; + uchar a4 = a & 4; + uchar a8 = a & 8; + uchar a16 = a & 16; + uchar a32 = a & 32; + uchar a64 = a & 64; + uchar a128 = a & 128; + + uchar b = p_trained[i]; + uchar b1 = b & 1; + uchar b2 = b & 2; + uchar b4 = b & 4; + uchar b8 = b & 8; + uchar b16 = b & 16; + uchar b32 = b & 32; + uchar b64 = b & 64; + uchar b128 = b & 128; + + if( a1 == b1 ) + count++; + if( a2 == b2 ) + count++; + if( a4 == b4 ) + count++; + if( a8 == b8 ) + count++; + if( a16 == b16 ) + count++; + if( a32 == b32 ) + count++; + if( a64 == b64 ) + count++; + if( a128 == b128 ) + count++; + } + return count; +} + +std::vector computeBruteForceSingleImages( Mat descriptor_query, Mat descriptor_db ) +{ + //BRUTE FORCE// + + std::vector matches; + + for ( int i = 0; i < descriptor_query.rows; i++ ) + { + + const uchar * p_descriptor = ( descriptor_query.ptr() ) + i * 32; + + const uchar * p_trained = descriptor_db.ptr(); + int min_dist = 0; + int min_index = -1; + for ( int k = 0; k < descriptor_db.rows; k++ ) + { + int dist = binaryDist( p_descriptor, p_trained + ( k * 32 ) ); + if( dist > min_dist ) + { + min_dist = dist; + min_index = k; + } + } + DMatch m( i, min_index, (float) min_dist ); + matches.push_back( m ); + + } + + return matches; +} + +void computeDescr( Mat sm_image, Mat img ) +{ + Mat query = sm_image.clone(); + Mat db = img.clone(); + + Ptr bd = BinaryDescriptor::createBinaryDescriptor(); + + /* compute lines */ + std::vector keylines1, keylines2; + bd->detect( query, keylines1 ); + bd->detect( db, keylines2 ); + + /* compute descriptors */ + cv::Mat descr1, descr2; + bd->compute( query, keylines1, descr1 ); + bd->compute( db, keylines2, descr2 ); + + std::vector keypoints_1; + std::vector keypoints_2; + std::vector > v_pair_k1; + std::vector > v_pair_k2; + for ( int i = 0; i < keylines1.size(); i++ ) + { + KeyLine l = keylines1[i]; + keypoints_1.push_back( cv::KeyPoint( l.startPointX, l.startPointY, 8, l.angle ) ); + v_pair_k1.push_back( std::make_pair( cv::KeyPoint( l.startPointX, l.startPointY, 8, l.angle ), i ) ); + + } + for ( int i = 0; i < keylines2.size(); i++ ) + { + KeyLine l = keylines2[i]; + keypoints_2.push_back( cv::KeyPoint( l.startPointX, l.startPointY, 8, l.angle ) ); + v_pair_k2.push_back( std::make_pair( cv::KeyPoint( l.startPointX, l.startPointY, 8, l.angle ), i ) ); + } + +// vector matches = ImageFinderFLANN::computeBruteForceSingleImages(purged_descriptor_query, purged_descriptor_db ); + std::vector matches = computeBruteForceSingleImages( descr1, descr2 ); + + Mat img_draw_matches, img_draw_matches_debug; + + std::vector good_matches; + int thresh_good = 200; + for ( int i = 0; i < matches.size(); i++ ) + { + if( matches[i].distance > thresh_good ) + { + good_matches.push_back( matches[i] ); + + } + } + + srand( (unsigned) time( 0 ) ); + int lowest = 100, highest = 255; + int range = ( highest - lowest ) + 1; + unsigned int r, g, b; + + //DISEGNO MATCHES + std::vector fake_k1; + std::vector fake_k2; + std::vector fake_match; + drawMatches( sm_image, fake_k1, img, fake_k2, fake_match, img_draw_matches, Scalar::all( -1 ), Scalar::all( -1 ), Mat(), + DrawMatchesFlags::NOT_DRAW_SINGLE_POINTS ); + for ( int i = 0; i < keylines1.size(); i++ ) + { + KeyLine line = keylines1[i]; + cv::Point startP( line.sPointInOctaveX, line.sPointInOctaveY ); + cv::Point endP( line.ePointInOctaveX, line.ePointInOctaveY ); + + cv::Point midP( ( startP.x + endP.x ) / 2, ( startP.y + endP.y ) / 2 ); + //cv::putText(img_draw_matches, std::to_string(i), midP, 1, 1, Scalar(255,0,0), 1 ); + + cv::line( img_draw_matches, startP, endP, Scalar( 0, 0, 255 ) ); + + } + for ( int i = 0; i < keylines2.size(); i++ ) + { + KeyLine line = keylines2[i]; + cv::Point startP( line.sPointInOctaveX + sm_image.cols, line.sPointInOctaveY ); + cv::Point endP( line.ePointInOctaveX + sm_image.cols, line.ePointInOctaveY ); + + cv::Point midP( ( startP.x + endP.x ) / 2, ( startP.y + endP.y ) / 2 ); + //cv::putText(img_draw_matches, std::to_string(i), midP, 1, 1, Scalar(255,0,0), 1 ); + + cv::line( img_draw_matches, startP, endP, Scalar( 0, 0, 255 ) ); + + } + + for ( int i = 0; i < good_matches.size(); i++ ) + { + r = lowest + int( rand() % range ); + g = lowest + int( rand() % range ); + b = lowest + int( rand() % range ); + + std::pair tmp_pair_1 = v_pair_k1[good_matches[i].queryIdx]; + std::pair tmp_pair_2 = v_pair_k2[good_matches[i].trainIdx]; + cv::KeyPoint tmp_key_1 = tmp_pair_1.first; + cv::KeyPoint tmp_key_2 = tmp_pair_2.first; + + KeyLine line1 = keylines1[tmp_pair_1.second]; + cv::Point startP1( line1.sPointInOctaveX, line1.sPointInOctaveY ); + cv::Point endP1( line1.ePointInOctaveX, line1.ePointInOctaveY ); + cv::line( img_draw_matches, startP1, endP1, Scalar( r, g, b ), 2 ); + + KeyLine line2 = keylines2[tmp_pair_2.second]; + cv::Point startP2( line2.sPointInOctaveX + sm_image.cols, line2.sPointInOctaveY ); + cv::Point endP2( line2.ePointInOctaveX + sm_image.cols, line2.ePointInOctaveY ); + cv::line( img_draw_matches, startP2, endP2, Scalar( r, g, b ), 2 ); + + cv::Point startP_connect( tmp_key_1.pt.x, tmp_key_1.pt.y ); + cv::Point endP_connect( tmp_key_2.pt.x + sm_image.cols, tmp_key_2.pt.y ); + cv::line( img_draw_matches, startP_connect, endP_connect, Scalar( r, g, b ), 2 ); + + } + + imshow( "Imshow", img_draw_matches ); + waitKey(); +} + int main( int argc, char** argv ) { /* get parameters from comand line */ @@ -80,7 +296,6 @@ int main( int argc, char** argv ) cv::Mat imageMat1 = imread( image_path1, 1 ); cv::Mat imageMat2 = imread( image_path2, 1 ); - waitKey(); if( imageMat1.data == NULL || imageMat2.data == NULL ) { std::cout << "Error, images could not be loaded. Please, check their path" << std::endl; @@ -95,13 +310,21 @@ int main( int argc, char** argv ) /* compute lines */ std::vector keylines1, keylines2; - bd->detect( imageMat1, keylines1, mask1 ); - bd->detect( imageMat2, keylines2, mask2 ); - /* compute descriptors */ - cv::Mat descr1, descr2; - bd->compute( imageMat1, keylines1, descr1 ); - bd->compute( imageMat2, keylines2, descr2 ); + bd->detect( imageMat2, keylines2, mask2 ); + bd->detect( imageMat1, keylines1, mask1 ); + + //compute descriptors + /* cv::Mat descr1, descr2;*/ + cv::Mat descr1, descr2; + bd->compute( imageMat1, keylines1, descr1 ); + bd->compute( imageMat2, keylines2, descr2 ); + + //cv::Mat descr1, descr2; + //( *bd )( imageMat1, mask1, keylines1, descr1, true, false ); + + //( *bd )( imageMat2, mask2, keylines2, descr2, true, false ); + /* create a BinaryDescriptorMatcher object */ Ptr bdm = BinaryDescriptorMatcher::createBinaryDescriptorMatcher(); @@ -109,14 +332,59 @@ int main( int argc, char** argv ) /* require match */ std::vector matches; bdm->match( descr1, descr2, matches ); + /* Mat newd1, newd2; + loadMat(newd1, "bd_descriptors0"); + loadMat(newd2, "bd_descriptors1");*/ + //matches = computeBruteForceSingleImages(newd1, newd2); + //matches = computeBruteForceSingleImages( descr1, descr2 ); + + std::vector good_matches; + int thresh_good = 25; + for(int i = 0; i mask( matches.size(), 1 ); - drawLineMatches( imageMat1, keylines1, imageMat2, keylines2, matches, outImg, Scalar::all( -1 ), Scalar::all( -1 ), mask, + drawLineMatches( imageMat1, keylines1, imageMat2, keylines2, good_matches , outImg, Scalar::all( -1 ), Scalar::all( -1 ), mask, DrawLinesMatchesFlags::DEFAULT ); imshow( "Matches", outImg ); waitKey(); + + Ptr lsd = LSDDetector::createLSDDetector(); + std::vector klsd1, klsd2; + Mat lsd_descr1, lsd_descr2; + lsd->detect(imageMat1, klsd1, 2, 2, mask1); + lsd->detect(imageMat2, klsd2, 2, 2, mask2); + + bd->compute( imageMat1, klsd1, lsd_descr1 ); + bd->compute( imageMat2, klsd2, lsd_descr2 ); + + std::vector lsd_matches; + bdm->match( lsd_descr1, lsd_descr2, lsd_matches); + good_matches.clear(); + for(int i = 0; i lsd_mask( matches.size(), 1 ); + drawLineMatches( imageMat1, klsd1, imageMat2, klsd2, good_matches , lsd_outImg, Scalar::all( -1 ), Scalar::all( -1 ), lsd_mask, + DrawLinesMatchesFlags::DEFAULT ); + + imshow("LSD matches", lsd_outImg); + waitKey(); } diff --git a/modules/line_descriptor/src/LSDDetector.cpp b/modules/line_descriptor/src/LSDDetector.cpp index 270d69a7e..7315eb09b 100644 --- a/modules/line_descriptor/src/LSDDetector.cpp +++ b/modules/line_descriptor/src/LSDDetector.cpp @@ -156,6 +156,7 @@ void LSDDetector::detectImpl( const Mat& imageSrc, std::vector& keyline } /* create keylines */ + int class_counter = -1; for ( int j = 0; j < (int) lines_lsd.size(); j++ ) { for ( int k = 0; k < (int) lines_lsd[j].size(); k++ ) @@ -182,7 +183,7 @@ void LSDDetector::detectImpl( const Mat& imageSrc, std::vector& keyline kl.numOfPixels = li.count; kl.angle = atan2( ( kl.endPointY - kl.startPointY ), ( kl.endPointX - kl.startPointX ) ); - kl.class_id = k; + kl.class_id = ++class_counter; kl.octave = j; kl.size = ( kl.endPointX - kl.startPointX ) * ( kl.endPointY - kl.startPointY ); kl.response = kl.lineLength / max( gaussianPyrs[j].cols, gaussianPyrs[j].rows ); diff --git a/modules/line_descriptor/src/binary_descriptor.cpp b/modules/line_descriptor/src/binary_descriptor.cpp index ddb546224..5f0035e9c 100644 --- a/modules/line_descriptor/src/binary_descriptor.cpp +++ b/modules/line_descriptor/src/binary_descriptor.cpp @@ -154,13 +154,12 @@ Ptr BinaryDescriptor::createBinaryDescriptor( Params parameter BinaryDescriptor::BinaryDescriptor( const BinaryDescriptor::Params ¶meters ) : params( parameters ) { - /* reserve enough space for EDLine objects and images in Gaussian pyramid */ edLineVec_.resize( params.numOfOctave_ ); images_sizes.resize( params.numOfOctave_ ); for ( int i = 0; i < params.numOfOctave_; i++ ) - edLineVec_[i] = new EDLineDetector; + edLineVec_[i] = Ptr( new EDLineDetector() ); /* prepare a vector to host local weights F_l*/ gaussCoefL_.resize( params.widthOfBand_ * 3 ); @@ -208,22 +207,40 @@ void BinaryDescriptor::operator()( InputArray image, InputArray mask, CV_OUT std imageMat = image.getMat(); maskMat = mask.getMat(); - /* initialize output matrix */ - descriptors.create( Size( 32, (int) keylines.size() ), CV_8UC1 ); - - /* store reference to output matrix */ - descrMat = descriptors.getMat(); - /* require drawing KeyLines detection if demanded */ if( !useProvidedKeyLines ) + { + keylines.clear(); + BinaryDescriptor *bn = const_cast( this ); + bn->edLineVec_.clear(); + bn->edLineVec_.resize( params.numOfOctave_ ); + + for ( int i = 0; i < params.numOfOctave_; i++ ) + bn->edLineVec_[i] = Ptr( new EDLineDetector() ); + detectImpl( imageMat, keylines, maskMat ); + } + + /* initialize output matrix */ + //descriptors.create( Size( 32, (int) keylines.size() ), CV_8UC1 ); + + /* store reference to output matrix */ + //descrMat = descriptors.getMat(); + /* compute descriptors */ - computeImpl( imageMat, keylines, descrMat, returnFloatDescr ); + if( !useProvidedKeyLines ) + computeImpl( imageMat, keylines, descrMat, returnFloatDescr, true ); + + else + computeImpl( imageMat, keylines, descrMat, returnFloatDescr, false ); + + descrMat.copyTo(descriptors); } BinaryDescriptor::~BinaryDescriptor() { + } /* read parameters from a FileNode object and store them (class function ) */ @@ -268,6 +285,57 @@ static inline int get2Pow( int i ) } } +/* compute Gaussian pyramids */ +void BinaryDescriptor::computeGaussianPyramid( const Mat& image ) +{ + /* clear class fields */ + images_sizes.clear(); + octaveImages.clear(); + + /* insert input image into pyramid */ + cv::Mat currentMat = image.clone(); + cv::GaussianBlur( currentMat, currentMat, cv::Size( 5, 5 ), 1 ); + octaveImages.push_back( currentMat ); + images_sizes.push_back( currentMat.size() ); + + /* fill Gaussian pyramid */ + for ( int pyrCounter = 1; pyrCounter < params.numOfOctave_; pyrCounter++ ) + { + /* compute and store next image in pyramid and its size */ + pyrDown( currentMat, currentMat, Size( currentMat.cols / params.reductionRatio, currentMat.rows / params.reductionRatio ) ); + octaveImages.push_back( currentMat ); + images_sizes.push_back( currentMat.size() ); + } +} + +/* compute Sobel's derivatives */ +void BinaryDescriptor::computeSobel( const cv::Mat& image ) +{ + std::cout << "SOBEL" << std::endl; + + /* compute Gaussian pyramids */ + computeGaussianPyramid( image ); + + /* reinitialize class structures */ + dxImg_vector.clear(); + dyImg_vector.clear(); + + dxImg_vector.resize( params.numOfOctave_ ); + dyImg_vector.resize( params.numOfOctave_ ); + + std::cout<<"octaveImages.size(): "<& images, std::vector& keylines, const Mat& mask ) const { + std::cout<<"n channels imageSRC: "<& 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, - bool returnFloatDescr ) const +void BinaryDescriptor::compute( const Mat& image, CV_OUT CV_IN_OUT std::vector& keylines, CV_OUT Mat& descriptors, bool returnFloatDescr, + bool useDetectionData ) const { - computeImpl( image, keylines, descriptors, returnFloatDescr ); + computeImpl( image, keylines, descriptors, returnFloatDescr, useDetectionData ); } /* requires descriptors computation (more than one image) */ void BinaryDescriptor::compute( const std::vector& images, std::vector >& keylines, std::vector& descriptors, - bool returnFloatDescr ) const + bool returnFloatDescr, bool useDetectionData ) const { for ( size_t i = 0; i < images.size(); i++ ) - computeImpl( images[i], keylines[i], descriptors[i], returnFloatDescr ); + computeImpl( images[i], keylines[i], descriptors[i], returnFloatDescr, useDetectionData ); } /* implementation of descriptors computation */ -void BinaryDescriptor::computeImpl( const Mat& imageSrc, std::vector& keylines, Mat& descriptors, bool returnFloatDescr ) const +void BinaryDescriptor::computeImpl( const Mat& imageSrc, std::vector& keylines, Mat& descriptors, bool returnFloatDescr, + bool useDetectionData ) const { /* convert input image to gray scale */ cv::Mat image; @@ -411,6 +488,11 @@ void BinaryDescriptor::computeImpl( const Mat& imageSrc, std::vector& k return; } + BinaryDescriptor* bd = const_cast( this ); + + if( !useDetectionData ) + bd->computeSobel( image ); + /* get maximum class_id */ int numLines = 0; for ( size_t l = 0; l < keylines.size(); l++ ) @@ -472,8 +554,7 @@ void BinaryDescriptor::computeImpl( const Mat& imageSrc, std::vector& k } /* compute LBD descriptors */ - BinaryDescriptor* bd = const_cast( this ); - bd->computeLBD( sl ); + bd->computeLBD( sl, useDetectionData ); /* resize output matrix */ if( !returnFloatDescr ) @@ -509,7 +590,6 @@ void BinaryDescriptor::computeImpl( const Mat& imageSrc, std::vector& k else { - std::cout << "Descrittori float" << std::endl; /* get a pointer to correspondent row in output matrix */ float* pointerToRow = descriptors.ptr( originalIndex ); @@ -866,7 +946,7 @@ int BinaryDescriptor::OctaveKeyLines( cv::Mat& image, ScaleLines &keyLines ) return 1; } -int BinaryDescriptor::computeLBD( ScaleLines &keyLines ) +int BinaryDescriptor::computeLBD( ScaleLines &keyLines, bool useDetectionData ) { //the default length of the band is the line length. short numOfFinalLine = (short) keyLines.size(); @@ -922,14 +1002,29 @@ int BinaryDescriptor::computeLBD( ScaleLines &keyLines ) pSingleLine = & ( keyLines[lineIDInScaleVec][lineIDInSameLine] ); octaveCount = (short) pSingleLine->octaveCount; - /* retrieve associated dxImg and dyImg */ - pdxImg = edLineVec_[octaveCount]->dxImg_.ptr(); - pdyImg = edLineVec_[octaveCount]->dyImg_.ptr(); + if( useDetectionData ) + { + /* retrieve associated dxImg and dyImg */ + pdxImg = edLineVec_[octaveCount]->dxImg_.ptr(); + pdyImg = edLineVec_[octaveCount]->dyImg_.ptr(); - /* get image size to work on from real one */ - realWidth = (short) edLineVec_[octaveCount]->imageWidth; - imageWidth = realWidth - 1; - imageHeight = (short) ( edLineVec_[octaveCount]->imageHeight - 1 ); + /* get image size to work on from real one */ + realWidth = (short) edLineVec_[octaveCount]->imageWidth; + imageWidth = realWidth - 1; + imageHeight = (short) ( edLineVec_[octaveCount]->imageHeight - 1 ); + } + + else + { + /* retrieve associated dxImg and dyImg */ + pdxImg = dxImg_vector[octaveCount].ptr(); + pdyImg = dyImg_vector[octaveCount].ptr(); + + /* get image size to work on from real one */ + realWidth = (short) images_sizes[octaveCount].width; + imageWidth = realWidth - 1; + imageHeight = (short) ( images_sizes[octaveCount].height - 1 ); + } /* initialize memory areas */ memset( pgdLBandSum, 0, numOfBitsBand ); diff --git a/modules/line_descriptor/src/draw.cpp b/modules/line_descriptor/src/draw.cpp index 8ccd83c00..b265ca3a1 100644 --- a/modules/line_descriptor/src/draw.cpp +++ b/modules/line_descriptor/src/draw.cpp @@ -49,6 +49,12 @@ void drawLineMatches( const Mat& img1, const std::vector& keylines1, co const std::vector& matchesMask, int flags ) { + if(img1.type() != img2.type()) + { + std::cout << "Input images have different types" << std::endl; + CV_Assert(img1.type() == img2.type()); + } + /* initialize output matrix (if necessary) */ if( flags == DrawLinesMatchesFlags::DEFAULT ) { diff --git a/modules/line_descriptor/src/ed_line_detector.cpp b/modules/line_descriptor/src/ed_line_detector.cpp index b4a5b18fa..8f1e82178 100644 --- a/modules/line_descriptor/src/ed_line_detector.cpp +++ b/modules/line_descriptor/src/ed_line_detector.cpp @@ -123,11 +123,11 @@ int EDLineDetector::EdgeDrawing( cv::Mat &image, EdgeChains &edgeChains, bool sm imageHeight = image.rows; unsigned int pixelNum = imageWidth * imageHeight; - if( !smoothed ) + /*if( !smoothed ) { //input image hasn't been smoothed. cv::Mat InImage = image.clone(); cv::GaussianBlur( InImage, image, cv::Size( ksize_, ksize_ ), sigma_ ); - } + }*/ unsigned int edgePixelArraySize = pixelNum / 5; unsigned int maxNumOfEdge = edgePixelArraySize / 20;