1

enter image description here

As you can see in the picture a cone is generated when a person is using maps. I would like to know if it is possible to detect the two outer-lines of the cones like this but the ultimate goal is to use this information to find the angles at which the lines are at.

I was following this tutorial on hough-transform but end up with this. Looking for an easier way to find the angles if possible.

import numpy as np

from skimage.transform import hough_line
from scipy import misc

import matplotlib.pyplot as plt
from matplotlib import cm

image = misc.imread("cone.jpg", flatten=True)

# Classic straight-line Hough transform
h, theta, d = hough_line(image)

# Generating figure 1
fig, axes = plt.subplots(1, 3, figsize=(9, 3),
                         subplot_kw={'adjustable': 'box-forced'})
ax = axes.ravel()

ax[0].imshow(image, cmap=cm.gray)
ax[0].set_title('Input image')
ax[0].set_axis_off()

ax[1].imshow(np.log(1 + h),
             extent=[np.rad2deg(theta[-1]), np.rad2deg(theta[0]), d[-1], d[0]],
             cmap=cm.gray, aspect=1/1.5)
ax[1].set_title('Hough transform')
ax[1].set_xlabel('Angles (degrees)')
ax[1].set_ylabel('Distance (pixels)')
ax[1].axis('image')

ax[2].imshow(image, cmap=cm.gray)
for _, angle, dist in zip(*hough_line_peaks(h, theta, d)):
    y0 = (dist - 0 * np.cos(angle)) / np.sin(angle)
    y1 = (dist - image.shape[1] * np.cos(angle)) / np.sin(angle)
    ax[2].plot((0, image.shape[1]), (y0, y1), '-r')
ax[2].set_xlim((0, image.shape[1]))
ax[2].set_ylim((image.shape[0], 0))
ax[2].set_axis_off()
ax[2].set_title('Detected lines')

plt.tight_layout()
plt.show()
Miki
  • 37,220
  • 12
  • 98
  • 183
Bill Ma
  • 13
  • 3
  • 1
    did you (Canny) edge detect 1st? – f5r5e5d Dec 18 '17 at 08:12
  • 1
    may I ask what the purpose of this is and how many of those google maps screenshots you have to process? and I find your question misleading. are you sure you are interested in the angle between those lines? because that angle is very likely a constant. or do you want where the person is facing to? – Piglet Dec 18 '17 at 10:01

1 Answers1

2

Here is my result: enter image description here


You should take refer to this first: Detect Colored Segment in an image


My steps are:

  1. Convert it to HSV, and get the S
  2. Do canny on S
  3. Detect on canny edges, filter by some rulers.
Kinght 金
  • 14,440
  • 4
  • 49
  • 62
  • Hi. Thanks for the help. I am able to get it working for some images. However I run into some trouble with some test cases. Any advice on how I would handle [this situation?](https://i.imgur.com/PO48J1i.png). I am doing a hough transform on the canny edge and finding the min and max lines calculated, which is usually the cone. However as you can see in the picture, there are some obstacles in the way... Anyway to filter out the obstacle? I don't want to crop because sometimes the obstacle is right next to the cone. Thanks... – Bill Ma Jan 03 '18 at 00:26