[ Video ]
[ About ]
昨日の落書きに高さの概念を加えてみました。
PixelがBoxに変更されて、Noiseによって選ばれたFrame NumberがBoxの高さになっています。背の高いBoxほど最新の情報が見えて、背の低いBoxには古い情報です。Boxにすることでそれぞれの時間の違いが可視化されて、厚みとして見ることができるようになりました。
[ 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 |
#pragma once #include "ofMain.h" #include "ofxBullet.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; ofLight light; cv::VideoCapture cap; static const int frame_number = 120; cv::Mat save_frame[frame_number]; cv::Mat blend_frame; ofImage blend_image; cv::Mat wipe_frame; ofImage wipe_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 86 87 88 89 90 91 92 93 94 |
#include "ofApp.h" //-------------------------------------------------------------- void ofApp::setup() { ofSetFrameRate(60); ofBackground(255); ofSetWindowTitle("Insta"); ofEnableDepthTest(); ofSetRectMode(ofRectMode::OF_RECTMODE_CENTER); this->cap.open(1); this->blend_image.allocate(this->cap.get(CV_CAP_PROP_FRAME_WIDTH), this->cap.get(CV_CAP_PROP_FRAME_HEIGHT), OF_IMAGE_COLOR_ALPHA); this->blend_frame = cv::Mat(this->blend_image.getHeight(), this->blend_image.getWidth(), CV_MAKETYPE(CV_8UC4, this->blend_image.getPixels().getNumChannels()), this->blend_image.getPixels().getData(), 0); this->wipe_image.allocate(this->cap.get(CV_CAP_PROP_FRAME_WIDTH) * 0.3, this->cap.get(CV_CAP_PROP_FRAME_HEIGHT) * 0.3, OF_IMAGE_COLOR); this->wipe_frame = cv::Mat(this->wipe_image.getHeight(), this->wipe_image.getWidth(), CV_MAKETYPE(CV_8UC3, this->wipe_image.getPixels().getNumChannels()), this->wipe_image.getPixels().getData(), 0); } //-------------------------------------------------------------- void ofApp::update() { cv::Mat src; this->cap >> src; cv::cvtColor(src, src, cv::COLOR_BGR2RGB); cv::flip(src, src, 1); 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.06) * this->frame_number; this->blend_frame.at<cv::Vec4b>(y, x) = cv::Vec4b(this->save_frame[index].at<cv::Vec3b>(y, x)[0], this->save_frame[index].at<cv::Vec3b>(y, x)[1], this->save_frame[index].at<cv::Vec3b>(y, x)[2], index); } } this->blend_image.update(); } cv::resize(src, this->wipe_frame, cv::Size(), 0.3, 0.3); this->wipe_image.update(); this->light.setPosition(ofVec3f(0, 0, 512)); ofEnableLighting(); this->light.enable(); } //-------------------------------------------------------------- void ofApp::draw() { this->cam.begin(); ofSetColor(255); this->wipe_image.draw(0, -250); if (ofGetFrameNum() > this->frame_number) { int size = 5; for (int y = 0; y < this->blend_frame.rows; y += size) { for (int x = 0; x < this->blend_frame.cols; x += size) { ofSetColor(this->blend_frame.at<cv::Vec4b>(y, x)[0], this->blend_frame.at<cv::Vec4b>(y, x)[1], this->blend_frame.at<cv::Vec4b>(y, x)[2]); int height = this->frame_number - this->blend_frame.at<cv::Vec4b>(y, x)[3]; ofPushMatrix(); ofTranslate(0, 0, height / 2); ofDrawBox(ofVec3f(x - 320, ofGetHeight() / 2 - y, 0), size, size, height); ofPopMatrix(); } } } this->cam.end(); } //======================================================================== int main() { ofSetupOpenGL(720, 720, OF_WINDOW); ofRunApp(new ofApp()); } |