Created
September 18, 2017 20:29
-
-
Save vanderlin/40425b495e942dffac24a361d8a25df1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "ofApp.h" | |
vector<ofVideoDevice> devices; | |
int deviceCount = 0; | |
ofVideoGrabber vidGrabber; | |
int camWidth; | |
int camHeight; | |
//-------------------------------------------------------------- | |
void ofApp::setup() { | |
camWidth = 320; | |
camHeight = 240; | |
devices = vidGrabber.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 "; | |
} | |
} | |
setDevice(devices[0]); | |
ofSetVerticalSync(true); | |
} | |
//-------------------------------------------------------------- | |
void ofApp::update(){ | |
vidGrabber.update(); | |
} | |
//-------------------------------------------------------------- | |
void ofApp::draw(){ | |
ofSetHexColor(0xffffff); | |
vidGrabber.draw(20, 20); | |
} | |
//-------------------------------------------------------------- | |
void ofApp::setDevice(ofVideoDevice &device) { | |
if(vidGrabber.isInitialized()) { | |
vidGrabber.close(); | |
} | |
cout << "Device " << device.deviceName << " ID " << device.id << endl; | |
vidGrabber.setDeviceID(device.id); | |
vidGrabber.initGrabber(camWidth, camHeight); | |
camWidth = vidGrabber.getWidth(); camHeight = vidGrabber.getHeight(); | |
} | |
//-------------------------------------------------------------- | |
void ofApp::keyPressed(int key){ | |
if (key == OF_KEY_UP) { | |
deviceCount ++; | |
deviceCount %= devices.size(); | |
setDevice(devices[deviceCount]); | |
} | |
if (key == OF_KEY_DOWN) { | |
deviceCount ++; | |
if(deviceCount < 0) { | |
deviceCount = devices.size()-1; | |
} | |
setDevice(devices[deviceCount]); | |
} | |
} | |
//-------------------------------------------------------------- | |
void ofApp::keyReleased(int key){ | |
} | |
//-------------------------------------------------------------- | |
void ofApp::mouseMoved(int x, int y){ | |
} | |
//-------------------------------------------------------------- | |
void ofApp::mouseDragged(int x, int y, int button){ | |
} | |
//-------------------------------------------------------------- | |
void ofApp::mousePressed(int x, int y, int button){ | |
} | |
//-------------------------------------------------------------- | |
void ofApp::mouseReleased(int x, int y, int button){ | |
} | |
//-------------------------------------------------------------- | |
void ofApp::mouseEntered(int x, int y){ | |
} | |
//-------------------------------------------------------------- | |
void ofApp::mouseExited(int x, int y){ | |
} | |
//-------------------------------------------------------------- | |
void ofApp::windowResized(int w, int h){ | |
} | |
//-------------------------------------------------------------- | |
void ofApp::gotMessage(ofMessage msg){ | |
} | |
//-------------------------------------------------------------- | |
void ofApp::dragEvent(ofDragInfo dragInfo){ | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment