[ Video ]
[ About ]
動画の断片化。
Video fragmentation.
[ 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 |
#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) {}; ofEasyCam cam; cv::VideoCapture cap; cv::Size cap_size; ofImage image; cv::Mat frame; }; |
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 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 |
#include "ofApp.h" //-------------------------------------------------------------- void ofApp::setup() { ofSetFrameRate(60); ofSetWindowTitle("openframeworks"); ofBackground(0); ofSetLineWidth(2); ofEnableDepthTest(); this->cap.open("D:\\MP4\\MOV_1030.mp4"); this->cap_size = cv::Size(1280, 720); 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); } //-------------------------------------------------------------- void ofApp::update() { ofSeedRandom(39); cv::Mat src; this->cap >> src; if (src.empty()) { this->cap.set(cv::CAP_PROP_POS_FRAMES, 0); return; } cv::cvtColor(src, src, cv::COLOR_BGR2RGB); cv::resize(src, this->frame, this->cap_size); cv::flip(this->frame, this->frame, 0); this->image.update(); } //-------------------------------------------------------------- void ofApp::draw() { this->cam.begin(); ofRotateY(ofGetFrameNum()); ofTranslate(-640, -360); int span = 40; vector<ofMesh> mesh_list; for (int x = 0; x < 1280; x += span) { for (int y = 0; y < 720; y += span) { ofMesh mesh; mesh.addVertex(glm::vec3(x, y, 0)); mesh.addVertex(glm::vec3(x + span, y, 0)); mesh.addVertex(glm::vec3(x + span, y + span, 0)); mesh.addVertex(glm::vec3(x, y + span, 0)); mesh.addTexCoord(glm::vec3(x, y, 0)); mesh.addTexCoord(glm::vec3(x + span, y, 0)); mesh.addTexCoord(glm::vec3(x + span, y + span, 0)); mesh.addTexCoord(glm::vec3(x, y + span, 0)); mesh.addIndex(0); mesh.addIndex(1); mesh.addIndex(2); mesh.addIndex(0); mesh.addIndex(2); mesh.addIndex(3); mesh_list.push_back(mesh); } } for (auto& mesh : mesh_list) { auto rotate = glm::vec3(ofRandom(360), ofRandom(360), ofRandom(360)); auto speed = glm::vec3(ofRandom(5, 10), ofRandom(5, 10), ofRandom(5, 10)); auto center = glm::vec3(mesh.getVertex(0).x + span * 0.5, mesh.getVertex(0).y + span * 0.5, 0); auto tmp_center = center; mesh.setVertex(0, mesh.getVertex(0) - center); mesh.setVertex(1, mesh.getVertex(1) - center); mesh.setVertex(2, mesh.getVertex(2) - center); mesh.setVertex(3, mesh.getVertex(3) - center); auto noise_value = ofNoise(glm::vec4(center * 0.001, ofGetFrameNum() * 0.005)); if (noise_value < 0.48) { tmp_center += glm::vec3(0, 0, -250); rotate = glm::vec3(); } else if (noise_value < 0.52) { tmp_center += glm::vec3(0, 0, ofMap(noise_value, 0.48, 0.52, -250, 250)); rotate.x += ofGetFrameNum() * speed.x; rotate.y += ofGetFrameNum() * speed.y; rotate.z += ofGetFrameNum() * speed.z; } else { tmp_center += glm::vec3(0, 0, 250); rotate = glm::vec3(); } ofPushMatrix(); ofTranslate(tmp_center); ofRotateZ(rotate.z); ofRotateY(rotate.y); ofRotateX(rotate.x); ofSetColor(255); this->image.bind(); mesh.draw(); this->image.unbind(); ofMesh line; line.setMode(ofPrimitiveMode::OF_PRIMITIVE_LINES); if (noise_value > 0.48 && noise_value < 0.52) { line.addVertex(mesh.getVertex(0)); line.addVertex(mesh.getVertex(1)); line.addVertex(mesh.getVertex(2)); line.addVertex(mesh.getVertex(3)); line.addIndex(0); line.addIndex(1); line.addIndex(1); line.addIndex(2); line.addIndex(2); line.addIndex(3); line.addIndex(3); line.addIndex(0); } else { auto top_noise_value = ofNoise(glm::vec4((center + glm::vec3(0, span, 0)) * 0.001, ofGetFrameNum() * 0.005)); if ((top_noise_value > 0.48 && top_noise_value < 0.52 || center.y >= 720 - span * 0.5) ) { line.addVertex(mesh.getVertex(2)); line.addVertex(mesh.getVertex(3)); line.addIndex(line.getNumVertices() - 1); line.addIndex(line.getNumVertices() - 2); } auto bottom_noise_value = ofNoise(glm::vec4((center - glm::vec3(0, span, 0)) * 0.001, ofGetFrameNum() * 0.005)); if (bottom_noise_value > 0.48 && bottom_noise_value < 0.52 || center.y <= span * 0.5) { line.addVertex(mesh.getVertex(0)); line.addVertex(mesh.getVertex(1)); line.addIndex(line.getNumVertices() - 1); line.addIndex(line.getNumVertices() - 2); } auto right_noise_value = ofNoise(glm::vec4((center + glm::vec3(span, 0, 0)) * 0.001, ofGetFrameNum() * 0.005)); if (right_noise_value > 0.48 && right_noise_value < 0.52 || center.x >= 1280 - span * 0.5) { line.addVertex(mesh.getVertex(1)); line.addVertex(mesh.getVertex(2)); line.addIndex(line.getNumVertices() - 1); line.addIndex(line.getNumVertices() - 2); } auto left_noise_value = ofNoise(glm::vec4((center - glm::vec3(span, 0, 0)) * 0.001, ofGetFrameNum() * 0.005)); if (left_noise_value > 0.48 && left_noise_value < 0.52 || center.x <= span * 0.5) { line.addVertex(mesh.getVertex(3)); line.addVertex(mesh.getVertex(0)); line.addIndex(line.getNumVertices() - 1); line.addIndex(line.getNumVertices() - 2); } } line.drawWireframe(); ofPopMatrix(); } this->cam.end(); } //-------------------------------------------------------------- int main() { ofSetupOpenGL(720, 720, OF_WINDOW); ofRunApp(new ofApp()); } |