當前位置: 首頁>>代碼示例>>Python>>正文


Python Image.open方法代碼示例

本文整理匯總了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()
開發者ID:AndreaCensi,項目名稱:surf12adam,代碼行數:102,代碼來源:learner.py

示例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')
開發者ID:AndreaCensi,項目名稱:surf12adam,代碼行數:33,代碼來源:demo_processed.py


注:本文中的sensor_msgs.msg.Image.open方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。