给定Keras预测,如何在OpenCV中绘制边界框?

时间:2019-01-26 15:50:56

标签: python opencv keras resnet

我的代码是:

model = ResNet50(weights='imagenet')

ret_val, frame = video_capture.read()
frame = cv2.resize(frame,(224,224))
cv2.imshow(windowName, frame)
frame = np.expand_dims(frame, axis=0)
frame = preprocess_input(frame)

preds = model.predict(frame)
print('Predicted:', decode_predictions(preds, top=3)[0])

我得到的结果是:

Predicted: [('n04550184', 'wardrobe', 0.40715462), ('n04209239', 'shower_curtain', 0.09730709), ('n04005630', 'prison', 0.04603362)]

我没有x, y, w, h,所以我不知道在哪里绘制边界框。

有什么提示吗?

1 个答案:

答案 0 :(得分:2)

您不能使用ResNet。 ResNet具有一个FC层,用于处理位置信息。尝试改用YOLO。它具有非常高效的位置和对象分类功能。对此的另一种解决方案不是使用Keras,而是使用OpenCV的内置Haar小波变换级联。 This link拥有训练OpenCV Haar级联所需的全部知识。