Merge pull request #1526 from vpisarev:linedetector_python

pull/1474/merge
Roman Donchenko 12 years ago committed by OpenCV Buildbot
commit 184ae873d4
  1. 6
      modules/imgproc/doc/feature_detection.rst
  2. 10
      modules/imgproc/include/opencv2/imgproc.hpp
  3. 2
      modules/imgproc/src/lsd.cpp
  4. 24
      modules/imgproc/test/test_lsd.cpp
  5. 1
      modules/python/src2/cv2.cpp
  6. 4
      samples/cpp/lsd_lines.cpp

@ -509,11 +509,11 @@ Line segment detector class, following the algorithm described at [Rafael12]_.
.. ocv:class:: LineSegmentDetector : public Algorithm .. ocv:class:: LineSegmentDetector : public Algorithm
createLineSegmentDetectorPtr createLineSegmentDetector
---------------------------- -------------------------
Creates a smart pointer to a LineSegmentDetector object and initializes it. Creates a smart pointer to a LineSegmentDetector object and initializes it.
.. ocv:function:: Ptr<LineSegmentDetector> createLineSegmentDetectorPtr(int _refine = LSD_REFINE_STD, double _scale = 0.8, double _sigma_scale = 0.6, double _quant = 2.0, double _ang_th = 22.5, double _log_eps = 0, double _density_th = 0.7, int _n_bins = 1024) .. ocv:function:: Ptr<LineSegmentDetector> createLineSegmentDetector(int _refine = LSD_REFINE_STD, double _scale = 0.8, double _sigma_scale = 0.6, double _quant = 2.0, double _ang_th = 22.5, double _log_eps = 0, double _density_th = 0.7, int _n_bins = 1024)
:param _refine: The way found lines will be refined: :param _refine: The way found lines will be refined:

@ -904,7 +904,7 @@ protected:
Point2f bottomRight; Point2f bottomRight;
}; };
class LineSegmentDetector : public Algorithm class CV_EXPORTS_W LineSegmentDetector : public Algorithm
{ {
public: public:
/** /**
@ -926,7 +926,7 @@ public:
* * 1 corresponds to 0.1 mean false alarms * * 1 corresponds to 0.1 mean false alarms
* This vector will be calculated _only_ when the objects type is REFINE_ADV * This vector will be calculated _only_ when the objects type is REFINE_ADV
*/ */
virtual void detect(InputArray _image, OutputArray _lines, CV_WRAP virtual void detect(InputArray _image, OutputArray _lines,
OutputArray width = noArray(), OutputArray prec = noArray(), OutputArray width = noArray(), OutputArray prec = noArray(),
OutputArray nfa = noArray()) = 0; OutputArray nfa = noArray()) = 0;
@ -937,7 +937,7 @@ public:
* Should have the size of the image, where the lines were found * Should have the size of the image, where the lines were found
* @param lines The lines that need to be drawn * @param lines The lines that need to be drawn
*/ */
virtual void drawSegments(InputOutputArray _image, InputArray lines) = 0; CV_WRAP virtual void drawSegments(InputOutputArray _image, InputArray lines) = 0;
/** /**
* Draw both vectors on the image canvas. Uses blue for lines 1 and red for lines 2. * Draw both vectors on the image canvas. Uses blue for lines 1 and red for lines 2.
@ -949,13 +949,13 @@ public:
* Should have the size of the image, where the lines were found * Should have the size of the image, where the lines were found
* @return The number of mismatching pixels between lines1 and lines2. * @return The number of mismatching pixels between lines1 and lines2.
*/ */
virtual int compareSegments(const Size& size, InputArray lines1, InputArray lines2, InputOutputArray _image = noArray()) = 0; CV_WRAP virtual int compareSegments(const Size& size, InputArray lines1, InputArray lines2, InputOutputArray _image = noArray()) = 0;
virtual ~LineSegmentDetector() {}; virtual ~LineSegmentDetector() {};
}; };
//! Returns a pointer to a LineSegmentDetector class. //! Returns a pointer to a LineSegmentDetector class.
CV_EXPORTS Ptr<LineSegmentDetector> createLineSegmentDetectorPtr( CV_EXPORTS_W Ptr<LineSegmentDetector> createLineSegmentDetector(
int _refine = LSD_REFINE_STD, double _scale = 0.8, int _refine = LSD_REFINE_STD, double _scale = 0.8,
double _sigma_scale = 0.6, double _quant = 2.0, double _ang_th = 22.5, double _sigma_scale = 0.6, double _quant = 2.0, double _ang_th = 22.5,
double _log_eps = 0, double _density_th = 0.7, int _n_bins = 1024); double _log_eps = 0, double _density_th = 0.7, int _n_bins = 1024);

@ -388,7 +388,7 @@ private:
///////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////
CV_EXPORTS Ptr<LineSegmentDetector> createLineSegmentDetectorPtr( CV_EXPORTS Ptr<LineSegmentDetector> createLineSegmentDetector(
int _refine, double _scale, double _sigma_scale, double _quant, double _ang_th, int _refine, double _scale, double _sigma_scale, double _quant, double _ang_th,
double _log_eps, double _density_th, int _n_bins) double _log_eps, double _density_th, int _n_bins)
{ {

@ -110,7 +110,7 @@ TEST_F(Imgproc_LSD_ADV, whiteNoise)
for (int i = 0; i < EPOCHS; ++i) for (int i = 0; i < EPOCHS; ++i)
{ {
GenerateWhiteNoise(test_image); GenerateWhiteNoise(test_image);
Ptr<LineSegmentDetector> detector = createLineSegmentDetectorPtr(LSD_REFINE_ADV); Ptr<LineSegmentDetector> detector = createLineSegmentDetector(LSD_REFINE_ADV);
detector->detect(test_image, lines); detector->detect(test_image, lines);
if(40u >= lines.size()) ++passedtests; if(40u >= lines.size()) ++passedtests;
@ -123,7 +123,7 @@ TEST_F(Imgproc_LSD_ADV, constColor)
for (int i = 0; i < EPOCHS; ++i) for (int i = 0; i < EPOCHS; ++i)
{ {
GenerateConstColor(test_image); GenerateConstColor(test_image);
Ptr<LineSegmentDetector> detector = createLineSegmentDetectorPtr(LSD_REFINE_ADV); Ptr<LineSegmentDetector> detector = createLineSegmentDetector(LSD_REFINE_ADV);
detector->detect(test_image, lines); detector->detect(test_image, lines);
if(0u == lines.size()) ++passedtests; if(0u == lines.size()) ++passedtests;
@ -137,7 +137,7 @@ TEST_F(Imgproc_LSD_ADV, lines)
{ {
const unsigned int numOfLines = 1; const unsigned int numOfLines = 1;
GenerateLines(test_image, numOfLines); GenerateLines(test_image, numOfLines);
Ptr<LineSegmentDetector> detector = createLineSegmentDetectorPtr(LSD_REFINE_ADV); Ptr<LineSegmentDetector> detector = createLineSegmentDetector(LSD_REFINE_ADV);
detector->detect(test_image, lines); detector->detect(test_image, lines);
if(numOfLines * 2 == lines.size()) ++passedtests; // * 2 because of Gibbs effect if(numOfLines * 2 == lines.size()) ++passedtests; // * 2 because of Gibbs effect
@ -150,7 +150,7 @@ TEST_F(Imgproc_LSD_ADV, rotatedRect)
for (int i = 0; i < EPOCHS; ++i) for (int i = 0; i < EPOCHS; ++i)
{ {
GenerateRotatedRect(test_image); GenerateRotatedRect(test_image);
Ptr<LineSegmentDetector> detector = createLineSegmentDetectorPtr(LSD_REFINE_ADV); Ptr<LineSegmentDetector> detector = createLineSegmentDetector(LSD_REFINE_ADV);
detector->detect(test_image, lines); detector->detect(test_image, lines);
if(2u <= lines.size()) ++passedtests; if(2u <= lines.size()) ++passedtests;
@ -163,7 +163,7 @@ TEST_F(Imgproc_LSD_STD, whiteNoise)
for (int i = 0; i < EPOCHS; ++i) for (int i = 0; i < EPOCHS; ++i)
{ {
GenerateWhiteNoise(test_image); GenerateWhiteNoise(test_image);
Ptr<LineSegmentDetector> detector = createLineSegmentDetectorPtr(LSD_REFINE_STD); Ptr<LineSegmentDetector> detector = createLineSegmentDetector(LSD_REFINE_STD);
detector->detect(test_image, lines); detector->detect(test_image, lines);
if(50u >= lines.size()) ++passedtests; if(50u >= lines.size()) ++passedtests;
@ -176,7 +176,7 @@ TEST_F(Imgproc_LSD_STD, constColor)
for (int i = 0; i < EPOCHS; ++i) for (int i = 0; i < EPOCHS; ++i)
{ {
GenerateConstColor(test_image); GenerateConstColor(test_image);
Ptr<LineSegmentDetector> detector = createLineSegmentDetectorPtr(LSD_REFINE_STD); Ptr<LineSegmentDetector> detector = createLineSegmentDetector(LSD_REFINE_STD);
detector->detect(test_image, lines); detector->detect(test_image, lines);
if(0u == lines.size()) ++passedtests; if(0u == lines.size()) ++passedtests;
@ -190,7 +190,7 @@ TEST_F(Imgproc_LSD_STD, lines)
{ {
const unsigned int numOfLines = 1; const unsigned int numOfLines = 1;
GenerateLines(test_image, numOfLines); GenerateLines(test_image, numOfLines);
Ptr<LineSegmentDetector> detector = createLineSegmentDetectorPtr(LSD_REFINE_STD); Ptr<LineSegmentDetector> detector = createLineSegmentDetector(LSD_REFINE_STD);
detector->detect(test_image, lines); detector->detect(test_image, lines);
if(numOfLines * 2 == lines.size()) ++passedtests; // * 2 because of Gibbs effect if(numOfLines * 2 == lines.size()) ++passedtests; // * 2 because of Gibbs effect
@ -203,7 +203,7 @@ TEST_F(Imgproc_LSD_STD, rotatedRect)
for (int i = 0; i < EPOCHS; ++i) for (int i = 0; i < EPOCHS; ++i)
{ {
GenerateRotatedRect(test_image); GenerateRotatedRect(test_image);
Ptr<LineSegmentDetector> detector = createLineSegmentDetectorPtr(LSD_REFINE_STD); Ptr<LineSegmentDetector> detector = createLineSegmentDetector(LSD_REFINE_STD);
detector->detect(test_image, lines); detector->detect(test_image, lines);
if(4u <= lines.size()) ++passedtests; if(4u <= lines.size()) ++passedtests;
@ -216,7 +216,7 @@ TEST_F(Imgproc_LSD_NONE, whiteNoise)
for (int i = 0; i < EPOCHS; ++i) for (int i = 0; i < EPOCHS; ++i)
{ {
GenerateWhiteNoise(test_image); GenerateWhiteNoise(test_image);
Ptr<LineSegmentDetector> detector = createLineSegmentDetectorPtr(LSD_REFINE_STD); Ptr<LineSegmentDetector> detector = createLineSegmentDetector(LSD_REFINE_STD);
detector->detect(test_image, lines); detector->detect(test_image, lines);
if(50u >= lines.size()) ++passedtests; if(50u >= lines.size()) ++passedtests;
@ -229,7 +229,7 @@ TEST_F(Imgproc_LSD_NONE, constColor)
for (int i = 0; i < EPOCHS; ++i) for (int i = 0; i < EPOCHS; ++i)
{ {
GenerateConstColor(test_image); GenerateConstColor(test_image);
Ptr<LineSegmentDetector> detector = createLineSegmentDetectorPtr(LSD_REFINE_NONE); Ptr<LineSegmentDetector> detector = createLineSegmentDetector(LSD_REFINE_NONE);
detector->detect(test_image, lines); detector->detect(test_image, lines);
if(0u == lines.size()) ++passedtests; if(0u == lines.size()) ++passedtests;
@ -243,7 +243,7 @@ TEST_F(Imgproc_LSD_NONE, lines)
{ {
const unsigned int numOfLines = 1; const unsigned int numOfLines = 1;
GenerateLines(test_image, numOfLines); GenerateLines(test_image, numOfLines);
Ptr<LineSegmentDetector> detector = createLineSegmentDetectorPtr(LSD_REFINE_NONE); Ptr<LineSegmentDetector> detector = createLineSegmentDetector(LSD_REFINE_NONE);
detector->detect(test_image, lines); detector->detect(test_image, lines);
if(numOfLines * 2 == lines.size()) ++passedtests; // * 2 because of Gibbs effect if(numOfLines * 2 == lines.size()) ++passedtests; // * 2 because of Gibbs effect
@ -256,7 +256,7 @@ TEST_F(Imgproc_LSD_NONE, rotatedRect)
for (int i = 0; i < EPOCHS; ++i) for (int i = 0; i < EPOCHS; ++i)
{ {
GenerateRotatedRect(test_image); GenerateRotatedRect(test_image);
Ptr<LineSegmentDetector> detector = createLineSegmentDetectorPtr(LSD_REFINE_NONE); Ptr<LineSegmentDetector> detector = createLineSegmentDetector(LSD_REFINE_NONE);
detector->detect(test_image, lines); detector->detect(test_image, lines);
if(8u <= lines.size()) ++passedtests; if(8u <= lines.size()) ++passedtests;

@ -137,6 +137,7 @@ typedef Ptr<StereoSGBM> Ptr_StereoSGBM;
typedef Ptr<cv::softcascade::ChannelFeatureBuilder> Ptr_ChannelFeatureBuilder; typedef Ptr<cv::softcascade::ChannelFeatureBuilder> Ptr_ChannelFeatureBuilder;
typedef Ptr<CLAHE> Ptr_CLAHE; typedef Ptr<CLAHE> Ptr_CLAHE;
typedef Ptr<LineSegmentDetector > Ptr_LineSegmentDetector;
typedef SimpleBlobDetector::Params SimpleBlobDetector_Params; typedef SimpleBlobDetector::Params SimpleBlobDetector_Params;

@ -30,9 +30,9 @@ int main(int argc, char** argv)
// Create and LSD detector with standard or no refinement. // Create and LSD detector with standard or no refinement.
#if 1 #if 1
Ptr<LineSegmentDetector> ls = createLineSegmentDetectorPtr(LSD_REFINE_STD); Ptr<LineSegmentDetector> ls = createLineSegmentDetector(LSD_REFINE_STD);
#else #else
Ptr<LineSegmentDetector> ls = createLineSegmentDetectorPtr(LSD_REFINE_NONE); Ptr<LineSegmentDetector> ls = createLineSegmentDetector(LSD_REFINE_NONE);
#endif #endif
double start = double(getTickCount()); double start = double(getTickCount());

Loading…
Cancel
Save