mirror of
https://github.com/opencv/opencv.git
synced 2026-07-29 07:13:02 +04:00
Merge pull request #11253 from mshabunin:decrease-tbb-dependency
This commit is contained in:
@@ -101,9 +101,6 @@ public:
|
||||
context(_context), depthGenerator(_depthGenerator), imageGenerator(_imageGenerator),
|
||||
maxBufferSize(_maxBufferSize), isCircleBuffer(_isCircleBuffer), maxTimeDuration(_maxTimeDuration)
|
||||
{
|
||||
#ifdef HAVE_TBB
|
||||
task = 0;
|
||||
#endif
|
||||
|
||||
CV_Assert( depthGenerator.IsValid() );
|
||||
CV_Assert( imageGenerator.IsValid() );
|
||||
@@ -112,9 +109,6 @@ public:
|
||||
void setMaxBufferSize( int _maxBufferSize )
|
||||
{
|
||||
maxBufferSize = _maxBufferSize;
|
||||
#ifdef HAVE_TBB
|
||||
task->setMaxBufferSize();
|
||||
#endif
|
||||
}
|
||||
inline int getMaxBufferSize() const { return maxBufferSize; }
|
||||
|
||||
@@ -132,9 +126,7 @@ public:
|
||||
|
||||
while( task->grab(depthMetaData, imageMetaData) == false )
|
||||
{
|
||||
#ifndef HAVE_TBB
|
||||
task->spin();
|
||||
#endif
|
||||
}
|
||||
return true;
|
||||
|
||||
@@ -144,22 +136,12 @@ public:
|
||||
{
|
||||
CV_Assert( depthGenerator.IsValid() );
|
||||
CV_Assert( imageGenerator.IsValid() );
|
||||
#ifdef HAVE_TBB
|
||||
task = new( tbb::task::allocate_root() ) TBBApproximateSynchronizerTask( *this );
|
||||
tbb::task::enqueue(*task);
|
||||
#else
|
||||
task.reset( new ApproximateSynchronizer( *this ) );
|
||||
#endif
|
||||
}
|
||||
|
||||
void finish()
|
||||
{
|
||||
#ifdef HAVE_TBB
|
||||
if( task )
|
||||
tbb::task::destroy( *task );
|
||||
#else
|
||||
task.release();
|
||||
#endif
|
||||
}
|
||||
|
||||
bool isRun() const { return task != 0; }
|
||||
@@ -305,120 +287,7 @@ private:
|
||||
std::queue<cv::Ptr<xn::ImageMetaData> > imageQueue;
|
||||
};
|
||||
|
||||
#ifdef HAVE_TBB
|
||||
// If there is TBB the synchronization will be executed in own thread.
|
||||
class TBBApproximateSynchronizer: public ApproximateSynchronizerBase
|
||||
{
|
||||
public:
|
||||
TBBApproximateSynchronizer( ApproximateSyncGrabber& _approxSyncGrabber ) :
|
||||
ApproximateSynchronizerBase(_approxSyncGrabber)
|
||||
{
|
||||
setMaxBufferSize();
|
||||
}
|
||||
|
||||
void setMaxBufferSize()
|
||||
{
|
||||
int maxBufferSize = approxSyncGrabber.getMaxBufferSize();
|
||||
if( maxBufferSize >= 0 )
|
||||
{
|
||||
depthQueue.set_capacity( maxBufferSize );
|
||||
imageQueue.set_capacity( maxBufferSize );
|
||||
}
|
||||
}
|
||||
|
||||
virtual inline bool isSpinContinue() const { return true; }
|
||||
|
||||
virtual inline void pushDepthMetaData( xn::DepthMetaData& depthMetaData )
|
||||
{
|
||||
cv::Ptr<xn::DepthMetaData> depthPtr = cv::makePtr<xn::DepthMetaData>(), tmp;
|
||||
depthPtr->CopyFrom(depthMetaData);
|
||||
|
||||
tbb::mutex mtx;
|
||||
mtx.lock();
|
||||
if( depthQueue.try_push(depthPtr) == false )
|
||||
{
|
||||
if( approxSyncGrabber.getIsCircleBuffer() )
|
||||
{
|
||||
CV_Assert( depthQueue.try_pop(tmp) );
|
||||
CV_Assert( depthQueue.try_push(depthPtr) );
|
||||
}
|
||||
}
|
||||
mtx.unlock();
|
||||
}
|
||||
|
||||
virtual inline void pushImageMetaData( xn::ImageMetaData& imageMetaData )
|
||||
{
|
||||
cv::Ptr<xn::ImageMetaData> imagePtr = cv::makePtr<xn::ImageMetaData>(), tmp;
|
||||
imagePtr->CopyFrom(imageMetaData);
|
||||
|
||||
tbb::mutex mtx;
|
||||
mtx.lock();
|
||||
if( imageQueue.try_push(imagePtr) == false )
|
||||
{
|
||||
if( approxSyncGrabber.getIsCircleBuffer() )
|
||||
{
|
||||
CV_Assert( imageQueue.try_pop(tmp) );
|
||||
CV_Assert( imageQueue.try_push(imagePtr) );
|
||||
}
|
||||
}
|
||||
mtx.unlock();
|
||||
}
|
||||
|
||||
virtual inline bool popDepthMetaData( xn::DepthMetaData& depthMetaData )
|
||||
{
|
||||
cv::Ptr<xn::DepthMetaData> depthPtr;
|
||||
bool isPop = depthQueue.try_pop(depthPtr);
|
||||
if( isPop )
|
||||
depthMetaData.CopyFrom(*depthPtr);
|
||||
return isPop;
|
||||
}
|
||||
virtual inline bool popImageMetaData( xn::ImageMetaData& imageMetaData )
|
||||
{
|
||||
cv::Ptr<xn::ImageMetaData> imagePtr;
|
||||
bool isPop = imageQueue.try_pop(imagePtr);
|
||||
if( isPop )
|
||||
imageMetaData.CopyFrom(*imagePtr);
|
||||
return isPop;
|
||||
}
|
||||
|
||||
private:
|
||||
tbb::concurrent_bounded_queue<cv::Ptr<xn::DepthMetaData> > depthQueue;
|
||||
tbb::concurrent_bounded_queue<cv::Ptr<xn::ImageMetaData> > imageQueue;
|
||||
};
|
||||
|
||||
class TBBApproximateSynchronizerTask: public tbb::task
|
||||
{
|
||||
public:
|
||||
TBBApproximateSynchronizerTask( ApproximateSyncGrabber& approxSyncGrabber ) :
|
||||
synchronizer(approxSyncGrabber)
|
||||
{}
|
||||
|
||||
void setMaxBufferSize()
|
||||
{
|
||||
synchronizer.setMaxBufferSize();
|
||||
}
|
||||
|
||||
bool grab( xn::DepthMetaData& depthMetaData,
|
||||
xn::ImageMetaData& imageMetaData )
|
||||
{
|
||||
return synchronizer.grab( depthMetaData, imageMetaData );
|
||||
}
|
||||
|
||||
private:
|
||||
tbb::task* execute()
|
||||
{
|
||||
synchronizer.spin();
|
||||
return 0;
|
||||
}
|
||||
TBBApproximateSynchronizer synchronizer;
|
||||
};
|
||||
#endif // HAVE_TBB
|
||||
|
||||
#ifdef HAVE_TBB
|
||||
TBBApproximateSynchronizerTask* task;
|
||||
#else
|
||||
cv::Ptr<ApproximateSynchronizer> task;
|
||||
#endif
|
||||
};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
@@ -430,11 +299,7 @@ public:
|
||||
static const int INVALID_PIXEL_VAL = 0;
|
||||
static const int INVALID_COORDINATE_VAL = 0;
|
||||
|
||||
#ifdef HAVE_TBB
|
||||
static const int DEFAULT_MAX_BUFFER_SIZE = 8;
|
||||
#else
|
||||
static const int DEFAULT_MAX_BUFFER_SIZE = 2;
|
||||
#endif
|
||||
static const int DEFAULT_IS_CIRCLE_BUFFER = 0;
|
||||
static const int DEFAULT_MAX_TIME_DURATION = 20;
|
||||
|
||||
|
||||
@@ -78,11 +78,7 @@ public:
|
||||
static const int INVALID_PIXEL_VAL = 0;
|
||||
static const int INVALID_COORDINATE_VAL = 0;
|
||||
|
||||
#ifdef HAVE_TBB
|
||||
static const int DEFAULT_MAX_BUFFER_SIZE = 8;
|
||||
#else
|
||||
static const int DEFAULT_MAX_BUFFER_SIZE = 2;
|
||||
#endif
|
||||
static const int DEFAULT_IS_CIRCLE_BUFFER = 0;
|
||||
static const int DEFAULT_MAX_TIME_DURATION = 20;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user