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()
json和plt画图
最新推荐文章于 2024-10-11 13:05:51 发布