Skip to content
This repository was archived by the owner on Mar 6, 2025. It is now read-only.

Commit 66e6ab8

Browse files
committed
add YOLO 🍻
1 parent af274bd commit 66e6ab8

10 files changed

Lines changed: 379 additions & 20 deletions

File tree

.vscode/settings.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"cris",
1010
"cristobal",
1111
"cristóbal",
12-
"runwayml"
12+
"runwayml",
13+
"yolo"
1314
],
1415
}

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ Examples are separated by current available models.
1717
- [Receiving data from Runway](/openpose/receivesOnly)
1818
- [Sending live webcam feed](/openpose/sendWebcam)
1919
- [Sending static images](/openpose/sendImage)
20+
- [YOLO](/yolo)
21+
- [Receiving data from Runway](/yolo/receivesOnly)
22+
- [Sending live webcam feed](/yolo/sendWebcam)
2023

2124
## Library
2225

openpose/receivesOnly/script.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ var colors;
3434

3535
// This are all the body connections we want to draw
3636
var bodyConnections = [
37-
['Nose', 'Left_Eye'],
37+
['Nose', 'Right_Shoulder'],
3838
['Left_Eye', 'Left_Ear'],
3939
['Nose', 'Right_Eye'],
4040
['Right_Eye', 'Right_Ear'],

openpose/sendImage/script.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ var socket;
3535

3636
// This are all the body connections we want to draw
3737
var bodyConnections = [
38-
['Nose', 'Left_Eye'],
38+
['Nose', 'Right_Shoulder'],
3939
['Left_Eye', 'Left_Ear'],
4040
['Nose', 'Right_Eye'],
4141
['Right_Eye', 'Right_Ear'],

openpose/sendWebcam/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
<!--
2222
OpenPose Demo: This example creates a video stream and send images to Runway
2323
24-
// Cristóbal Valenzuela, George Profenza (merging sendImage and receivesOnly examples)
24+
Cristóbal Valenzuela, George Profenza (merging sendImage and receivesOnly examples)
2525
2626
-->
2727

openpose/sendWebcam/script.js

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ var capture;
3131
var w = 400;
3232
var h = 225;
3333
var colors;
34+
var canvas;
3435

3536
// This are all the body connections we want to draw
3637
var bodyConnections = [
@@ -71,47 +72,48 @@ document.addEventListener("DOMContentLoaded", function(event) {
7172
// When a connection is established
7273
socket.on('connect', function() {
7374
status.innerHTML = 'Connected';
74-
setInterval(sendImgToRunway,500,capture);
7575
});
7676

77-
// When there is a data event, update the humans array
77+
// When there is a data event, update the humans array and send new data
7878
socket.on('update_response', function(data) {
7979
humans = data.results.humans;
80+
sendCanvasToRunway();
8081
});
8182
});
8283

84+
// Send the current canvas to Runway
85+
function sendCanvasToRunway() {
86+
socket.emit('update_request', {
87+
data: canvas.elt.toDataURL('image/jpeg'),
88+
model: "mobilenet_thin"
89+
});
90+
}
91+
8392
// p5 setup function
8493
function setup() {
8594
// Create a canvas
86-
createCanvas(w, h);
95+
canvas = createCanvas(w, h);
96+
8797
// Create a video element.
8898
// Although we are getting the images from Runway, this is just to show the video behind
8999
capture = createCapture(VIDEO);
90100
capture.size(w, h);
101+
capture.hide();
102+
91103
// Set some style and colors
92104
strokeWeight(2);
93105
colors = [color('#00ff00'), color('#ffff00'), color('#ff0000'), color('#00ffff'), color('#ffffff'), color('#f4f'), color('#00ff'), color('#ffaf00'), color('#aff'), color('#aaf'), color('#33a'), color('#55f'), color('#771'), color('#15f'), color('#ff0000'), color('#00ff00'), color('#ffff00'), color('#ff0000')];
94106

95-
}
96107

97-
function sendImgToRunway(img){
98-
if(img){
99-
// update camera pixels
100-
img.loadPixels();
101-
// send data
102-
socket.emit('update_request', {
103-
data: img.canvas.toDataURL('image/jpeg'),
104-
model: "mobilenet_thin"
105-
});
106-
}else{
107-
console.warn("invalid pixels, skipping request to Runway");
108-
}
108+
sendCanvasToRunway();
109109
}
110110

111111
// p5 draw function
112112
function draw() {
113+
113114
// Every frame, draw the current video frame
114115
image(capture, 0, 0, w, h);
116+
115117
// If there are humans detected, draw them in top of video frames
116118
if (humans.length > 0) {
117119
humans.forEach(human => drawHuman(human));

yolo/receivesOnly/index.html

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
<!--
2+
Copyright (C) 2018 Cristobal Valenzuela
3+
4+
This file is part of RunwayML.
5+
6+
RunwayML is free software: you can redistribute it and/or modify
7+
it under the terms of the GNU General Public License as published by
8+
the Free Software Foundation, either version 3 of the License, or
9+
(at your option) any later version.
10+
11+
RunwayML is distributed in the hope that it will be useful,
12+
but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
GNU General Public License for more details.
15+
16+
You should have received a copy of the GNU General Public License
17+
along with RunwayML. If not, see <http://www.gnu.org/licenses/>.
18+
19+
-->
20+
21+
<!--
22+
YOLO Demo: This example receives objects detected by Runway using YOLO
23+
24+
Cristóbal Valenzuela
25+
26+
-->
27+
28+
<!DOCTYPE html>
29+
<html lang="en">
30+
31+
<head>
32+
<meta charset="UTF-8">
33+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
34+
<meta http-equiv="X-UA-Compatible" content="ie=edge">
35+
<title>Runway: YOLO Demo</title>
36+
<!-- We are using socket.io to establish a socket connection to Runway -->
37+
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/2.0.4/socket.io.js"></script>
38+
<!-- We are using p5.js to draw in the canvas -->
39+
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.6.0/p5.min.js"></script>
40+
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.6.0/addons/p5.dom.js"></script>
41+
42+
<style>
43+
* {
44+
font-family: Arial, Helvetica, sans-serif;
45+
font-weight: lighter;
46+
}
47+
48+
</style>
49+
</head>
50+
51+
<body>
52+
<!-- Information about the model -->
53+
<div>
54+
<h2>YOLO Demo: receiving data coming from Runway</h2>
55+
<p>About the model: You only look once (YOLO) is a state-of-the-art, real-time object detection system.</p>
56+
<p>More information: <a href="https://runwayml.com/tutorials/yolo/">https://runwayml.com/tutorials/yolo/</a></p>
57+
<p>This example uses <a href="https://p5js.org/">p5.js</a> to draw body connections</p>
58+
<hr />
59+
</div>
60+
61+
<!-- A log element to show the connection status -->
62+
<div id="status">Not Connected</div>
63+
64+
<script src="script.js"></script>
65+
</body>
66+
67+
</html>

yolo/receivesOnly/script.js

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
// Copyright (C) 2018 Cristobal Valenzuela
2+
//
3+
// This file is part of RunwayML.
4+
//
5+
// RunwayML is free software: you can redistribute it and/or modify
6+
// it under the terms of the GNU General Public License as published by
7+
// the Free Software Foundation, either version 3 of the License, or
8+
// (at your option) any later version.
9+
//
10+
// RunwayML is distributed in the hope that it will be useful,
11+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
// GNU General Public License for more details.
14+
//
15+
// You should have received a copy of the GNU General Public License
16+
// along with RunwayML. If not, see <http://www.gnu.org/licenses/>.
17+
//
18+
// ===============================================================
19+
//
20+
// Runway: YOLO Webcam Demo
21+
// This example receives incoming data from Runway.
22+
// p5.js is used to draw rectangles
23+
// You should select Camera from the Input Panel
24+
//
25+
// Cristóbal Valenzuela
26+
// cris@runwayml.com
27+
//
28+
// ===============================================================
29+
30+
var capture;
31+
var WIDTH = 432;
32+
var HEIGHT = 368;
33+
34+
// All the objects detected with YOLO will be in this results variable
35+
var results = [];
36+
37+
// Wait until the page is loaded
38+
document.addEventListener("DOMContentLoaded", function(event) {
39+
// A variable to hold the status of the connection
40+
var status = document.getElementById('status');
41+
42+
// Create a connection with Runway
43+
// *You should update this address to match the URL provided by the app
44+
var socket = io.connect('http://127.0.0.1:3333');
45+
46+
// When a connection is established
47+
socket.on('connect', function() {
48+
status.innerHTML = 'Connected';
49+
});
50+
51+
// Whenever there is data coming fron Runway, update the results variable
52+
socket.on('data', function(data) {
53+
results = data.results;
54+
});
55+
});
56+
57+
// p5 setup function
58+
function setup() {
59+
// Create a canvas
60+
createCanvas(WIDTH, HEIGHT);
61+
// Create a video element.
62+
// Although we are getting the images from Runway, this is just to show the video behind
63+
capture = createCapture(VIDEO);
64+
capture.size(WIDTH, HEIGHT);
65+
// Hide the video element. We will be showing only the canvas
66+
capture.hide();
67+
}
68+
69+
// p5 draw function
70+
function draw() {
71+
// Every frame, draw the current video frame
72+
image(capture, 0, 0, WIDTH, HEIGHT);
73+
// Loop through all the elements detected and draw a bounding box around them
74+
results.forEach(function(object, i) {
75+
var bounds = object.bounds;
76+
var x = bounds[0];
77+
var y = bounds[1];
78+
var w = bounds[2];
79+
var h = bounds[3];
80+
fill(0, 255, 0)
81+
noStroke();
82+
// Draw a text over the bounding box
83+
text(object.cat, x*WIDTH, y*HEIGHT-5);
84+
noFill();
85+
strokeWeight(4);
86+
stroke(0, 255, 0);
87+
// Draw the bounding box
88+
rect(x*WIDTH, y*HEIGHT, w*WIDTH, h*HEIGHT);
89+
})
90+
}

yolo/sendWebcam/index.html

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
<!--
2+
Copyright (C) 2018 Cristobal Valenzuela
3+
4+
This file is part of RunwayML.
5+
6+
RunwayML is free software: you can redistribute it and/or modify
7+
it under the terms of the GNU General Public License as published by
8+
the Free Software Foundation, either version 3 of the License, or
9+
(at your option) any later version.
10+
11+
RunwayML is distributed in the hope that it will be useful,
12+
but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
GNU General Public License for more details.
15+
16+
You should have received a copy of the GNU General Public License
17+
along with RunwayML. If not, see <http://www.gnu.org/licenses/>.
18+
19+
-->
20+
21+
<!--
22+
YOLO Example: This example creates a video stream and send images to Runway
23+
24+
Cristóbal Valenzuela
25+
26+
-->
27+
28+
<!DOCTYPE HTML>
29+
<html>
30+
31+
<head>
32+
<title>Runway: YOLO Demo</title>
33+
<!-- We are using socket.io to establish a socket connection to Runway -->
34+
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/2.0.4/socket.io.js"></script>
35+
<!-- We are using p5.js to draw in the canvas -->
36+
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.6.0/p5.min.js"></script>
37+
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.6.0/addons/p5.dom.js"></script>
38+
<style>
39+
* {
40+
font-family: Arial, Helvetica, sans-serif;
41+
font-weight: lighter;
42+
}
43+
video{
44+
display:block
45+
}
46+
47+
</style>
48+
</head>
49+
50+
<body>
51+
52+
<!-- Information about the model -->
53+
<div>
54+
<h2>YOLO Demo: sending live webcam stream to Runway</h2>
55+
<p>About the model: You only look once (YOLO) is a state-of-the-art, real-time object detection system.</p>
56+
<p>More information: <a href="https://runwayml.com/tutorials/yolo/">https://runwayml.com/tutorials/yolo/</a></p>
57+
<hr />
58+
</div>
59+
60+
<!-- Connection status -->
61+
<p id="status">Not Connected</p>
62+
63+
<!-- Control Buttos -->
64+
<button id="start">Start</button>
65+
<button id="stop">Stop</button>
66+
67+
<!-- The main script -->
68+
<script src="script.js"></script>
69+
</body>
70+
71+
</html>

0 commit comments

Comments
 (0)