使用OpenCVDNN模块直接读取模型

之前写过一篇直接读取模型输出检测结果的文章

https://blog.csdn.net/qq_36501182/article/details/87919038

后来发现OpenCV 3.4.1之后的版本中contrib扩展库中的dnn模块支持TensorFlow、Caffe、Pytorch三种深度学习框架的模型,能够修改或者读取网络结构,并且也能够读取已经训练好的模型。

实例如下:

import cv2 as cv

#cvNet = cv.dnn.readNetFromTensorflow('frozen_inference_graph.pb', 'graph.pbtxt')
cvNet = cv.dnn.readNetFromTensorflow('frozen_inference_graph.pb')

img = cv.imread('example.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])

    print("looping here score ", score)
    if score > 0.5:
        print("get stuff looping here ")
        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()

具体参考官网说明:https://github.com/opencv/opencv/wiki/TensorFlow-Object-Detection-API

  • 4
    点赞
  • 26
    收藏
    觉得还不错? 一键收藏
  • 4
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值