本文整理汇总了Python中sensor_msgs.msg.Image.open方法的典型用法代码示例。如果您正苦于以下问题:Python Image.open方法的具体用法?Python Image.open怎么用?Python Image.open使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sensor_msgs.msg.Image
的用法示例。
在下文中一共展示了Image.open方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_diffeo
# 需要导入模块: from sensor_msgs.msg import Image [as 别名]
# 或者: from sensor_msgs.msg.Image import open [as 别名]
def test_diffeo(argv):
# Find diffeomorphisms file
try:
dfile = argv[argv.index('-dl')+1]
except ValueError:
dfile = '/media/data/learned_diffeo/camera_ptz.dynamics.pickle'
print 'Using diffeomorphism from file: ',dfile
# Find diffeomorphisms file
try:
outpath = argv[argv.index('-o')+1]
except ValueError:
outpath = '/media/data/tempimages/'
print 'Saving images to path: ',outpath
# Find output prefix file
try:
prefix = argv[argv.index('-p')+1]
except ValueError:
prefix = 'logitech_cam_ptz'
print 'Using prefix for output files: ',prefix
# Find Input image
try:
infile = argv[argv.index('-im')+1]
except ValueError:
infile = '/home/adam/git/surf12adam/diffeo_experiments/lighttower640.jpg'
print 'Using image file: ',infile
# Number of levels to apply
try:
levels = int(argv[argv.index('-l')+1])
except ValueError:
levels = 5
print 'Applying diffeomorphism ',levels,' times'
# Image size
try:
size = eval(argv[argv.index('-size')+1])
except ValueError:
size = [160,120]
print 'Image size: ',size
logfile = open(outpath+prefix+'log.html','w')
logfile.write('<html><body><h1>Diffeomorphism test log: '+dfile+'</h1>')
logfile.write('Diffeomorphism file: '+dfile+'<br/>')
logfile.write('Test image: <br/><img src="'+infile+'.png"/><br/><br/>')
logfile.write('<table>\n')
logfile.write('<tr align="center">\n <td>Command</td>\n')
logfile.write('<td>Diffeomorphism<br/>Angle</td>')
logfile.write('<td>Diffeomorphism<br/>Norm</td>')
logfile.write('<td>Diffeomorphism<br/>Variance</td>')
for i in range(levels+1):
logfile.write('<td>'+str(i)+'</td>')
logfile.write('</tr>')
im = np.array(Image.open(infile).resize(size).getdata(),np.uint8).reshape((size[1],size[0],3))
#Y0,Y1 = get_Y_pair((30,30),(0,0),(160,120),im)
# pdb.set_trace()
diffeo_list = pickle.load(open(dfile,'rb'))
for D in diffeo_list:
logfile.write('<tr>')
cmdstr = str(D.command).replace(' ','')
# outpath+prefix+'diffeo'+cmdstr+'angle'+'.png'
logfile.write('<td>')
logfile.write(str(D.command))
logfile.write('</td>')
Image.fromarray(diffeo_to_rgb_angle(D.d)).save(outpath+prefix+'diffeo'+cmdstr+'angle'+'.png')
logfile.write('<td>')
logfile.write('<img src="'+outpath+prefix+'diffeo'+cmdstr+'angle'+'.png'+'"/>')
logfile.write('</td>')
Image.fromarray(diffeo_to_rgb_norm(D.d)).save(outpath+prefix+'diffeo'+cmdstr+'norm'+'.png')
logfile.write('<td>')
logfile.write('<img src="'+outpath+prefix+'diffeo'+cmdstr+'norm'+'.png'+'"/>')
logfile.write('</td>')
Image.fromarray((D.variance*255).astype(np.uint8)).save(outpath+prefix+'diffeo'+cmdstr+'variance'+'.png')
logfile.write('<td>')
logfile.write('<img src="'+outpath+prefix+'diffeo'+cmdstr+'variance'+'.png'+'"/>')
logfile.write('</td>')
Y = im
Image.fromarray(Y).save(outpath+prefix+cmdstr+str(0)+'.png')
logfile.write('<td>')
logfile.write('<img src="'+outpath+prefix+cmdstr+str(0)+'.png'+'"/>')
logfile.write('</td>')
for i in range(levels):
Y, var = D.apply(Y)
Image.fromarray(Y).save(outpath+prefix+cmdstr+str(i+1)+'.png')
logfile.write('<td>')
logfile.write('<img src="'+outpath+prefix+cmdstr+str(i+1)+'.png'+'"/>')
logfile.write('</td>')
logfile.write('</tr>')
logfile.write('</table></body></html>')
logfile.flush()
logfile.close()
示例2: show
# 需要导入模块: from sensor_msgs.msg import Image [as 别名]
# 或者: from sensor_msgs.msg.Image import open [as 别名]
#command_list = [[200,0,0],[-200,0,0],[0,150,0],[0,-150,0],[0,0,5],[0,0,-5],[0,0,0]]
#command_list = [[0,0,5],[0,0,-5]]
# Keep track of the actual zoom for the last command and the current zoom
zoom_last = 1.0
zoom = 1.0
out_bag = rosbag.Bag(outfile, 'w')
# Load image to crop subimages from
if image_str == 'random':
M = np.random.randint(0,255,(748,1024,3)).astype(np.uint8)
im = Image.fromarray(M)
else:
im = Image.open(image_str+'.png')
cam_sim = logitech_cam_simulation(size,im,scale_factor)
#
Y0,Y1,cmd = cam_sim.simulate_Y_pair(size,[0,0,50])
print('simulated')
def show(Y0,Y1):
Image.fromarray(Y0).show()
Image.fromarray(Y1).show()
#pdb.set_trace()
for i in range(duration):
print(i)
command = command_list[np.random.randint(0,len(command_list))]
Y0,Y1,cmd = cam_sim.simulate_Y_pair(size,command)
# Image.fromarray(Y0).save('test'+str(i)+'y0cmd'+str(cmd)+'.png')
# Image.fromarray(Y1).save('test'+str(i)+'y1cmd'+str(cmd)+'.png')