当使用张量流模型(更快的rcnn)检测obj时,opencvdnn的结果看起来很奇怪

2024-03-28 18:52:12 发布

您现在位置:Python中文网/ 问答频道 /正文

复制步骤

1:通过tf_text_graph生成配置文件更快_rcnn.py公司在

python tf_text_graph_更快_rcnn.py公司--输入冻结推理_图形.pb--配置管道.config--输出速度更快_旧版.pbtxt在

冻结推理_图形.pb以及管道.config文件是解压后的吗

2:通过示例代码检测对象

import cv2 as cv

cvNet = cv.dnn.readNetFromTensorflow('tensorflow/faster_rcnn_inception_resnet_v2_atrous_oid.pb', 'tensorflow/faster_rcnn_inception_resnet_v2_atrous_oid.pbtxt')

img = cv.imread('traffic_jam.jpg')
rows = img.shape[0]
cols = img.shape[1]
cvNet.setInput(cv.dnn.blobFromImage(img, size=(300, 300), swapRB=True, crop=False))
cvOut = cvNet.forward()

for detection in cvOut[0,0,:,:]:
    score = float(detection[2])
    if score > 0.1:
        left = detection[3] * cols
        top = detection[4] * rows
        right = detection[5] * cols
        bottom = detection[6] * rows
        cv.rectangle(img, (int(left), int(top)), (int(right), int(bottom)), (23, 230, 210), thickness=2)

cv.imshow('img', img)
cv.waitKey()

结果

  1. 输入图像

enter image description here

  1. 结果

enter image description here

tensorflow算法在this page上的检测结果

enter image description here

虽然仍有很多车辆无法检测,但与opencv的api相比,检测结果有较大差异

编辑:结果检测到的ssd_mobilenet_v1_coco,效果好得多,我猜opencv dnn模块不能很好地与我发布的模型一起工作?在

enter image description here

编辑2:ssd检测代码

^{pr2}$

Tags: oftheimgtensorflowlinkopencvcvrows
1条回答
网友
1楼 · 发布于 2024-03-28 18:52:12
cvNet.setInput(cv.dnn.blobFromImage(img, size=(300, 300), swapRB=True, crop=False))

300x300的输入大小不正确,因为pipeline.config具有以下预处理指令:

^{pr2}$

这意味着你必须保持图像比例。尝试处理原始帧(它有800x600):

cvNet.setInput(cv.dnn.blobFromImage(img, swapRB=True))

包含置信阈值0.3pipeline.config修改的输出here

^{4}$

enter image description here

相关问题 更多 >