Browse Source

Attempt to fix camera example to be compatible with ofxRPiCameraVideoGrabber 0.9.0-compatible release

master
Krisjanis Rijnieks 9 years ago
parent
commit
a29561fb60
  1. 63
      example-camera/src/CameraSource.cpp
  2. 5
      example-camera/src/CameraSource.h

63
example-camera/src/CameraSource.cpp

@ -3,43 +3,60 @@
CameraSource::CameraSource(){ CameraSource::CameraSource(){
name = "Camera Source"; name = "Camera Source";
_cameraWidth = 320; _cameraWidth = 1280;
_cameraHeight = 240; _cameraHeight = 720;
vector<ofVideoDevice> devices = _videoGrabber.listDevices(); #ifdef TARGET_RASPBERRY_PI
_cameraFound = false; _omxCameraSettings.width = _cameraWidth;
_omxCameraSettings.height = _cameraHeight;
_omxCameraSettings.framerate = 30;
_omxCameraSettings.isUsingTexture = true;
_omxCameraSettings.doRecording = false;
_videoGrabber.setup(omxCameraSettings);
#else
vector<ofVideoDevice> devices = _videoGrabber.listDevices();
_cameraFound = false;
for(int i = 0; i < devices.size(); i++){ for(int i = 0; i < devices.size(); i++){
if(devices[i].bAvailable){ if(devices[i].bAvailable){
ofLogNotice() << devices[i].id << ": " << devices[i].deviceName; ofLogNotice() << devices[i].id << ": " << devices[i].deviceName;
_cameraFound = true; _cameraFound = true;
break; break;
}
} }
}
if(_cameraFound){
_videoGrabber.setDeviceID(0);
_videoGrabber.setup(_cameraWidth, _cameraHeight);
}
if(_cameraFound){
_videoGrabber.setDeviceID(0);
_videoGrabber.setup(_cameraWidth, _cameraHeight);
}
#endif
allocate(_cameraWidth, _cameraHeight); allocate(_cameraWidth, _cameraHeight);
} }
void CameraSource::update(){ void CameraSource::update(){
if(_videoGrabber.isInitialized()){ #ifndef TARGET_RASPBERRY_PI
_videoGrabber.update(); if(_videoGrabber.isInitialized()){
} _videoGrabber.update();
}
#endif
} }
void CameraSource::draw(){ void CameraSource::draw(){
ofClear(0); ofClear(0);
ofSetHexColor(0xffffff); ofSetHexColor(0xffffff);
#ifdef TARGET_RASPBERRY_PI
if(_videoGrabber.isInitialized()){
ofDisableNormalizedTexCoords(); ofDisableNormalizedTexCoords();
_videoGrabber.draw(0, 0); _videoGrabber.draw(0, 0);
ofEnableNormalizedTexCoords(); ofEnableNormalizedTexCoords();
}else{ #else
ofDrawBitmapString("no camera", _cameraWidth / 2.0f - 40.0f, _cameraHeight / 2.0f + 10.0f); if(_videoGrabber.isInitialized()){
} ofDisableNormalizedTexCoords();
_videoGrabber.draw(0, 0);
ofEnableNormalizedTexCoords();
}else{
ofDrawBitmapString("no camera", _cameraWidth / 2.0f - 40.0f, _cameraHeight / 2.0f + 10.0f);
}
#endif
} }

5
example-camera/src/CameraSource.h

@ -10,7 +10,7 @@
#include "FboSource.h" #include "FboSource.h"
#ifdef TARGET_RASPBERRY_PI #ifdef TARGET_RASPBERRY_PI
#include "RPiVideoGrabber.h" #include "ofxRPiCameraVideoGrabber.h"
#endif #endif
class CameraSource : public ofx::piMapper::FboSource { class CameraSource : public ofx::piMapper::FboSource {
@ -23,7 +23,8 @@ class CameraSource : public ofx::piMapper::FboSource {
private: private:
#ifdef TARGET_RASPBERRY_PI #ifdef TARGET_RASPBERRY_PI
RPiVideoGrabber _videoGrabber; OMXCameraSettings _omxCameraSettings;
ofxRPiCameraVideoGrabber _videoGrabber;
#else #else
ofVideoGrabber _videoGrabber; ofVideoGrabber _videoGrabber;
#endif #endif

Loading…
Cancel
Save