ubuntu16.04下运用TensorFlow object Detection API和摄像头实现物体实时检测

目标:摄像头捕获视频流,对视频流中的物体进行实时检测

具体实现步骤如下:

1、安装opencv

我是在tensorflow的安装环境下,直接利用anaconda安装opencv

ubuntu16.04下运用TensorFlow object Detection API和摄像头实现物体实时检测

 2、测试代码

基于object_detection文件夹下的object_detection_tutorial.ipynb文件程序进行修改(注:按照如下步骤一步一步修改,源程序多余部分都删除):

2.1 此处添加导入cv2包,调用摄像头设备程序

import cv2

cap = cv2.VideoCapture(0)

ubuntu16.04下运用TensorFlow object Detection API和摄像头实现物体实时检测

2.2 此处不变,从utils模块引入label_map_util和visualization_utils

ubuntu16.04下运用TensorFlow object Detection API和摄像头实现物体实时检测

2.3 此处获取模型和标签路径(此处选用了object_detection文件夹下现成的一个模型和标签,当然你还可以运用其他模型)

ubuntu16.04下运用TensorFlow object Detection API和摄像头实现物体实时检测

2.4 此处加载模型

ubuntu16.04下运用TensorFlow object Detection API和摄像头实现物体实时检测

2.5 此处加载label map

ubuntu16.04下运用TensorFlow object Detection API和摄像头实现物体实时检测

2.6 此处为主要运行代码

ubuntu16.04下运用TensorFlow object Detection API和摄像头实现物体实时检测

3、 测试

拿了只女朋友抓的熊测试了一下,运行结果 如下:

 ubuntu16.04下运用TensorFlow object Detection API和摄像头实现物体实时检测