[ 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 |
#pragma once #include "ofMain.h" #include "opencv2/opencv.hpp" #include "RecuRect.h" 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) {}; RecuRect r_rect; cv::VideoCapture cap; cv::Mat frame; }; |
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 |
#include "ofApp.h" //-------------------------------------------------------------- void ofApp::setup() { ofSetFrameRate(60); ofBackground(0); ofSetWindowTitle("Insta"); ofSetRectMode(ofRectMode::OF_RECTMODE_CENTER); this->frame = cv::imread("D:\\video\\image.jpg"); } //-------------------------------------------------------------- void ofApp::update() { this->r_rect = RecuRect(9, ofVec2f(ofGetWidth() / 2, ofGetHeight() / 2), 1280, true); this->r_rect.update(); } //-------------------------------------------------------------- void ofApp::draw() { r_rect.draw(this->frame); } //======================================================================== int main() { ofSetupOpenGL(1280, 1280, OF_WINDOW); ofRunApp(new ofApp()); } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
#pragma once #include "ofMain.h" #include "opencv2/opencv.hpp" class RecuRect { public: RecuRect(); RecuRect(int level, ofVec2f location, float size, bool origin = false); ~RecuRect(); void update(); void draw(cv::Mat frame); private: int level; ofVec2f location; float size; int type; bool origin; std::vector<RecuRect> rects; }; |
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 |
#include "RecuRect.h" RecuRect::RecuRect() { } RecuRect::RecuRect(int level, ofVec2f location, float size, bool origin) { //this->type = ofRandom(100); this->type = ofNoise(location.x * 0.005, location.y * 0.005, ofGetFrameNum() * 0.05) * 100; if (this->origin || (level > 0 && this->type < 80)) { this->rects.push_back(RecuRect(level - 1, ofVec2f(location.x - size / 4, location.y - size / 4), size / 2)); this->rects.push_back(RecuRect(level - 1, ofVec2f(location.x - size / 4, location.y + size / 4), size / 2)); this->rects.push_back(RecuRect(level - 1, ofVec2f(location.x + size / 4, location.y - size / 4), size / 2)); this->rects.push_back(RecuRect(level - 1, ofVec2f(location.x + size / 4, location.y + size / 4), size / 2)); } this->level = level; this->location = location; this->size = size; this->origin = origin; } RecuRect::~RecuRect() { } void RecuRect::update() { } void RecuRect::draw(cv::Mat frame) { if (this->origin || (this->level != 0 && this->type < 80)) { for (int i = 0; i < this->rects.size(); i++) { this->rects[i].draw(frame); } } else { cv::Vec3b frame_color = frame.at<cv::Vec3b>((int)this->location.y, (int)this->location.x); ofColor color = ofColor(frame_color[2], frame_color[1], frame_color[0]); ofSetColor(color); ofDrawRectangle(this->location, this->size, this->size); } } |