#include <iostream>
int main(
int argc,
char** argv)
{
string in;
CommandLineParser parser(argc, argv,
"{@input|corridor.jpg|input image}{help h||show help message}");
if (parser.has("help"))
{
parser.printMessage();
return 0;
}
in = samples::findFile(parser.get<string>("@input"));
{
return -1;
}
int length_threshold = 10;
float distance_threshold = 1.41421356f;
double canny_th1 = 50.0;
double canny_th2 = 50.0;
int canny_aperture_size = 3;
bool do_merge = false;
distance_threshold, canny_th1, canny_th2, canny_aperture_size,
do_merge);
vector<Vec4f> lines;
for (int run_count = 0; run_count < 5; run_count++) {
lines.clear();
fld->detect(image, lines);
double duration_ms = double(
getTickCount() - start) * 1000 / freq;
cout << "FLD耗时 " << duration_ms << " ms." << endl;
}
Mat line_image_fld(image);
fld->drawSegments(line_image_fld, lines);
imshow("FLD结果", line_image_fld);
waitKey(1);
ed->params.EdgeDetectionOperator = EdgeDrawing::SOBEL;
ed->params.GradientThresholdValue = 38;
ed->params.AnchorThresholdValue = 8;
vector<Vec6d> ellipses;
for (int run_count = 0; run_count < 5; run_count++) {
double freq = getTickFrequency();
lines.clear();
int64 start = getTickCount();
ed->detectEdges(image);
ed->detectLines(lines);
double duration_ms = double(getTickCount() - start) * 1000 / freq;
cout << "EdgeDrawing检测直线耗时 " << duration_ms << " ms." << endl;
start = getTickCount();
ed->detectEllipses(ellipses);
duration_ms = double(getTickCount() - start) * 1000 / freq;
cout << "EdgeDrawing检测椭圆耗时 " << duration_ms << " ms." << endl;
}
vector<vector<Point> > segments = ed->getSegments();
for (size_t i = 0; i < segments.size(); i++)
{
const Point* pts = &segments[i][0];
int n = (int)segments[i].
size();
polylines(edge_image_ed, &pts, &n, 1,
false,
Scalar((rand() & 255), (rand() & 255), (rand() & 255)), 1);
}
imshow(
"EdgeDrawing检测到的边缘", edge_image_ed);
Mat line_image_ed(image);
fld->drawSegments(line_image_ed, lines);
for (size_t i = 0; i < ellipses.size(); i++)
{
Point center((
int)ellipses[i][0], (
int)ellipses[i][1]);
Size axes((
int)ellipses[i][2] + (
int)ellipses[i][3], (
int)ellipses[i][2] + (
int)ellipses[i][4]);
double angle(ellipses[i][5]);
ellipse(line_image_ed, center, axes, angle, 0, 360, color, 2, LINE_AA);
}
imshow(
"EdgeDrawing结果", line_image_ed);
return 0;
}
用于命令行解析。
定义 utility.hpp:890
MatSize size
定义 mat.hpp:2177
bool empty() const
如果数组没有元素,则返回true。
用于指定图像或矩形大小的模板类。
定义 types.hpp:335
std::shared_ptr< _Tp > Ptr
定义 cvstd_wrapper.hpp:23
int64_t int64
定义 interface.h:61
#define CV_8UC3
定义 interface.h:90
double getTickFrequency()
返回每秒的滴答数。
int64 getTickCount()
返回滴答数。
void imshow(const String &winname, InputArray mat)
在指定的窗口中显示图像。
int waitKey(int delay=0)
等待按下的键。
CV_EXPORTS_W Mat imread(const String &filename, int flags=IMREAD_COLOR_BGR)
从文件加载图像。
void ellipse(InputOutputArray img, Point center, Size axes, double angle, double startAngle, double endAngle, const Scalar &color, int thickness=1, int lineType=LINE_8, int shift=0)
绘制简单的或粗的椭圆弧或填充椭圆扇区。
void polylines(InputOutputArray img, InputArrayOfArrays pts, bool isClosed, const Scalar &color, int thickness=1, int lineType=LINE_8, int shift=0)
绘制几条多边形曲线。
int main(int argc, char *argv[])
定义 highgui_qt.cpp:3
GOpaque< Size > size(const GMat &src)
从Mat获取尺寸。