[ Video ]
[ About ]
WebCameraの映像を再帰でデフォルメしてみました。
[ 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 34 35 36 37 38 39 40  | 
						#include "ofApp.h" //-------------------------------------------------------------- void ofApp::setup() { 	ofSetFrameRate(60); 	ofBackground(0); 	ofSetWindowTitle("Insta"); 	ofSetRectMode(ofRectMode::OF_RECTMODE_CENTER); 	ofSetLineWidth(0.3); 	this->cap.open(1); 	this->cap.set(cv::CAP_PROP_FRAME_WIDTH, 640); 	this->cap.set(cv::CAP_PROP_FRAME_HEIGHT, 640); } //-------------------------------------------------------------- void ofApp::update() { 	this->cap >> this->frame; 	if (this->frame.empty()) { 		return; 	} 	cv::flip(this->frame, this->frame, 1); 	if (ofGetFrameNum() % 90 == 0) { 		this->r_rect = RecuRect(8, ofVec2f(ofGetWidth() / 2, ofGetHeight() / 2), 640, true); 	} 	this->r_rect.update(); } //-------------------------------------------------------------- void ofApp::draw() { 	r_rect.draw(this->frame); }  | 
					
| 
					 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  | 
						#include "RecuRect.h" RecuRect::RecuRect() { } RecuRect::RecuRect(int level, ofVec2f location, float size, bool origin) { 	if (level > 0) { 		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->type = ofRandom(100); 	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); 	} }  |