Line Detection. [closed]

asked 2014-10-18 05:36:55 -0600

Vivek Goel gravatar image

updated 2014-10-20 03:39:36 -0600

thdrksdfthmn gravatar image

After increasing the minLineLength and decreasing maxLineGap program is still showing number of lines and also the gap is also visible. Can someone tell me the problem in the program? Image is:-image description Code is-:

include "stdafx.h"

include <cv.h>
include <highgui.h>
include <math.h>
using namespace cv;
int main(int argc, char** argv)
    Mat src, dst, color_dst;
    src = imread("line2.jpg", 0);
    Canny(src, dst, 50, 200, 3);
    cvtColor(dst, color_dst, CV_GRAY2BGR);

    vector<Vec4i> lines;
    for (size_t i = 0; i < lines.size(); i++)
        line(color_dst, Point(lines[i][0], lines[i][1]),
            Point(lines[i][2], lines[i][3]), Scalar(0, 0, 255), 3, 8);
    namedWindow("Source", 1);
    imshow("Source", src);
    namedWindow("Detected Lines", 1);
    imshow("Detected Lines", color_dst);
edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by sturkmen
close date 2020-09-27 14:13:26.773454



IT is due to the fact you are using a canny filter. Offcourse this will generate double edges if you increase the line thickness. Why not apply dilate and erode operations. First dilate enough to merge them, then erode the same amount and only a single line will remain.

StevenPuttemans gravatar imageStevenPuttemans ( 2014-10-20 04:15:43 -0600 )edit

ya it's good to use morphological operations but HoughP transform already have parameters to do this. Can you tell me the working and use of last 2 parameters in which i have given 600 and 300 value?

Vivek Goel gravatar imageVivek Goel ( 2014-10-20 14:59:02 -0600 )edit

Just go for the manual erosion dilation which gives you way more control than the embedded options. That is what I prefer in my software.

StevenPuttemans gravatar imageStevenPuttemans ( 2014-10-21 01:22:03 -0600 )edit

Actually if I will use morphological operations, the edges on which I have to work will be lost! Since they are of same thickness.

Vivek Goel gravatar imageVivek Goel ( 2014-10-21 10:47:22 -0600 )edit

I think that you are using the opposite operation, try the other way (open <-> close, dilate <-> erode, top hat <-> black hat)

thdrksdfthmn gravatar imagethdrksdfthmn ( 2014-10-21 10:49:10 -0600 )edit

Since all the edges are of same thickness it doesn't matter what I should use first opening or closing. I want to use the parameters in Hough P Transform to eliminate redundant lines.

Vivek Goel gravatar imageVivek Goel ( 2014-10-21 23:25:51 -0600 )edit

I do not know more than the docs, but you can test it and verify what is happening when changing the parameters. Do this one by one, so you do not change more than one parameter at once.

thdrksdfthmn gravatar imagethdrksdfthmn ( 2014-10-22 02:21:02 -0600 )edit

@Vivek Goel : that is not correct! If you apply dilate first then reduce, then lines will NOT dissappear! Only the thickest line will be a bit thicker...

StevenPuttemans gravatar imageStevenPuttemans ( 2014-10-22 04:50:20 -0600 )edit

Will canny give edges of different thickness? Since if the canny output give edges of different thickness then it will be correct solution but if the detected edges are of same thickness then the morphological operations will be much hard to calibrate and I will to design a much good and sophisticated structuring element.

Vivek Goel gravatar imageVivek Goel ( 2014-10-22 09:10:08 -0600 )edit

At first all edges are equal, but at a certain moment the two closest edges merge with dilation into a single element. Applying the same amount of erosion elements then will not remove the others NOR will it return to 2 edges. I do not see the problem. I think you are missing something.

StevenPuttemans gravatar imageStevenPuttemans ( 2014-10-23 03:06:10 -0600 )edit