[ Video ]
[ About ]
2種類の動画を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 28 | #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_1; 	cv::VideoCapture cap_2; 	cv::Size cap_size; 	cv::Mat blend_frame; 	ofImage blend_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 70 | #include "ofApp.h" //-------------------------------------------------------------- void ofApp::setup() { 	ofSetFrameRate(30); 	ofBackground(39); 	ofSetWindowTitle("Insta"); 	this->cap_size = cv::Size(1280, 720); 	this->cap_1.open("D:\\video\\beach.mp4"); 	this->cap_2.open("D:\\video\\city2.mp4"); 	this->blend_image.allocate(this->cap_size.width, this->cap_size.height, OF_IMAGE_COLOR); 	this->blend_frame = cv::Mat(this->blend_image.getHeight(), this->blend_image.getWidth(), CV_MAKETYPE(CV_8UC3, this->blend_image.getPixels().getNumChannels()), this->blend_image.getPixels().getData(), 0); } //-------------------------------------------------------------- void ofApp::update() { 	cv::Mat src_1, src_2, mini_1, mini_2; 	this->cap_1 >> src_1; 	if (src_1.empty()) { 		this->cap_1.set(CV_CAP_PROP_POS_FRAMES, 1); 		return; 	} 	this->cap_2 >> src_2; 	if (src_2.empty()) { 		this->cap_2.set(CV_CAP_PROP_POS_FRAMES, 1); 		return; 	} 	cv::resize(src_1, mini_1, this->cap_size); 	cv::resize(src_2, mini_2, this->cap_size); 	for (int x = 0; x < this->blend_frame.cols; x += 1) { 		for (int y = 0; y < this->blend_frame.rows; y += 1) { 			float noise_value = ofNoise(x * 0.005, y * 0.005, ofGetFrameNum() * 0.005); 			if (noise_value < 0.5) { 				this->blend_frame.at<cv::Vec3b>(y, x) = mini_1.at<cv::Vec3b>(y, x); 			} 			else { 				this->blend_frame.at<cv::Vec3b>(y, x) = mini_2.at<cv::Vec3b>(y, x); 			} 		} 	} 	cv::cvtColor(this->blend_frame, this->blend_frame, CV_BGR2RGB); 	this->blend_image.update(); } //-------------------------------------------------------------- void ofApp::draw() { 	this->blend_image.draw(0, 0); } //-------------------------------------------------------------- int main() { 	ofSetupOpenGL(1280, 720, OF_WINDOW); 	ofRunApp(new ofApp()); } |