[ Video ]
[ About ]
文字で動画をマスク
Font mask.
[ Source ]
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
#pragma once #include "ofMain.h" #include "opencv2/opencv.hpp" class ofApp : public ofBaseApp { public: void setup(); void update(); void draw(); void keyPressed(int key) {}; void keyReleased(int key) {}; void mouseMoved(int x, int y) {}; void mouseDragged(int x, int y, int button) {}; void mousePressed(int x, int y, int button) {}; void mouseReleased(int x, int y, int button) {}; void windowResized(int w, int h) {}; void dragEvent(ofDragInfo dragInfo) {}; void gotMessage(ofMessage msg) {}; cv::Size cap_size; cv::VideoCapture cap; cv::Mat frame; ofImage image; ofFbo fbo; ofShader shader; float font_size; ofTrueTypeFont font; }; |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
#include "ofApp.h" //-------------------------------------------------------------- void ofApp::setup() { ofSetFrameRate(30); ofSetWindowTitle("openFrameworks"); ofBackground(239); this->cap_size = cv::Size(1280, 720); this->cap.open("video.mp4"); this->image.allocate(this->cap_size.width, this->cap_size.height, OF_IMAGE_COLOR); this->frame = cv::Mat(cv::Size(this->image.getWidth(), this->image.getHeight()), CV_MAKETYPE(CV_8UC3, this->image.getPixels().getNumChannels()), this->image.getPixels().getData(), 0); this->fbo.allocate(ofGetWidth(), ofGetHeight()); this->shader.load("shader/shader.vert", "shader/shader.frag"); this->font_size = 80; this->font.loadFont("fonts/Kazesawa-Bold.ttf", this->font_size, true, true, true); } //-------------------------------------------------------------- void ofApp::update() { // Read mp4 file. cv::Mat src; this->cap >> src; if (src.empty()) { this->cap.set(CV_CAP_PROP_POS_FRAMES, 1); return; } cv::resize(src, this->frame, this->cap_size); cv::cvtColor(this->frame, this->frame, CV_BGR2RGB); this->image.update(); // Draw image. this->fbo.begin(); ofClear(0); ofBackground(60); ofSetColor(255); for (int x = 0; x < ofGetWidth(); x += this->font_size) { for (int y = this->font_size; y <= ofGetHeight(); y += this->font_size) { char noise_value = ofMap(ofNoise(x * 0.005, y * 0.0005 - ofGetFrameNum() * this->font_size * 0.00001), 0, 1, 'A', 'Z'); this->font.drawString({ noise_value }, x, y); } } this->fbo.end(); } //-------------------------------------------------------------- void ofApp::draw() { this->shader.begin(); this->shader.setUniform1f("time", ofGetElapsedTimef()); this->shader.setUniform2f("resolution", ofGetWidth(), ofGetHeight()); this->shader.setUniformTexture("tex1", this->image, 1); this->shader.setUniformTexture("tex2", this->fbo.getTexture(), 2); ofFill(); ofSetColor(255); ofDrawRectangle(0, 0, ofGetWidth(), ofGetHeight()); this->shader.end(); } //-------------------------------------------------------------- int main() { ofGLWindowSettings settings; settings.setGLVersion(3, 2); settings.setSize(1280, 720); ofCreateWindow(settings); ofRunApp(new ofApp()); } |
1 2 3 4 5 6 7 8 |
#version 150 uniform mat4 modelViewProjectionMatrix; in vec4 position; void main(){ gl_Position = modelViewProjectionMatrix * position; } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
#version 150 uniform float time; uniform vec2 resolution; uniform sampler2DRect tex1; uniform sampler2DRect tex2; in vec2 texCoordVarying; out vec4 outputColor; void main() { vec4 t1 = texture(tex1, vec2(gl_FragCoord.x, resolution.y - gl_FragCoord.y)); vec4 t2 = texture(tex2, vec2(gl_FragCoord.x, resolution.y - gl_FragCoord.y)); outputColor = t1 * t2; } |