def on_mouse(event, x, y, flags, param):

    if not src:
        return

    if event == cv.CV_EVENT_LBUTTONDOWN:
        cv.LogPolar(src, dst, (x, y), 40,
                    cv.CV_INTER_LINEAR + cv.CV_WARP_FILL_OUTLIERS)
        cv.LogPolar(
            dst, src2, (x, y), 40, cv.CV_INTER_LINEAR +
            cv.CV_WARP_FILL_OUTLIERS + cv.CV_WARP_INVERSE_MAP)
        cv.ShowImage("log-polar", dst)
        cv.ShowImage("inverse log-polar", src2)
Beispiel #2
0
def getPolar2CartImg(image, rad):
    imgSize = cv.GetSize(image)
    c = (float(imgSize[0] / 2.0), float(imgSize[1] / 2.0))
    imgRes = cv.CreateImage((rad * 3, int(360)), 8, 3)
    #cv.LogPolar(image,imgRes,c,50.0, cv.CV_INTER_LINEAR+cv.CV_WARP_FILL_OUTLIERS)
    cv.LogPolar(image, imgRes, c, 60.0,
                cv.CV_INTER_LINEAR + cv.CV_WARP_FILL_OUTLIERS)
    return (imgRes)
def logpolar(img, center=None, mag=1):
    des = N.empty_like(img)
    if center is None:
        center = N.divide(img.shape, 2)

    # cv.fromarray: array can be 2D or 3D only
    cimg = cv.fromarray(img)
    cdes = cv.fromarray(des)

    cv.LogPolar(cimg, cdes, tuple(center), mag)#, cv.CV_WARP_FILL_OUTLIERS)

    return N.array(cdes)
Beispiel #4
0
def log_polar_transform(img):
    center = (img.width / 2, img.height)
    maxradius = math.sqrt((img.width / 2)**2 + (img.height)**2)
    width = int(logscale * math.log(maxradius))

    logpolar = cv.CreateImage(
        (width, anglescale),
        cv.IPL_DEPTH_8U,
        3  # why is this need to be 3 here, but 1 in polar_processor.py?
    )

    cv.LogPolar(img, logpolar, center, logscale,
                cv.CV_INTER_LINEAR + cv.CV_WARP_FILL_OUTLIERS)

    aligned = cv.GetSubRect(logpolar,
                            (0, anglescale / 2, width, anglescale / 2))

    return aligned
Beispiel #5
0
  cam = cv.QueryFrame(capture)
  sleep(3)
  cv.ShowImage('cam', cam)

  ##GUI #Enable these lines to allow mouse interaction with the polar transform
  ##GUI cv.SetMouseCallback('cam', on_mouse)
  cv.SetMouseCallback('unwrapped', on_mouse)
  #on_mouse(cv.CV_EVENT_LBUTTONDOWN, centerX, centerY, None, None)
  
  # The magic number M determines how deep the polar transformation goes.
  M = 69

  #This is the main loop
  while True:
    cam = cv.QueryFrame(capture)
    cv.LogPolar(cam, polar, (centerX, centerY), M+1, cv.CV_INTER_NN) #possible speedup - get subrect src
    #unwrapped = cv.GetSubRect(polar,(280,0,40,360))
    #cv.Transpose(unwrapped, unwrapped)
    cv.Transpose(cv.GetSubRect(polar,(280,0,40,360)), unwrapped)
    cv.Flip(unwrapped) #just for viewing (possible speedup)

    cv.InRangeS(unwrapped, lower, upper, cones)
    cv.Erode(cones, cones) # just once might be too much, but unavoidable

    k = cv.CreateStructuringElementEx(3, 43, 1, 1, cv.CV_SHAPE_RECT) # create a 3x43 rectangular dilation element k
    cv.Dilate(cones, cones, k) 

    #Display (should probably be disabled with a usage flag)
    cv.ShowImage('cam', cam)
    cv.ShowImage('unwrapped', unwrapped)
    cv.ShowImage('cones', cones)