Example

This example will cover how to adapt the sample code from the API's github repo to apply object detection to streaming video from our webcam.

We're going to bring in the Python Open CV wrapper:

If you do not have OpenCV installed, you will need to grab it.

import numpy as np
import os
import six.moves.urllib as urllib
import sys
import tarfile
import tensorflow as tf
import zipfile

from collections import defaultdict
from io import StringIO
from matplotlib import pyplot as plt
from PIL import Image

Here i need to add the path especific to the object_detection folder of the git that we have download with git, this issually is not need it but i have some issue referring to it.

sys.path
sys.path.insert(0,'/Users/reyes/Desktop/git/models/research/object_detection')

import cv2
cap = cv2.VideoCapture(-0)

# This is needed since the notebook is stored in the object_detection folder.
sys.path.append("..")


# ## Object detection imports
# Here are the imports from the object detection module.

# In[3]:

from utils import label_map_util
#from object_detecion.utils import label_map_util
#from protos import string_int_label_map_pb2
from utils import visualization_utils as vis_util


# # Model preparation 

# In[4]:

# What model to download.
MODEL_NAME = 'ssd_mobilenet_v1_coco_11_06_2017'
MODEL_FILE = MODEL_NAME + '.tar.gz'
DOWNLOAD_BASE = 'http://download.tensorflow.org/models/object_detection/'

# 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'

Also at this part we i need to specify with label we are going to use , another time i need to specify the path to this file for some error of referring.

You should have a streaming webcam feed that is also being labeled. Some objects that you can test with: Yourself, a cellphone, or a bottle of water. All of those should work.

Last updated

Was this helpful?