2018年4月9日星期一

darkflow同时输出图片和json文件

命令行:

python flow --imgdir sample_img_test/ --model cfg/yolo-voc-6c.cfg --load -1 --json
如果要在sample_img_test/out文件夹同时输出图片和json文件,只需将darkflow/darkflow/net/yolov2/predict.py中红色语句删除即可。

def postprocess(self, net_out, im, save = True):
"""
Takes net output, draw net_out, save to disk
"""
boxes = self.findboxes(net_out)

# meta
meta = self.meta
threshold = meta['thresh']
colors = meta['colors']
labels = meta['labels']
if type(im) is not np.ndarray:
imgcv = cv2.imread(im)
else: imgcv = im
h, w, _ = imgcv.shape

resultsForJSON = []
for b in boxes:
boxResults = self.process_box(b, h, w, threshold)
if boxResults is None:
continue
left, right, top, bot, mess, max_indx, confidence = boxResults
thick = int((h + w) // 300)
if self.FLAGS.json:
resultsForJSON.append({"label": mess, "confidence": float('%.2f' % confidence), "topleft": {"x": left, "y": top}, "bottomright": {"x": right, "y": bot}})
#continue

cv2.rectangle(imgcv,
(left, top), (right, bot),
colors[max_indx], thick)
cv2.putText(imgcv, mess, (left, top - 12),
0, 1e-3 * h, colors[max_indx],thick//3)

if not save: return imgcv

outfolder = os.path.join(self.FLAGS.imgdir, 'out')
img_name = os.path.join(outfolder, os.path.basename(im))
cv2.imwrite(img_name, imgcv)#####   
if self.FLAGS.json:
textJSON = json.dumps(resultsForJSON)
textFile = os.path.splitext(img_name)[0] + ".json"
with open(textFile, 'w') as f:
f.write(textJSON)
return

没有评论:

发表评论

Failed to find TIFF library

ImportError: Failed to find TIFF library. Make sure that libtiff is installed and its location is listed in PATH|LD_LIBRARY_PATH|.. 解决方法: ...