[ Video ]
[ About ]
奥行が感じれる(かもしれない)画面を作ってみまいた。だいぶ前にSNSで見かけてやってみたかったヤツです。視点の認識はOpenCVの顔認識を使いました。
Surfaceの内蔵センサーの値を使っても何かしらできそう。
[ 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 |
#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) {} // Make Member cv::VideoCapture cap; cv::Size cap_size; cv::Mat src, mini_src; cv::CascadeClassifier face_cascade; ofPoint gap; }; |
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 |
#include "ofApp.h" //-------------------------------------------------------------- void ofApp::setup() { ofSetFrameRate(60); ofBackground(39); ofSetWindowTitle("Insta"); ofEnableDepthTest(); ofSetLineWidth(2); this->cap.open(1); this->cap_size = cv::Size(320, 180); this->face_cascade.load("opencv-3.4.1\\build\\install\\etc\\haarcascades\\haarcascade_frontalface_default.xml"); this->gap = ofPoint(0, 0); } //-------------------------------------------------------------- void ofApp::update() { this->cap >> src; cv::resize(src, mini_src, this->cap_size); vector<cv::Rect> faces; this->face_cascade.detectMultiScale(mini_src, faces); if(faces.size() > 0){ this->gap = ofPoint(ofMap(faces[0].x + faces[0].width / 2, 0, this->cap_size.width, 30, -30), ofMap(faces[0].y, 0, this->cap_size.height, -30, 30)); } cv::imshow("mini_src", mini_src); cv::waitKey(1); } //-------------------------------------------------------------- void ofApp::draw() { ofTranslate(ofGetWidth() / 2, ofGetHeight() / 2); for (int z = 0; z > -600; z += -20) { ofFill(); ofSetColor(239, ofMap(z, 0, -600, 255, 0)); ofBeginShape(); ofVertex(ofGetWidth() * 0.5, ofGetHeight() * 0.5, z); ofVertex(-ofGetWidth() * 0.5, ofGetHeight() * 0.5, z); ofVertex(-ofGetWidth() * 0.5, -ofGetHeight() * 0.5, z); ofVertex(ofGetWidth() * 0.5, -ofGetHeight() * 0.5, z); ofNextContour(true); ofVertex(ofGetWidth() * 0.47, ofGetHeight() * 0.47, z); ofVertex(-ofGetWidth() * 0.47, ofGetHeight() * 0.47, z); ofVertex(-ofGetWidth() * 0.47, -ofGetHeight() * 0.47, z); ofVertex(ofGetWidth() * 0.47, -ofGetHeight() * 0.47, z); ofEndShape(true); ofNoFill(); ofSetColor(39); ofBeginShape(); ofVertex(ofGetWidth() * 0.47, ofGetHeight() * 0.47, z); ofVertex(-ofGetWidth() * 0.47, ofGetHeight() * 0.47, z); ofVertex(-ofGetWidth() * 0.47, -ofGetHeight() * 0.47, z); ofVertex(ofGetWidth() * 0.47, -ofGetHeight() * 0.47, z); ofEndShape(true); ofTranslate(this->gap.x, this->gap.y); } } //-------------------------------------------------------------- int main() { ofSetupOpenGL(1920, 1080, OF_WINDOW); ofRunApp(new ofApp()); } |