[ Video ]
[ About ]
2つの動画をミックス
Mix 2 video.
[ 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 36 37 38 |
#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 mouseEntered(int x, int y) {}; void mouseExited(int x, int y) {}; void windowResized(int w, int h) {}; void dragEvent(ofDragInfo dragInfo) {}; void gotMessage(ofMessage msg) {}; cv::Size cap_size; cv::VideoCapture cap1; cv::Mat frame1; ofImage image1; cv::VideoCapture cap2; cv::Mat frame2; ofImage image2; ofFbo src; ofFbo dst; ofShader shader; }; |
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 |
#include "ofApp.h" //-------------------------------------------------------------- void ofApp::setup() { ofSetFrameRate(60); ofSetWindowTitle("openframeworks"); this->cap1.open("video1.mp4"); this->cap2.open("video2.mp4"); this->cap_size = cv::Size(1280, 720); this->image1.allocate(this->cap_size.width, this->cap_size.height, OF_IMAGE_COLOR); this->frame1 = cv::Mat(cv::Size(this->image1.getWidth(), this->image1.getHeight()), CV_MAKETYPE(CV_8UC3, this->image1.getPixels().getNumChannels()), this->image1.getPixels().getData(), 0); this->image2.allocate(this->cap_size.width, this->cap_size.height, OF_IMAGE_COLOR); this->frame2 = cv::Mat(cv::Size(this->image2.getWidth(), this->image2.getHeight()), CV_MAKETYPE(CV_8UC3, this->image2.getPixels().getNumChannels()), this->image2.getPixels().getData(), 0); this->src.allocate(ofGetWidth(), ofGetHeight()); this->dst.allocate(ofGetWidth(), ofGetHeight()); this->shader.load("shader/shader.vert", "shader/shader.frag"); } //-------------------------------------------------------------- void ofApp::update() { cv::Mat src; this->cap1 >> src; if (src.empty()) { this->cap1.set(CV_CAP_PROP_POS_FRAMES, 1); return; } cv::resize(src, this->frame1, this->cap_size); cv::cvtColor(this->frame1, this->frame1, CV_BGR2RGB); this->image1.update(); this->cap2 >> src; if (src.empty()) { this->cap2.set(CV_CAP_PROP_POS_FRAMES, 1); return; } cv::resize(src, this->frame2, this->cap_size); cv::cvtColor(this->frame2, this->frame2, CV_BGR2RGB); this->image2.update(); } //-------------------------------------------------------------- void ofApp::draw() { this->dst.begin(); ofClear(0); this->shader.begin(); this->shader.setUniform1f("time", ofGetElapsedTimef()); this->shader.setUniform2f("resolution", ofGetWidth(), ofGetHeight()); this->shader.setUniformTexture("tex1", this->image1, 1); this->shader.setUniformTexture("tex2", this->image2, 2); this->src.draw(0, 0); this->shader.end(); this->dst.end(); this->dst.draw(0, 0); } //-------------------------------------------------------------- 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 9 10 11 12 |
#version 150 uniform mat4 modelViewProjectionMatrix; in vec4 position; in vec2 texcoord; out vec2 texCoordVarying; void main(){ texCoordVarying = texcoord; gl_Position = modelViewProjectionMatrix * position; } |
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 |
#version 150 uniform float time; uniform vec2 resolution; uniform sampler2DRect tex1; uniform sampler2DRect tex2; in vec2 texCoordVarying; out vec4 outputColor; float mod289(float x){return x - floor(x * (1.0 / 289.0)) * 289.0;} vec4 mod289(vec4 x){return x - floor(x * (1.0 / 289.0)) * 289.0;} vec4 perm(vec4 x){return mod289(((x * 34.0) + 1.0) * x);} float noise(vec3 p){ vec3 a = floor(p); vec3 d = p - a; d = d * d * (3.0 - 2.0 * d); vec4 b = a.xxyy + vec4(0.0, 1.0, 0.0, 1.0); vec4 k1 = perm(b.xyxy); vec4 k2 = perm(k1.xyxy + b.zzww); vec4 c = k2 + a.zzzz; vec4 k3 = perm(c); vec4 k4 = perm(c + 1.0); vec4 o1 = fract(k3 * (1.0 / 41.0)); vec4 o2 = fract(k4 * (1.0 / 41.0)); vec4 o3 = o2 * d.z + o1 * (1.0 - d.z); vec2 o4 = o3.yw * d.x + o3.xz * (1.0 - d.x); return o4.y * d.y + o4.x * (1.0 - d.y); } void main() { vec2 p = (gl_FragCoord.xy * 2.0 - resolution) / min(resolution.x, resolution.y); float v = noise(vec3(p.x * 1.5, p.y * 1.5 + time, 0.0)); vec4 c1 = texture(tex1, texCoordVarying) * v; vec4 c2 = texture(tex2, texCoordVarying) * (1 - v); outputColor = c1 + c2; } |