Example #1
0
def select_roi():
    #from matplotlib.backend_bases import mplDeprecation
    print('[*guitools] Define a Rectanglular ROI by clicking two points.')
    try:
        sys.stdout.flush()
        fig = df2.gcf()
        # Disconnect any other button_press events
        oldcbid, oldcbfn = df2.disconnect_callback(fig, 'button_press_event')
        #with warnings.catch_warnings():
            #warnings.filterwarnings("ignore", category=mplDeprecation)
        pts = fig.ginput(2)
        print('[*guitools] ginput(2) = %r' % (pts,))
        [(x1, y1), (x2, y2)] = pts
        xm = min(x1, x2)
        xM = max(x1, x2)
        ym = min(y1, y2)
        yM = max(y1, y2)
        xywh = map(int, map(round, (xm, ym, xM - xm, yM - ym)))
        roi = np.array(xywh, dtype=np.int32)
        # Reconnect the old button press events
        df2.connect_callback(fig, 'button_press_event', oldcbfn)
        print('[*guitools] roi = %r ' % (roi,))
        return roi
    except Exception as ex:
        print('[*guitools] ROI selection Failed:\n%r' % (ex,))
        return None
Example #2
0
def select_orientation():
    #from matplotlib.backend_bases import mplDeprecation
    print('[*guitools] Define an orientation angle by clicking two points')
    try:
        # Compute an angle from user interaction
        sys.stdout.flush()
        fig = df2.gcf()
        oldcbid, oldcbfn = df2.disconnect_callback(fig, 'button_press_event')
        #with warnings.catch_warnings():
            #warnings.filterwarnings("ignore", category=mplDeprecation)
        pts = np.array(fig.ginput(2))
        #print('[*guitools] ginput(2) = %r' % pts)
        # Get reference point to origin
        refpt = pts[1] - pts[0]
        #theta = np.math.atan2(refpt[1], refpt[0])
        theta = np.math.atan2(refpt[1], refpt[0])
        print('The angle in radians is: %r' % theta)
        df2.connect_callback(fig, 'button_press_event', oldcbfn)
        return theta
    except Exception as ex:
        print('Annotate Orientation Failed %r' % ex)
        return None