提交 48c985e7 编写于 作者: A Alexander Alekhin

Merge pull request #20797 from sturkmen72:restore_LSD

......@@ -1220,12 +1220,17 @@ protected:
//! @addtogroup imgproc_feature
//! @{
/** @example samples/cpp/lsd_lines.cpp
An example using the LineSegmentDetector
\image html building_lsd.png "Sample output image" width=434 height=300
*/
/** @brief Line segment detector class
following the algorithm described at @cite Rafael12 .
@note Implementation has been removed due original code license conflict
@note Implementation has been removed from OpenCV version 3.4.6 to 3.4.15 and version 4.1.0 to 4.5.3 due original code license conflict.
restored again after [Computation of a NFA](https://github.com/rafael-grompone-von-gioi/binomial_nfa) code published under the MIT license.
*/
class CV_EXPORTS_W LineSegmentDetector : public Algorithm
{
......@@ -1239,8 +1244,8 @@ public:
@param image A grayscale (CV_8UC1) input image. If only a roi needs to be selected, use:
`lsd_ptr-\>detect(image(roi), lines, ...); lines += Scalar(roi.x, roi.y, roi.x, roi.y);`
@param lines A vector of Vec4i or Vec4f elements specifying the beginning and ending point of a line. Where
Vec4i/Vec4f is (x1, y1, x2, y2), point 1 is the start, point 2 - end. Returned lines are strictly
@param lines A vector of Vec4f elements specifying the beginning and ending point of a line. Where
Vec4f is (x1, y1, x2, y2), point 1 is the start, point 2 - end. Returned lines are strictly
oriented depending on the gradient.
@param width Vector of widths of the regions, where the lines are found. E.g. Width of line.
@param prec Vector of precisions with which the lines are found.
......@@ -1288,8 +1293,6 @@ to edit those, as to tailor it for their own application.
@param log_eps Detection threshold: -log10(NFA) \> log_eps. Used only when advance refinement is chosen.
@param density_th Minimal density of aligned region points in the enclosing rectangle.
@param n_bins Number of bins in pseudo-ordering of gradient modulus.
@note Implementation has been removed due original code license conflict
*/
CV_EXPORTS_W Ptr<LineSegmentDetector> createLineSegmentDetector(
int refine = LSD_REFINE_STD, double scale = 0.8,
......
此差异已折叠。
......@@ -5,8 +5,6 @@
namespace opencv_test { namespace {
#if 0 // LSD implementation has been removed due original code license issues
const Size img_size(640, 480);
const int LSD_TEST_SEED = 0x134679;
const int EPOCHS = 20;
......@@ -404,6 +402,4 @@ TEST_F(Imgproc_LSD_Common, compareSegmentsVec4i)
ASSERT_EQ(result2, 11);
}
#endif
}} // namespace
#include "opencv2/imgproc.hpp"
#include "opencv2/imgcodecs.hpp"
#include "opencv2/highgui.hpp"
#include <iostream>
using namespace std;
using namespace cv;
int main(int argc, char** argv)
{
cv::CommandLineParser parser(argc, argv,
"{input i|building.jpg|input image}"
"{refine r|false|if true use LSD_REFINE_STD method, if false use LSD_REFINE_NONE method}"
"{canny c|false|use Canny edge detector}"
"{overlay o|false|show result on input image}"
"{help h|false|show help message}");
if (parser.get<bool>("help"))
{
parser.printMessage();
return 0;
}
parser.printMessage();
String filename = samples::findFile(parser.get<String>("input"));
bool useRefine = parser.get<bool>("refine");
bool useCanny = parser.get<bool>("canny");
bool overlay = parser.get<bool>("overlay");
Mat image = imread(filename, IMREAD_GRAYSCALE);
if( image.empty() )
{
cout << "Unable to load " << filename;
return 1;
}
imshow("Source Image", image);
if (useCanny)
{
Canny(image, image, 50, 200, 3); // Apply Canny edge detector
}
// Create and LSD detector with standard or no refinement.
Ptr<LineSegmentDetector> ls = useRefine ? createLineSegmentDetector(LSD_REFINE_STD) : createLineSegmentDetector(LSD_REFINE_NONE);
double start = double(getTickCount());
vector<Vec4f> lines_std;
// Detect the lines
ls->detect(image, lines_std);
double duration_ms = (double(getTickCount()) - start) * 1000 / getTickFrequency();
std::cout << "It took " << duration_ms << " ms." << std::endl;
// Show found lines
if (!overlay || useCanny)
{
image = Scalar(0, 0, 0);
}
ls->drawSegments(image, lines_std);
String window_name = useRefine ? "Result - standard refinement" : "Result - no refinement";
window_name += useCanny ? " - Canny edge detector used" : "";
imshow(window_name, image);
waitKey();
return 0;
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册