本文整理汇总了Python中matplotlib.pyplot.ginput函数的典型用法代码示例。如果您正苦于以下问题:Python ginput函数的具体用法?Python ginput怎么用?Python ginput使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ginput函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: findall2
def findall2(all_trees,all_files):
#show 10 candidates
k=10
for files in all_files:
for f in files:
temp={'ds':[],'ids':[],'files':[]}
fsg=getHash3(f)
for tree in all_trees:
ds,ids=tree.query(fsg,k)
temp['ds'].append(ds)
temp['ids'].append(ids)
temp['files'].append(files)
id_sort=np.argsort(temp['ds'])
sort_d=temp['ds'][id_sort[0:k]]
sort_ids=temp['ids'][id_sort[0:k]]
sort_files=temp['files'][id_sort[0:k]]
plt.figure(1)
for i in xrange(k):
print "%03d dis: %.3f %s"%(sort_ids[i],sort_d[i],sort_files[i])
plt.subplot(2,5,i+1)
plt.title("%03d dis: %.3f"%(sort_ids[i],sort_d[i]),fontsize=10)
im_icon=np.array(Image.open(sort_files[i]).convert('L'))
plt.imshow(im_icon)
plt.axis('off')
plt.set_cmap('gray')
plt.show()
plt.ginput(1)
示例2: main
def main(base_dir):
BASE_DIR = base_dir
# Load the set of pictures
ic = io.ImageCollection(BASE_DIR + '*.JPG')
# Select points on the first picture
f, ax = plt.subplots(1,1)
ax.get_xaxis().set_visible(False)
ax.get_yaxis().set_visible(False)
ax.autoscale(enable=True, axis='both', tight=True);
plt.tight_layout(pad=0.4, w_pad=0.0, h_pad=0.0)
ax.imshow(ic[0])
coords = [plt.ginput(8, timeout=0)]
plt.close()
# Load first picture side-by side with second, select points.
# Scroll through images one-by-one
for i, img in enumerate(ic[1:]):
ax1 = plt.subplot2grid((6,10),(0,1), rowspan=6, colspan=9)
ax0 = plt.subplot2grid((6,10),(0,0))
for ax in [ax0, ax1]:
ax.get_xaxis().set_visible(False)
ax.get_yaxis().set_visible(False)
plt.tight_layout(pad=0.4, w_pad=0.0, h_pad=0.0)
#f, (ax0,ax1) = plt.subplots(1,2)
ax0.imshow(ic[i])
for coord in coords[i]:
ax0.scatter(coord[0],coord[1])
ax1.imshow(img)
coords.append(plt.ginput(8, timeout=0))
plt.close()
# Use a similarity transformation to transform each one.
if not os.path.exists(BASE_DIR + 'corrected'):
os.mkdir(BASE_DIR + 'corrected')
np.save(BASE_DIR + 'corrected/coords.npy', coords)
io.imsave(BASE_DIR + 'corrected/0.jpg', ic[0])
for i, img in enumerate(ic[1:]):
tf = transform.estimate_transform('similarity', np.array(coords[0]), np.array(coords[i+1]))
# Use a translation transformation to center both images for display purposes
img_warped = transform.warp(img, inverse_map=tf,
output_shape=(1728,3072))
print BASE_DIR + 'corrected/%d.jpg' %(i+1)
print img_warped
io.imsave(BASE_DIR + 'corrected/%d.jpg' %(i+1), img_warped)
示例3: manual_sync_pick
def manual_sync_pick(flow, gyro_ts, gyro_data):
# First pick good points in flow
plt.clf()
plt.plot(flow)
plt.title('Select two points')
selected_frames = [int(round(x[0])) for x in plt.ginput(2)]
# Now pick good points in gyro
plt.clf()
plt.subplot(211)
plt.plot(flow)
plt.plot(selected_frames, flow[selected_frames], 'ro')
plt.subplot(212)
plt.plot(gyro_ts, gyro_data.T)
plt.title('Select corresponding sequence in gyro data')
plt.draw()
selected = plt.ginput(2) #[int(round(x[0])) for x in plt.ginput(2)]
gyro_idxs = [(gyro_ts >= x[0]).nonzero()[0][0] for x in selected]
plt.plot(gyro_ts[gyro_idxs], gyro_data[:, gyro_idxs].T, 'ro')
plt.title('Ok, click to continue to next')
plt.draw()
plt.waitforbuttonpress(timeout=10.0)
plt.close()
return (tuple(selected_frames), gyro_idxs)
示例4: selectStartGoalPoints
def selectStartGoalPoints(ax, img):
print 'Select a starting point'
ax.set_xlabel('Select a starting point')
occupied = True
while(occupied):
point = ppl.ginput(1, timeout=-1, show_clicks=False, mouse_pop=2)
start = [ round(point[0][0]), round(point[0][1]) ]
if(img[int(start[1])][int(start[0])][0] == 255):
occupied = False
ax.plot(start[0], start[1], '.r')
else:
print 'Cannot place a starting point there'
ax.set_xlabel('Cannot place a starting point there, choose another point')
print 'Select a goal point'
ax.set_xlabel('Select a goal point')
occupied = True
while(occupied):
point = ppl.ginput(1, timeout=-1, show_clicks=False, mouse_pop=2)
goal = [ round(point[0][0]), round(point[0][1]) ]
if(img[int(goal[1])][int(goal[0])][0] == 255):
occupied = False
ax.plot(goal[0], goal[1], '.b')
else:
print 'Cannot place a goal point there'
ax.set_xlabel('Cannot place a goal point there, choose another point')
ppl.draw()
return start, goal
示例5: trainZone
def trainZone(self,event):
if str(event.keysym) == 'space':
flag, frame = self.cap.read()
if flag == True:
#~ grayFrame = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
plt.imshow(frame)
#~ self.mask = np.zeros(frame.shape[:2],dtype = 'uint8')
pnt1 = np.int32(plt.ginput(n=0, timeout=-1, show_clicks=True))
self.pnt1 = pnt1.reshape((-1,1,2))
xMax = max(self.pnt1[:,:,0])[0]
yMax = max(self.pnt1[:,:,1])[0]
xMin = min(self.pnt1[:,:,0])[0]
yMin = min(self.pnt1[:,:,1])[0]
cv2.polylines(frame,[self.pnt1],True,(0,255,255),thickness=3)
plt.imshow(frame)
pnt2 = np.int32(plt.ginput(n=0, timeout=-1, show_clicks=True))
self.pnt2 = pnt2.reshape((-1,1,2))
xMax = max(self.pnt2[:,:,0])[0]
yMax = max(self.pnt2[:,:,1])[0]
xMin = min(self.pnt2[:,:,0])[0]
yMin = min(self.pnt2[:,:,1])[0]
cv2.polylines(frame,[self.pnt2],True,(0,255,255),thickness=3)
plt.imshow(frame)
示例6: show
def show(self):
import matplotlib.pyplot as plt
print("number of images: {}".format(len(self.I)))
for i in xrange(len(self.jsonfiles)):
f=open(self.jsonfiles[i],"r")
js=json.loads(f.read())
f.close()
##init and show
img_path=''
if js['path'][0:2]=='./':
img_path= rootdir + js['path'][1:]
elif js['path'][0]=='/':
img_path= rootdir + js['path']
else:
img_path= rootdir + '/' +js['path']
print(img_path)
im=np.array(Image.open(img_path).convert('L'))
plt.hold(False)
plt.imshow(im)
plt.hold(True)
for j in range(self.size):
#samples[x]=[0_class,1_img, 2_row, 3_column]^T
if self.samples[1,j]==i:
plt.text(self.samples[3,j], self.samples[2,j], "%03d"%self.samples[0,j], fontsize=12,color='red')
#plt.plot(self.samples[3,j],self.samples[2,j],markers[self.samples[0,j]])
plt.set_cmap('gray')
plt.show()
plt.ginput(1)
plt.close('all')
示例7: solver
def solver(N):
for i in range(N):
for j in range(N):
vic, tab = maneja_reinas(reinas, 'Agregar reina', i, j)
img_reinas.set_data(tab)
plt.draw()
plt.ginput()
if vic:
fig.text(
0.5, 0.5, 'Felicitaciones!', color='orange', size='xx-large',
family='humor sans', ha='center', va='center', alpha=0.5,
bbox=dict(facecolor='ivory', edgecolor='orange', boxstyle='round')
)
plt.draw()
plt.ginput()
if tab[i][j]==4:
if i in range(N) and j in range(N):
vic, tab = maneja_reinas(reinas, 'Agregar reina', i, j)
j=j+1
print ("{}{}".format(i,j))
示例8: get_point
def get_point(im1, im2):
plt.imshow(im1)
im1_pt = plt.ginput()[0]
plt.close()
plt.imshow(im2)
im2_pt = plt.ginput()[0]
plt.close()
return im1_pt,im2_pt
示例9: get_points
def get_points(im1, im2):
print('Please select 2 points in each image for alignment.')
plt.imshow(im1)
p1, p2 = plt.ginput(2)
plt.close()
plt.imshow(im2)
p3, p4 = plt.ginput(2)
plt.close()
return (p1, p2, p3, p4)
示例10: tps_rpm
def tps_rpm(x_nd, y_md, n_iter = 5, reg_init = .1, reg_final = .001, rad_init = .2, rad_final = .001, plotting = False, verbose=True, f_init = None):
n,d = x_nd.shape
regs = loglinspace(reg_init, reg_final, n_iter)
rads = loglinspace(rad_init, rad_final, n_iter)
f = ThinPlateSpline.identity(d)
for i in xrange(n_iter):
if f.d==2 and i%plotting==0:
import matplotlib.pyplot as plt
plt.clf()
if i==0 and f_init is not None:
xwarped_nd = f_init(x_nd)
print xwarped_nd.max(axis=0)
else:
xwarped_nd = f.transform_points(x_nd)
# targ_nd = find_targets(x_nd, y_md, corr_opts = dict(r = rads[i], p = .1))
corr_nm = calc_correspondence_matrix(xwarped_nd, y_md, r=rads[i], p=.2)
wt_n = corr_nm.sum(axis=1)
targ_nd = np.dot(corr_nm/wt_n[:,None], y_md)
# if plotting:
# plot_correspondence(x_nd, targ_nd)
f.fit(x_nd, targ_nd, regs[i], wt_n = wt_n, angular_spring = regs[i]*200, verbose=verbose)
if plotting and i%plotting==0:
if f.d==2:
plt.plot(x_nd[:,1], x_nd[:,0],'r.')
plt.plot(y_md[:,1], y_md[:,0], 'b.')
pred = f.transform_points(x_nd)
if f.d==2:
plt.plot(pred[:,1], pred[:,0], 'g.')
if f.d == 2:
plot_warped_grid_2d(f.transform_points, x_nd.min(axis=0), x_nd.max(axis=0))
plt.ginput()
elif f.d == 3:
from lfd import warping
from brett2.ros_utils import Marker
from utils import conversions
Globals.setup()
mins = x_nd.min(axis=0)
maxes = x_nd.max(axis=0)
mins[2] -= .1
maxes[2] += .1
Globals.handles = warping.draw_grid(Globals.rviz, f.transform_points, mins, maxes, 'base_footprint', xres=.1, yres=.1)
orig_pose_array = conversions.array_to_pose_array(x_nd, "base_footprint")
target_pose_array = conversions.array_to_pose_array(y_md, "base_footprint")
warped_pose_array = conversions.array_to_pose_array(f.transform_points(x_nd), 'base_footprint')
Globals.handles.append(Globals.rviz.draw_curve(orig_pose_array,rgba=(1,0,0,1),type=Marker.CUBE_LIST))
Globals.handles.append(Globals.rviz.draw_curve(target_pose_array,rgba=(0,0,1,1),type=Marker.CUBE_LIST))
Globals.handles.append(Globals.rviz.draw_curve(warped_pose_array,rgba=(0,1,0,1),type=Marker.CUBE_LIST))
f.corr = corr_nm
return f
示例11: checkSignals
def checkSignals(self):
from matplotlib.pyplot import plot, figure, close, ginput
for i in range(0, len(self.Signals)):
print('Signal ' + str(i))
s = self.Signals[i]
if not self.isGoodSignal(s, self.SamplingPeriod):
figure()
plot(s)
ginput(timeout=0)
close("all")
示例12: plot_cost
def plot_cost(grid):
import matplotlib.pyplot as plt
import scipy.stats as ss
plt.clf()
#plot_arr = ss.rankdata(grid.array).reshape(grid.array.shape)
plot_arr = grid.array
print grid.array.max(), grid.array.min()
plt.imshow(plot_arr, extent = [grid.xticks[0], grid.xticks[-1], grid.yticks[0], grid.yticks[-1]])
plt.title("cost")
print "click on the plot to continue"
plt.ginput()
示例13: _ginput
def _ginput(*args, **kwargs):
"""
Hides the stupid default warnings when using ginput. There has to be
a better way...
"""
if MatplotlibDeprecationWarning is None:
return plt.ginput(*args, **kwargs)
else:
warnings.simplefilter('ignore', MatplotlibDeprecationWarning)
out = plt.ginput(*args, **kwargs)
warnings.warn('default', MatplotlibDeprecationWarning)
return out
示例14: get_all_linepoints_user_input
def get_all_linepoints_user_input(ImgName, DirToSave, NumPointVecs=45):
# user input to select lines for enhanced measurement detection
Img = cv2.imread(ImgName, 0)
if not os.path.isfile(ImgName):
raise Exception("Accumulated image not defined or not on right path", "raised in get_all_linepoints_user_input")
cOrigImg = cv2.cvtColor(Img, cv2.COLOR_GRAY2BGR)
if not os.path.isfile(DirToSave + "/LinePoints.p"):
print "pick lines"
plt.ion()
Lines = []
for i in range(0, NumPointVecs / 3):
while True:
cImg = cOrigImg.copy()
TryAgain = []
plt.title("Please click 3 lines")
plt.imshow(cImg)
RawLineUV = plt.ginput(6)
LineUV = [RawLineUV[i:i + 2] for i in range(0, len(RawLineUV), 2)]
if len(LineUV) == 3:
# convert ot int
for CurLineUV in LineUV:
LineUVShow = [(int(x[0]), int(x[1])) for x in CurLineUV]
cv2.line(cImg, LineUVShow[0], LineUVShow[1], (255, 0, 0), 2)
plt.title("click on lower half of image to accept, on upper to neglect")
plt.imshow(cImg)
# click on image to do anew
UV = plt.ginput(1)
if not not UV and UV[0][1] > Img.shape[0] / 2:
break
Lines.extend(LineUV)
cv2.line(cOrigImg, LineUVShow[0], LineUVShow[1], (255, 0, 0), 2)
pickle.dump(Lines, open(DirToSave + "/LinePoints.p", "wb"))
print "saved lines as " + DirToSave + "/LinePoints.p"
else:
print "!!!!!!!!!!!!!! loading lines !!!!!!!!!!!!!!!!!"
Lines = pickle.load(open(DirToSave + "/LinePoints.p", "rb"))
cImg = cOrigImg.copy()
for Line in Lines:
CurLine = [(int(x[0]), int(x[1])) for x in Line]
cv2.line(cOrigImg, CurLine[0], CurLine[1], (255, 0, 0), 2)
plt.imshow(cOrigImg)
plt.ioff()
print "please close the window"
plt.show()
# sort left and right
return sorted(Lines, key=lambda x: x[0][0]), cImg
示例15: pickloc
def pickloc(ax=None, zoom=10):
"""
:INPUTS:
ax : (axes instance) -- axes in which to pick a location
zoom : int -- zoom radius for target confirmation
: 2-tuple -- (x,y) radii for zoom confirmation.
"""
# 2011-04-29 19:26 IJC:
# 2011-09-03 20:59 IJMC: Zoom can now be a tuple; x,y not cast as int.
pickedloc = False
if ax is None:
ax = plt.gca()
axlimits = ax.axis()
if hasattr(zoom, '__iter__') and len(zoom)>1:
xzoom, yzoom = zoom
else:
xzoom = zoom
yzoom = zoom
while not pickedloc:
ax.set_title("click to select location")
ax.axis(axlimits)
x = None
while x is None:
selectevent = plt.ginput(n=1,show_clicks=False)
if len(selectevent)>0: # Prevent user from cancelling out.
x,y = selectevent[0]
#x = x.astype(int)
#y = y.astype(int)
if zoom is not None:
ax.axis([x-xzoom,x+xzoom,y-yzoom,y+yzoom])
ax.set_title("you selected xy=(%i,%i)\nclick again to confirm, or press Enter/Return to try again" %(x,y) )
plt.draw()
confirmevent = plt.ginput(n=1,show_clicks=False)
if len(confirmevent)>0:
pickedloc = True
loc = confirmevent[0]
return loc