Skip to content

Instantly share code, notes, and snippets.

@micromeeeter
Created September 9, 2017 02:57
Show Gist options
  • Save micromeeeter/20a203269ff41b832e9823664d1c4547 to your computer and use it in GitHub Desktop.
Save micromeeeter/20a203269ff41b832e9823664d1c4547 to your computer and use it in GitHub Desktop.
transboundary :: webcam
#include "ofMain.h"
#include "ofApp.h"
//========================================================================
int main( ){
ofSetupOpenGL(1024,768,OF_WINDOW); // <-------- setup the GL context
// this kicks off the running of my app
// can be OF_WINDOW or OF_FULLSCREEN
// pass in width and height too:
ofRunApp(new ofApp());
}
#include "ofApp.h"
//--------------------------------------------------------------
void ofApp::setup(){
// ofSetWindowPosition(2561, 0); //拡張ディスプレイ上でフルスクリーン
// ofSetFullscreen(true);
// ofHideCursor();
//webcam
camWidth = ofGetWidth() / 2;
camHeight = ofGetWidth() / 16 * 9;;
vector<ofVideoDevice> devices = cam1.listDevices();
for(int i = 0; i < devices.size(); i++){
if(devices[i].bAvailable){
ofLogNotice() << devices[i].id << ": " << devices[i].deviceName;
}else{
ofLogNotice() << devices[i].id << ": " << devices[i].deviceName << " - unavailable ";
}
}
ofEnableAlphaBlending();
cam1.setVerbose(true); //画面左側
cam1.listDevices();
cam1.setDeviceID(1);
cam1.initGrabber(camWidth, camHeight);
cam2.setVerbose(true); //画面右側
cam2.listDevices();
cam2.setDeviceID(2);
cam2.initGrabber(camWidth, camHeight);
}
//--------------------------------------------------------------
void ofApp::update(){
ofSetWindowTitle(ofToString(ofToString(ofGetFrameRate()))); //ウィンドウの上のバーにフレームレートを表示
cam1.update();
cam2.update();
}
//--------------------------------------------------------------
void ofApp::draw(){
ofBackground(0, 0, 0);
cam1.draw(0, ofGetHeight() / 2 - camHeight / 2, camWidth, camHeight);
cam2.draw(camWidth, ofGetHeight() / 2 - camHeight / 2, camWidth, camHeight);
}
#pragma once
#include "ofMain.h"
class ofApp : public ofBaseApp{
public:
void setup();
void update();
void draw();
ofVideoGrabber cam1, cam2; //webcamからの入力映像
int camWidth, camHeight;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment