 |
OpenCV
3.2.0
Open Source Computer Vision
|
An example using the Hough line detector
#include <cmath>
#include <iostream>
using namespace std;
static void help()
{
cout << "This program demonstrates line finding with the Hough transform." << endl;
cout << "Usage:" << endl;
cout << "./gpu-example-houghlines <image_name>, Default is ../data/pic1.png\n" << endl;
}
int main(int argc, const char* argv[])
{
const string filename = argc >= 2 ? argv[1] : "../data/pic1.png";
{
help();
cout << "can not open " << filename << endl;
return -1;
}
vector<Vec4i> lines_cpu;
{
cout << "CPU Time : " << timeSec * 1000 << " ms" << endl;
cout << "CPU Found : " << lines_cpu.size() << endl;
}
for (
size_t i = 0;
i < lines_cpu.size(); ++
i)
{
}
{
hough->
detect(d_src, d_lines);
cout << "GPU Time : " << timeSec * 1000 << " ms" << endl;
cout <<
"GPU Found : " << d_lines.
cols << endl;
}
vector<Vec4i> lines_gpu;
{
lines_gpu.resize(d_lines.
cols);
}
for (
size_t i = 0;
i < lines_gpu.size(); ++
i)
{
}
imshow(
"detected lines [CPU]", dst_cpu);
imshow(
"detected lines [GPU]", dst_gpu);
return 0;
}
bool empty() const
returns true if GpuMat data is NULL
void cvtColor(InputArray src, OutputArray dst, int code, int dstCn=0)
Converts an image from one color space to another.
int waitKey(int delay=0)
Waits for a pressed key.
int cols
Definition: cuda.hpp:286
Ptr< HoughSegmentDetector > createHoughSegmentDetector(float rho, float theta, int minLineLength, int maxLineGap, int maxLines=4096)
Creates implementation for cuda::HoughSegmentDetector .
void Canny(InputArray image, OutputArray edges, double threshold1, double threshold2, int apertureSize=3, bool L2gradient=false)
Finds edges in an image using the Canny algorithm .
@ IMREAD_GRAYSCALE
If set, always convert image to the single channel grayscale image.
Definition: imgcodecs.hpp:66
int64_t int64
Definition: interface.h:57
void line(InputOutputArray img, Point pt1, Point pt2, const Scalar &color, int thickness=1, int lineType=LINE_8, int shift=0)
Draws a line segment connecting two points.
Mat imread(const String &filename, int flags=IMREAD_COLOR)
Loads an image from a file.
void download(OutputArray dst) const
pefroms download data from device to host memory (Blocking call)
bool empty() const
Returns true if the array has no elements.
Template class for short numerical vectors, a partial case of Matx.
Definition: matx.hpp:306
Template class for smart pointers with shared ownership.
Definition: cvstd.hpp:281
int64 getTickCount()
Returns the number of ticks.
@ LINE_AA
antialiased line
Definition: core.hpp:218
Base storage class for GPU memory with reference counting.
Definition: cuda.hpp:97
void imshow(const String &winname, InputArray mat)
Displays an image in the specified window.
#define CV_32SC4
Definition: interface.h:109
double getTickFrequency()
Returns the number of ticks per second.
Scalar_< double > Scalar
Definition: types.hpp:606
Mat clone() const
Creates a full copy of the array and the underlying data.
Point2i Point
Definition: types.hpp:183
n-dimensional dense array class
Definition: mat.hpp:741
for i
Definition: modelConvert.m:63
void HoughLinesP(InputArray image, OutputArray lines, double rho, double theta, int threshold, double minLineLength=0, double maxLineGap=0)
Finds line segments in a binary image using the probabilistic Hough transform.
Definition: affine.hpp:52
#define CV_PI
Definition: cvdef.h:302
@ COLOR_GRAY2BGR
Definition: imgproc.hpp:540
virtual void detect(InputArray src, OutputArray lines, Stream &stream=Stream::Null())=0
Finds line segments in a binary image using the probabilistic Hough transform.