[ Video ]
[ About ]
動画のピクセル値を文字に変換。
Changing video to Ascii.
[ 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 |
#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; cv::Size cap_size; ofTrueTypeFont font; 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 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
#include "ofApp.h" //-------------------------------------------------------------- void ofApp::setup() { ofSetFrameRate(30); ofSetWindowTitle("openFrameworks"); ofBackground(239); ofSetColor(0); ofEnableDepthTest(); ofSetRectMode(ofRectMode::OF_RECTMODE_CENTER); this->cap.open("D:\\Pexels Videos 2441067.mp4"); this->cap_size = cv::Size(1280, 720); this->cap.set(cv::CAP_PROP_POS_FRAMES, 90 * 24); // Sec * FrameRate this->font.loadFont("fonts/Kazesawa-Bold.ttf", 5, true, true, true); } //-------------------------------------------------------------- void ofApp::update() { ofSeedRandom(39); cv::Mat src; this->cap >> src; if (src.empty()) { this->cap.set(cv::CAP_PROP_POS_FRAMES, 1); return; } cv::resize(src, this->frame, this->cap_size); cv::cvtColor(this->frame, this->frame, cv::COLOR_BGR2GRAY); } //-------------------------------------------------------------- void ofApp::draw() { this->cam.begin(); char moji[11] = { ' ', '#', 'M', 'W', 'A', 'B', 'G', 'C', 'L', 'I', 'T' }; int value; for (int y = 0; y < this->frame.rows; y += 5) { for (int x = 0; x < this->frame.cols; x += 5) { value = this->frame.at<unsigned char>(y, x); if (value < 150) { this->font.drawStringAsShapes(string{ moji[(int)ofMap(value, 0, 150, 0, 11)] }, x - 640, 360 - y); } } } this->cam.end(); } //-------------------------------------------------------------- int main() { ofSetupOpenGL(1280, 720, OF_WINDOW); ofRunApp(new ofApp()); } |