mirror of
https://github.com/opencv/opencv.git
synced 2026-07-30 07:43:03 +04:00
Grabcut with frozen models (#11339)
* model is not learned when grabcut is called with GC_EVAL * fixed test, was writing to wrong file. * modified patch by Iwan Paolucci; added GC_EVAL_FREEZE_MODEL in addition to GC_EVAL (which semantics is retained)
This commit is contained in:
@@ -92,7 +92,9 @@ void CV_GrabcutTest::run( int /* start_from */)
|
||||
mask = Scalar(0);
|
||||
Mat bgdModel, fgdModel;
|
||||
grabCut( img, mask, rect, bgdModel, fgdModel, 0, GC_INIT_WITH_RECT );
|
||||
grabCut( img, mask, rect, bgdModel, fgdModel, 2, GC_EVAL );
|
||||
bgdModel.copyTo(exp_bgdModel);
|
||||
fgdModel.copyTo(exp_fgdModel);
|
||||
grabCut( img, mask, rect, bgdModel, fgdModel, 2, GC_EVAL_FREEZE_MODEL );
|
||||
|
||||
// Multiply images by 255 for more visuality of test data.
|
||||
if( mask_prob.empty() )
|
||||
@@ -105,12 +107,20 @@ void CV_GrabcutTest::run( int /* start_from */)
|
||||
exp_mask1 = (mask & 1) * 255;
|
||||
imwrite(string(ts->get_data_path()) + "grabcut/exp_mask1.png", exp_mask1);
|
||||
}
|
||||
|
||||
if (!verify((mask & 1) * 255, exp_mask1))
|
||||
{
|
||||
ts->set_failed_test_info(cvtest::TS::FAIL_MISMATCH);
|
||||
return;
|
||||
}
|
||||
// The model should not be changed after calling with GC_EVAL_FREEZE_MODEL
|
||||
double sumBgdModel = cv::sum(cv::abs(bgdModel) - cv::abs(exp_bgdModel))[0];
|
||||
double sumFgdModel = cv::sum(cv::abs(fgdModel) - cv::abs(exp_fgdModel))[0];
|
||||
if (sumBgdModel >= 0.1 || sumFgdModel >= 0.1)
|
||||
{
|
||||
ts->printf(cvtest::TS::LOG, "sumBgdModel = %f, sumFgdModel = %f\n", sumBgdModel, sumFgdModel);
|
||||
ts->set_failed_test_info(cvtest::TS::FAIL_MISMATCH);
|
||||
return;
|
||||
}
|
||||
|
||||
mask = mask_prob;
|
||||
bgdModel.release();
|
||||
@@ -124,7 +134,6 @@ void CV_GrabcutTest::run( int /* start_from */)
|
||||
exp_mask2 = (mask & 1) * 255;
|
||||
imwrite(string(ts->get_data_path()) + "grabcut/exp_mask2.png", exp_mask2);
|
||||
}
|
||||
|
||||
if (!verify((mask & 1) * 255, exp_mask2))
|
||||
{
|
||||
ts->set_failed_test_info(cvtest::TS::FAIL_MISMATCH);
|
||||
|
||||
Reference in New Issue
Block a user