首页 > 解决方案 > 如何使用python在检测到的对象周围绘制一个框?

问题描述

我使用了一个包含几个卷积层的顺序模型来识别图像中的拇指和食指。
经过训练的模型可以很好地识别图片中是否有拇指或食指。现在,我想添加脚本以在我想在其上应用模型的新图像中识别的手指周围绘制一个框。
在识别步骤之后,我需要该框从图像中提取手指。有人可以帮我吗?

标签: pythonimage-processingobject-detectionbounding-boxconv-neural-network

解决方案


使用 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

参考示例示例:

极客极客样本如何使用

CV2 矩形文档


推荐阅读