[ Video ]
[ About ]
世界一かわいい猫が同時に楽しめます。
You can enjoy the world’s cutest cat at the same time.
[ 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 |
#pragma once #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 windowResized(int w, int h) {}; void dragEvent(ofDragInfo dragInfo) {}; void gotMessage(ofMessage msg) {}; ofEasyCam cam; cv::VideoCapture cap_1, cap_2; cv::Size cap_size; int number_of_frames_1, number_of_frames_2; vector<cv::Mat> frame_list_1, frame_list_2; float rect_size; vector<cv::Mat> rect_frames; vector<unique_ptr<ofImage>> rect_images; vector<cv::Rect> cv_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 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 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 |
#include "ofApp.h" //-------------------------------------------------------------- void ofApp::setup() { ofSetFrameRate(60); ofSetWindowTitle("openFrameworks"); ofBackground(239); ofSetLineWidth(2); ofEnableDepthTest(); ofDisableArbTex(); this->cap_1.open("D:\\MP4\\VN20210917_143130.mp4"); this->cap_size = cv::Size(640, 360); this->rect_size = 40; for (int x = 0; x < this->cap_size.width; x += this->rect_size) { for (int y = 0; y < this->cap_size.height; y += this->rect_size) { auto image = make_unique<ofImage>(); image->allocate(this->rect_size, this->rect_size, OF_IMAGE_COLOR); cv::Mat frame = cv::Mat(cv::Size(image->getWidth(), image->getHeight()), CV_MAKETYPE(CV_8UC3, image->getPixels().getNumChannels()), image->getPixels().getData(), 0); cv::Rect rect = cv::Rect(x, y, this->rect_size, this->rect_size); this->rect_images.push_back(move(image)); this->cv_rects.push_back(rect); this->rect_frames.push_back(frame); } } this->number_of_frames_1 = this->cap_1.get(cv::CAP_PROP_FRAME_COUNT); for (int i = 0; i < this->number_of_frames_1; i++) { cv::Mat src, tmp; this->cap_1 >> src; if (src.empty()) { return; } cv::resize(src, tmp, this->cap_size); cv::cvtColor(tmp, tmp, cv::COLOR_BGR2RGB); this->frame_list_1.push_back(tmp); } this->cap_2.open("D:\\MP4\\MOV_0324.mp4"); this->number_of_frames_2 = this->cap_2.get(cv::CAP_PROP_FRAME_COUNT); for (int i = 0; i < this->number_of_frames_2; i++) { cv::Mat src, tmp; this->cap_2 >> src; if (src.empty()) { return; } cv::resize(src, tmp, this->cap_size); cv::cvtColor(tmp, tmp, cv::COLOR_BGR2RGB); this->frame_list_2.push_back(tmp); } } //-------------------------------------------------------------- void ofApp::update() { } //-------------------------------------------------------------- void ofApp::draw() { this->cam.begin(); ofTranslate(this->cap_size.width * -0.5 + 20, this->cap_size.height * -0.5 - 20, 0); for (int i = 0; i < this->rect_frames.size(); i += 1) { ofPushMatrix(); ofTranslate(this->cv_rects[i].x, this->cap_size.height - this->cv_rects[i].y, 0); float noise_value = ofNoise(this->cv_rects[i].x * 0.0025, this->cv_rects[i].y * 0.0025, ofGetFrameNum() * 0.008); float deg = 0; if (noise_value <= 0.45) { deg = 0; } if (noise_value > 0.45 && noise_value < 0.55) { deg = ofMap(noise_value, 0.45, 0.55, 0, 180); } if (noise_value >= 0.55) { deg = 180; } ofRotateY(deg); int frame_index = ofGetFrameNum() % this->number_of_frames_1; cv::Mat tmp_box_image_1(this->frame_list_1[frame_index], this->cv_rects[i]); tmp_box_image_1.copyTo(this->rect_frames[i]); this->rect_images[i]->update(); this->rect_images[i]->getTexture().bind(); ofSetColor(255); ofFill(); ofDrawBox(glm::vec3(0, 0, 1), this->rect_size, this->rect_size, 1); this->rect_images[i]->unbind(); ofSetColor(39); ofNoFill(); ofDrawBox(glm::vec3(0, 0, 1), this->rect_size, this->rect_size, 1); ofPopMatrix(); } for (int i = 0; i < this->rect_frames.size(); i += 1){ ofPushMatrix(); ofTranslate(this->cv_rects[i].x, this->cap_size.height - this->cv_rects[i].y, 0); float noise_value = ofNoise(this->cv_rects[i].x * 0.0025, this->cv_rects[i].y * 0.0025, ofGetFrameNum() * 0.008); float deg = 0; if (noise_value <= 0.45) { deg = 0; } if (noise_value > 0.45 && noise_value < 0.55) { deg = ofMap(noise_value, 0.45, 0.55, 0, 180); } if (noise_value >= 0.55) { deg = 180; } ofRotateY(deg); int frame_index = ofGetFrameNum() % this->number_of_frames_2; cv::Mat tmp_box_image_2(this->frame_list_2[frame_index], this->cv_rects[i]); tmp_box_image_2.copyTo(this->rect_frames[i]); this->rect_images[i]->update(); this->rect_images[i]->getTexture().bind(); ofSetColor(255); ofFill(); ofDrawBox(glm::vec3(0, 0, -1), this->rect_size, this->rect_size, 1); this->rect_images[i]->unbind(); ofSetColor(39); ofNoFill(); ofDrawBox(glm::vec3(0, 0, -1), this->rect_size, this->rect_size, 1); ofPopMatrix(); } this->cam.end(); } //-------------------------------------------------------------- int main() { ofSetupOpenGL(720, 720, OF_WINDOW); ofRunApp(new ofApp()); } |