Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions ofxMachineVisionLib/ofxMachineVisionLib.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -55,18 +55,22 @@
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
<Import Project="..\..\..\libs\openFrameworksCompiled\project\vs\openFrameworksDebug.props" />
<Import Project="..\..\ofxCvMin\ofxCvMinLib\ofxCvMin.props" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
<Import Project="..\..\..\libs\openFrameworksCompiled\project\vs\openFrameworksDebug64.props" />
<Import Project="..\..\ofxCvMin\ofxCvMinLib\ofxCvMin.props" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
<Import Project="..\..\..\libs\openFrameworksCompiled\project\vs\openFrameworksRelease.props" />
<Import Project="..\..\ofxCvMin\ofxCvMinLib\ofxCvMin.props" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
<Import Project="..\..\..\libs\openFrameworksCompiled\project\vs\openFrameworksRelease64.props" />
<Import Project="..\..\ofxCvMin\ofxCvMinLib\ofxCvMin.props" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
Expand Down
27 changes: 27 additions & 0 deletions src/ofxMachineVision/Grabber/Simple.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
#include "ofAppRunner.h"
#include "ofSystemUtils.h"

using namespace ofxCv;
using namespace cv;

namespace ofxMachineVision {
namespace Grabber {
//----------
Expand Down Expand Up @@ -249,6 +252,30 @@ namespace ofxMachineVision {
}
}

//----------
shared_ptr<Frame> Simple::getFreshFrameAveraged(int numExposures) {
if (numExposures <= 1)
return this->getFreshFrame();

shared_ptr<Frame> averagedFrame(new Frame());
averagedFrame->getPixelsRef().allocate(this->getWidth(), this->getHeight(), OF_IMAGE_COLOR);

Mat exposureMat;
Mat accumulatedMat = Mat(this->getHeight(), this->getWidth(), CV_16UC3, Scalar(0));
for (int i = 0; i < numExposures; i++) {
auto frame = this->getFreshFrame();
frame->lockForReading();
toCv(frame->getPixelsRef()).convertTo(exposureMat, CV_16UC3);
frame->unlock();

accumulatedMat += exposureMat;
}
accumulatedMat *= (1.f / numExposures);
accumulatedMat.convertTo(toCv(averagedFrame->getPixelsRef()), CV_8UC3);

return averagedFrame;
}

//----------
void Simple::update() {
CHECK_OPEN_SILENT
Expand Down
2 changes: 2 additions & 0 deletions src/ofxMachineVision/Grabber/Simple.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

#include "Base.h"
#include "ofxMachineVision/Frame.h"
#include "ofxCvMin.h"

namespace ofxMachineVision {
namespace Grabber {
Expand All @@ -28,6 +29,7 @@ namespace ofxMachineVision {
Microseconds getLastTimestamp() const { return this->lastTimestamp; }
long getLastFrameIndex() const { return this->lastFrameIndex; }
shared_ptr<Frame> getFreshFrame(float timeoutSeconds = 5.0f);
shared_ptr<Frame> getFreshFrameAveraged(int numExposures = 1);

/**
\name ofBaseUpdates
Expand Down