1

I have a map with curved latitude lines. I can able to detect some longitude lines. I used HoughlineP to detect lines. My goal is to detect latitude and longitude lines and find the intersection points. Problem is latitude line follow greater circle and are curved with higher altitudes (ex North 40 degrees). Also terrain features giving Houghline lots of trouble finding correct lines. I am looking a for a better curved line detection algorithm in any Python package.

Here is the source image: c_6.jpg

Here is the code I used:

import cv2
import numpy as np

def draw_lines(hough, image, nlines):
  n_x, n_y=image.shape
  #convert to color image so that you can see the lines
  draw_im = cv2.cvtColor(image, cv2.COLOR_GRAY2BGR)

  for (rho, theta) in hough[0][:nlines]:
   try:
     x0 = np.cos(theta)*rho
     y0 = np.sin(theta)*rho
     pt1 = ( int(x0 + (n_x+n_y)*(-np.sin(theta))),
             int(y0 + (n_x+n_y)*np.cos(theta)) )
     pt2 = ( int(x0 - (n_x+n_y)*(-np.sin(theta))),
             int(y0 - (n_x+n_y)*np.cos(theta)) )
     alph = np.arctan( (pt2[1]-pt1[1])/( pt2[0]-pt1[0]) )
     alphdeg = alph*180/np.pi
     #OpenCv uses weird angle system, see: http://docs.opencv.org/3.0-beta/doc/py_tutorials/py_imgproc/py_houghlines/py_houghlines.html
     if abs( np.cos( alph - 180 )) > 0.8: #0.995:
        cv2.line(draw_im, pt1, pt2, (255,0,0), 2)
     if rho>0 and abs( np.cos( alphdeg - 90)) > 0.7:
        cv2.line(draw_im, pt1, pt2, (0,0,255), 2)    
  except:
     pass
 cv2.imwrite("/home/dino/Desktop/3HoughLines.png", draw_im,
         [cv2.IMWRITE_PNG_COMPRESSION, 12])   

 img = cv2.imread('c_6.jpg')
 gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)

 flag,b = cv2.threshold(gray,160,255,cv2.THRESH_BINARY)
 cv2.imwrite("1tresh.jpg", b)

element = np.ones((3,3))
b = cv2.erode(b,element)
cv2.imwrite("2erodedtresh.jpg", b)

edges = cv2.Canny(b,10,100,apertureSize = 3)
cv2.imwrite("3Canny.jpg", edges)

hough = cv2.HoughLines(edges, 1, np.pi/180, 200)   
draw_lines(hough, b, 100)**

1 Answer 1

0

I have just two ideas and no code :-)

First idea: the longitude lines seems to me straight lines and so HoughLines should be good enough. The latitude lines, as you wrote, are not straight, maybe you can find an analytic expression (with suitable parameters, now for the straight line you just have rho and theta, I think you will need more parameters) for them and then try to apply an Hough transformation that maybe you will have to code by yourself.

If the latitude lines are circle maybe you can use HoughCircles to detect them, or you can use also information about the vertical position of the edges in your edges in order to put some constraints in the (arc of) circle you are looking for.

Second idea: instead of using the gray image maybe you can try to work in a suitable color space in order to use the information that the longitude and latitude lines have different color from the background.

2
  • good idea about trying out houghcircles for latitude lines. I will try it out and let you know...
    – user914425
    Nov 25, 2015 at 19:35
  • houghcircles does not work for large circles arc with entire circle does not contain in the image. I need to try out the greater circle approach and see how well it approximate latitude lines.
    – user914425
    Dec 2, 2015 at 20:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.