• Stars
    star
    179
  • Rank 214,039 (Top 5 %)
  • Language
    Python
  • License
    MIT License
  • Created almost 7 years ago
  • Updated almost 7 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Tensorflow Object Detection API Web Service wrapper that works on any <video> tag and WebRTC streams

Tensorflow Object Detection API Web Service

This is an example of how to turn the TensorFlow Object API into a web service. A Python Flask web server is used to interact with a JavaScript a client library. The example shows how you can extract frames from WebRTC's getUserMedia, upload them to the API, and then use the canvas to display them. This allows use of the TensorFlow Object API on any HTML <video> element.

Please see the Computer Vision on the Web with WebRTC and TensorFlow post on webrtcHacks for a walkthrough and more details.

Example image: Detecting Cats

TensorFlow Object Detection API on a WebRTC getUserMedia stream demo video:

TensorFlow Object Detection API on a video element

TensorFlow Object Detection API on a video element demo video:

TensorFlow Object Detection API on a video element

Quick start with Docker

docker run -it -p 5000:5000 chadhart/tensorflow-object-detection:runserver

Installation

Docker Install

git clone https://github.com/webrtcHacks/tfObjWebrtc.git
cd tfObjWebrtc
docker run -it -p 5000:5000 --name tf-webrtchacks -v $(pwd):/code chadhart/tensorflow-object-detection:webrtchacks
python setup.py install
python server.py

Manual install

Follow the TensorFlow Object API install instructions. Then run the the instructions above.

Example web apps

Point your browser to:

  • https://localhost:5000/local - shows a mirrored video from a webcam
  • https://localhost:5000/video - shows object detection running on a HTML <video> tag

Browser support

WebRTC browsers have secure origin restrictions:

  • Chrome will only work on localhost unless you add TLS certificates to your server
  • Firefox will work on any domain as long as you allow it
  • Safari will work, but you will need to "Allow Media Capture on Insecure Domains"

These should all work fine with any other video source.

Edge is currently not supported (polyfill for canvas.toBlob needed)

See the webrtcHacks link for details.

API Details

Point to a <script> tag to objDetect.js with an id of objDetect. Include data-source="myVideo" and other optional data- tags to set parameters.

Example:

<script id="objDetect" src="/static/objDetect.js" data-source="myVideo" data-mirror="true" data-uploadWidth="1280" data-scoreThreshold="0.40"></script>

Data tags:

  • data-source - the ID of the source <video> to use. Must be specified.
  • data-uploadWidth - the width of the upload file. Height will automatically be calculated based on the source video's aspect ratio. Default is 640.
  • data-mirror - mirror the boundary boxes. Used is the image is mirrored (as is usual with a local getUserMedia view). Default is false.
  • data-scoreThreshold - only show objects above this confidence threshold. Default is 0.5
  • data-apiServer - the full URL of the TensorFlow Object Detection Web API server location. Default is /image off of the current domain - i.e. http://localhost:5000/image

More Repositories

1

adapter

Shim to insulate apps from spec changes and prefix differences. Latest adapter.js release:
JavaScript
3,627
star
2

WebRTC-Camera-Resolution

WebRTC Camera Resolution Finder
JavaScript
128
star
3

sdp-anatomy

Source code for webrtcHacks' Anatomy of a SDP
JavaScript
87
star
4

jitsiLocalRecorder

100% browser-based, local audio & screen recording for Jitsi Meet
JavaScript
77
star
5

facetouchmonitor

monitor how often you touch your face with WebRTC and tensorflow.js
JavaScript
71
star
6

webrtc_baby_monitor

A motion detecting baby monitor from webrtcHacks
JavaScript
67
star
7

transparent-virtual-background

Transparent backgrounds with WebRTC
HTML
66
star
8

ChadWallaceHart.com

Source for ChadWallaceHart.com
JavaScript
47
star
9

aiy_vision_web_server

Show camera feed and annotations of the AIY Vision Kit in a webpage
Python
44
star
10

webrtcnotify

JavaScript
10
star
11

first-steps-ortc

First steps with ORTC
HTML
10
star
12

webcodecPacketLoss

simulate packet loss effects with webcodecs
HTML
9
star
13

still-image-from-webcam-stream-approaches

Different ways of getting an image from a webcam stream
HTML
8
star
14

webrtcPresenceMonitor

Send a webhook when getUserMedia is active and inactive
JavaScript
7
star
15

smart-gallery

HTML
5
star
16

canvasMirror

5
star
17

gitHub-WebRTC-analysis

An analysis of WebRTC trends on GitHub
4
star
18

videoFileStream

Experiments in streaming a video file to WebRTC
HTML
2
star
19

fuzzit

C
1
star
20

cssMirror

Mirroring a getUserMedia video capture with CSS
HTML
1
star
21

chromestatus

grab datasets from chromestatus and display them a bit nicer
HTML
1
star
22

WebRTC-tool-directory

Repository for webrtcHacks tool directory
1
star