Ask Your Question

# Generalizing the size for Detecting Horizontal and Vertical Lines [closed]

Is there a way to generalize the vertical and horizontal size in the given code below? The given Vertical and horizontal size for getStucturingElement() doesn't work in all the cases and I should change them depending on ther grid thickness.

Please find the inputs and desired outputs below:

code link

edit retag reopen merge delete

## Comments

You mean, to have sort of an adaptive structuring element? I don't think so. What exactly is your goal?

( 2019-07-18 16:02:24 -0500 )edit

Yes, I would like to denote each intersection point as coordinates starting from top left as (0,0),(1,0),....

( 2019-07-18 23:31:07 -0500 )edit

Adaptive structuring element or if not any other method.

( 2019-07-18 23:32:04 -0500 )edit

## 1 answer

Sort by ยป oldest newest most voted

To get only the intersections, just use the Harris corner detector. It will have maximum values in the middle, no matter the line width.

To get the structure, use a morphological skeleton algorithm (it's a kind of adaptive erosion). It's not part of OpenCV if I remember correctly, but you can find some implementations on the web.

more

## Comments

I have to name each corner as a coordinate and I am not sure how to make it possible when I detect corners.

( 2019-07-19 05:49:32 -0500 )edit
1
( 2019-07-19 06:20:35 -0500 )edit

I have to name each corner as a coordinate...

Just detect the maxima of the image given by the Harris corner detector.

( 2019-07-19 06:54:28 -0500 )edit

@sturkmen I have tried using thinning algorithm and then trying getStructuringElement but the continuous lines are separated while finding horizontal and vertical lines which make it difficult for counting the number of lines.

( 2019-07-19 07:35:47 -0500 )edit

@kbarni When I try to find corner detection there are few false positives. While changing the parameters I have 2 corners at the same intersection point.

( 2019-07-19 08:06:32 -0500 )edit

@Dronzer. Are you talking about the size of black sqaures?

( 2019-07-20 08:37:16 -0500 )edit
1

@supra56 yes, I mean the size.

( 2019-07-20 12:45:38 -0500 )edit

@Dronzer You need to detect the local maxima in the image, to eliminate multiple detections.

There are several ways to do this, you can eliminate every corner in a D pixel radius around a detection. The subpixel accuracy method in the description I linked can be another solution.

( 2019-07-22 08:51:58 -0500 )edit

@kbarni I have modified the question a bit and provided input and desired output that I am looking for. Thank you!

( 2019-07-22 10:06:39 -0500 )edit

...and did you try so solve it? Or you are just waiting for us to give you the solution? (it won't happen)

( 2019-07-23 10:25:58 -0500 )edit

Official site

GitHub

Wiki

Documentation

## Stats

Asked: 2019-07-18 10:32:20 -0500

Seen: 64 times

Last updated: Jul 22