Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

updates #12

Merged
merged 2 commits into from
Feb 25, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added examples/HTTP/DenseCap/.DS_Store
Binary file not shown.
55 changes: 30 additions & 25 deletions examples/HTTP/DenseCap/DenseCap.pde
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ void setup() {
// disable automatic polling: request data manually when a new frame is ready
runway.setAutoUpdate(false);
// setup camera
camera = new Capture(this,640,480);
camera = new Capture(this, 640, 480);
camera.start();
// setup timer
lastMillis = millis();
Expand All @@ -63,16 +63,16 @@ void draw() {
// update timer
int currentMillis = millis();
// if the difference between current millis and last time we checked past the wait time
if(currentMillis - lastMillis >= waitTime){
if (currentMillis - lastMillis >= waitTime) {
// call the timed function
sendFrameToRunway();
// update lastMillis, preparing for another wait
lastMillis = currentMillis;
}
background(0);
// draw webcam image
image(camera,0,0);
image(camera, 0, 0);

// Display captions
drawCaptions();
}
Expand All @@ -81,47 +81,52 @@ void draw() {
// A function to display the captions
void drawCaptions() {
// if no data is loaded yet, exit
if(data == null){
if (data == null) {
return;
}

// access boxes and labels JSON arrays within the result
JSONArray results = data.getJSONArray("results");


// for each array element
for(int i = 0 ; i < results.size(); i++){
JSONObject result = results.getJSONObject(i);

String className = result.getString("class");
float score = result.getFloat("score");
JSONArray box = result.getJSONArray("bbox");
// extract values from the float array
float x = box.getFloat(0);
float y = box.getFloat(1);
float w = box.getFloat(2);
float h = box.getFloat(3);
for (int i = 0; i < data.size(); i++) {


JSONArray className = data.getJSONArray("classes");
JSONArray score = data.getJSONArray("scores");
JSONArray boxes = data.getJSONArray("bboxes");

String label = className.getString(i);
float val=score.getFloat(i);
JSONArray box = boxes.getJSONArray(i);
// //// extract values from the float array
float x = box.getFloat(0)* width;
float y = box.getFloat(1)* height;
float w = (box.getFloat(2) * width) - x;
float h = (box.getFloat(3) * height) - y;

// display bounding boxes
noFill();
rect(x,y,w,h);
rect(x, y, w, h);
fill(255);
text(className + " score: " + String.format("%.2f",score),x,y);
text(label + " score: " + String.format("%.2f", val), x, y);

}
}

void sendFrameToRunway(){
void sendFrameToRunway() {
// nothing to send if there's no new camera data available
if(camera.available() == false){
if (camera.available() == false) {
return;
}
// read a new frame
camera.read();
// crop image to Runway input format (600x400)
PImage image = camera.get(0,0,600,400);
PImage image = camera.get(0, 0, 600, 400);
// query Runway with webcam image
runway.query(image);
}

// this is called when new Runway data is available
void runwayDataEvent(JSONObject runwayData){
void runwayDataEvent(JSONObject runwayData) {
// point the sketch data to the Runway incoming data
data = runwayData;
}
Binary file added examples/HTTP/GPT2/.DS_Store
Binary file not shown.
2 changes: 1 addition & 1 deletion examples/HTTP/GPT2/GPT2.pde
Original file line number Diff line number Diff line change
Expand Up @@ -107,5 +107,5 @@ void runwayDataEvent(JSONObject runwayData){
// point the sketch data to the Runway incoming data
data = runwayData;
//get the value of the "text" key
text_output = data.getString("text");
text_output = data.getString("generated_text");
}