how detect ( 2 or 3 ) number lines in opencv - opencv

How many way to tell if a photo (in a few lines) in opencv
In the example below that line there are 3
http://www.uploadimage.co.uk/images/1511642.jpg
Thanks

Try dilating the white portion of the image first. This will make the black strip thinner. Once it is thin comparatively, you could use hough lines transform which returns an array of lines it finds. The task would then be as simple as counting the number of elements in the arrray. Of course, you will have to do a lot of trial and error in passing appropriate parameters to the Hough transform, lest it returns you closely spaced lines which represent the same region in your image. You might probably need to group the lines based on the slope and the intercept also.

Related

How can you measure the length of curved grid lines on an image?

Suppose you have an image like this:
How can you measure the combined length of all the lines in this image?
I have tried (naively) skeletonising the image and then counting the number of pixels. However, this gives inaccurate results, as diagonal steps are actually longer than vertical/horizontal ones.
My other idea is to generate a chain code for all the line segments , and then use something like Freeman's method to measure the length from the chain code. However, generating the chain code is going to be quite tricky I think, as usually they start/stop at the same point, and this won't work for the grid shape.
Am I missing something obvious here? Is there an easier way to do this?
As far as I can see, the strokes are 3 pixels wide. So dividing the number of black pixels by three isn't a too bad approximation.
Alternatively, use a thinning algorithm to reduce the width to a single pixel (connexity 8), then seed-fill the whole outline. You will use a simple recursive 8-ways fill, and count the lateral and diagonal moves separately. In the end the length is given by L + D√2.

Condition of lines that are results of perspective transform

I have set of lines that have been transformed using a perspective transformation.
The information that I know about these lines are:
They are lines not line segments (no length or start point or end point is known)
They are all parallel
Distances between them are unknown and vary from pair to pair.
So, to make it clear again, I do not know the blue lines. I have just the greens. Even, I do not know what is the Homograph Matrix that was applied.
Question:
I need a method, a measurement, an algorithm or even a hint about the condition that must all the green lines satisfied.
For example if I add this red line to the set:
It is obvious that the red line could not be exist in the set of lines before applying the transformation so it is a noise of course.
So I need a measurement if I applied it on the green lines would give me positive response and if add the red line to the green set it would show a negative response or at least a lower confidence.
P.S. OpenCV is available and preferred.
If they are parallel before perspective projection all lines should intersect in the same vanishing point. I would say you should compute this point using your green lines (maybe this is helpful) and if the distance from your red line to the vanishing point is to big it can be rejected.

OpenCV parallel lines cull

I have an algorithm that simply goes through a number of corners and finds those which are parallel. My problem is, as shown below, that I sometimes get false positive results.
To eliminate this I was going to check if both points fell onto a single hough line but this would be quite computationally intensive and I was wondering if anyone had any simpler ideas.
Thanks.
Ok based on the comments, this should be fix-able. When you detect a pair of parallel lines, get the equation of the line using the two corners that you've used to construct it. This line may be of the form y = mx + c. Then for every y coordinate between the two points, compute the x coordinate. This gives you a set of all the pixels that the line segment covers. Go through these pixels, and check if the intensity at every pixel is closer to black than white. If a majority of the pixels in the set are black-ish, then it's a line. If not, it's probably a non-line.

Calculate harmonics for a set of data extracted from images

I am implementing a method known as trace transform for image analysis. The algorithm extracts a lot of features of an image (in my case features pertained to texture) using a set of transforms on the values of the pixels. Here is a paper describing the algorithm: http://www.google.com/url?sa=t&rct=j&q=&esrc=s&source=web&cd=18&cad=rja&ved=0CGoQFjAHOAo&url=http%3A%2F%2Fpdf.aminer.org%2F000%2F067%2F295%2Ftexture_classification_with_thousands_of_features.pdf&ei=lV9cUez_GYrx2QX-voCgDw&usg=AFQjCNEbCd8GBm4X8V4vk0PYyQwPZPlWyg&sig2=KTtvd1XxtvuUpCDeBzUu4A (sorry for the long link)
The algorithm finally constructs a "triple feature" which is a number that characterizes the image and was calculated by applying a first set of transforms on the pixel values extracted by all the tracing lines going through the image at all angles. On the paper you can see this description starting on page 2, Figure 1 shows an abstraction of such a tracing line which is defined by its angle (phi) and the distance (d) of the line from the center of the image. So we can describe each tracing line by the pair (phi,d).
Now on the next page on the paper (page 3) we have Table 1 which is the set of functionals that is applied to the pixel values extracted by the tracing lines. Each of these functionals applied to all the tracing lines generates another representation of the image. Then another set of functionals (those that appear on Table 2 on page 4) are applied to the new representation of the image along the columns which is basically along parameter d generating, this way, another new representation of the image.
Finally another set of functionals is applied to this last representation which is an array of values over parameter phi which was the angle parameter (that means we have 360 values describing the image, one for each angle of the tracing lines). You can see these functionals in the paper on Table 3 page 4.
Now some of this last set of functionals that have to be applied to the last representation of the image over parameter phi need to calculate the harmonics of this set of 360 values. First I need to calculate the first harmonic and then the amplitude and phase of the first through fourth harmonic but I don't know how to do this.
I hope this explains it better. You can read the first couple of pages of the paper since it's probably better explained there. And figure 1 makes it clear what I mean by tracing lines and the representation of each line by the (phi,d) pair.
Thanks

Hough transform to determine lines and their width

Are there any implementations or papers that modify the Hough transform to detect the width of line segments? Hough space maxima can be used to determine potential lines, and line segments are groups of pixels that are on the line for sufficient intervals. After doing that, I'm trying to determine the width of each line segment.
All I've been able to find thus far is this poster:
http://www.cse.cuhk.edu.hk/~lyu/staff/SongJQ/poster_47_song_j.pdf
Depending if you are willing to spend some money, there is a package called Halcon that has the kind of things you are after.
For example http://www.mvtec.com/download/reference/lines_gauss.html (that's not a Hough transform, but the main package does have those as well).
I used Google to find a paper called "Extraction of Curved Lines from Images" which mentions line width (I can't get the link to work either).
If you have a binary mask for each line segment could you possibly take the maximum of the distance transform on that line segment? It should tell you how far away the center of the line is from the edge, the width should be 2*max(distanceTranform(segment)) - 1 for odd widths and 2*max(distanceTranform(segment)) for even widths.
OpenCV has an implementation of this method here. They also have HoughLinesP to detect line segments, but sounds like you already have that worked out.

Resources