[ Video ]
[ About ]
Instagramで夜景を分割+ズラすという画像をアップされている方がいて、カッコいいなと思ったので、インスパイアされ(パクり)ました。画像のピクセル処理はOpenCVを使っていますが、仕組み的にはofImageを使ってopenFrameworksで完結できるはずです。
[ 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 |
#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 mouseEntered(int x, int y) {}; void mouseExited(int x, int y) {}; void windowResized(int w, int h) {}; void dragEvent(ofDragInfo dragInfo) {}; void gotMessage(ofMessage msg) {}; ofFbo fbo; cv::VideoCapture cap; cv::Size cap_size; cv::Mat frame; ofImage 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 |
#include "ofApp.h" //-------------------------------------------------------------- void ofApp::setup() { ofSetFrameRate(60); ofBackground(0); ofSetWindowTitle("Insta"); this->cap.open("D:\\video\\beach.mp4"); this->cap_size = cv::Size(1280, 720); ofSetFrameRate(this->cap.get(CV_CAP_PROP_FPS)); this->image.allocate(this->cap_size.width, this->cap_size.height, OF_IMAGE_COLOR); this->frame = cv::Mat(this->image.getHeight(), this->image.getWidth(), CV_MAKETYPE(CV_8UC3, this->image.getPixels().getNumChannels()), this->image.getPixels().getData(), 0); } //-------------------------------------------------------------- void ofApp::update() { cv::Mat cap_frame, src, blend_frame; this->cap >> cap_frame; if (cap_frame.empty()) { cap.set(CV_CAP_PROP_POS_FRAMES, 1); return; } cv::resize(cap_frame, src, this->cap_size); cv::cvtColor(src, src, CV_RGB2BGR); blend_frame = cv::Mat::zeros(this->frame.size(), this->frame.type()); int gap = 0; int tmp_y = 0; for (int x = 0; x < src.cols; x++) { if (x % 30 == 0) { gap = ofMap(ofNoise(x * 0.005, ofGetFrameNum() * 0.005), 0, 1, -50, 50); } for (int y = 0; y < src.rows; y++) { tmp_y = y + gap; if (tmp_y >= 0 && tmp_y < src.rows) { blend_frame.at<cv::Vec3b>(tmp_y, x) = src.at<cv::Vec3b>(y, x); } } } blend_frame.copyTo(this->frame); this->image.update(); } //-------------------------------------------------------------- void ofApp::draw() { this->image.draw(0, 0); } //-------------------------------------------------------------- int main() { ofSetupOpenGL(1280, 720, OF_WINDOW); ofRunApp(new ofApp()); } |