OpenCV python - Distance from Origin to Harris Corners
Question: I'm writing a python library to do basic processing on geometric images. One
of the desired functions is to return a list of distance of all corners'
distance from the origin. I'm struggling with how to do this after looking at
the print of my corner objects;

    
    
    [[  9.20031281e+01   9.20031281e+01   9.20031281e+01 ...,   6.66796863e-01
    1.01710939e+01   1.01710939e+01]
    [  1.36668701e+02   1.36668701e+02   1.36668701e+02 ...,   1.33374023e+00
    1.07448441e+02   1.07448441e+02]
    [  1.36668701e+02   1.36668701e+02   1.36668701e+02 ...,   1.33374023e+00
    1.07448441e+02   1.07448441e+02]
    ..., 
    [ -7.81250012e-04   3.12500005e-03   1.83593743e-02 ...,   3.36616707e+01
    2.24355469e+01   2.24355469e+01]
    [ -4.88281257e-05   3.12500005e-03   5.41992206e-03 ...,   3.67563972e+01
    2.24355469e+01   2.24355469e+01]
    [ -4.88281257e-05   5.37109387e-04   5.37109387e-04 ...,   3.67563972e+01
    2.24355469e+01   2.24355469e+01]]
    

This image looked like this (note the two pink detected corners);

![enter image description here](http://i.stack.imgur.com/6nHDr.jpg)

How can I find the distance (angle is not required although would be useful
too) from origin to the corners?

Thanks!


Answer: Here is an example of retrieving the `(x,y)` location of each match. I'll be
honest its not the neatest way to do things nor probably the quickest, but it
works (also I haven't fine tuned the parameters for detection).

    
    
    import cv2
    import numpy as np
    import math
    
    filename = "/Users/me/Downloads/square.jpg"
    img = cv2.imread(filename)
    gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
    gray = np.float32(gray)
    dst = cv2.cornerHarris(gray,2,3,0.04)
    
    for y in range(0, gray.shape[0]):
     for x in range(0, gray.shape[1]):
      harris = cv2.cv.Get2D(cv2.cv.fromarray(dst), y, x) # get the x,y value
      # check the corner detector response
      if harris[0] > 0.01*dst.max():
       print x,y # these are the locations of the matches
       print 'Distance in pixels from origin: %d' % math.sqrt(x**2+y**2)
       # draw a small circle on the original image
       cv2.circle(img,(x,y),2,(155, 0, 25))
    
    cv2.imshow('Harris', img) # show the image
    cv2.waitKey()
    

