vendor: OpenCV 5.0.0 snapshot at 755e50675d97db9b7d449d8bd6b09888646f6c6e
This commit is contained in:
@@ -0,0 +1,111 @@
|
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2014, Biagio Montesano, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include <iostream>
|
||||
#include <opencv2/opencv_modules.hpp>
|
||||
|
||||
#ifdef HAVE_OPENCV_FEATURES
|
||||
|
||||
#include <opencv2/line_descriptor.hpp>
|
||||
#include <opencv2/core/utility.hpp>
|
||||
#include <opencv2/imgproc.hpp>
|
||||
#include <opencv2/features.hpp>
|
||||
#include <opencv2/highgui.hpp>
|
||||
|
||||
using namespace cv;
|
||||
using namespace cv::line_descriptor;
|
||||
|
||||
|
||||
static const char* keys =
|
||||
{ "{@image_path | | Image path }" };
|
||||
|
||||
static void help()
|
||||
{
|
||||
std::cout << "\nThis example shows the functionalities of lines extraction " << "and descriptors computation furnished by BinaryDescriptor class\n"
|
||||
<< "Please, run this sample using a command in the form\n" << "./example_line_descriptor_compute_descriptors <path_to_input_image>"
|
||||
<< std::endl;
|
||||
}
|
||||
|
||||
int main( int argc, char** argv )
|
||||
{
|
||||
/* get parameters from command line */
|
||||
CommandLineParser parser( argc, argv, keys );
|
||||
String image_path = parser.get<String>( 0 );
|
||||
|
||||
if( image_path.empty() )
|
||||
{
|
||||
help();
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* load image */
|
||||
cv::Mat imageMat = imread( image_path, 1 );
|
||||
if( imageMat.data == NULL )
|
||||
{
|
||||
std::cout << "Error, image could not be loaded. Please, check its path" << std::endl;
|
||||
}
|
||||
|
||||
/* create a binary mask */
|
||||
cv::Mat mask = Mat::ones( imageMat.size(), CV_8UC1 );
|
||||
|
||||
/* create a pointer to a BinaryDescriptor object with default parameters */
|
||||
Ptr<BinaryDescriptor> bd = BinaryDescriptor::createBinaryDescriptor();
|
||||
|
||||
/* compute lines */
|
||||
std::vector<KeyLine> keylines;
|
||||
bd->detect( imageMat, keylines, mask );
|
||||
|
||||
/* compute descriptors */
|
||||
cv::Mat descriptors;
|
||||
|
||||
bd->compute( imageMat, keylines, descriptors);
|
||||
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
int main()
|
||||
{
|
||||
std::cerr << "OpenCV was built without features module" << std::endl;
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif // HAVE_OPENCV_FEATURES
|
||||
@@ -0,0 +1,208 @@
|
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2014, Biagio Montesano, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include <iostream>
|
||||
#include <opencv2/opencv_modules.hpp>
|
||||
|
||||
#ifdef HAVE_OPENCV_FEATURES
|
||||
|
||||
#include <opencv2/line_descriptor.hpp>
|
||||
#include <opencv2/core/utility.hpp>
|
||||
#include <opencv2/imgproc.hpp>
|
||||
#include <opencv2/features.hpp>
|
||||
#include <opencv2/highgui.hpp>
|
||||
|
||||
#include <vector>
|
||||
#include <time.h>
|
||||
|
||||
using namespace cv;
|
||||
using namespace cv::line_descriptor;
|
||||
|
||||
static const char* keys =
|
||||
{ "{@image_path1 | | Image path 1 }"
|
||||
"{@image_path2 | | Image path 2 }" };
|
||||
|
||||
static void help()
|
||||
{
|
||||
std::cout << "\nThis example shows the functionalities of descriptors matching\n" << "Please, run this sample using a command in the form\n"
|
||||
<< "./example_line_descriptor_matching <path_to_input_image 1>" << "<path_to_input_image 2>" << std::endl;
|
||||
|
||||
}
|
||||
|
||||
uchar invertSingleBits( uchar dividend_char, int numBits );
|
||||
|
||||
/* invert numBits bits in input char */
|
||||
uchar invertSingleBits( uchar dividend_char, int numBits )
|
||||
{
|
||||
std::vector<int> bin_vector;
|
||||
long dividend;
|
||||
long bin_num;
|
||||
|
||||
/* convert input char to a long */
|
||||
dividend = (long) dividend_char;
|
||||
|
||||
/*if a 0 has been obtained, just generate a 8-bit long vector of zeros */
|
||||
if( dividend == 0 )
|
||||
bin_vector = std::vector<int>( 8, 0 );
|
||||
|
||||
/* else, apply classic decimal to binary conversion */
|
||||
else
|
||||
{
|
||||
while ( dividend >= 1 )
|
||||
{
|
||||
bin_num = dividend % 2;
|
||||
dividend /= 2;
|
||||
bin_vector.push_back( bin_num );
|
||||
}
|
||||
}
|
||||
|
||||
/* ensure that binary vector always has length 8 */
|
||||
if( bin_vector.size() < 8 )
|
||||
{
|
||||
std::vector<int> zeros( 8 - bin_vector.size(), 0 );
|
||||
bin_vector.insert( bin_vector.end(), zeros.begin(), zeros.end() );
|
||||
}
|
||||
|
||||
/* invert numBits bits */
|
||||
for ( int index = 0; index < numBits; index++ )
|
||||
{
|
||||
if( bin_vector[index] == 0 )
|
||||
bin_vector[index] = 1;
|
||||
|
||||
else
|
||||
bin_vector[index] = 0;
|
||||
}
|
||||
|
||||
/* reconvert to decimal */
|
||||
uchar result = 0;
|
||||
for ( int i = (int) bin_vector.size() - 1; i >= 0; i-- )
|
||||
result += (uchar) ( bin_vector[i] * (1 << i) );
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
int main( int argc, char** argv )
|
||||
{
|
||||
/* get parameters from comand line */
|
||||
CommandLineParser parser( argc, argv, keys );
|
||||
String image_path1 = parser.get<String>( 0 );
|
||||
String image_path2 = parser.get<String>( 1 );
|
||||
|
||||
if( image_path1.empty() || image_path2.empty() )
|
||||
{
|
||||
help();
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* load image */
|
||||
cv::Mat imageMat1 = imread( image_path1, 1 );
|
||||
cv::Mat imageMat2 = imread( image_path2, 1 );
|
||||
|
||||
if( imageMat1.data == NULL || imageMat2.data == NULL )
|
||||
{
|
||||
std::cout << "Error, images could not be loaded. Please, check their paths" << std::endl;
|
||||
}
|
||||
|
||||
/* create binary masks */
|
||||
cv::Mat mask1 = Mat::ones( imageMat1.size(), CV_8UC1 );
|
||||
cv::Mat mask2 = Mat::ones( imageMat2.size(), CV_8UC1 );
|
||||
|
||||
/* create a pointer to a BinaryDescriptor object with default parameters */
|
||||
Ptr<BinaryDescriptor> bd = BinaryDescriptor::createBinaryDescriptor();
|
||||
|
||||
/* compute lines */
|
||||
std::vector<KeyLine> 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 );
|
||||
|
||||
/* create a BinaryDescriptorMatcher object */
|
||||
Ptr<BinaryDescriptorMatcher> bdm = BinaryDescriptorMatcher::createBinaryDescriptorMatcher();
|
||||
|
||||
/* make a copy of descr2 mat */
|
||||
Mat descr2Copy = descr1.clone();
|
||||
|
||||
/* randomly change some bits in original descriptors */
|
||||
srand( (unsigned int) time( NULL ) );
|
||||
|
||||
for ( int j = 0; j < descr1.rows; j++ )
|
||||
{
|
||||
/* select a random column */
|
||||
int randCol = rand() % 32;
|
||||
|
||||
/* get correspondent data */
|
||||
uchar u = descr1.at<uchar>( j, randCol );
|
||||
|
||||
/* change bits */
|
||||
for ( int k = 1; k <= 5; k++ )
|
||||
{
|
||||
/* copy current row to train matrix */
|
||||
descr2Copy.push_back( descr1.row( j ) );
|
||||
|
||||
/* invert k bits */
|
||||
uchar uc = invertSingleBits( u, k );
|
||||
|
||||
/* update current row in train matrix */
|
||||
descr2Copy.at<uchar>( descr2Copy.rows - 1, randCol ) = uc;
|
||||
}
|
||||
}
|
||||
|
||||
/* prepare a structure to host matches */
|
||||
std::vector<std::vector<DMatch> > matches;
|
||||
|
||||
/* require knn match */
|
||||
bdm->knnMatch( descr1, descr2, matches, 6 );
|
||||
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
int main()
|
||||
{
|
||||
std::cerr << "OpenCV was built without features module" << std::endl;
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif // HAVE_OPENCV_FEATURES
|
||||
@@ -0,0 +1,135 @@
|
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2014, Biagio Montesano, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include <iostream>
|
||||
#include <opencv2/opencv_modules.hpp>
|
||||
|
||||
#ifdef HAVE_OPENCV_FEATURES
|
||||
|
||||
#include <opencv2/line_descriptor.hpp>
|
||||
#include <opencv2/core/utility.hpp>
|
||||
#include <opencv2/imgproc.hpp>
|
||||
#include <opencv2/features.hpp>
|
||||
#include <opencv2/highgui.hpp>
|
||||
|
||||
using namespace cv;
|
||||
using namespace cv::line_descriptor;
|
||||
using namespace std;
|
||||
|
||||
static const char* keys =
|
||||
{ "{@image_path | | Image path }" };
|
||||
|
||||
static void help()
|
||||
{
|
||||
cout << "\nThis example shows the functionalities of lines extraction " << "furnished by BinaryDescriptor class\n"
|
||||
<< "Please, run this sample using a command in the form\n" << "./example_line_descriptor_lines_extraction <path_to_input_image>" << endl;
|
||||
}
|
||||
|
||||
int main( int argc, char** argv )
|
||||
{
|
||||
/* get parameters from comand line */
|
||||
CommandLineParser parser( argc, argv, keys );
|
||||
String image_path = parser.get<String>( 0 );
|
||||
|
||||
if( image_path.empty() )
|
||||
{
|
||||
help();
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* load image */
|
||||
cv::Mat imageMat = imread( image_path, 1 );
|
||||
if( imageMat.data == NULL )
|
||||
{
|
||||
std::cout << "Error, image could not be loaded. Please, check its path" << std::endl;
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* create a random binary mask */
|
||||
cv::Mat mask = Mat::ones( imageMat.size(), CV_8UC1 );
|
||||
|
||||
/* create a pointer to a BinaryDescriptor object with deafult parameters */
|
||||
Ptr<BinaryDescriptor> bd = BinaryDescriptor::createBinaryDescriptor();
|
||||
|
||||
/* create a structure to store extracted lines */
|
||||
vector<KeyLine> lines;
|
||||
|
||||
/* extract lines */
|
||||
cv::Mat output = imageMat.clone();
|
||||
bd->detect( imageMat, lines, mask );
|
||||
|
||||
/* draw lines extracted from octave 0 */
|
||||
if( output.channels() == 1 )
|
||||
cvtColor( output, output, COLOR_GRAY2BGR );
|
||||
for ( size_t i = 0; i < lines.size(); i++ )
|
||||
{
|
||||
KeyLine kl = lines[i];
|
||||
if( kl.octave == 0)
|
||||
{
|
||||
/* get a random color */
|
||||
int R = ( rand() % (int) ( 255 + 1 ) );
|
||||
int G = ( rand() % (int) ( 255 + 1 ) );
|
||||
int B = ( rand() % (int) ( 255 + 1 ) );
|
||||
|
||||
/* get extremes of line */
|
||||
Point pt1 = Point2f( kl.startPointX, kl.startPointY );
|
||||
Point pt2 = Point2f( kl.endPointX, kl.endPointY );
|
||||
|
||||
/* draw line */
|
||||
line( output, pt1, pt2, Scalar( B, G, R ), 3 );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/* show lines on image */
|
||||
imshow( "Lines", output );
|
||||
waitKey();
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
int main()
|
||||
{
|
||||
std::cerr << "OpenCV was built without features module" << std::endl;
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif // HAVE_OPENCV_FEATURES
|
||||
@@ -0,0 +1,135 @@
|
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2014, Biagio Montesano, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include <iostream>
|
||||
#include <opencv2/opencv_modules.hpp>
|
||||
|
||||
#ifdef HAVE_OPENCV_FEATURES
|
||||
|
||||
#include <opencv2/line_descriptor.hpp>
|
||||
#include <opencv2/core/utility.hpp>
|
||||
#include <opencv2/imgproc.hpp>
|
||||
#include <opencv2/features.hpp>
|
||||
#include <opencv2/highgui.hpp>
|
||||
|
||||
using namespace cv;
|
||||
using namespace cv::line_descriptor;
|
||||
using namespace std;
|
||||
|
||||
static const char* keys =
|
||||
{ "{@image_path | | Image path }" };
|
||||
|
||||
static void help()
|
||||
{
|
||||
cout << "\nThis example shows the functionalities of lines extraction " << "furnished by BinaryDescriptor class\n"
|
||||
<< "Please, run this sample using a command in the form\n" << "./example_line_descriptor_lines_extraction <path_to_input_image>" << endl;
|
||||
}
|
||||
|
||||
int main( int argc, char** argv )
|
||||
{
|
||||
/* get parameters from comand line */
|
||||
CommandLineParser parser( argc, argv, keys );
|
||||
String image_path = parser.get<String>( 0 );
|
||||
|
||||
if( image_path.empty() )
|
||||
{
|
||||
help();
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* load image */
|
||||
cv::Mat imageMat = imread( image_path, 1 );
|
||||
if( imageMat.data == NULL )
|
||||
{
|
||||
std::cout << "Error, image could not be loaded. Please, check its path" << std::endl;
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* create a random binary mask */
|
||||
cv::Mat mask = Mat::ones( imageMat.size(), CV_8UC1 );
|
||||
|
||||
/* create a pointer to a BinaryDescriptor object with deafult parameters */
|
||||
Ptr<LSDDetector> bd = LSDDetector::createLSDDetector();
|
||||
|
||||
/* create a structure to store extracted lines */
|
||||
vector<KeyLine> lines;
|
||||
|
||||
/* extract lines */
|
||||
cv::Mat output = imageMat.clone();
|
||||
bd->detect( imageMat, lines, 2, 1, mask );
|
||||
|
||||
/* draw lines extracted from octave 0 */
|
||||
if( output.channels() == 1 )
|
||||
cvtColor( output, output, COLOR_GRAY2BGR );
|
||||
for ( size_t i = 0; i < lines.size(); i++ )
|
||||
{
|
||||
KeyLine kl = lines[i];
|
||||
if( kl.octave == 0)
|
||||
{
|
||||
/* get a random color */
|
||||
int R = ( rand() % (int) ( 255 + 1 ) );
|
||||
int G = ( rand() % (int) ( 255 + 1 ) );
|
||||
int B = ( rand() % (int) ( 255 + 1 ) );
|
||||
|
||||
/* get extremes of line */
|
||||
Point pt1 = Point2f( kl.startPointX, kl.startPointY );
|
||||
Point pt2 = Point2f( kl.endPointX, kl.endPointY );
|
||||
|
||||
/* draw line */
|
||||
line( output, pt1, pt2, Scalar( B, G, R ), 3 );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/* show lines on image */
|
||||
imshow( "LSD lines", output );
|
||||
waitKey();
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
int main()
|
||||
{
|
||||
std::cerr << "OpenCV was built without features module" << std::endl;
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif // HAVE_OPENCV_FEATURES
|
||||
@@ -0,0 +1,220 @@
|
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2014, Biagio Montesano, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include <iostream>
|
||||
#include <opencv2/opencv_modules.hpp>
|
||||
|
||||
#ifdef HAVE_OPENCV_FEATURES
|
||||
|
||||
#include <opencv2/line_descriptor.hpp>
|
||||
#include <opencv2/core/utility.hpp>
|
||||
#include <opencv2/imgproc.hpp>
|
||||
#include <opencv2/features.hpp>
|
||||
#include <opencv2/highgui.hpp>
|
||||
|
||||
#define MATCHES_DIST_THRESHOLD 25
|
||||
|
||||
using namespace cv;
|
||||
using namespace cv::line_descriptor;
|
||||
|
||||
static const char* keys =
|
||||
{ "{@image_path1 | | Image path 1 }"
|
||||
"{@image_path2 | | Image path 2 }" };
|
||||
|
||||
static void help()
|
||||
{
|
||||
std::cout << "\nThis example shows the functionalities of lines extraction " << "and descriptors computation furnished by BinaryDescriptor class\n"
|
||||
<< "Please, run this sample using a command in the form\n" << "./example_line_descriptor_compute_descriptors <path_to_input_image 1>"
|
||||
<< "<path_to_input_image 2>" << std::endl;
|
||||
|
||||
}
|
||||
|
||||
int main( int argc, char** argv )
|
||||
{
|
||||
/* get parameters from command line */
|
||||
CommandLineParser parser( argc, argv, keys );
|
||||
String image_path1 = parser.get<String>( 0 );
|
||||
String image_path2 = parser.get<String>( 1 );
|
||||
|
||||
if( image_path1.empty() || image_path2.empty() )
|
||||
{
|
||||
help();
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* load image */
|
||||
cv::Mat imageMat1 = imread( image_path1, 1 );
|
||||
cv::Mat imageMat2 = imread( image_path2, 1 );
|
||||
|
||||
if( imageMat1.data == NULL || imageMat2.data == NULL )
|
||||
{
|
||||
std::cout << "Error, images could not be loaded. Please, check their path" << std::endl;
|
||||
}
|
||||
|
||||
/* create binary masks */
|
||||
cv::Mat mask1 = Mat::ones( imageMat1.size(), CV_8UC1 );
|
||||
cv::Mat mask2 = Mat::ones( imageMat2.size(), CV_8UC1 );
|
||||
|
||||
/* create a pointer to a BinaryDescriptor object with default parameters */
|
||||
Ptr<BinaryDescriptor> bd = BinaryDescriptor::createBinaryDescriptor( );
|
||||
|
||||
/* compute lines and descriptors */
|
||||
std::vector<KeyLine> keylines1, keylines2;
|
||||
cv::Mat descr1, descr2;
|
||||
|
||||
( *bd )( imageMat1, mask1, keylines1, descr1, false, false );
|
||||
( *bd )( imageMat2, mask2, keylines2, descr2, false, false );
|
||||
|
||||
/* select keylines from first octave and their descriptors */
|
||||
std::vector<KeyLine> lbd_octave1, lbd_octave2;
|
||||
Mat left_lbd, right_lbd;
|
||||
for ( int i = 0; i < (int) keylines1.size(); i++ )
|
||||
{
|
||||
if( keylines1[i].octave == 0 )
|
||||
{
|
||||
lbd_octave1.push_back( keylines1[i] );
|
||||
left_lbd.push_back( descr1.row( i ) );
|
||||
}
|
||||
}
|
||||
|
||||
for ( int j = 0; j < (int) keylines2.size(); j++ )
|
||||
{
|
||||
if( keylines2[j].octave == 0 )
|
||||
{
|
||||
lbd_octave2.push_back( keylines2[j] );
|
||||
right_lbd.push_back( descr2.row( j ) );
|
||||
}
|
||||
}
|
||||
|
||||
/* create a BinaryDescriptorMatcher object */
|
||||
Ptr<BinaryDescriptorMatcher> bdm = BinaryDescriptorMatcher::createBinaryDescriptorMatcher();
|
||||
|
||||
/* require match */
|
||||
std::vector<DMatch> matches;
|
||||
bdm->match( left_lbd, right_lbd, matches );
|
||||
|
||||
/* select best matches */
|
||||
std::vector<DMatch> good_matches;
|
||||
for ( int i = 0; i < (int) matches.size(); i++ )
|
||||
{
|
||||
if( matches[i].distance < MATCHES_DIST_THRESHOLD )
|
||||
good_matches.push_back( matches[i] );
|
||||
}
|
||||
|
||||
/* plot matches */
|
||||
cv::Mat outImg;
|
||||
cv::Mat scaled1, scaled2;
|
||||
std::vector<char> mask( matches.size(), 1 );
|
||||
drawLineMatches( imageMat1, lbd_octave1, imageMat2, lbd_octave2, good_matches, outImg, Scalar::all( -1 ), Scalar::all( -1 ), mask,
|
||||
DrawLinesMatchesFlags::DEFAULT );
|
||||
|
||||
imshow( "Matches", outImg );
|
||||
waitKey();
|
||||
imwrite("/home/ubisum/Desktop/images/env_match/matches.jpg", outImg);
|
||||
/* create an LSD detector */
|
||||
Ptr<LSDDetector> lsd = LSDDetector::createLSDDetector();
|
||||
|
||||
/* detect lines */
|
||||
std::vector<KeyLine> klsd1, klsd2;
|
||||
Mat lsd_descr1, lsd_descr2;
|
||||
lsd->detect( imageMat1, klsd1, 2, 2, mask1 );
|
||||
lsd->detect( imageMat2, klsd2, 2, 2, mask2 );
|
||||
|
||||
/* compute descriptors for lines from first octave */
|
||||
bd->compute( imageMat1, klsd1, lsd_descr1 );
|
||||
bd->compute( imageMat2, klsd2, lsd_descr2 );
|
||||
|
||||
/* select lines and descriptors from first octave */
|
||||
std::vector<KeyLine> octave0_1, octave0_2;
|
||||
Mat leftDEscr, rightDescr;
|
||||
for ( int i = 0; i < (int) klsd1.size(); i++ )
|
||||
{
|
||||
if( klsd1[i].octave == 1 )
|
||||
{
|
||||
octave0_1.push_back( klsd1[i] );
|
||||
leftDEscr.push_back( lsd_descr1.row( i ) );
|
||||
}
|
||||
}
|
||||
|
||||
for ( int j = 0; j < (int) klsd2.size(); j++ )
|
||||
{
|
||||
if( klsd2[j].octave == 1 )
|
||||
{
|
||||
octave0_2.push_back( klsd2[j] );
|
||||
rightDescr.push_back( lsd_descr2.row( j ) );
|
||||
}
|
||||
}
|
||||
|
||||
/* compute matches */
|
||||
std::vector<DMatch> lsd_matches;
|
||||
bdm->match( leftDEscr, rightDescr, lsd_matches );
|
||||
|
||||
/* select best matches */
|
||||
good_matches.clear();
|
||||
for ( int i = 0; i < (int) lsd_matches.size(); i++ )
|
||||
{
|
||||
if( lsd_matches[i].distance < MATCHES_DIST_THRESHOLD )
|
||||
good_matches.push_back( lsd_matches[i] );
|
||||
}
|
||||
|
||||
/* plot matches */
|
||||
cv::Mat lsd_outImg;
|
||||
resize( imageMat1, imageMat1, Size( imageMat1.cols / 2, imageMat1.rows / 2 ), 0, 0, INTER_LINEAR_EXACT );
|
||||
resize( imageMat2, imageMat2, Size( imageMat2.cols / 2, imageMat2.rows / 2 ), 0, 0, INTER_LINEAR_EXACT );
|
||||
std::vector<char> lsd_mask( matches.size(), 1 );
|
||||
drawLineMatches( imageMat1, octave0_1, imageMat2, octave0_2, good_matches, lsd_outImg, Scalar::all( -1 ), Scalar::all( -1 ), lsd_mask,
|
||||
DrawLinesMatchesFlags::DEFAULT );
|
||||
|
||||
imshow( "LSD matches", lsd_outImg );
|
||||
waitKey();
|
||||
|
||||
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
int main()
|
||||
{
|
||||
std::cerr << "OpenCV was built without features module" << std::endl;
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif // HAVE_OPENCV_FEATURES
|
||||
@@ -0,0 +1,155 @@
|
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2014, Biagio Montesano, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include <iostream>
|
||||
#include <opencv2/opencv_modules.hpp>
|
||||
|
||||
#ifdef HAVE_OPENCV_FEATURES
|
||||
|
||||
#include <opencv2/line_descriptor.hpp>
|
||||
#include <opencv2/core/utility.hpp>
|
||||
#include <opencv2/imgproc.hpp>
|
||||
#include <opencv2/features.hpp>
|
||||
#include <opencv2/highgui.hpp>
|
||||
|
||||
#include <vector>
|
||||
|
||||
using namespace cv;
|
||||
using namespace cv::line_descriptor;
|
||||
|
||||
static const std::string images[] =
|
||||
{ "cameraman.jpg", "church.jpg", "church2.png", "einstein.jpg", "stuff.jpg" };
|
||||
|
||||
static const char* keys =
|
||||
{ "{@image_path | | Image path }" };
|
||||
|
||||
static void help()
|
||||
{
|
||||
std::cout << "\nThis example shows the functionalities of radius matching " << "Please, run this sample using a command in the form\n"
|
||||
<< "./example_line_descriptor_radius_matching <path_to_input_images>/" << std::endl;
|
||||
}
|
||||
|
||||
int main( int argc, char** argv )
|
||||
{
|
||||
/* get parameters from comand line */
|
||||
CommandLineParser parser( argc, argv, keys );
|
||||
String pathToImages = parser.get < String > ( 0 );
|
||||
|
||||
/* create structures for hosting KeyLines and descriptors */
|
||||
int num_elements = sizeof ( images ) / sizeof ( images[0] );
|
||||
std::vector < Mat > descriptorsMat;
|
||||
std::vector < std::vector<KeyLine> > linesMat;
|
||||
|
||||
/*create a pointer to a BinaryDescriptor object */
|
||||
Ptr < BinaryDescriptor > bd = BinaryDescriptor::createBinaryDescriptor();
|
||||
|
||||
/* compute lines and descriptors */
|
||||
for ( int i = 0; i < num_elements; i++ )
|
||||
{
|
||||
/* get path to image */
|
||||
std::stringstream image_path;
|
||||
image_path << pathToImages << images[i];
|
||||
std::cout << image_path.str().c_str() << std::endl;
|
||||
|
||||
/* load image */
|
||||
Mat loadedImage = imread( image_path.str().c_str(), 1 );
|
||||
if( loadedImage.data == NULL )
|
||||
{
|
||||
std::cout << "Could not load images." << std::endl;
|
||||
help();
|
||||
exit( -1 );
|
||||
}
|
||||
|
||||
/* compute lines and descriptors */
|
||||
std::vector < KeyLine > lines;
|
||||
Mat computedDescr;
|
||||
bd->detect( loadedImage, lines );
|
||||
bd->compute( loadedImage, lines, computedDescr );
|
||||
|
||||
descriptorsMat.push_back( computedDescr );
|
||||
linesMat.push_back( lines );
|
||||
|
||||
}
|
||||
|
||||
/* compose a queries matrix */
|
||||
Mat queries;
|
||||
for ( size_t j = 0; j < descriptorsMat.size(); j++ )
|
||||
{
|
||||
if( descriptorsMat[j].rows >= 5 )
|
||||
queries.push_back( descriptorsMat[j].rowRange( 0, 5 ) );
|
||||
|
||||
else if( descriptorsMat[j].rows > 0 && descriptorsMat[j].rows < 5 )
|
||||
queries.push_back( descriptorsMat[j] );
|
||||
}
|
||||
|
||||
std::cout << "It has been generated a matrix of " << queries.rows << " descriptors" << std::endl;
|
||||
|
||||
/* create a BinaryDescriptorMatcher object */
|
||||
Ptr < BinaryDescriptorMatcher > bdm = BinaryDescriptorMatcher::createBinaryDescriptorMatcher();
|
||||
|
||||
/* populate matcher */
|
||||
bdm->add( descriptorsMat );
|
||||
|
||||
/* compute matches */
|
||||
std::vector < std::vector<DMatch> > matches;
|
||||
bdm->radiusMatch( queries, matches, 30 );
|
||||
std::cout << "size matches sample " << matches.size() << std::endl;
|
||||
|
||||
for ( int i = 0; i < (int) matches.size(); i++ )
|
||||
{
|
||||
for ( int j = 0; j < (int) matches[i].size(); j++ )
|
||||
{
|
||||
std::cout << "match: " << matches[i][j].queryIdx << " " << matches[i][j].trainIdx << " " << matches[i][j].distance << std::endl;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
int main()
|
||||
{
|
||||
std::cerr << "OpenCV was built without features module" << std::endl;
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif // HAVE_OPENCV_FEATURES
|
||||
Reference in New Issue
Block a user