Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#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