mirror of
https://github.com/opencv/opencv_contrib.git
synced 2025-10-18 17:24:28 +08:00
Added LSD sample. Removed python macros.
This commit is contained in:
@@ -62,155 +62,155 @@ struct CV_EXPORTS KeyLine
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
/* orientation of the line */
|
/* orientation of the line */
|
||||||
CV_PROP_RW
|
/*CV_PROP_RW*/
|
||||||
float angle;
|
float angle;
|
||||||
|
|
||||||
/* object ID, that can be used to cluster keylines by the line they represent */
|
/* object ID, that can be used to cluster keylines by the line they represent */
|
||||||
CV_PROP_RW
|
/*CV_PROP_RW*/
|
||||||
int class_id;
|
int class_id;
|
||||||
|
|
||||||
/* octave (pyramid layer), from which the keyline has been extracted */
|
/* octave (pyramid layer), from which the keyline has been extracted */
|
||||||
CV_PROP_RW
|
/*CV_PROP_RW*/
|
||||||
int octave;
|
int octave;
|
||||||
|
|
||||||
/* coordinates of the middlepoint */
|
/* coordinates of the middlepoint */
|
||||||
CV_PROP_RW
|
/*CV_PROP_RW*/
|
||||||
Point2f pt;
|
Point2f pt;
|
||||||
|
|
||||||
/* the response, by which the strongest keylines have been selected.
|
/* the response, by which the strongest keylines have been selected.
|
||||||
It's represented by the ratio between line's length and maximum between
|
It's represented by the ratio between line's length and maximum between
|
||||||
image's width and height */
|
image's width and height */
|
||||||
CV_PROP_RW
|
/*CV_PROP_RW*/
|
||||||
float response;
|
float response;
|
||||||
|
|
||||||
/* minimum area containing line */
|
/* minimum area containing line */
|
||||||
CV_PROP_RW
|
/*CV_PROP_RW*/
|
||||||
float size;
|
float size;
|
||||||
|
|
||||||
/* lines's extremes in original image */
|
/* lines's extremes in original image */
|
||||||
CV_PROP_RW
|
/*CV_PROP_RW*/
|
||||||
float startPointX;CV_PROP_RW
|
float startPointX;/*CV_PROP_RW*/
|
||||||
float startPointY;CV_PROP_RW
|
float startPointY;/*CV_PROP_RW*/
|
||||||
float endPointX;CV_PROP_RW
|
float endPointX;/*CV_PROP_RW*/
|
||||||
float endPointY;
|
float endPointY;
|
||||||
|
|
||||||
/* line's extremes in image it was extracted from */
|
/* line's extremes in image it was extracted from */
|
||||||
CV_PROP_RW
|
/*CV_PROP_RW*/
|
||||||
float sPointInOctaveX;CV_PROP_RW
|
float sPointInOctaveX;/*CV_PROP_RW*/
|
||||||
float sPointInOctaveY;CV_PROP_RW
|
float sPointInOctaveY;/*CV_PROP_RW*/
|
||||||
float ePointInOctaveX;CV_PROP_RW
|
float ePointInOctaveX;/*CV_PROP_RW*/
|
||||||
float ePointInOctaveY;
|
float ePointInOctaveY;
|
||||||
|
|
||||||
/* the length of line */
|
/* the length of line */
|
||||||
CV_PROP_RW
|
/*CV_PROP_RW*/
|
||||||
float lineLength;
|
float lineLength;
|
||||||
|
|
||||||
/* number of pixels covered by the line */
|
/* number of pixels covered by the line */
|
||||||
CV_PROP_RW
|
/*CV_PROP_RW*/
|
||||||
int numOfPixels;
|
int numOfPixels;
|
||||||
|
|
||||||
/* constructor */
|
/* constructor */
|
||||||
CV_WRAP
|
/*CV_WRAP*/
|
||||||
KeyLine()
|
KeyLine()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
class CV_EXPORTS_W BinaryDescriptor : public Algorithm
|
class CV_EXPORTS BinaryDescriptor : public Algorithm
|
||||||
{
|
{
|
||||||
|
|
||||||
public:
|
public:
|
||||||
struct CV_EXPORTS Params
|
struct CV_EXPORTS Params
|
||||||
{
|
{
|
||||||
CV_WRAP
|
/*CV_WRAP*/
|
||||||
Params();
|
Params();
|
||||||
|
|
||||||
/* the number of image octaves (default = 1) */
|
/* the number of image octaves (default = 1) */
|
||||||
CV_PROP_RW
|
/*CV_PROP_RW*/
|
||||||
int numOfOctave_;
|
int numOfOctave_;
|
||||||
|
|
||||||
/* the width of band; (default: 7) */
|
/* the width of band; (default: 7) */
|
||||||
CV_PROP_RW
|
/*CV_PROP_RW*/
|
||||||
int widthOfBand_;
|
int widthOfBand_;
|
||||||
|
|
||||||
/* image's reduction ratio in construction of Gaussian pyramids */
|
/* image's reduction ratio in construction of Gaussian pyramids */
|
||||||
CV_PROP_RW
|
/*CV_PROP_RW*/
|
||||||
int reductionRatio;
|
int reductionRatio;
|
||||||
|
|
||||||
CV_PROP_RW
|
/*CV_PROP_RW*/
|
||||||
int ksize_;
|
int ksize_;
|
||||||
|
|
||||||
/* read parameters from a FileNode object and store them (struct function) */
|
/* read parameters from a FileNode object and store them (struct function) */
|
||||||
CV_WRAP
|
/*CV_WRAP*/
|
||||||
void read( const FileNode& fn );
|
void read( const FileNode& fn );
|
||||||
|
|
||||||
/* store parameters to a FileStorage object (struct function) */
|
/* store parameters to a FileStorage object (struct function) */
|
||||||
CV_WRAP
|
/*CV_WRAP*/
|
||||||
void write( FileStorage& fs ) const;
|
void write( FileStorage& fs ) const;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/* constructor */
|
/* constructor */
|
||||||
CV_WRAP
|
/*CV_WRAP*/
|
||||||
BinaryDescriptor( const BinaryDescriptor::Params ¶meters = BinaryDescriptor::Params() );
|
BinaryDescriptor( const BinaryDescriptor::Params ¶meters = BinaryDescriptor::Params() );
|
||||||
|
|
||||||
/* constructors with smart pointers */
|
/* constructors with smart pointers */
|
||||||
CV_WRAP
|
/*CV_WRAP*/
|
||||||
static Ptr<BinaryDescriptor> createBinaryDescriptor();CV_WRAP
|
static Ptr<BinaryDescriptor> createBinaryDescriptor();/*CV_WRAP*/
|
||||||
static Ptr<BinaryDescriptor> createBinaryDescriptor( Params parameters );
|
static Ptr<BinaryDescriptor> createBinaryDescriptor( Params parameters );
|
||||||
|
|
||||||
/* destructor */
|
/* destructor */
|
||||||
~BinaryDescriptor();
|
~BinaryDescriptor();
|
||||||
|
|
||||||
/* setters and getters */
|
/* setters and getters */
|
||||||
CV_WRAP
|
/*CV_WRAP*/
|
||||||
int getNumOfOctaves();CV_WRAP
|
int getNumOfOctaves();/*CV_WRAP*/
|
||||||
void setNumOfOctaves( int octaves );CV_WRAP
|
void setNumOfOctaves( int octaves );/*CV_WRAP*/
|
||||||
int getWidthOfBand();CV_WRAP
|
int getWidthOfBand();/*CV_WRAP*/
|
||||||
void setWidthOfBand( int width );CV_WRAP
|
void setWidthOfBand( int width );/*CV_WRAP*/
|
||||||
int getReductionRatio();CV_WRAP
|
int getReductionRatio();/*CV_WRAP*/
|
||||||
void setReductionRatio( int rRatio );
|
void setReductionRatio( int rRatio );
|
||||||
|
|
||||||
/* reads parameters from a FileNode object and store them (class function ) */
|
/* reads parameters from a FileNode object and store them (class function ) */
|
||||||
CV_WRAP
|
/*CV_WRAP*/
|
||||||
virtual void read( const cv::FileNode& fn );
|
virtual void read( const cv::FileNode& fn );
|
||||||
|
|
||||||
/* stores parameters to a FileStorage object (class function) */
|
/* stores parameters to a FileStorage object (class function) */
|
||||||
CV_WRAP
|
/*CV_WRAP*/
|
||||||
virtual void write( cv::FileStorage& fs ) const;
|
virtual void write( cv::FileStorage& fs ) const;
|
||||||
|
|
||||||
/* requires line detection (only one image) */
|
/* requires line detection (only one image) */
|
||||||
CV_WRAP
|
/*CV_WRAP*/
|
||||||
void detect( const Mat& image, CV_OUT std::vector<KeyLine>& keypoints, const Mat& mask = Mat() );
|
void detect( const Mat& image, CV_OUT std::vector<KeyLine>& keypoints, const Mat& mask = Mat() );
|
||||||
|
|
||||||
/* requires line detection (more than one image) */
|
/* requires line detection (more than one image) */
|
||||||
CV_WRAP
|
/*CV_WRAP*/
|
||||||
void detect( const std::vector<Mat>& images, std::vector<std::vector<KeyLine> >& keylines, const std::vector<Mat>& masks =
|
void detect( const std::vector<Mat>& images, std::vector<std::vector<KeyLine> >& keylines, const std::vector<Mat>& masks =
|
||||||
std::vector<Mat>() ) const;
|
std::vector<Mat>() ) const;
|
||||||
|
|
||||||
/* requires descriptors computation (only one image) */
|
/* requires descriptors computation (only one image) */
|
||||||
CV_WRAP
|
/*CV_WRAP*/
|
||||||
void compute( const Mat& image, CV_OUT CV_IN_OUT std::vector<KeyLine>& keylines, CV_OUT Mat& descriptors, bool returnFloatDescr = false ) 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) */
|
/* requires descriptors computation (more than one image) */
|
||||||
CV_WRAP
|
/*CV_WRAP*/
|
||||||
void compute( const std::vector<Mat>& images, std::vector<std::vector<KeyLine> >& keylines, std::vector<Mat>& descriptors, bool returnFloatDescr =
|
void compute( const std::vector<Mat>& images, std::vector<std::vector<KeyLine> >& keylines, std::vector<Mat>& descriptors, bool returnFloatDescr =
|
||||||
false ) const;
|
false ) const;
|
||||||
|
|
||||||
/* returns descriptor size */
|
/* returns descriptor size */
|
||||||
CV_WRAP
|
/*CV_WRAP*/
|
||||||
int descriptorSize() const;
|
int descriptorSize() const;
|
||||||
|
|
||||||
/* returns data type */
|
/* returns data type */
|
||||||
CV_WRAP
|
/*CV_WRAP*/
|
||||||
int descriptorType() const;
|
int descriptorType() const;
|
||||||
|
|
||||||
/* returns norm mode */
|
/* returns norm mode */
|
||||||
CV_WRAP
|
/*CV_WRAP*/
|
||||||
int defaultNorm() const;
|
int defaultNorm() const;
|
||||||
|
|
||||||
/* definition of operator () */
|
/* definition of operator () */
|
||||||
CV_WRAP_AS(detectAndCompute)
|
//CV_WRAP_AS(detectAndCompute)
|
||||||
virtual void operator()( InputArray image, InputArray mask, CV_OUT std::vector<KeyLine>& keylines, OutputArray descriptors,
|
virtual void operator()( InputArray image, InputArray mask, CV_OUT std::vector<KeyLine>& keylines, OutputArray descriptors,
|
||||||
bool useProvidedKeyLines = false, bool returnFloatDescr = false ) const;
|
bool useProvidedKeyLines = false, bool returnFloatDescr = false ) const;
|
||||||
|
|
||||||
@@ -268,27 +268,27 @@ class CV_EXPORTS_W BinaryDescriptor : public Algorithm
|
|||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class CV_EXPORTS_W LSDDetector : public Algorithm
|
class CV_EXPORTS LSDDetector : public Algorithm
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
/* constructor */
|
/* constructor */
|
||||||
CV_WRAP
|
/*CV_WRAP*/
|
||||||
LSDDetector()
|
LSDDetector()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
;
|
;
|
||||||
|
|
||||||
/* constructor with smart pointer */
|
/* constructor with smart pointer */
|
||||||
CV_WRAP
|
/*CV_WRAP*/
|
||||||
static Ptr<LSDDetector> createLSDDetector();
|
static Ptr<LSDDetector> createLSDDetector();
|
||||||
|
|
||||||
/* requires line detection (only one image) */
|
/* requires line detection (only one image) */
|
||||||
CV_WRAP
|
/*CV_WRAP*/
|
||||||
void detect( const Mat& image, CV_OUT std::vector<KeyLine>& keypoints, int scale, int numOctaves, const Mat& mask = Mat() );
|
void detect( const Mat& image, CV_OUT std::vector<KeyLine>& keypoints, int scale, int numOctaves, const Mat& mask = Mat() );
|
||||||
|
|
||||||
/* requires line detection (more than one image) */
|
/* requires line detection (more than one image) */
|
||||||
CV_WRAP
|
/*CV_WRAP*/
|
||||||
void detect( const std::vector<Mat>& images, std::vector<std::vector<KeyLine> >& keylines, int scale, int numOctaves,
|
void detect( const std::vector<Mat>& images, std::vector<std::vector<KeyLine> >& keylines, int scale, int numOctaves,
|
||||||
const std::vector<Mat>& masks = std::vector<Mat>() ) const;
|
const std::vector<Mat>& masks = std::vector<Mat>() ) const;
|
||||||
|
|
||||||
@@ -307,63 +307,63 @@ class CV_EXPORTS_W LSDDetector : public Algorithm
|
|||||||
AlgorithmInfo* info() const;
|
AlgorithmInfo* info() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
class CV_EXPORTS_W BinaryDescriptorMatcher : public Algorithm
|
class CV_EXPORTS BinaryDescriptorMatcher : public Algorithm
|
||||||
{
|
{
|
||||||
|
|
||||||
public:
|
public:
|
||||||
/* for every input descriptor,
|
/* for every input descriptor,
|
||||||
find the best matching one (for a pair of images) */
|
find the best matching one (for a pair of images) */
|
||||||
CV_WRAP
|
/*CV_WRAP*/
|
||||||
void match( const Mat& queryDescriptors, const Mat& trainDescriptors, std::vector<DMatch>& matches, const Mat& mask = Mat() ) const;
|
void match( const Mat& queryDescriptors, const Mat& trainDescriptors, std::vector<DMatch>& matches, const Mat& mask = Mat() ) const;
|
||||||
|
|
||||||
/* for every input descriptor,
|
/* for every input descriptor,
|
||||||
find the best matching one (from one image to a set) */
|
find the best matching one (from one image to a set) */
|
||||||
CV_WRAP
|
/*CV_WRAP*/
|
||||||
void match( const Mat& queryDescriptors, std::vector<DMatch>& matches, const std::vector<Mat>& masks = std::vector<Mat>() );
|
void match( const Mat& queryDescriptors, std::vector<DMatch>& matches, const std::vector<Mat>& masks = std::vector<Mat>() );
|
||||||
|
|
||||||
/* for every input descriptor,
|
/* for every input descriptor,
|
||||||
find the best k matching descriptors (for a pair of images) */
|
find the best k matching descriptors (for a pair of images) */
|
||||||
CV_WRAP
|
/*CV_WRAP*/
|
||||||
void knnMatch( const Mat& queryDescriptors, const Mat& trainDescriptors, std::vector<std::vector<DMatch> >& matches, int k, const Mat& mask = Mat(),
|
void knnMatch( const Mat& queryDescriptors, const Mat& trainDescriptors, std::vector<std::vector<DMatch> >& matches, int k, const Mat& mask = Mat(),
|
||||||
bool compactResult = false ) const;
|
bool compactResult = false ) const;
|
||||||
|
|
||||||
/* for every input descriptor,
|
/* for every input descriptor,
|
||||||
find the best k matching descriptors (from one image to a set) */
|
find the best k matching descriptors (from one image to a set) */
|
||||||
CV_WRAP
|
/*CV_WRAP*/
|
||||||
void knnMatch( const Mat& queryDescriptors, std::vector<std::vector<DMatch> >& matches, int k, const std::vector<Mat>& masks = std::vector<Mat>(),
|
void knnMatch( const Mat& queryDescriptors, std::vector<std::vector<DMatch> >& matches, int k, const std::vector<Mat>& masks = std::vector<Mat>(),
|
||||||
bool compactResult = false );
|
bool compactResult = false );
|
||||||
|
|
||||||
/* for every input descriptor, find all the ones falling in a
|
/* for every input descriptor, find all the ones falling in a
|
||||||
certain matching radius (for a pair of images) */
|
certain matching radius (for a pair of images) */
|
||||||
CV_WRAP
|
/*CV_WRAP*/
|
||||||
void radiusMatch( const Mat& queryDescriptors, const Mat& trainDescriptors, std::vector<std::vector<DMatch> >& matches, float maxDistance,
|
void radiusMatch( const Mat& queryDescriptors, const Mat& trainDescriptors, std::vector<std::vector<DMatch> >& matches, float maxDistance,
|
||||||
const Mat& mask = Mat(), bool compactResult = false ) const;
|
const Mat& mask = Mat(), bool compactResult = false ) const;
|
||||||
|
|
||||||
/* for every input descriptor, find all the ones falling in a
|
/* for every input descriptor, find all the ones falling in a
|
||||||
certain matching radius (from one image to a set) */
|
certain matching radius (from one image to a set) */
|
||||||
CV_WRAP
|
/*CV_WRAP*/
|
||||||
void radiusMatch( const Mat& queryDescriptors, std::vector<std::vector<DMatch> >& matches, float maxDistance, const std::vector<Mat>& masks =
|
void radiusMatch( const Mat& queryDescriptors, std::vector<std::vector<DMatch> >& matches, float maxDistance, const std::vector<Mat>& masks =
|
||||||
std::vector<Mat>(),
|
std::vector<Mat>(),
|
||||||
bool compactResult = false );
|
bool compactResult = false );
|
||||||
|
|
||||||
/* store new descriptors to be inserted in dataset */
|
/* store new descriptors to be inserted in dataset */
|
||||||
CV_WRAP
|
/*CV_WRAP*/
|
||||||
void add( const std::vector<Mat>& descriptors );
|
void add( const std::vector<Mat>& descriptors );
|
||||||
|
|
||||||
/* store new descriptors into dataset */
|
/* store new descriptors into dataset */
|
||||||
CV_WRAP
|
/*CV_WRAP*/
|
||||||
void train();
|
void train();
|
||||||
|
|
||||||
/* constructor with smart pointer */
|
/* constructor with smart pointer */
|
||||||
CV_WRAP
|
/*CV_WRAP*/
|
||||||
static Ptr<BinaryDescriptorMatcher> createBinaryDescriptorMatcher();
|
static Ptr<BinaryDescriptorMatcher> createBinaryDescriptorMatcher();
|
||||||
|
|
||||||
/* clear dataset and internal data */
|
/* clear dataset and internal data */
|
||||||
CV_WRAP
|
/*CV_WRAP*/
|
||||||
void clear();
|
void clear();
|
||||||
|
|
||||||
/* constructor */
|
/* constructor */
|
||||||
CV_WRAP
|
/*CV_WRAP*/
|
||||||
BinaryDescriptorMatcher();
|
BinaryDescriptorMatcher();
|
||||||
|
|
||||||
/* destructor */
|
/* destructor */
|
||||||
@@ -420,13 +420,13 @@ struct CV_EXPORTS DrawLinesMatchesFlags
|
|||||||
};
|
};
|
||||||
|
|
||||||
/* draw matches between two images */
|
/* draw matches between two images */
|
||||||
CV_EXPORTS_W void drawLineMatches( const Mat& img1, const std::vector<KeyLine>& keylines1, const Mat& img2, const std::vector<KeyLine>& keylines2,
|
CV_EXPORTS void drawLineMatches( const Mat& img1, const std::vector<KeyLine>& keylines1, const Mat& img2, const std::vector<KeyLine>& keylines2,
|
||||||
const std::vector<DMatch>& matches1to2, Mat& outImg, const Scalar& matchColor = Scalar::all( -1 ),
|
const std::vector<DMatch>& matches1to2, Mat& outImg, const Scalar& matchColor = Scalar::all( -1 ),
|
||||||
const Scalar& singleLineColor = Scalar::all( -1 ), const std::vector<char>& matchesMask = std::vector<char>(),
|
const Scalar& singleLineColor = Scalar::all( -1 ), const std::vector<char>& matchesMask = std::vector<char>(),
|
||||||
int flags = DrawLinesMatchesFlags::DEFAULT );
|
int flags = DrawLinesMatchesFlags::DEFAULT );
|
||||||
|
|
||||||
/* draw extracted lines on original image */
|
/* draw extracted lines on original image */
|
||||||
CV_EXPORTS_W void drawKeylines( const Mat& image, const std::vector<KeyLine>& keylines, Mat& outImage, const Scalar& color = Scalar::all( -1 ),
|
CV_EXPORTS void drawKeylines( const Mat& image, const std::vector<KeyLine>& keylines, Mat& outImage, const Scalar& color = Scalar::all( -1 ),
|
||||||
int flags = DrawLinesMatchesFlags::DEFAULT );
|
int flags = DrawLinesMatchesFlags::DEFAULT );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
123
modules/line_descriptor/samples/lsd_lines_extraction.cpp
Normal file
123
modules/line_descriptor/samples/lsd_lines_extraction.cpp
Normal file
@@ -0,0 +1,123 @@
|
|||||||
|
/*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 <opencv2/line_descriptor.hpp>
|
||||||
|
|
||||||
|
#include "opencv2/core/utility.hpp"
|
||||||
|
#include "opencv2/core/private.hpp"
|
||||||
|
#include <opencv2/imgproc.hpp>
|
||||||
|
#include <opencv2/features2d.hpp>
|
||||||
|
#include <opencv2/highgui.hpp>
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
using namespace cv;
|
||||||
|
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();
|
||||||
|
}
|
@@ -146,7 +146,7 @@ int main( int argc, char** argv )
|
|||||||
|
|
||||||
imshow( "Matches", outImg );
|
imshow( "Matches", outImg );
|
||||||
waitKey();
|
waitKey();
|
||||||
|
imwrite("/home/ubisum/Desktop/images/matches.jpg", outImg);
|
||||||
/* create an LSD detector */
|
/* create an LSD detector */
|
||||||
Ptr<LSDDetector> lsd = LSDDetector::createLSDDetector();
|
Ptr<LSDDetector> lsd = LSDDetector::createLSDDetector();
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user