AI(十六):

在命令行dnn文件夹路径下,python 那个文件,然后–input pb文件的路径,–output 输出路径/graph.pbtxt --config pipelin.config文件路径

python tf_text_graph_ssd.py --input C:/Machine_learning/models-master/research/object_detection/zjl_detection/frozen_inference_graph.pb --output C:/Machine_learning/models-master/research/object_detection/zjl_detection/graph.pbtxt --config C:/Machine_learning/models-master/research/object_detection/zjl_detection/pipeline.config

opencv文件地址
在这里插入图片描述

import cv2 as cv
import time

inference_pb = "C:/Machine_learning/models-master/research/object_detection/zjl_detection/frozen_inference_graph.pb"
graph_txt = "C:/Machine_learning/models-master/research/object_detection/zjl_detection/z.pbtxt"
net = cv.dnn.readNetFromTensorflow(inference_pb, graph_txt)#用cv的dnn模块调取tensorflow训练模型
layNames = net.getLayerNames()#调取所有标签文件的名字
id = net.getLayerId(layNames[-1])#通过调取.getLayerId函数调取倒数第一个标签的名字的id
last_layer = net.getLayer(id)
#print(id)
#print(layNames)
#print(last_layer.type)
cap = cv.VideoCapture('C:/Machine_learning/models-master/research/object_detection/video1.mp4')
#捕获视频文件
while True:
    ret,frame = cap.read()
    start=time.time()
    cv.line(frame, (0, 960), (1900, 960), (0, 0, 255), 2)
    h, w = frame.shape[:2]
    im_tensor = cv.dnn.blobFromImage(frame, size=(300, 300), swapRB=True, crop=False)
    net.setInput(im_tensor)
    cvOut = net.forward()
    #print(cvOut.shape)
    
    point_list = []

    for detect in cvOut[0, 0, :, :]:
        score = detect[2]

        if score > 0.3:
            left = detect[3] * w
            top = detect[4] * h
            right = detect[5] * w
            bottom = detect[6] * h
            cv.rectangle(frame, (int(left), int(top)), (int(right), int(bottom)), (0, 255, 255), 2)
            point = (int((detect[3] * w + detect[5] * w) / 2), int((detect[4] * h + detect[6] * h) / 2))

            cv.circle(frame, point, 1, (0, 255, 0), 4)


            if point[1] <= 960:
                point_list.append(point[1])
                #print(point_list)


    #print(len(point_list))
    font = cv.FONT_HERSHEY_SIMPLEX
    cv.putText(frame, 'All_people: %d' % len(point_list), (10, 100), font, 1, (0, 0, 255),2)
    end = time.time()
    seconds = end-start
    fps=1/seconds
    cv.putText(frame, 'fps: %s' % fps, (10, 200), font, 1, (0, 0, 255), 2, cv.LINE_AA)
    cv.imshow("image", frame)
    cv.waitKey(1)
cv.destroyAllWindows()

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值