Created
September 18, 2017 20:27
-
-
Save vanderlin/a3eaac076c188393b29f3aae5c533c4f to your computer and use it in GitHub Desktop.
have to create a pointer object to change device.
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 = NULL; | |
int camWidth; | |
int camHeight; | |
//-------------------------------------------------------------- | |
void ofApp::setup() { | |
camWidth = 320; | |
camHeight = 240; | |
vidGrabber = new ofVideoGrabber(); | |
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(){ | |
if (vidGrabber) vidGrabber->update(); | |
} | |
//-------------------------------------------------------------- | |
void ofApp::draw(){ | |
ofSetHexColor(0xffffff); | |
if (vidGrabber) vidGrabber->draw(20, 20); | |
} | |
//-------------------------------------------------------------- | |
void ofApp::setDevice(ofVideoDevice &device) { | |
if(vidGrabber && vidGrabber->isInitialized()) { | |
vidGrabber->close(); | |
delete vidGrabber; | |
} | |
vidGrabber = new ofVideoGrabber(); | |
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