From 2903c7a96975f8ddc9ea72e36af20eadbb5ab55c Mon Sep 17 00:00:00 2001 From: Jamie Allen Date: Tue, 21 Feb 2012 19:31:58 +0100 Subject: [PATCH] david commit 19:31 --- example/RefractiveIndex.cpp | 19 +++++++++++-------- src/IResponseAnalysis.cpp | 2 ++ src/ShadowScapesAnalysis.cpp | 22 +++++++++++++++++----- src/ShadowScapesAnalysis.h | 9 ++++++++- 4 files changed, 38 insertions(+), 14 deletions(-) diff --git a/example/RefractiveIndex.cpp b/example/RefractiveIndex.cpp index 9ed9a12..ca1df18 100644 --- a/example/RefractiveIndex.cpp +++ b/example/RefractiveIndex.cpp @@ -115,7 +115,7 @@ void RefractiveIndex::setup() _analysisVector.push_back(new DiffNoiseAnalysis()); _currentAnalysisIndx = 0; - _currentAnalysis = _analysisVector.at(_currentAnalysisIndx); + _currentAnalysis = _analysisVector.at(_currentAnalysisIndx++); _state = ISTATE_START; @@ -216,18 +216,21 @@ void RefractiveIndex::draw() void RefractiveIndex::setup_camera() { stop_camera(); - - if(!_vidGrabber.initGrabber(_vid_w, _vid_h)) { + + _vidGrabber.setDeviceID(_vid_id); + _vidGrabber.listDevices(); + + if(!_vidGrabber.initGrabber(_vid_w, _vid_h)) { ofLog(OF_LOG_ERROR) << "RefractiveIndex::setup_camera - could not initialise grabber"; return; } - + + _vidGrabber.setVerbose(true); _vidGrabber.setUseTexture(false); - _vidGrabber.listDevices(); - _vidGrabber.setVerbose(true); _vid_stream_open = true; - _vidGrabber.setDeviceID(_vid_id); - + cout << "CAMERA SETUP " << endl; + return; + } void RefractiveIndex::stop_camera() diff --git a/src/IResponseAnalysis.cpp b/src/IResponseAnalysis.cpp index c18757d..1e42690 100755 --- a/src/IResponseAnalysis.cpp +++ b/src/IResponseAnalysis.cpp @@ -281,6 +281,8 @@ void IResponseAnalysis::save_cb(Timer& timer) if (RefractiveIndex::_vidGrabber.isFrameNew()) { RefractiveIndex::_pixels = RefractiveIndex::_vidGrabber.getPixelsRef(); //get ofPixels from the camera + } else { + return; } //cout << "IResponseAnalysis::saving...\n"; diff --git a/src/ShadowScapesAnalysis.cpp b/src/ShadowScapesAnalysis.cpp index 458cf0b..5e402be 100755 --- a/src/ShadowScapesAnalysis.cpp +++ b/src/ShadowScapesAnalysis.cpp @@ -5,6 +5,8 @@ #include "Poco/Thread.h" #include "RefractiveIndex.h" +#include "ofxOpenCv.h" + using Poco::Timer; using Poco::TimerCallback; using Poco::Thread; @@ -16,7 +18,7 @@ void ShadowScapesAnalysis::setup(int camWidth, int camHeight) { NUM_RUN = 1; - int acq_run_time = 20; // 10 seconds of acquiring per run + int acq_run_time = 1; // 10 seconds of acquiring per run int screenSpan; if (_dir == V) screenSpan = ofGetHeight(); @@ -37,7 +39,7 @@ void ShadowScapesAnalysis::setup(int camWidth, int camHeight) _run_cnt = 0; _save_cnt = 0; - int anim_time = 5; // 10 seconds + int anim_time = 1; // 10 seconds _anim_cnt_max = anim_time*ofGetFrameRate(); // e.g.: 30 frames per second = 150 frames _show_image = false; @@ -48,6 +50,10 @@ void ShadowScapesAnalysis::setup(int camWidth, int camHeight) image1.setUseTexture(false); image2.setUseTexture(true); + + cvGrayImage1.allocate(320,240); + cvGrayDiff1.allocate(320,240); + } void ShadowScapesAnalysis::acquire() @@ -78,8 +84,6 @@ void ShadowScapesAnalysis::acquire() void ShadowScapesAnalysis::synthesise() { - //cvImage1.allocate(image2.getWidth(), image2.getHeight()); - //cvImage1.setFromPixels(image2); // _saved_filenames has all the file names of all the saved images while(!_RUN_DONE) @@ -309,7 +313,15 @@ void ShadowScapesAnalysis::draw() ofSetColor(255, 255, 255, 255); image2.setFromPixels(image1.getPixels(),image1.width,image1.height, OF_IMAGE_COLOR); - image2.draw(0,0, ofGetWidth(), ofGetHeight()); + //image2.draw(0,0, ofGetWidth(), ofGetHeight()); + + //cvImage1.allocate(image1.getWidth(), image2.getHeight()); + cvImage1.setFromPixels(image1.getPixels(), 320, 240); + cvGrayImage1 = cvImage1; + cvGrayDiff1.absDiff(cvGrayImage1, cvGrayImage1); + + cvGrayImage1.draw(0,0, ofGetWidth(), ofGetHeight()); + //cvGrayDiff1.draw(0,0, ofGetWidth(), ofGetHeight()); ofDisableAlphaBlending(); } diff --git a/src/ShadowScapesAnalysis.h b/src/ShadowScapesAnalysis.h index 74e11a2..2ebcf72 100755 --- a/src/ShadowScapesAnalysis.h +++ b/src/ShadowScapesAnalysis.h @@ -44,6 +44,13 @@ protected: bool _show_image, _image_shown; ofImage image1; ofImage image2; - ofxCvColorImage cvImage1; + ofxCvColorImage cvImage1; + + ofxCvGrayscaleImage cvGrayImage1; + ofxCvGrayscaleImage cvGrayBg1; + ofxCvGrayscaleImage cvGrayDiff1; + + ofxCvContourFinder cvContourFinder1; + }; \ No newline at end of file