-
Notifications
You must be signed in to change notification settings - Fork 24
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
updates #12
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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(); | ||
|
@@ -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(); | ||
} | ||
|
@@ -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++) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. are these console logs still needed ? |
||
//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; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -107,5 +107,5 @@ void runwayDataEvent(JSONObject runwayData){ | |
// point the sketch data to the Runway incoming data | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Last remarks:
Thank you so much for the contribution and apologies for the late reponse. |
||
data = runwayData; | ||
//get the value of the "text" key | ||
text_output = data.getString("text"); | ||
text_output = data.getString("generated_text"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. JSON update in the GPT example is great |
||
} |
There was a problem hiding this comment.
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