当前位置: 首页>>代码示例>>Python>>正文


Python Image.fromarray方法代码示例

本文整理汇总了Python中sensor_msgs.msg.Image.fromarray方法的典型用法代码示例。如果您正苦于以下问题:Python Image.fromarray方法的具体用法?Python Image.fromarray怎么用?Python Image.fromarray使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在sensor_msgs.msg.Image的用法示例。


在下文中一共展示了Image.fromarray方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: show_diffeomorphisms

# 需要导入模块: from sensor_msgs.msg import Image [as 别名]
# 或者: from sensor_msgs.msg.Image import fromarray [as 别名]
 def show_diffeomorphisms(self):
     for i in range(len(self.estimators)): #estr in self.estimators:
         D = self.estimators[i].summarize()
         cmd = self.command_list[i]
         save_path = '/home/adam/'
         #Image.fromarray(diffeo_to_rgb_angle(D.d)).show()
         Image.fromarray(diffeo_to_rgb_angle(D.d)).save(save_path+'cmd'+str(cmd).replace(' ','')+'angle.png')
         Image.fromarray(diffeo_to_rgb_norm(D.d)).save(save_path+'cmd'+str(cmd).replace(' ','')+'nomr.png')
         Image.fromarray((D.variance*255).astype(np.uint8)).save(save_path+'cmd'+str(cmd).replace(' ','')+'variance.png')
开发者ID:AndreaCensi,项目名称:surf12adam,代码行数:11,代码来源:learner.py

示例2: test_diffeo

# 需要导入模块: from sensor_msgs.msg import Image [as 别名]
# 或者: from sensor_msgs.msg.Image import fromarray [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()
开发者ID:AndreaCensi,项目名称:surf12adam,代码行数:102,代码来源:learner.py

示例3: show

# 需要导入模块: from sensor_msgs.msg import Image [as 别名]
# 或者: from sensor_msgs.msg.Image import fromarray [as 别名]
def show(Y0,Y1):
    Image.fromarray(Y0).show()
    Image.fromarray(Y1).show()
开发者ID:AndreaCensi,项目名称:surf12adam,代码行数:5,代码来源:demo_processed.py

示例4: logitech_cam_simulation

# 需要导入模块: from sensor_msgs.msg import Image [as 别名]
# 或者: from sensor_msgs.msg.Image import fromarray [as 别名]
scale_factor = [1.0/50,2.0/50,1.0/50]
#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)
开发者ID:AndreaCensi,项目名称:surf12adam,代码行数:32,代码来源:demo_processed.py


注:本文中的sensor_msgs.msg.Image.fromarray方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。