tf之object detect摄像头物体识别测试
来源:互联网 发布:linux中压缩文件命令 编辑:程序博客网 时间:2024/06/02 21:19
import numpy as npimport osimport six.moves.urllib as urllibimport sysimport tarfileimport tensorflow as tfimport zipfileimport cv2import time from collections import defaultdictfrom io import StringIOfrom matplotlib import pyplot as pltfrom PIL import Image# This is needed since the notebook is stored in the object_detection folder.sys.path.append("..")from utils import label_map_utilfrom utils import visualization_utils as vis_util# What model to download.MODEL_NAME = 'ssd_mobilenet_v1_coco_11_06_2017'#MODEL_NAME = 'faster_rcnn_resnet101_coco_11_06_2017'#MODEL_NAME = 'ssd_inception_v2_coco_11_06_2017'MODEL_FILE = MODEL_NAME + '.tar.gz'# Path to frozen detection graph. This is the actual model that is used for the object detection.PATH_TO_CKPT = MODEL_NAME + '/frozen_inference_graph.pb'# List of the strings that is used to add correct label for each box.PATH_TO_LABELS = os.path.join('/home/chenqy/tf36/models/object_detection/data', 'mscoco_label_map.pbtxt')#extract the ssd_mobilenetstart = time.clock()NUM_CLASSES = 90opener = urllib.request.URLopener()#opener.retrieve(DOWNLOAD_BASE + MODEL_FILE, MODEL_FILE)# tar_file = tarfile.open(MODEL_FILE)# for file in tar_file.getmembers():# file_name = os.path.basename(file.name)# if 'frozen_inference_graph.pb' in file_name:# tar_file.extract(file, os.getcwd())end= time.clock()print('load the model',(end-start))detection_graph = tf.Graph()with detection_graph.as_default(): od_graph_def = tf.GraphDef() with tf.gfile.GFile(PATH_TO_CKPT, 'rb') as fid: serialized_graph = fid.read() od_graph_def.ParseFromString(serialized_graph) tf.import_graph_def(od_graph_def, name='')label_map = label_map_util.load_labelmap(PATH_TO_LABELS)categories = label_map_util.convert_label_map_to_categories(label_map, max_num_classes=NUM_CLASSES, use_display_name=True)category_index = label_map_util.create_category_index(categories)cap = cv2.VideoCapture(0)with detection_graph.as_default(): with tf.Session(graph=detection_graph) as sess: writer = tf.summary.FileWriter("logs/", sess.graph) sess.run(tf.global_variables_initializer()) while(1): start = time.clock() ret, frame = cap.read() if cv2.waitKey(1) & 0xFF == ord('q'): break image_np=frame # the array based representation of the image will be used later in order to prepare the # result image with boxes and labels on it. # Expand dimensions since the model expects images to have shape: [1, None, None, 3] image_np_expanded = np.expand_dims(image_np, axis=0) image_tensor = detection_graph.get_tensor_by_name('image_tensor:0') # Each box represents a part of the image where a particular object was detected. boxes = detection_graph.get_tensor_by_name('detection_boxes:0') # Each score represent how level of confidence for each of the objects. # Score is shown on the result image, together with the class label. scores = detection_graph.get_tensor_by_name('detection_scores:0') classes = detection_graph.get_tensor_by_name('detection_classes:0') num_detections = detection_graph.get_tensor_by_name('num_detections:0') # Actual detection. (boxes, scores, classes, num_detections) = sess.run( [boxes, scores, classes, num_detections], feed_dict={image_tensor: image_np_expanded}) # Visualization of the results of a detection. vis_util.visualize_boxes_and_labels_on_image_array( image_np, np.squeeze(boxes), np.squeeze(classes).astype(np.int32), np.squeeze(scores), category_index, use_normalized_coordinates=True, line_thickness=6) end = time.clock() print('frame:',1.0/(end - start)) #print 'frame:',time.time() - start cv2.imshow("capture", image_np) cv2.waitKey(1)cap.release()cv2.destroyAllWindows()
测试比较卡,估计电脑以及虚拟机配置比较差,显示结果:
阅读全文
2 0
- tf之object detect摄像头物体识别测试
- tf之object detect安装测试
- object detect
- object detect
- TF实现物体识别、行人检测和图像
- Vuforia sdk 之物体识别
- DSAPI之摄像头追踪指定颜色物体
- 谷歌开源TensorFlow Object Detection API物体识别系统
- 利用Google Object Detection模块识别图片中的物体
- 使用tensorflow object detection API 进行物体识别
- DM8148 摄像头采集 显示 识别测试 一
- DM8148 摄像头采集 显示 识别测试 二
- DM8148 摄像头采集 显示 识别测试 三
- DM8148 摄像头采集 显示 识别测试 四
- 物体识别
- 物体识别
- 物体识别
- 谷歌新玩具Vision Kit,带你DIY一个能识别千种物体的AI摄像头
- SpringMvc之参数绑定注解详解
- 设计模式之对象行为型模式 — COMMAND (命令)模式
- maven学习笔记(四) 使用maven命令创建项目
- [SDUT](2143)图结构练习——最短路径 ---单源最短路径(图)
- LeetCode 633. Sum of Square Numbers
- tf之object detect摄像头物体识别测试
- echo 改变输出文本颜色
- js系列教程11-json、ajax(XMLHttpRequest)、comet、SSE、WebSocket全解
- qt例子不能运行,qt编译错误,qmake不能呢运行;error while building deploying解决
- opengl光照效果之点光源
- LeetCode
- 信号量 和 自旋锁
- 连点器
- 寻找第k大数的N种解法