|
|
@ -13,12 +13,15 @@ void ofApp::setup(){ |
|
|
|
videoFrame.allocate(1280, 720, OF_IMAGE_COLOR); |
|
|
|
|
|
|
|
webcam.setDeviceID(0); |
|
|
|
webcam.setDesiredFrameRate(60); |
|
|
|
webcam.setDesiredFrameRate(30); |
|
|
|
webcam.setup(webcamWidth, webcamHeight); |
|
|
|
|
|
|
|
ofLog() << "Webcam size: " << webcam.getWidth() << "x" << webcam.getHeight(); |
|
|
|
|
|
|
|
onnx.setup(&inputImage); // setup onnx -> will need to pass in a pointer to the two fbos?
|
|
|
|
|
|
|
|
textFont.load("Avara-Bold.otf", 32); |
|
|
|
infoFont.load("Avara-Bold.otf", 24); |
|
|
|
} |
|
|
|
|
|
|
|
//--------------------------------------------------------------
|
|
|
@ -48,6 +51,50 @@ void ofApp::update(){ |
|
|
|
//--------------------------------------------------------------
|
|
|
|
void ofApp::draw(){ |
|
|
|
onnx.draw(); |
|
|
|
|
|
|
|
ofPushStyle(); |
|
|
|
ofSetColor(ofColor::red); |
|
|
|
|
|
|
|
// Get current info from teleprompter
|
|
|
|
std::string speakerText = "Speaker: " + teleprompter->currentSpeaker.getParameter().toString(); |
|
|
|
std::string emotionText = "Emotion: " + teleprompter->currentEmotion.getParameter().toString(); |
|
|
|
|
|
|
|
// Calculate positions for speaker and emotion text
|
|
|
|
ofRectangle speakerBox = infoFont.getStringBoundingBox(speakerText, 0, 0); |
|
|
|
float speakerX = (ofGetWidth() - speakerBox.width) / 2.0f; |
|
|
|
float speakerY = 128; |
|
|
|
|
|
|
|
ofRectangle emotionBox = infoFont.getStringBoundingBox(emotionText, 0, 0); |
|
|
|
float emotionX = (ofGetWidth() - emotionBox.width) / 2.0f; |
|
|
|
float emotionY = speakerY + speakerBox.height + 10; |
|
|
|
|
|
|
|
// Draw speaker and emotion
|
|
|
|
infoFont.drawString(speakerText, speakerX, speakerY); |
|
|
|
infoFont.drawString(emotionText, emotionX, emotionY); |
|
|
|
|
|
|
|
ofSetColor(ofColor::red); |
|
|
|
float margin = 128; |
|
|
|
float maxWidth = ofGetWidth() - margin * 2; |
|
|
|
std::string wrapped = wrapStringToWidth(teleprompter->displayedSentence, maxWidth); |
|
|
|
|
|
|
|
// Split and draw wrapped text
|
|
|
|
std::vector<std::string> lines; |
|
|
|
std::istringstream iss(wrapped); |
|
|
|
std::string line; |
|
|
|
while (std::getline(iss, line)) { |
|
|
|
lines.push_back(line); |
|
|
|
} |
|
|
|
|
|
|
|
float totalHeight = lines.size() * textFont.getLineHeight(); |
|
|
|
float startY = (ofGetHeight() / 2.0f) - (totalHeight / 2.0f); |
|
|
|
|
|
|
|
for (size_t i = 0; i < lines.size(); ++i) { |
|
|
|
ofRectangle bbox = textFont.getStringBoundingBox(lines[i], 0, 0); |
|
|
|
float x = (ofGetWidth() - bbox.width) / 2.0f; // Calculate center position
|
|
|
|
float y = startY + i * textFont.getLineHeight(); |
|
|
|
textFont.drawString(lines[i], x, y); |
|
|
|
} |
|
|
|
ofPopStyle(); |
|
|
|
} |
|
|
|
|
|
|
|
//--------------------------------------------------------------
|
|
|
@ -65,4 +112,22 @@ void ofApp::keyPressed(int key){ |
|
|
|
//--------------------------------------------------------------
|
|
|
|
void ofApp::keyReleased(int key){ |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
std::string ofApp::wrapStringToWidth(const std::string& text, float maxWidth) { |
|
|
|
std::istringstream iss(text); |
|
|
|
std::string word; |
|
|
|
std::string wrapped, line; |
|
|
|
while (iss >> word) { |
|
|
|
std::string testLine = line.empty() ? word : line + " " + word; |
|
|
|
ofRectangle bbox = textFont.getStringBoundingBox(testLine, 0, 0); |
|
|
|
if (bbox.width > maxWidth && !line.empty()) { |
|
|
|
wrapped += line + "\n"; |
|
|
|
line = word; |
|
|
|
} else { |
|
|
|
line = testLine; |
|
|
|
} |
|
|
|
} |
|
|
|
if (!line.empty()) wrapped += line; |
|
|
|
return wrapped; |
|
|
|
} |