[ Video ]
[ About ]
OpenCVで取得した動画の色情報を、円に転写。それぞれの円をNoise関数でユラユラさせました
[ 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 |
#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) {}; cv::VideoCapture cap; cv::Mat cap_frame; ofImage cap_image; cv::Size cap_size; }; |
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 |
#include "ofApp.h" //-------------------------------------------------------------- void ofApp::setup() { ofSetFrameRate(60); ofBackground(39); ofSetWindowTitle("Insta"); ofSetLineWidth(3); this->cap.open("D:\\video\\image2.mp4"); this->cap_size = cv::Size(1280, 720); this->cap_image.allocate(this->cap_size.width, this->cap_size.height, OF_IMAGE_COLOR); this->cap_frame = cv::Mat(this->cap_image.getHeight(), this->cap_image.getWidth(), CV_MAKETYPE(CV_8UC3, this->cap_image.getPixels().getNumChannels()), this->cap_image.getPixels().getData(), 0); } //-------------------------------------------------------------- void ofApp::update() { cv::Mat origin; this->cap >> origin; if (origin.empty()) { this->cap.set(CV_CAP_PROP_POS_FRAMES, 1); return; } cv::resize(origin, this->cap_frame, this->cap_size); cv::cvtColor(this->cap_frame, this->cap_frame, CV_BGR2RGB); this->cap_image.update(); } //-------------------------------------------------------------- void ofApp::draw() { ofTranslate(ofGetWidth() * 0.5, ofGetHeight() * 0.5); for (int radius = 0; radius < 720; radius += 10) { float noise_value = ofMap(ofNoise(radius * 0.005 + ofGetFrameNum() * 0.05), 0, 1, -60, 60); ofPushMatrix(); ofRotate(noise_value); for (int deg = 0; deg < 360; deg++) { int x = radius * cos(deg * DEG_TO_RAD); int y = radius * sin(deg * DEG_TO_RAD); int x_index = x + this->cap_size.width * 0.5; int y_index = y + this->cap_size.height * 0.5; if (x_index < 0 || x_index >= this->cap_size.width || y_index < 0 || y_index >= this->cap_size.height) { continue; } ofColor color(this->cap_frame.at<cv::Vec3b>(y_index, x_index)[0], this->cap_frame.at<cv::Vec3b>(y_index, x_index)[1], this->cap_frame.at<cv::Vec3b>(y_index, x_index)[2]); ofSetColor(color); int next_x = radius * cos((deg + 1) * DEG_TO_RAD); int next_y = radius * sin((deg + 1) * DEG_TO_RAD); ofDrawLine(x, y, next_x, next_y); } ofPopMatrix(); } } //-------------------------------------------------------------- int main() { ofSetupOpenGL(1280, 720, OF_WINDOW); ofRunApp(new ofApp()); } |