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 1 commit
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
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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the spaces are great: makes the code easier to read

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,57 @@ 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++) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

JSON update in the DenseCap example is great



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);

//console logs
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are these console logs still needed ?
(if not, please remove)

//println("className: "+className);
//println("score: "+score);
//println("bboxes: "+boxes);
//println(x, y, w, h);
}
}

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.
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Last remarks:

  • please remove the .DS_Store file (I should've added that to a .gitignore, my bad)
  • have the sketches changed names ? (e.g. GPT2.pde -> GPT2_012.pde / DenseCap.pde -> DenseCap_012.pde ?) if so, can they be renamed without the _012 suffix ?

Thank you so much for the contribution and apologies for the late reponse.
I will have another look after you commit the changes and merge 🙌

data = runwayData;
//get the value of the "text" key
text_output = data.getString("text");
text_output = data.getString("generated_text");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

JSON update in the GPT example is great

}