bool MotionSpecialTest() { Video video; if (SOURCE.length() == 0) { TEST_LOG_SS(Error, "Video source is undefined (-s parameter)!"); return false; } if(!video.SetSource(SOURCE)) { TEST_LOG_SS(Error, "Can't open video file '" << SOURCE << "'!"); return false; } Filter filter; video.SetFilter(&filter); video.Start(); #ifdef TEST_PERFORMANCE_TEST_ENABLE TEST_LOG_SS(Info, PerformanceMeasurerStorage::s_storage.Report(false, true)); PerformanceMeasurerStorage::s_storage.Clear(); #endif return true; }
Options(int argc, char* argv[]) : mode(Auto) , threads(0) , help(false) , printAlign(false) { for (int i = 1; i < argc; ++i) { String arg = argv[i]; if (arg.substr(0, 2) == "-h" || arg.substr(0, 2) == "-?") { help = true; break; } else if (arg.find("-m=") == 0) { switch (arg[3]) { case 'a': mode = Auto; break; case 'c': mode = Create; break; case 'v': mode = Verify; break; case 's': mode = Special; break; default: TEST_LOG_SS(Error, "Unknown command line options: '" << arg << "'!" << std::endl); exit(1); } } else if (arg.find("-t=") == 0) { #ifdef NDEBUG threads = FromString<size_t>(arg.substr(3, arg.size() - 3)); #endif } else if (arg.find("-f=") == 0) { filters.push_back(arg.substr(3, arg.size() - 3)); } else if (arg.find("-o=") == 0) { output = arg.substr(3, arg.size() - 3); } else if (arg.find("-r=") == 0) { ROOT_PATH = arg.substr(3, arg.size() - 3); } else if (arg.find("-pa=") == 0) { printAlign = FromString<bool>(arg.substr(4, arg.size() - 4)); } else { TEST_LOG_SS(Error, "Unknown command line options: '" << arg << "'!" << std::endl); exit(1); } } }
template <class T> bool Compare(const T * a, const T * b, size_t size, int64_t differenceMax, bool printError, int errorCountMax) { std::stringstream message; int errorCount = 0; for(size_t i = 0; i < size; ++i) { if(a[i] != b[i]) { if(differenceMax > 0) { int64_t difference = Simd::Max<int64_t>(a[i], b[i]) - Simd::Min<int64_t>(a[i], b[i]); if(difference <= differenceMax) continue; } errorCount++; if(printError) { if(errorCount == 1) message << std::endl << "Fail comparison: " << std::endl; message << "Error at [" << i << "] : " << a[i] << " != " << b[i] << "." << std::endl; } if(errorCount > errorCountMax) { if(printError) message << "Stop comparison." << std::endl; break; } } } if(printError && errorCount > 0) TEST_LOG_SS(Error, message.str()); return errorCount == 0; }
bool Compare(const float * a, const float * b, size_t size, float relativeDifferenceMax, bool printError, int errorCountMax, bool relative, const String & description) { std::stringstream message; int errorCount = 0; for(size_t i = 0; i < size; ++i) { float relativeDifference = relative ? ::fabs(a[i] - b[i]) /Simd::Max(::fabs(a[i]), ::fabs(b[i])) : ::fabs(a[i] - b[i]); if(relativeDifference >= relativeDifferenceMax) { errorCount++; if(printError) { if(errorCount == 1) message << std::endl << "Fail comparison: " << description << std::endl; message << "Error at [" << i << "] : " << a[i] << " != " << b[i] << "; (relative difference = " << relativeDifference << ")!" << std::endl; } if(errorCount > errorCountMax) { if(printError) message << "Stop comparison." << std::endl; break; } } } if(printError && errorCount > 0) TEST_LOG_SS(Error, message.str()); return errorCount == 0; }
bool AveragingBinarizationAutoTest(int width, int height, SimdCompareType type, const Func2 & f1, const Func2 & f2) { bool result = true; TEST_LOG_SS(Info, "Test " << f1.description << " & " << f2.description << " [" << width << ", " << height << "]."); View src(width, height, View::Gray8, NULL, TEST_ALIGN(width)); FillRandom(src); uint8_t value = 127; size_t neighborhood = 17; uint8_t threshold = 128; uint8_t positive = 7; uint8_t negative = 3; View d1(width, height, View::Gray8, NULL, TEST_ALIGN(width)); View d2(width, height, View::Gray8, NULL, TEST_ALIGN(width)); TEST_EXECUTE_AT_LEAST_MIN_TIME(f1.Call(src, value, neighborhood, threshold, positive, negative, d1, type)); TEST_EXECUTE_AT_LEAST_MIN_TIME(f2.Call(src, value, neighborhood, threshold, positive, negative, d2, type)); result = result && Compare(d1, d2, 0, true, 64); return result; }
bool AddFeatureDifferenceAutoTest(int width, int height, uint16_t weight, const Func & f1, const Func & f2) { bool result = true; TEST_LOG_SS(Info, "Test " << f1.description << " & " << f2.description << " [" << width << ", " << height << "] (" << weight/256 << "*256)."); View value(width, height, View::Gray8, NULL, TEST_ALIGN(width)); FillRandom(value); View lo(width, height, View::Gray8, NULL, TEST_ALIGN(width)); FillRandom(lo); View hi(width, height, View::Gray8, NULL, TEST_ALIGN(width)); FillRandom(hi); View differenceSrc(width, height, View::Gray8, NULL, TEST_ALIGN(width)); FillRandom(differenceSrc); View differenceDst1(width, height, View::Gray8, NULL, TEST_ALIGN(width)); View differenceDst2(width, height, View::Gray8, NULL, TEST_ALIGN(width)); TEST_EXECUTE_AT_LEAST_MIN_TIME(f1.Call(value, lo, hi, weight, differenceSrc, differenceDst1)); TEST_EXECUTE_AT_LEAST_MIN_TIME(f2.Call(value, lo, hi, weight, differenceSrc, differenceDst2)); result = result && Compare(differenceDst1, differenceDst2, 0, true, 32, 0); return result; }
bool IntegralAutoTest(int width, int height, bool sqsumEnable, bool tiltedEnable, View::Format sumFormat, View::Format sqsumFormat, const Func & f1, const Func & f2) { bool result = true; TEST_LOG_SS(Info, "Test " << f1.description << " & " << f2.description << " [" << width << ", " << height << "]."); View src(width, height, View::Gray8, NULL, TEST_ALIGN(width)); FillRandom(src); View sum1(width + 1, height + 1, sumFormat, NULL, TEST_ALIGN(width)); View sum2(width + 1, height + 1, sumFormat, NULL, TEST_ALIGN(width)); View sqsum1, sqsum2, tilted1, tilted2; if(sqsumEnable) { sqsum1.Recreate(width + 1, height + 1, sqsumFormat, NULL, TEST_ALIGN(width)); sqsum2.Recreate(width + 1, height + 1, sqsumFormat, NULL, TEST_ALIGN(width)); } if(tiltedEnable) { tilted1.Recreate(width + 1, height + 1, sumFormat, NULL, TEST_ALIGN(width)); tilted2.Recreate(width + 1, height + 1, sumFormat, NULL, TEST_ALIGN(width)); } TEST_EXECUTE_AT_LEAST_MIN_TIME(f1.Call(src, sum1, sqsum1, tilted1)); TEST_EXECUTE_AT_LEAST_MIN_TIME(f2.Call(src, sum2, sqsum2, tilted2)); result = result && Compare(sum1, sum2, 0, true, 32, 0, "sum"); if(sqsumEnable) result = result && Compare(sqsum1, sqsum2, 0, true, 32, 0, "sqsum"); if(tiltedEnable) result = result && Compare(tilted1, tilted2, 0, true, 32, 0, "tilted"); return result; }
bool ShiftDetectorFileSpecialTest() { typedef Simd::ShiftDetector<Simd::Allocator> ShiftDetector; ShiftDetector shiftDetector; ShiftDetector::View background; String path = ROOT_PATH + "/data/image/face/lena.pgm"; if (!background.Load(path)) { TEST_LOG_SS(Error, "Can't load test image '" << path << "' !"); return false; } shiftDetector.InitBuffers(background.Size(), 4); shiftDetector.SetBackground(background); ShiftDetector::Rect region(64, 64, 192, 192); ShiftDetector::View current = background.Region(region.Shifted(10, 10)); if (shiftDetector.Estimate(current, region, 32)) { ShiftDetector::Point shift = shiftDetector.Shift(); std::cout << "Shift = (" << shift.x << ", " << shift.y << "). " << std::endl; } else std::cout << "Can't find shift for current image!" << std::endl; return true; }
bool YuvToBgraAutoTest(int width, int height, const Func & f1, const Func & f2, int dx, int dy) { bool result = true; TEST_LOG_SS(Info, "Test " << f1.description << " & " << f2.description << " [" << width << ", " << height << "]."); const int uvWidth = width/dx; const int uvHeight = height/dy; View y(width, height, View::Gray8, NULL, TEST_ALIGN(width)); FillRandom(y); View u(uvWidth, uvHeight, View::Gray8, NULL, TEST_ALIGN(uvWidth)); FillRandom(u); View v(uvWidth, uvHeight, View::Gray8, NULL, TEST_ALIGN(uvWidth)); FillRandom(v); View bgra1(width, height, View::Bgra32, NULL, TEST_ALIGN(width)); View bgra2(width, height, View::Bgra32, NULL, TEST_ALIGN(width)); TEST_EXECUTE_AT_LEAST_MIN_TIME(f1.Call(y, u, v, bgra1)); TEST_EXECUTE_AT_LEAST_MIN_TIME(f2.Call(y, u, v, bgra2)); result = result && Compare(bgra1, bgra2, 0, true, 64); return result; }
bool Bgr48pToBgra32AutoTest(int width, int height, const Func & f1, const Func & f2) { bool result = true; TEST_LOG_SS(Info, "Test " << f1.description << " & " << f2.description << " for size [" << width << "," << height << "]."); View blue(width, height, View::Int16, NULL, TEST_ALIGN(width)); FillRandom(blue); View green(width, height, View::Int16, NULL, TEST_ALIGN(width)); FillRandom(green); View red(width, height, View::Int16, NULL, TEST_ALIGN(width)); FillRandom(red); uint8_t alpha = 0xFF; View bgra1(width, height, View::Bgra32, NULL, TEST_ALIGN(width)); View bgra2(width, height, View::Bgra32, NULL, TEST_ALIGN(width)); TEST_EXECUTE_AT_LEAST_MIN_TIME(f1.Call(blue, green, red, bgra1, alpha)); TEST_EXECUTE_AT_LEAST_MIN_TIME(f2.Call(blue, green, red, bgra2, alpha)); result = result && Compare(bgra1, bgra2, 0, true, 32); return result; }
int MakeSpecialTests(const Groups & groups, const Options & options) { for (const Test::Group & group : groups) { TEST_LOG_SS(Info, group.name << "SpecialTest - is started :"); bool result = group.specialTest(); TEST_LOG_SS(Info, group.name << "SpecialTest - data is finished " << (result ? "successfully." : "with errors!") << std::endl); if (!result) { TEST_LOG_SS(Error, "ERROR! TEST EXECUTION IS TERMINATED !" << std::endl); return 1; } } TEST_LOG_SS(Info, "ALL TESTS ARE FINISHED SUCCESSFULLY!" << std::endl); return 0; }
bool ShiftDetectorRandSpecialTest() { typedef Simd::ShiftDetector<Simd::Allocator> ShiftDetector; ::srand(1); Rect region; View background(1920, 1080, View::Gray8); if (!CreateBackground(background, region)) return false; ShiftDetector shiftDetector; double time; time = GetTime(); shiftDetector.InitBuffers(background.Size(), 6, ShiftDetector::TextureGray, ShiftDetector::SquaredDifference); TEST_LOG_SS(Info, "InitBuffers : " << (GetTime() - time) * 1000 << " ms "); time = GetTime(); shiftDetector.SetBackground(background); TEST_LOG_SS(Info, "SetBackground : " << (GetTime() - time) * 1000 << " ms "); int n = 10; time = GetTime(); for (int i = 0; i < n; ++i) { const int ms = (int)region.Width() / 4; Point ss(Random(2*ms) - ms, Random(2*ms) - ms); shiftDetector.Estimate(background.Region(region), region.Shifted(ss), ms*2); ShiftDetector::FPoint ds = shiftDetector.ProximateShift(); if (Simd::SquaredDistance(ShiftDetector::FPoint(ss), ds) > 1.0) { Simd::DrawRectangle(background, region, uint8_t(255)); Simd::DrawRectangle(background, region.Shifted(ss), uint8_t(0)); background.Save("background.pgm"); TEST_LOG_SS(Error, "Detected shift (" << ds.x << ", " << ds.y << ") is not equal to original shift (" << ss.x << ", " << ss.y << ") !"); return false; } } TEST_LOG_SS(Info, "Estimate : " << (GetTime() - time) * 1000.0 / n << " ms "); return true; }
void Run() { for(size_t i = 0; i < _groups.size() && !s_stopped; ++i) { _progress = double(i)/double(_groups.size()); const Group & group = _groups[i]; TEST_LOG_SS(Info, group.name << "AutoTest is started :"); bool result = group.autoTest(); TEST_LOG_SS(Info, group.name << "AutoTest - is finished " << (result ? "successfully." : "with errors!") << std::endl); if(!result) { s_stopped = true; TEST_LOG_SS(Error, "ERROR! TEST EXECUTION IS TERMINATED !" << std::endl); return; } } _progress = 1.0; }
int MakeDataTests(const Groups & groups, const Options & options) { for (const Test::Group & group : groups) { bool create = options.mode == Test::Options::Create; TEST_LOG_SS(Info, group.name << "DataTest - data " << (create ? "creation" : "verification") << " is started :"); bool result = group.dataTest(create); TEST_LOG_SS(Info, group.name << "DataTest - data " << (create ? "creation" : "verification") << " is finished " << (result ? "successfully." : "with errors!") << std::endl); if (!result) { TEST_LOG_SS(Error, "ERROR! TEST EXECUTION IS TERMINATED !" << std::endl); return 1; } } TEST_LOG_SS(Info, "ALL TESTS ARE FINISHED SUCCESSFULLY!" << std::endl); return 0; }
bool Compare(const Rect & a, const Rect & b, bool printError) { bool result(a == b); if(!result && printError) { TEST_LOG_SS(Error, "Rectangles is not equal: (" << a.left << ", " << a.top << ", " << a.right << ", " << a.bottom << ") != (" << b.left << ", " << b.top << ", " << b.right << ", " << b.bottom << ") !"); } return result; }
int MakeAutoTests(const Groups & groups, const Options & options) { if (options.threads > 0) { TEST_LOG_SS(Info, "Test threads count = " << options.threads); Test::Log::s_log.SetLevel(Test::Log::Error); Test::TaskPtrs tasks; for (size_t i = 0; i < options.threads; ++i) tasks.push_back(Test::TaskPtr(new Test::Task(groups, true))); std::cout << std::endl; double progress; do { progress = 0; for (size_t i = 0; i < tasks.size(); ++i) progress += tasks[i]->Progress(); progress /= double(tasks.size()); std::cout << "\rTest progress = " << int(progress*100.0) << "%."; Test::Sleep(40); } while (progress < 1.0 && !Test::Task::s_stopped); std::cout << std::endl << std::endl; Test::Log::s_log.SetLevel(Test::Log::Info); } else { Test::Task task(groups, false); task.Run(); } if (Test::Task::s_stopped) return 1; TEST_LOG_SS(Info, "ALL TESTS ARE FINISHED SUCCESSFULLY!" << std::endl); #ifdef TEST_PERFORMANCE_TEST_ENABLE TEST_LOG_SS(Info, Test::PerformanceMeasurerStorage::s_storage.Report(true, options.printAlign, false)); #endif return 0; }
bool AddFeatureDifferenceDataTest(bool create, int width, int height, const Func & f) { bool result = true; Data data(f.description); TEST_LOG_SS(Info, (create ? "Create" : "Verify") << " test " << f.description << " [" << width << ", " << height << "]."); View value(width, height, View::Gray8, NULL, TEST_ALIGN(width)); View lo(width, height, View::Gray8, NULL, TEST_ALIGN(width)); View hi(width, height, View::Gray8, NULL, TEST_ALIGN(width)); View differenceSrc(width, height, View::Gray8, NULL, TEST_ALIGN(width)); View differenceDst1(width, height, View::Gray8, NULL, TEST_ALIGN(width)); View differenceDst2(width, height, View::Gray8, NULL, TEST_ALIGN(width)); const uint16_t weight = 256*7; if(create) { FillRandom(value); FillRandom(lo); FillRandom(hi); FillRandom(differenceSrc); TEST_SAVE(value); TEST_SAVE(lo); TEST_SAVE(hi); TEST_SAVE(differenceSrc); f.Call(value, lo, hi, weight, differenceSrc, differenceDst1); TEST_SAVE(differenceDst1); } else { TEST_LOAD(value); TEST_LOAD(lo); TEST_LOAD(hi); TEST_LOAD(differenceSrc); TEST_LOAD(differenceDst1); f.Call(value, lo, hi, weight, differenceSrc, differenceDst2); TEST_SAVE(differenceDst2); result = result && Compare(differenceDst1, differenceDst2, 0, true, 32, 0); } return result; }
bool IntegralDataTest(bool create, int width, int height, const Func & f) { bool result = true; Data data(f.description); TEST_LOG_SS(Info, (create ? "Create" : "Verify") << " test " << f.description << " [" << width << ", " << height << "]."); View src(width, height, View::Gray8, NULL, TEST_ALIGN(width)); View sum1(width + 1, height + 1, View::Int32, NULL, TEST_ALIGN(width)); View sum2(width + 1, height + 1, View::Int32, NULL, TEST_ALIGN(width)); View sqsum1(width + 1, height + 1, View::Int32, NULL, TEST_ALIGN(width)); View sqsum2(width + 1, height + 1, View::Int32, NULL, TEST_ALIGN(width)); View tilted1(width + 1, height + 1, View::Int32, NULL, TEST_ALIGN(width)); View tilted2(width + 1, height + 1, View::Int32, NULL, TEST_ALIGN(width)); if(create) { FillRandom(src); TEST_SAVE(src); f.Call(src, sum1, sqsum1, tilted1); TEST_SAVE(sum1); TEST_SAVE(sqsum1); TEST_SAVE(tilted1); } else { TEST_LOAD(src); TEST_LOAD(sum1); TEST_LOAD(sqsum1); TEST_LOAD(tilted1); f.Call(src, sum2, sqsum2, tilted2); TEST_SAVE(sum2); TEST_SAVE(sqsum2); TEST_SAVE(tilted2); result = result && Compare(sum1, sum2, 0, true, 32, 0, "sum"); result = result && Compare(sqsum1, sqsum2, 0, true, 32, 0, "sqsum"); result = result && Compare(tilted1, tilted2, 0, true, 32, 0, "tilted"); } return result; }
template <class Channel> bool Compare(const View & a, const View & b, int differenceMax, bool printError, int errorCountMax, int valueCycle, const String & description) { std::stringstream message; int errorCount = 0; size_t channelCount = a.ChannelCount(); size_t width = channelCount*a.width; for(size_t row = 0; row < a.height && errorCount < errorCountMax; ++row) { const Channel * pA = (const Channel*)(a.data + row*a.stride); const Channel * pB = (const Channel*)(b.data + row*b.stride); for(size_t offset = 0; offset < width; ++offset) { if(pA[offset] != pB[offset]) { if(differenceMax > 0) { Channel difference = Simd::Max(pA[offset], pB[offset]) - Simd::Min(pA[offset], pB[offset]); if(valueCycle > 0) difference = Simd::Min<Channel>(difference, valueCycle - difference); if(difference <= differenceMax) continue; } errorCount++; if(printError) { if(errorCount == 1) message << std::endl << "Fail comparison: " << description << std::endl; size_t col = offset/channelCount; message << "Error at [" << col << "," << row << "] : (" << (int)pA[col*channelCount]; for(size_t channel = 1; channel < channelCount; ++channel) message << "," << (int)pA[col*channelCount + channel]; message << ") != (" << (int)pB[col*channelCount]; for(size_t channel = 1; channel < channelCount; ++channel) message << "," << (int)pB[col*channelCount + channel]; message << ")." << std::endl; } if(errorCount >= errorCountMax) { if(printError) message << "Stop comparison." << std::endl; break; } } } } if(printError && errorCount > 0) TEST_LOG_SS(Error, message.str()); return errorCount == 0; }
bool YuvToBgraDataTest(bool create, int width, int height, const Func & f, int dx, int dy) { bool result = true; Data data(f.description); TEST_LOG_SS(Info, (create ? "Create" : "Verify") << " test " << f.description << " [" << width << ", " << height << "]."); const int uvWidth = width/dx; const int uvHeight = height/dy; View y(width, height, View::Gray8, NULL, TEST_ALIGN(width)); View u(uvWidth, uvHeight, View::Gray8, NULL, TEST_ALIGN(uvWidth)); View v(uvWidth, uvHeight, View::Gray8, NULL, TEST_ALIGN(uvWidth)); View bgra1(width, height, View::Bgra32, NULL, TEST_ALIGN(width)); View bgra2(width, height, View::Bgra32, NULL, TEST_ALIGN(width)); if(create) { FillRandom(y); FillRandom(u); FillRandom(v); TEST_SAVE(y); TEST_SAVE(u); TEST_SAVE(v); f.Call(y, u, v, bgra1); TEST_SAVE(bgra1); } else { TEST_LOAD(y); TEST_LOAD(u); TEST_LOAD(v); TEST_LOAD(bgra1); f.Call(y, u, v, bgra2); TEST_SAVE(bgra2); result = result && Compare(bgra1, bgra2, 0, true, 64); } return result; }
bool SegmentationPropagate2x2DataTest(bool create, int width, int height, const FuncP & f) { bool result = true; Data data(f.description); TEST_LOG_SS(Info, (create ? "Create" : "Verify") << " test " << f.description << " [" << width << ", " << height << "]."); const uint8_t currentIndex = 3, invalidIndex = 2, emptyIndex = 0, differenceThreshold = 128; View parent(width, height, View::Gray8, NULL, TEST_ALIGN(width)); View childSrc(2*width, 2*height, View::Gray8, NULL, TEST_ALIGN(width)); View difference(2*width, 2*height, View::Gray8, NULL, TEST_ALIGN(width)); View childDst1(2*width, 2*height, View::Gray8, NULL, TEST_ALIGN(width)); View childDst2(2*width, 2*height, View::Gray8, NULL, TEST_ALIGN(width)); const uint8_t oldIndex = 3, newIndex = 2; if(create) { FillRandomMask(parent, currentIndex); FillRandom(childSrc, 0, currentIndex - 1); FillRandom(difference, 255); TEST_SAVE(parent); TEST_SAVE(childSrc); TEST_SAVE(difference); f.Call(parent, childSrc, childDst1, difference, currentIndex, invalidIndex, emptyIndex, differenceThreshold); TEST_SAVE(childDst1); } else { TEST_LOAD(parent); TEST_LOAD(childSrc); TEST_LOAD(difference); TEST_LOAD(childDst1); f.Call(parent, childSrc, childDst2, difference, currentIndex, invalidIndex, emptyIndex, differenceThreshold); TEST_SAVE(childDst2); result = result && Compare(childDst1, childDst2, 0, true, 64); } return result; }
bool Bgr48pToBgra32DataTest(bool create, int width, int height, const Func & f) { bool result = true; Data data(f.description); TEST_LOG_SS(Info, (create ? "Create" : "Verify") << " test " << f.description << " [" << width << ", " << height << "]."); View blue(width, height, View::Int16, NULL, TEST_ALIGN(width)); View green(width, height, View::Int16, NULL, TEST_ALIGN(width)); View red(width, height, View::Int16, NULL, TEST_ALIGN(width)); uint8_t alpha = 0xFF; View bgra1(width, height, View::Bgra32, NULL, TEST_ALIGN(width)); View bgra2(width, height, View::Bgra32, NULL, TEST_ALIGN(width)); if(create) { FillRandom(blue); FillRandom(green); FillRandom(red); TEST_SAVE(blue); TEST_SAVE(green); TEST_SAVE(red); f.Call(blue, green, red, bgra1, alpha); TEST_SAVE(bgra1); } else { TEST_LOAD(blue); TEST_LOAD(green); TEST_LOAD(red); TEST_LOAD(bgra1); f.Call(blue, green, red, bgra2, alpha); TEST_SAVE(bgra2); result = result && Compare(bgra1, bgra2, 0, true, 32); } return result; }
bool AlphaBlendingDataTest(bool create, View::Format format, int width, int height, const FuncAB & f) { bool result = true; Data data(f.description); TEST_LOG_SS(Info, (create ? "Create" : "Verify") << " test " << f.description << " [" << width << ", " << height << "]."); View s(width, height, format, NULL, TEST_ALIGN(width)); View a(width, height, View::Gray8, NULL, TEST_ALIGN(width)); View b(width, height, format, NULL, TEST_ALIGN(width)); View d1(width, height, format, NULL, TEST_ALIGN(width)); View d2(width, height, format, NULL, TEST_ALIGN(width)); if(create) { FillRandom(s); FillRandom(a); FillRandom(b); TEST_SAVE(s); TEST_SAVE(a); TEST_SAVE(b); f.Call(s, a, b, d1); TEST_SAVE(d1); } else { TEST_LOAD(s); TEST_LOAD(a); TEST_LOAD(b); TEST_LOAD(d1); f.Call(s, a, b, d2); TEST_SAVE(d2); result = result && Compare(d1, d2, 0, true, 64); } return result; }
bool TextureGetDifferenceSumDataTest(bool create, int width, int height, const Func3 & f) { bool result = true; Data data(f.description); TEST_LOG_SS(Info, (create ? "Create" : "Verify") << " test " << f.description << " [" << width << ", " << height << "]."); View src(width, height, View::Gray8, NULL, TEST_ALIGN(width)); View lo(width, height, View::Gray8, NULL, TEST_ALIGN(width)); View hi(width, height, View::Gray8, NULL, TEST_ALIGN(width)); int64_t s1, s2; if(create) { FillRandom(src); FillRandom(lo); FillRandom(hi); TEST_SAVE(src); TEST_SAVE(lo); TEST_SAVE(hi); f.Call(src, lo, hi, &s1); TEST_SAVE(s1); } else { TEST_LOAD(src); TEST_LOAD(lo); TEST_LOAD(hi); TEST_LOAD(s1); f.Call(src, lo, hi, &s2); TEST_SAVE(s2); TEST_CHECK_VALUE(s); } return result; }
bool TextureBoostedSaturatedGradientDataTest(bool create, int width, int height, const Func1 & f) { bool result = true; Data data(f.description); TEST_LOG_SS(Info, (create ? "Create" : "Verify") << " test " << f.description << " [" << width << ", " << height << "]."); View src(width, height, View::Gray8, NULL, TEST_ALIGN(width)); View dx1(width, height, View::Gray8, NULL, TEST_ALIGN(width)); View dy1(width, height, View::Gray8, NULL, TEST_ALIGN(width)); View dx2(width, height, View::Gray8, NULL, TEST_ALIGN(width)); View dy2(width, height, View::Gray8, NULL, TEST_ALIGN(width)); const int saturation = 16, boost = 4; if(create) { FillRandom(src); TEST_SAVE(src); f.Call(src, saturation, boost, dx1, dy1); TEST_SAVE(dx1); TEST_SAVE(dy1); } else { TEST_LOAD(src); TEST_LOAD(dx1); TEST_LOAD(dy1); f.Call(src, saturation, boost, dx2, dy2); TEST_SAVE(dx2); TEST_SAVE(dy2); result = result && Compare(dx1, dx2, 0, true, 32, 0, "dx"); result = result && Compare(dy1, dy2, 0, true, 32, 0, "dy"); } return result; }
bool DeinterleaveUvDataTest(bool create, int width, int height, const Func & f) { bool result = true; Data data(f.description); TEST_LOG_SS(Info, (create ? "Create" : "Verify") << " test " << f.description << " [" << width << ", " << height << "]."); View uv(width, height, View::Uv16, NULL, TEST_ALIGN(width)); View u1(width, height, View::Gray8, NULL, TEST_ALIGN(width)); View v1(width, height, View::Gray8, NULL, TEST_ALIGN(width)); View u2(width, height, View::Gray8, NULL, TEST_ALIGN(width)); View v2(width, height, View::Gray8, NULL, TEST_ALIGN(width)); if(create) { FillRandom(uv); TEST_SAVE(uv); f.Call(uv, u1, v1); TEST_SAVE(u1); TEST_SAVE(v1); } else { TEST_LOAD(uv); TEST_LOAD(u1); TEST_LOAD(v1); f.Call(uv, u2, v2); TEST_SAVE(u2); TEST_SAVE(v2); result = result && Compare(u1, u2, 0, true, 32, 0, "u"); result = result && Compare(v1, v2, 0, true, 32, 0, "v"); } return result; }
bool AveragingBinarizationDataTest(bool create, int width, int height, SimdCompareType type, const Func2 & f) { bool result = true; Data data(f.description); TEST_LOG_SS(Info, (create ? "Create" : "Verify") << " test " << f.description << " [" << width << ", " << height << "]."); View src(width, height, View::Gray8, NULL, TEST_ALIGN(width)); View dst1(width, height, View::Gray8, NULL, TEST_ALIGN(width)); View dst2(width, height, View::Gray8, NULL, TEST_ALIGN(width)); const uint8_t value = 127; const size_t neighborhood = 17; const uint8_t threshold = 128; const uint8_t positive = 7; const uint8_t negative = 3; if(create) { FillRandom(src); TEST_SAVE(src); f.Call(src, value, neighborhood, threshold, positive, negative, dst1, type); TEST_SAVE(dst1); } else { TEST_LOAD(src); TEST_LOAD(dst1); f.Call(src, value, neighborhood, threshold, positive, negative, dst2, type); TEST_SAVE(dst2); result = result && Compare(dst1, dst2, 0, true, 64); } return result; }
bool HistogramAutoTest(int width, int height, const FuncH & f1, const FuncH & f2) { bool result = true; TEST_LOG_SS(Info, "Test " << f1.description << " & " << f2.description << " [" << width << ", " << height << "]."); View s(int(width), int(height), View::Gray8, NULL, TEST_ALIGN(width)); FillRandom(s); Histogram h1 = {0}, h2 = {0}; TEST_EXECUTE_AT_LEAST_MIN_TIME(f1.Call(s, h1)); TEST_EXECUTE_AT_LEAST_MIN_TIME(f2.Call(s, h2)); result = result && Compare(h1, h2, 0, true, 32); return result; }
bool SegmentationShrinkRegionAutoTest(int width, int height, const FuncSR & f1, const FuncSR & f2) { bool result = true; TEST_LOG_SS(Info, "Test " << f1.description << " & " << f2.description << " for size [" << width << "," << height << "]."); const uint8_t index = 3; View s(width, height, View::Gray8, NULL, TEST_ALIGN(width)); Rect rs1(s.Size()), rs2(s.Size()), rd1, rd2; FillRhombMask(s, Rect(width*1/15, height*2/15, width*11/15, height*12/15), index); TEST_EXECUTE_AT_LEAST_MIN_TIME(f1.Call(s, index, rs1, rd1)); TEST_EXECUTE_AT_LEAST_MIN_TIME(f2.Call(s, index, rs2, rd2)); result = result && Compare(rd1, rd2, true); return result; }
bool ContourAnchorsDataTest(bool create, int width, int height, const FuncA & f) { bool result = true; Data data(f.description); TEST_LOG_SS(Info, (create ? "Create" : "Verify") << " test " << f.description << " [" << width << ", " << height << "]."); View s(width, height, View::Int16, NULL, TEST_ALIGN(width)); View d1(width, height, View::Gray8, NULL, TEST_ALIGN(width)); View d2(width, height, View::Gray8, NULL, TEST_ALIGN(width)); if(create) { FillRandom(s); TEST_SAVE(s); Simd::Fill(d1, 0); f.Call(s, 3, 0, d1); TEST_SAVE(d1); } else { TEST_LOAD(s); TEST_LOAD(d1); Simd::Fill(d2, 0); f.Call(s, 3, 0, d2); TEST_SAVE(d2); result = result && Compare(d1, d2, 0, true, 32, 0); } return result; }