visual genome 数据集使用


import matplotlib.pyplot as plt
from matplotlib.patches import Rectangle
from src import api as vg
from PIL import Image as PIL_Image
import requests
from StringIO import StringIO


ids = vg.GetImageIdsInRange(startIndex=0, endIndex=1)
image_id = ids[0]
print "We got an image with id: %d" % image_id


image = vg.GetImageData(id=image_id)
print "The url of the image is: %s" % image.ur



regions = vg.GetRegionDescriptionsOfImage(id=image_id)
print "The first region descriptions is: %s" % regions[0].phrase
print "It is located in a bounding box specified by x:%d, y:%d, width:%d, height:%d" % (regions[0].x, regions[0].y, regions[0].width, regions[0].height)



fig = plt.gcf()
fig.set_size_inches(18.5, 10.5)
def visualize_regions(image, regions):
    response = requests.get(image.url)
    img = PIL_Image.open(StringIO(response.content))
    plt.imshow(img)
    ax = plt.gca()
    for region in regions:
        ax.add_patch(Rectangle((region.x, region.y),
                               region.width,
                               region.height,
                               fill=False,
                               edgecolor='red',
                               linewidth=3))
        ax.text(region.x, region.y, region.phrase, style='italic', bbox={'facecolor':'white', 'alpha':0.7, 'pad':10})
    fig = plt.gcf()
    plt.tick_params(labelbottom='off', labelleft='off')
    plt.show()
visualize_regions(image, regions[:8])




参考:

https://github.com/ranjaykrishna/visual_genome_python_driver/blob/master/region_visualization_demo.ipynb


http://www.open-open.com/lib/view/open1393488232380.html



import matplotlib.pyplot as plt
from matplotlib.patches import Rectangle
from src import api as vg
from PIL import Image as PIL_Image
import requests
from StringIO import StringIO

>>> ids = vg.GetImageIdsInRange(startIndex=0, endIndex=3)
>>> image_id = ids[2]
>>> image = vg.GetImageData(id=image_id)
>>> regions = vg.GetRegionDescriptionsOfImage(id=image_id)
>>> visualize_regions(image, regions[:8])


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值