[ Video ]
[ About ]
昨日、一昨日とやってきた、配列の値から炎っぽい動きを作るロジックで出力した値を動画のフレーム番号と絡めてみました。定点カメラの映像になるので、道路の路面と手間にある木はあまり動かず、車やバイクはグニャグニャしていて不思議な感じが出せていると思います。
[ 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 "ofFbo.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 number_of_frames = 350; cv::Mat save_frames[number_of_frames]; cv::Mat blend_frame; ofImage blend_image; int size; vector<vector<float>> values; }; |
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 |
#include "ofApp.h" //-------------------------------------------------------------- void ofApp::setup() { ofSetFrameRate(25); ofBackground(0); ofSetWindowTitle("Insta"); this->size = 2; this->cap.open("D:\\video\\image9.mp4"); this->cap_size = cv::Size(1280, 720); 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); for (int i = 0; i < this->number_of_frames; i++) { cv::Mat src, mini_src; this->cap >> src; if (src.empty()) { break; } cv::resize(src, mini_src, this->cap_size); cv::cvtColor(mini_src, mini_src, CV_RGB2BGR); mini_src.copyTo(this->save_frames[(this->number_of_frames - 1) - i]); } } //-------------------------------------------------------------- void ofApp::update() { this->values.clear(); float x_count = ofGetWidth() / this->size; float y_count = ofGetHeight() / this->size; for (int y = 0; y < y_count; y++) { vector<float> tmp_values; for (int x = 0; x < x_count; x++) { if (y == 0) { float value = ofMap(ofNoise(x * 0.01, ofGetFrameNum() * 0.005), 0, 1, 0, this->number_of_frames); tmp_values.push_back(value); } else { float value = 0; int count = 0; for (int tmp_x = x - 1; tmp_x <= x + 1; tmp_x++) { if (tmp_x >= 0 && tmp_x < x_count) { value += this->values[y - 1][tmp_x]; count++; } } if (y >= 2) { value += this->values[y - 2][x]; count++; } float average = value / count + ofMap(ofNoise(x * 0.03, y * 0.01 - ofGetFrameNum() * 0.05), 0, 1, -0.5, 0.5); if (average > this->number_of_frames) { average = this->number_of_frames; } else if (average < 0) { average = 0; } tmp_values.push_back(average); } } this->values.push_back(tmp_values); } for (int y = 0; y < this->blend_frame.rows; y += 1) { for (int x = 0; x < this->blend_frame.cols; x += 1) { int tmp_x = x / this->size; int tmp_y = y / this->size; int index = this->values[tmp_y][tmp_x]; this->blend_frame.at<cv::Vec3b>(y, x) = this->save_frames[index].at<cv::Vec3b>(y, x); } } this->blend_image.update(); } //-------------------------------------------------------------- void ofApp::draw() { this->blend_image.draw(0, 0); } //======================================================================== int main() { ofSetupOpenGL(1280, 720, OF_WINDOW); ofRunApp(new ofApp()); } |