【问题标题】:How to draw a box around the detected objects using python?如何使用python在检测到的对象周围绘制一个框?
【发布时间】:2020-10-30 23:38:10
【问题描述】:
我使用了一个包含多个卷积层的顺序模型来识别图像中的拇指和食指。
经过训练的模型可以很好地识别图片中是否有拇指或食指。现在,我想添加脚本以在新图像中识别的手指周围绘制一个框,我想在其上应用模型。
在识别步骤之后,我需要该框从图像中提取手指。有人可以帮帮我吗?
【问题讨论】:
标签:
python
image-processing
object-detection
bounding-box
conv-neural-network
【解决方案1】:
使用cv2矩形函数,
(locations, preditions) = detect_and_predict_class(test_image, model) # make predictions from your model
for (box, pred) in zip(locationss, predictions):
(startX, startY, endX, endY) = box # box coordinates returned from your model's predictions
cv2.rectangle(input_image, (startX, startY), (endX, endY), color, 2) # color is the color of the bounding box you would like & 2 is the thickness of the bounding box
参考示例:
Geeks for geeks sample on how to use
CV2 rectangle documentation