json和plt画图

import json
import numpy as np
from collections import defaultdict
from os import listdir
from os.path import isfile, join
from scipy import misc
import matplotlib.pyplot as plt
from pylab import *



def draw_point(json_name, input_name, out_name):
    print json_name
    json_file=open(json_name)
    annos = json.load(json_file)
    figure()
    im = misc.imread(input_name)
    plt.imshow(im)



    curr = annos['shapes']
    # print curr[0]['points'][0]
    for item in curr:
        if item['label'][:5] == 'Empty':
            continue
        x = item['points'][0]
        plot(x[0], x[1], 'ro')

    # show()
    plt.savefig(out_name)

    # misc.imsave(out_name, im)
    # title('Plotting: "empire.jpg"')
    # show()


dirname = 'E:\picture\coco_part4\images'
imglist = [f for f in listdir(dirname) if isfile(join(dirname, f))]
for i in range (10):
    json_name = 'E:\picture\coco_part4\images\\annotations\\'+imglist[i][:-4] + '.json'
    input_name = 'E:\picture\coco_part4\images\\'+imglist[i]
    out_name = 'E:\picture\coco_part4\imagesss\\'+imglist[i]

    draw_point(json_name,input_name,out_name)



   # print '\nshow keys: '
# for annos_key in annos.keys():
#     print annos_key + ' len: ' + str(len(annos[str(annos_key)]))



        # for item_key, item_value in item.items():  # emp.values():  emp.items():
         # print item_key, '---',  item_value
        # break



    # print im.shape  # (512, 512, 3)



    # y[1] = im.shape[1] - y[1]
    # print 'x:',x ,'y:',y




# 
# plt.plot(x, 'r*')
# plt.figure(0)  

# plt.show()
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值