[ Video ]
[ About ]
Dance & Frame Difference.
Video source -> https://www.pexels.com/ja-jp/video/2795744/
[ 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 |
#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; int number_of_frames; vector<cv::Mat> frame_list; cv::Mat view_mat; ofImage view_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 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
#include "ofApp.h" //-------------------------------------------------------------- void ofApp::setup() { ofSetFrameRate(25); ofSetWindowTitle("openFrameworks"); ofBackground(239); ofSetColor(255); ofEnableDepthTest(); this->cap_size = cv::Size(1920, 1080); this->view_image.allocate(this->cap_size.width, this->cap_size.height, OF_IMAGE_COLOR); this->view_mat = cv::Mat(this->view_image.getHeight(), this->view_image.getWidth(), CV_MAKETYPE(CV_8UC3, this->view_image.getPixels().getNumChannels()), this->view_image.getPixels().getData(), 0); this->number_of_frames = 0; auto file_path = "D:\\MP4\\Pexels Videos 2795744.mp4"; this->cap.open(file_path); int frame_count = this->cap.get(cv::CAP_PROP_FRAME_COUNT); int read_count = 0; for (int i = 0; i < frame_count; i++) { cv::Mat src, tmp; this->cap >> src; if (src.empty()) { continue; } cv::resize(src, tmp, this->cap_size); cv::cvtColor(tmp, tmp, cv::COLOR_BGR2RGB); this->frame_list.push_back(tmp); read_count++; } this->number_of_frames += read_count; cout << number_of_frames << endl; } //-------------------------------------------------------------- void ofApp::update() { int blend_count = 4; int blend_span = 5; cv::Mat blend; for (int i = blend_count; i > 0; i--) { int frame_index = (ofGetFrameNum() + i * blend_span) % this->number_of_frames; if (i == blend_count) { this->frame_list[frame_index].copyTo(blend); } else { int prev_frame_index = (ofGetFrameNum() + (i - 1) *blend_span) % this->number_of_frames; cv::Mat tmp = this->frame_list[frame_index] - this->frame_list[prev_frame_index]; tmp -= 255; blend += tmp; } } blend.copyTo(this->view_mat); this->view_image.update(); } //-------------------------------------------------------------- void ofApp::draw() { this->cam.begin(); this->view_image.draw(this->view_image.getWidth() * -0.5, this->view_image.getHeight() * -0.5); this->cam.end(); } //-------------------------------------------------------------- int main() { ofSetupOpenGL(720, 720, OF_WINDOW); ofRunApp(new ofApp()); } |