Quantcast
Channel: openFrameworks - Latest posts
Viewing all articles
Browse latest Browse all 40524

ofVideoGrabber in Debian only shows first frame

$
0
0

I understand this has been solved for the nightly build.

However, I wanted to throw in my experience. I had a similar problem with my webcam under Ubuntu only grabbing the first frame. It still can't handle full fps (30), but this setup seems to get it to work.

Most important is to set the fps to 1/2 what your webcam viewer says it can handle, mine is camorama webcam viewer
ofApp.cpp:

#include "ofApp.h"

//--------------------------------------------------------------
void ofApp::setup(){

    ofSetLogLevel(OF_LOG_VERBOSE);

	camWidth 		= 1920;	// try to grab at this size.
	camHeight 		= 1080;

    //we can now get back a list of devices.
	vector<ofVideoDevice> devices = vidGrabber.listDevices();

    for(int i = 0; i < devices.size(); i++){
		cout << devices[i].id << ": " << devices[i].deviceName;
        if( devices[i].bAvailable ){
            cout << endl;
        }else{
            cout << " - unavailable " << endl;
        }
	}

	vidGrabber.setDeviceID(0);
	vidGrabber.setPixelFormat(OF_PIXELS_RGB);
	vidGrabber.setDesiredFrameRate(15);
	vidGrabber.setVerbose(true);
	vidGrabber.setUseTexture(false);
	vidGrabber.initGrabber(camWidth,camHeight);
	ofSetVerticalSync(true);

}


//--------------------------------------------------------------
void ofApp::update(){    
	vidGrabber.update();
}

//--------------------------------------------------------------
void ofApp::draw(){
	ofSetHexColor(0xffffff);
	vidGrabber.draw(0,0);

	ofSetHexColor(0xffffff);
    char reportStr[1024];
    sprintf(reportStr, "FPS: %3.2f", ofGetFrameRate() );
    ofDrawBitmapString(reportStr, ofGetWidth()-100, ofGetHeight() - 25);
}


//--------------------------------------------------------------
void ofApp::keyPressed  (int key){
   
}

//--------------------------------------------------------------
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::windowResized(int w, int h){

}

//--------------------------------------------------------------
void ofApp::gotMessage(ofMessage msg){

}

//--------------------------------------------------------------
void ofApp::dragEvent(ofDragInfo dragInfo){

}

Viewing all articles
Browse latest Browse all 40524

Trending Articles