数据读取:
import json
import numpyas np
import matplotlib.pyplotas plt
import cv2
train_json = json.load(open(r'D:\data2\mchar_train.json'))
# 数据标注处理
def pl(n):
plt.ion()
plt.pause(n)
plt.close()
def parse_json(d):
arr = np.array([
d['top'], d['height'], d['left'], d['width'], d['label']
])
arr = arr.astype(int)
return arr
i=str(500).rjust(6,'0')
img = cv2.imread('D:\\data2\\mchar_train\\'+i+'.png')
arr = parse_json(train_json[i+'.png'])
print('json',arr)
plt.figure(figsize=(10,10))
plt.subplot(1, arr.shape[1]+1,1)
plt.imshow(img)
plt.xticks([]); plt.yticks([])
for idxin range(arr.shape[1]):
plt.subplot(1, arr.shape[1]+1, idx+2)
plt.imshow(img[arr[0, idx]:arr[0, idx]+arr[1, idx],arr[2, idx]:arr[2, idx]+arr[3, idx]])
plt.title(arr[4, idx])
plt.xticks([]); plt.yticks([])
pl(1)
数据和方法都比较清楚了.现在选择实现方法.需提取出json中的位置和识别数据.
每张图片json数据如下,分别对应top,height,left,width.label
json [[ 7 8]
[ 56 56]
[ 84 100]
[ 18 22]
[ 5 8]]
分别对应top,height,left,width,label。for循环把top,height,left,width.放到一组,作为位置数据集。label放一组。
label作为模型正确率验证组。使用检测再识别方法,使用位置数据集,检测SSD模型效果。