[ Video ]
[ About ]
MP4の映像データに対して、時間の歪み処理をかけてみました。色々な動画にかけましたが、動くものと動かないものがはっきりしている動画に対しては不思議な絵が撮れました。
画面中央左側にいる不動のおばさん?が良い味を出しています。
[ 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 |
#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::VideoCapture cap; cv::Size cap_size; static const int frame_number = 60; cv::Mat save_frame[frame_number]; cv::Mat blend_frame; ofImage blend_image; }; |
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 |
#include "ofApp.h" //-------------------------------------------------------------- void ofApp::setup() { ofBackground(255); ofSetWindowTitle("Insta"); this->cap.open("city1.mp4"); this->cap_size = cv::Size(this->cap.get(CV_CAP_PROP_FRAME_WIDTH), this->cap.get(CV_CAP_PROP_FRAME_HEIGHT)); ofSetFrameRate(this->cap.get(CV_CAP_PROP_FPS)); this->blend_image.allocate(this->cap_size.width, this->cap_size.height, OF_IMAGE_COLOR); this->blend_frame = cv::Mat(this->blend_image.getHeight(), this->blend_image.getWidth(), CV_MAKETYPE(CV_8UC3, this->blend_image.getPixels().getNumChannels()), this->blend_image.getPixels().getData(), 0); } //-------------------------------------------------------------- void ofApp::update() { cv::Mat src; this->cap >> src; if (src.empty()) { return; } cv::cvtColor(src, src, CV_RGB2BGR); if (ofGetFrameNum() < this->frame_number) { for (int i = ofGetFrameNum() - 1; i > 0; i--) { this->save_frame[i - 1].copyTo(this->save_frame[i]); } src.copyTo(this->save_frame[0]); } else { for (int i = this->frame_number - 1; i > 0; i--) { this->save_frame[i - 1].copyTo(this->save_frame[i]); } src.copyTo(this->save_frame[0]); } if(ofGetFrameNum() > this->frame_number){ for (int y = 0; y < this->blend_frame.rows; y += 1) { for (int x = 0; x < this->blend_frame.cols; x += 1) { int index = ofNoise(x * 0.001, y * 0.001, ofGetFrameNum() * 0.03) * this->frame_number; this->blend_frame.at<cv::Vec3b>(y, x) = this->save_frame[index].at<cv::Vec3b>(y, x); } } this->blend_image.update(); } } //-------------------------------------------------------------- void ofApp::draw() { if (ofGetFrameNum() > this->frame_number) { this->blend_image.draw(0, 0); } } //======================================================================== int main() { ofSetupOpenGL(1920, 1080, OF_WINDOW); ofRunApp(new ofApp()); } |