[ Video ]
[ About ]
For PCD Japan 2021, we organize Daily Coding Week from Feb 13th! We made a "prompt list" as themes of the day, and those works tweeted with #PCD2021 by 23:59 (UTC+9) will be automatically included in our 3D online gallery! Use your favorite tool (not only p5/p5js) for submission! pic.twitter.com/WjcOwu1fnP
— PCD Japan (@PCD_Tokyo) February 11, 2021
[ 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 34 35 36 37 38 |
#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) {}; ofEasyCam cam; ofTrueTypeFont font; cv::VideoCapture cap; cv::Size cap_size; ofImage image; cv::Mat frame; cv::Mat gray; ofImage gray_image; cv::Mat edge; ofImage edge_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 71 72 73 74 75 76 77 78 |
#include "ofApp.h" //-------------------------------------------------------------- void ofApp::setup() { ofSetFrameRate(25); ofSetWindowTitle("openFrameworks"); ofBackground(239); ofSetRectMode(ofRectMode::OF_RECTMODE_CENTER); this->font.loadFont("fonts/Kazesawa-Bold.ttf", 100, true, true, true); this->cap.open("D:\\MP4\\Pexels Videos 2880.mp4"); this->cap_size = cv::Size(1280, 720); this->image.allocate(this->cap_size.width, this->cap_size.height, OF_IMAGE_COLOR); this->frame = cv::Mat(cv::Size(this->image.getWidth(), this->image.getHeight()), CV_MAKETYPE(CV_8UC3, this->image.getPixels().getNumChannels()), this->image.getPixels().getData(), 0); this->gray_image.allocate(this->cap_size.width, this->cap_size.height, OF_IMAGE_GRAYSCALE); this->gray = cv::Mat(this->gray_image.getHeight(), this->gray_image.getWidth(), CV_MAKETYPE(CV_8U, this->gray_image.getPixels().getNumChannels()), this->gray_image.getPixels().getData(), 0); this->edge_image.allocate(this->cap_size.width, this->cap_size.height, OF_IMAGE_GRAYSCALE); this->edge = cv::Mat(this->edge_image.getHeight(), this->edge_image.getWidth(), CV_MAKETYPE(CV_8U, this->edge_image.getPixels().getNumChannels()), this->edge_image.getPixels().getData(), 0); } //-------------------------------------------------------------- void ofApp::update() { cv::Mat cap_frame; this->cap >> cap_frame; if (cap_frame.empty()) { cap.set(cv::CAP_PROP_POS_FRAMES, 1); return; } cv::resize(cap_frame, this->frame, this->cap_size); cv::cvtColor(this->frame, this->frame, cv::COLOR_BGR2RGB); cv::cvtColor(this->frame, this->gray, cv::COLOR_RGB2GRAY); this->frame.forEach<cv::Vec3b>([](cv::Vec3b& p, const int* position) -> void { p[0] = floor(p[0] / 30) * 30; p[1] = floor(p[1] / 30) * 330; p[2] = floor(p[2] / 30) * 30; }); cv::Canny(this->gray, this->edge, 10, 200); cv::Mat color_edge; cv::cvtColor(this->edge, color_edge, cv::COLOR_GRAY2RGB); cv::subtract(this->frame, color_edge, this->frame); this->image.update(); this->gray_image.update(); this->edge_image.update(); } //-------------------------------------------------------------- void ofApp::draw() { this->cam.begin(); ofSetColor(255); this->image.draw(0, 0); ofSetColor(239); string word = "PCD 2021"; this->font.drawStringAsShapes(word, this->font.stringWidth(word) * -0.5, this->font.stringHeight(word) * 0.5); } //-------------------------------------------------------------- int main() { ofSetupOpenGL(720, 720, OF_WINDOW); ofRunApp(new ofApp()); } |