[ Video ]
[ About ]
ペンキのしぶきっぽい絵を描いて、動画をマスク
Paint 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 32 33 34 35 |
#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; glm::vec2 location; float percent; float noise_seed; float noise_scale; ofColor color; }; |
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 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
#include "ofApp.h" //-------------------------------------------------------------- void ofApp::setup() { ofSetFrameRate(30); ofSetWindowTitle("openFrameworks"); ofBackground(239); this->cap_size = cv::Size(1280, 720); this->cap.open("D:\\video\\image2.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->location = glm::vec2(ofRandom(ofGetWidth() * 0.2, ofGetWidth() * 0.8), ofRandom(ofGetHeight() * 0.2, ofGetHeight() * 0.8)); this->percent = 0.0; this->noise_seed = ofRandom(10000); this->noise_scale = ofRandom(3, 8); this->color.setHsb(ofRandom(255), 255, 255); } //-------------------------------------------------------------- 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. if (this->percent < 1.0) { this->percent += 0.30; } else { this->location = glm::vec2(ofRandom(ofGetWidth()), ofRandom(ofGetHeight())); this->percent = 0.f; this->noise_seed = ofRandom(10000); this->noise_scale = ofRandom(3, 8); this->color.setHsb(ofRandom(255), 255, 255); } this->fbo.begin(); float base_radius = 80; ofPushMatrix(); ofTranslate(this->location); vector<glm::vec2> vertices; for (int i = 0; i < 3600; i++) { float deg = i * 0.1; auto noise_point = glm::vec2(cos(deg * DEG_TO_RAD), sin(deg * DEG_TO_RAD)); auto noise_value = ofNoise(this->noise_seed, noise_point.x * this->noise_scale, noise_point.y * this->noise_scale); float grow_radius = base_radius + pow((1 + noise_value), 7) * this->percent; auto point = glm::vec2(grow_radius * cos(deg * DEG_TO_RAD), grow_radius * sin(deg * DEG_TO_RAD)); vertices.push_back(point); } ofSetColor(this->color); ofBeginShape(); ofVertices(vertices); ofEndShape(); ofPopMatrix(); 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; } |