1
0
mirror of https://github.com/opencv/opencv.git synced 2026-07-30 07:43:03 +04:00

Merge pull request #680 from vpisarev:c2cpp_video_take2

This commit is contained in:
Andrey Kamaev
2013-03-22 19:34:52 +04:00
committed by OpenCV Buildbot
32 changed files with 2604 additions and 2462 deletions
@@ -37,8 +37,7 @@ void CV_BackgroundSubtractorTest::run(int)
int width = 2 + ((unsigned int)rng)%98; //!< Mat will be 2 to 100 in width and height
int height = 2 + ((unsigned int)rng)%98;
Ptr<BackgroundSubtractorGMG> fgbg =
Algorithm::create<BackgroundSubtractorGMG>("BackgroundSubtractor.GMG");
Ptr<BackgroundSubtractorGMG> fgbg = createBackgroundSubtractorGMG();
Mat fgmask;
if (fgbg.empty())
@@ -47,19 +46,13 @@ void CV_BackgroundSubtractorTest::run(int)
/**
* Set a few parameters
*/
fgbg->set("smoothingRadius",7);
fgbg->set("decisionThreshold",0.7);
fgbg->set("initializationFrames",120);
fgbg->setSmoothingRadius(7);
fgbg->setDecisionThreshold(0.7);
fgbg->setNumFrames(120);
/**
* Generate bounds for the values in the matrix for each type
*/
uchar maxuc = 0, minuc = 0;
char maxc = 0, minc = 0;
unsigned int maxui = 0, minui = 0;
int maxi=0, mini = 0;
long int maxli = 0, minli = 0;
float maxf = 0, minf = 0;
double maxd = 0, mind = 0;
/**
@@ -69,34 +62,34 @@ void CV_BackgroundSubtractorTest::run(int)
if (type == CV_8U)
{
uchar half = UCHAR_MAX/2;
maxuc = (unsigned char)rng.uniform(half+32, UCHAR_MAX);
minuc = (unsigned char)rng.uniform(0, half-32);
maxd = (unsigned char)rng.uniform(half+32, UCHAR_MAX);
mind = (unsigned char)rng.uniform(0, half-32);
}
else if (type == CV_8S)
{
maxc = (char)rng.uniform(32, CHAR_MAX);
minc = (char)rng.uniform(CHAR_MIN, -32);
maxd = (char)rng.uniform(32, CHAR_MAX);
mind = (char)rng.uniform(CHAR_MIN, -32);
}
else if (type == CV_16U)
{
ushort half = USHRT_MAX/2;
maxui = (unsigned int)rng.uniform(half+32, USHRT_MAX);
minui = (unsigned int)rng.uniform(0, half-32);
maxd = (unsigned int)rng.uniform(half+32, USHRT_MAX);
mind = (unsigned int)rng.uniform(0, half-32);
}
else if (type == CV_16S)
{
maxi = rng.uniform(32, SHRT_MAX);
mini = rng.uniform(SHRT_MIN, -32);
maxd = rng.uniform(32, SHRT_MAX);
mind = rng.uniform(SHRT_MIN, -32);
}
else if (type == CV_32S)
{
maxli = rng.uniform(32, INT_MAX);
minli = rng.uniform(INT_MIN, -32);
maxd = rng.uniform(32, INT_MAX);
mind = rng.uniform(INT_MIN, -32);
}
else if (type == CV_32F)
{
maxf = rng.uniform(32.0f, FLT_MAX);
minf = rng.uniform(-FLT_MAX, -32.0f);
maxd = rng.uniform(32.0f, FLT_MAX);
mind = rng.uniform(-FLT_MAX, -32.0f);
}
else if (type == CV_64F)
{
@@ -104,60 +97,22 @@ void CV_BackgroundSubtractorTest::run(int)
mind = rng.uniform(-DBL_MAX, -32.0);
}
fgbg->setMinVal(mind);
fgbg->setMaxVal(maxd);
Mat simImage = Mat::zeros(height, width, channelsAndType);
const unsigned int numLearningFrames = 120;
for (unsigned int i = 0; i < numLearningFrames; ++i)
int numLearningFrames = 120;
for (int i = 0; i < numLearningFrames; ++i)
{
/**
* Genrate simulated "image" for any type. Values always confined to upper half of range.
*/
if (type == CV_8U)
{
rng.fill(simImage,RNG::UNIFORM,(unsigned char)(minuc/2+maxuc/2),maxuc);
if (i == 0)
fgbg->initialize(simImage.size(),minuc,maxuc);
}
else if (type == CV_8S)
{
rng.fill(simImage,RNG::UNIFORM,(char)(minc/2+maxc/2),maxc);
if (i==0)
fgbg->initialize(simImage.size(),minc,maxc);
}
else if (type == CV_16U)
{
rng.fill(simImage,RNG::UNIFORM,(unsigned int)(minui/2+maxui/2),maxui);
if (i==0)
fgbg->initialize(simImage.size(),minui,maxui);
}
else if (type == CV_16S)
{
rng.fill(simImage,RNG::UNIFORM,(int)(mini/2+maxi/2),maxi);
if (i==0)
fgbg->initialize(simImage.size(),mini,maxi);
}
else if (type == CV_32F)
{
rng.fill(simImage,RNG::UNIFORM,(float)(minf/2.0+maxf/2.0),maxf);
if (i==0)
fgbg->initialize(simImage.size(),minf,maxf);
}
else if (type == CV_32S)
{
rng.fill(simImage,RNG::UNIFORM,(long int)(minli/2+maxli/2),maxli);
if (i==0)
fgbg->initialize(simImage.size(),minli,maxli);
}
else if (type == CV_64F)
{
rng.fill(simImage,RNG::UNIFORM,(double)(mind/2.0+maxd/2.0),maxd);
if (i==0)
fgbg->initialize(simImage.size(),mind,maxd);
}
rng.fill(simImage, RNG::UNIFORM, (mind + maxd)*0.5, maxd);
/**
* Feed simulated images into background subtractor
*/
(*fgbg)(simImage,fgmask);
fgbg->apply(simImage,fgmask);
Mat fullbg = Mat::zeros(simImage.rows, simImage.cols, CV_8U);
//! fgmask should be entirely background during training
@@ -166,22 +121,9 @@ void CV_BackgroundSubtractorTest::run(int)
ts->set_failed_test_info( code );
}
//! generate last image, distinct from training images
if (type == CV_8U)
rng.fill(simImage,RNG::UNIFORM,minuc,minuc);
else if (type == CV_8S)
rng.fill(simImage,RNG::UNIFORM,minc,minc);
else if (type == CV_16U)
rng.fill(simImage,RNG::UNIFORM,minui,minui);
else if (type == CV_16S)
rng.fill(simImage,RNG::UNIFORM,mini,mini);
else if (type == CV_32F)
rng.fill(simImage,RNG::UNIFORM,minf,minf);
else if (type == CV_32S)
rng.fill(simImage,RNG::UNIFORM,minli,minli);
else if (type == CV_64F)
rng.fill(simImage,RNG::UNIFORM,mind,mind);
rng.fill(simImage, RNG::UNIFORM, mind, maxd);
(*fgbg)(simImage,fgmask);
fgbg->apply(simImage,fgmask);
//! now fgmask should be entirely foreground
Mat fullfg = 255*Mat::ones(simImage.rows, simImage.cols, CV_8U);
code = cvtest::cmpEps2( ts, fgmask, fullfg, 255, false, "The final foreground mask" );
+1 -1
View File
@@ -153,7 +153,7 @@ bool CV_RigidTransform_Test::testImage()
Mat aff_est = estimateRigidTransform(img, rotated, true);
const double thres = 0.03;
const double thres = 0.033;
if (norm(aff_est, aff, NORM_INF) > thres)
{
ts->set_failed_test_info(cvtest::TS::FAIL_BAD_ACCURACY);