问题
I've been trying to detect some lines (on edges) in live webcam images, so I tried to do canny edge detection followed by hough transform using C++ version of OpenCV 3.2.0.
There shouldn't be any issues since using HoughLinesP looks straightforward, but it seems that I can't make it work.
The problem is that the vector output that is supposed to contain detected lines, is filled with a couple million of garbage results!
This is how I call HoughLinesP:
vector<Vec4i> lines;
HoughLinesP(cannyd, lines, 1, CV_PI/180.0, 100, 100, 10);
and then try to output the detected lines like:
for (size_t i = 0; i < lines.size(); i++) {
Vec4i l = lines[i];
printf("line: %d %d %d %d\n", l[0], l[1], l[2], l[3]);
}
But I get about 3-4 million lines in return (size of lines vector after detection)! Most of which are (0, 0, 0, 0). Some other detected lines look like this:
line: 0 0 1161992204 -1946150912
line: 2000556868 1404 17730960 17730984
line: 17730968 17447528 2 2000558912
line: 0 0 0 0
line: 1163630597 -2147477248 0 17736008
line: 0 0 32 17736008
line: 0 1684957559 30575 0
line: 0 0 1163171842 -2147476992
which is totally strange as the input image is 640*480 in size, and these numbers are not nearly correct.
Appreciate your help
Edit: Posting more code (as per @Alexander's suggestion)
VideoCapture cap;
cap.open(0);
cap >> image;
cvtColor(image, gray, CV_BGR2GRAY);
blur(gray, gray, Size(3, 3));
Canny(gray, cannyd, 50, 150, 3);
// This is where above-mentioned Hough codes run
来源:https://stackoverflow.com/questions/44661140/opencv-3-2-0-houghlinesp-returns-out-of-bounds-lines-c