Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Detect slightly distorted line

Given the following (canny'd) image, I'd like to grab the start/end endpoints of the full upper horizontal line.

I've tried opencv's HoughLineP function, but get segments rather than a full line. I realise that this is due to the camera calibration distortion.

  • Is there some other technique that is more forgiving when it comes to curvy distortions?
  • Alternatively, what would be a good way to join points that close to each other (with somehow similar angle)

Original

Original

Code

Mat scene = imread("houghLines.png", 0);

vector<Vec4i> lines;
HoughLinesP(scene, lines, 1, CV_PI/180, 40, 100, 20 );

cvtColor(scene, scene, COLOR_GRAY2BGR); scene *= 0.5; // convert to colour

auto colours = generateColours((int)lines.size());
for(int i = 0; i < lines.size(); i++) {
    auto l = lines[i];
    line(scene, Point(l[0], l[1]), Point(l[2], l[3]), colours[i], 1, CV_AA);
}

imshow("scene", scene);
waitKey();

Result

Result

click to hide/show revision 2
original better visibility (binarized 0/255)

Detect slightly distorted line

Given the following (canny'd) image, I'd like to grab the start/end endpoints of the full upper horizontal line.

I've tried opencv's HoughLineP function, but get segments rather than a full line. I realise that this is due to the camera calibration distortion.

  • Is there some other technique that is more forgiving when it comes to curvy distortions?
  • Alternatively, what would be a good way to join points that close to each other (with somehow similar angle)

Original

OriginalOrignal-canny

Code

Mat scene = imread("houghLines.png", 0);

vector<Vec4i> lines;
HoughLinesP(scene, lines, 1, CV_PI/180, 40, 100, 20 );

cvtColor(scene, scene, COLOR_GRAY2BGR); scene *= 0.5; // convert to colour

auto colours = generateColours((int)lines.size());
for(int i = 0; i < lines.size(); i++) {
    auto l = lines[i];
    line(scene, Point(l[0], l[1]), Point(l[2], l[3]), colours[i], 1, CV_AA);
}

imshow("scene", scene);
waitKey();

Result

Result