From a29561fb60fe2b7f91ad4fbe9e2763181cd42388 Mon Sep 17 00:00:00 2001 From: Krisjanis Rijnieks Date: Sat, 26 Mar 2016 00:03:28 +0100 Subject: [PATCH] Attempt to fix camera example to be compatible with ofxRPiCameraVideoGrabber 0.9.0-compatible release --- example-camera/src/CameraSource.cpp | 63 ++++++++++++++++++----------- example-camera/src/CameraSource.h | 5 ++- 2 files changed, 43 insertions(+), 25 deletions(-) diff --git a/example-camera/src/CameraSource.cpp b/example-camera/src/CameraSource.cpp index 74db15d..9d9c0be 100644 --- a/example-camera/src/CameraSource.cpp +++ b/example-camera/src/CameraSource.cpp @@ -3,43 +3,60 @@ CameraSource::CameraSource(){ name = "Camera Source"; - _cameraWidth = 320; - _cameraHeight = 240; + _cameraWidth = 1280; + _cameraHeight = 720; - vector devices = _videoGrabber.listDevices(); - _cameraFound = false; + #ifdef TARGET_RASPBERRY_PI + _omxCameraSettings.width = _cameraWidth; + _omxCameraSettings.height = _cameraHeight; + _omxCameraSettings.framerate = 30; + _omxCameraSettings.isUsingTexture = true; + _omxCameraSettings.doRecording = false; + + _videoGrabber.setup(omxCameraSettings); + #else + vector devices = _videoGrabber.listDevices(); + _cameraFound = false; - for(int i = 0; i < devices.size(); i++){ - if(devices[i].bAvailable){ - ofLogNotice() << devices[i].id << ": " << devices[i].deviceName; - _cameraFound = true; - break; + for(int i = 0; i < devices.size(); i++){ + if(devices[i].bAvailable){ + ofLogNotice() << devices[i].id << ": " << devices[i].deviceName; + _cameraFound = true; + break; + } } - } - - if(_cameraFound){ - _videoGrabber.setDeviceID(0); - _videoGrabber.setup(_cameraWidth, _cameraHeight); - } + if(_cameraFound){ + _videoGrabber.setDeviceID(0); + _videoGrabber.setup(_cameraWidth, _cameraHeight); + } + #endif + allocate(_cameraWidth, _cameraHeight); } void CameraSource::update(){ - if(_videoGrabber.isInitialized()){ - _videoGrabber.update(); - } + #ifndef TARGET_RASPBERRY_PI + if(_videoGrabber.isInitialized()){ + _videoGrabber.update(); + } + #endif } void CameraSource::draw(){ ofClear(0); ofSetHexColor(0xffffff); - - if(_videoGrabber.isInitialized()){ + #ifdef TARGET_RASPBERRY_PI ofDisableNormalizedTexCoords(); _videoGrabber.draw(0, 0); ofEnableNormalizedTexCoords(); - }else{ - ofDrawBitmapString("no camera", _cameraWidth / 2.0f - 40.0f, _cameraHeight / 2.0f + 10.0f); - } + #else + if(_videoGrabber.isInitialized()){ + ofDisableNormalizedTexCoords(); + _videoGrabber.draw(0, 0); + ofEnableNormalizedTexCoords(); + }else{ + ofDrawBitmapString("no camera", _cameraWidth / 2.0f - 40.0f, _cameraHeight / 2.0f + 10.0f); + } + #endif } \ No newline at end of file diff --git a/example-camera/src/CameraSource.h b/example-camera/src/CameraSource.h index eeef906..5a6ecb2 100644 --- a/example-camera/src/CameraSource.h +++ b/example-camera/src/CameraSource.h @@ -10,7 +10,7 @@ #include "FboSource.h" #ifdef TARGET_RASPBERRY_PI - #include "RPiVideoGrabber.h" + #include "ofxRPiCameraVideoGrabber.h" #endif class CameraSource : public ofx::piMapper::FboSource { @@ -23,7 +23,8 @@ class CameraSource : public ofx::piMapper::FboSource { private: #ifdef TARGET_RASPBERRY_PI - RPiVideoGrabber _videoGrabber; + OMXCameraSettings _omxCameraSettings; + ofxRPiCameraVideoGrabber _videoGrabber; #else ofVideoGrabber _videoGrabber; #endif