made improvements in ECC code (comments from https://github.com/Itseez/opencv/pull/3845), as well as minor tweak in pthread's based parallel for.
This commit is contained in:
parent
78e07d3210
commit
a4073ed676
@ -252,7 +252,14 @@ pthread_mutex_t ThreadManager::m_manager_access_mutex = PTHREAD_RECURSIVE_MUTEX_
|
|||||||
|
|
||||||
ThreadManager::ptr_holder ThreadManager::m_instance;
|
ThreadManager::ptr_holder ThreadManager::m_instance;
|
||||||
const char ThreadManager::m_env_name[] = "OPENCV_FOR_THREADS_NUM";
|
const char ThreadManager::m_env_name[] = "OPENCV_FOR_THREADS_NUM";
|
||||||
|
|
||||||
|
#ifdef ANDROID
|
||||||
|
// many modern phones/tables have 4-core CPUs. Let's use no more
|
||||||
|
// than 2 threads by default not to overheat the devices
|
||||||
|
const unsigned int ThreadManager::m_default_number_of_threads = 2;
|
||||||
|
#else
|
||||||
const unsigned int ThreadManager::m_default_number_of_threads = 8;
|
const unsigned int ThreadManager::m_default_number_of_threads = 8;
|
||||||
|
#endif
|
||||||
|
|
||||||
ForThread::~ForThread()
|
ForThread::~ForThread()
|
||||||
{
|
{
|
||||||
@ -399,11 +406,10 @@ ThreadManager::~ThreadManager()
|
|||||||
|
|
||||||
void ThreadManager::run(const cv::Range& range, const cv::ParallelLoopBody& body, double nstripes)
|
void ThreadManager::run(const cv::Range& range, const cv::ParallelLoopBody& body, double nstripes)
|
||||||
{
|
{
|
||||||
bool is_work_thread;
|
bool is_work_thread = m_is_work_thread.get()->value;
|
||||||
|
|
||||||
is_work_thread = m_is_work_thread.get()->value;
|
if( (getNumOfThreads() > 1) && !is_work_thread &&
|
||||||
|
(range.end - range.start > 1) && (nstripes <= 0 || nstripes >= 1.5) )
|
||||||
if( (getNumOfThreads() > 1) && !is_work_thread && (range.end - range.start > 1) )
|
|
||||||
{
|
{
|
||||||
int res = pthread_mutex_trylock(&m_manager_access_mutex);
|
int res = pthread_mutex_trylock(&m_manager_access_mutex);
|
||||||
|
|
||||||
|
@ -402,16 +402,19 @@ double cv::findTransformECC(InputArray templateImage,
|
|||||||
|
|
||||||
Mat inputMaskMat = inputMask.getMat();
|
Mat inputMaskMat = inputMask.getMat();
|
||||||
//to use it for mask warping
|
//to use it for mask warping
|
||||||
Mat preMask =
|
Mat preMask;
|
||||||
inputMaskMat.empty() ? Mat::ones(hd, wd, CV_8U) : inputMaskMat;
|
if(inputMask.empty())
|
||||||
|
preMask = Mat::ones(hd, wd, CV_8U);
|
||||||
|
else
|
||||||
|
threshold(inputMask, preMask, 0, 1, THRESH_BINARY);
|
||||||
|
|
||||||
//gaussian filtering is optional
|
//gaussian filtering is optional
|
||||||
src.convertTo(templateFloat, templateFloat.type());
|
src.convertTo(templateFloat, templateFloat.type());
|
||||||
GaussianBlur(templateFloat, templateFloat, Size(5, 5), 0, 0);//is in-place filtering slower?
|
GaussianBlur(templateFloat, templateFloat, Size(5, 5), 0, 0);
|
||||||
|
|
||||||
Mat preMaskFloat = Mat(hd, wd, CV_32F);
|
Mat preMaskFloat;
|
||||||
preMask.convertTo(preMaskFloat, preMaskFloat.type());
|
preMask.convertTo(preMaskFloat, CV_32F);
|
||||||
GaussianBlur(preMaskFloat, preMaskFloat, Size(5, 5), 0, 0);//is in-place filtering slower?
|
GaussianBlur(preMaskFloat, preMaskFloat, Size(5, 5), 0, 0);
|
||||||
// Change threshold.
|
// Change threshold.
|
||||||
preMaskFloat *= (0.5/0.95);
|
preMaskFloat *= (0.5/0.95);
|
||||||
// Rounding conversion.
|
// Rounding conversion.
|
||||||
@ -512,7 +515,7 @@ double cv::findTransformECC(InputArray templateImage,
|
|||||||
// calculate enhanced correlation coefficiont (ECC)->rho
|
// calculate enhanced correlation coefficiont (ECC)->rho
|
||||||
last_rho = rho;
|
last_rho = rho;
|
||||||
rho = correlation/(imgNorm*tmpNorm);
|
rho = correlation/(imgNorm*tmpNorm);
|
||||||
if (isnan(rho)) {
|
if (cvIsNaN(rho)) {
|
||||||
CV_Error(Error::StsNoConv, "NaN encountered.");
|
CV_Error(Error::StsNoConv, "NaN encountered.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user