bool YuvToAnyAutoTest(int width, int height, bool is420, View::Format dstType, const Func & f1, const Func & f2) { bool result = true; std::cout << "Test " << f1.description << " & " << f2.description << " [" << width << ", " << height << "]." << std::endl; const int uvWidth = is420 ? width/2 : width; const int uvHeight = is420 ? height/2 : height; 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 dst1(width, height, dstType, NULL, TEST_ALIGN(width)); View dst2(width, height, dstType, NULL, TEST_ALIGN(width)); TEST_EXECUTE_AT_LEAST_MIN_TIME(f1.Call(y, u, v, dst1)); TEST_EXECUTE_AT_LEAST_MIN_TIME(f2.Call(y, u, v, dst2)); result = result && Compare(dst1, dst2, 0, true, 64); return result; }
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 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 DifferenceSumsMaskedAutoTest(int width, int height, const FuncM & f1, const FuncM & f2, int count) { bool result = true; std::cout << "Test " << f1.description << " & " << f2.description << " [" << width << ", " << height << "]." << std::endl; View a(width, height, View::Gray8, NULL, TEST_ALIGN(width)); FillRandom(a); View b(width, height, View::Gray8, NULL, TEST_ALIGN(width)); FillRandom(b); View m(width, height, View::Gray8, NULL, TEST_ALIGN(width)); uint8_t index = Random(256); FillRandomMask(m, index); Sums64 s1(count, 0), s2(count, 0); TEST_EXECUTE_AT_LEAST_MIN_TIME(f1.Call(a, b, m, index, s1.data())); TEST_EXECUTE_AT_LEAST_MIN_TIME(f2.Call(a, b, m, index, s2.data())); result = Compare(s1, s2, 0, true, count); 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; }
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 HistogramAutoTest(int width, int height, const FuncH & f1, const FuncH & f2) { bool result = true; std::cout << "Test " << f1.description << " & " << f2.description << " [" << width << ", " << height << "]." << std::endl; 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 AbsSecondDerivativeHistogramAutoTest(int width, int height, int step, int indent, const FuncASDH & f1, const FuncASDH & f2) { bool result = true; TEST_LOG_SS(Info, "Test " << f1.description << " & " << f2.description << " [" << width << ", " << height << "] (" << step << ", " << indent << ")."); 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, step, indent, h1)); TEST_EXECUTE_AT_LEAST_MIN_TIME(f2.Call(s, step, indent, h2)); result = result && Compare(h1, h2, 0, true, 32); return result; }
bool SegmentationChangeIndexAutoTest(int width, int height, const FuncCI & f1, const FuncCI & f2) { bool result = true; TEST_LOG_SS(Info, "Test " << f1.description << " & " << f2.description << " for size [" << width << "," << height << "]."); const uint8_t oldIndex = 3, newIndex = 2; View s(width, height, View::Gray8, NULL, TEST_ALIGN(width)); View d1(width, height, View::Gray8, NULL, TEST_ALIGN(width)); View d2(width, height, View::Gray8, NULL, TEST_ALIGN(width)); FillRandomMask(s, oldIndex); TEST_EXECUTE_AT_LEAST_MIN_TIME(f1.Call(s, oldIndex, newIndex, d1)); TEST_EXECUTE_AT_LEAST_MIN_TIME(f2.Call(s, oldIndex, newIndex, d2)); result = result && Compare(d1, d2, 0, true, 64); return result; }
bool ColorFilterAutoTest(View::Format format, int width, int height, const FuncC & f1, const FuncC & f2) { bool result = true; TEST_LOG_SS(Info, "Test " << f1.description << " & " << f2.description << " [" << width << ", " << height << "]."); View s(width, height, format, NULL, TEST_ALIGN(width)); FillRandom(s); View d1(width, height, format, NULL, TEST_ALIGN(width)); View d2(width, height, format, NULL, TEST_ALIGN(width)); TEST_EXECUTE_AT_LEAST_MIN_TIME(f1.Call(s, d1)); TEST_EXECUTE_AT_LEAST_MIN_TIME(f2.Call(s, d2)); result = result && Compare(d1, d2, 0, true, 32); return result; }
bool TexturePerformCompensationAutoTest(int width, int height, int shift, const Func4 & f1, const Func4 & f2) { bool result = true; TEST_LOG_SS(Info, "Test " << f1.description << " & " << f2.description << " [" << width << ", " << height << "] <" << shift << ">."); View src(width, height, View::Gray8, NULL, TEST_ALIGN(width)); FillRandom(src); View dst1(width, height, View::Gray8, NULL, TEST_ALIGN(width)); View dst2(width, height, View::Gray8, NULL, TEST_ALIGN(width)); TEST_EXECUTE_AT_LEAST_MIN_TIME(f1.Call(src, shift, dst1)); TEST_EXECUTE_AT_LEAST_MIN_TIME(f2.Call(src, shift, dst2)); result = result && Compare(dst1, dst2, 0, true, 32, 0); return result; }
bool AnyToAnyAutoTest(int width, int height, View::Format srcType, View::Format dstType, const Func & f1, const Func & f2) { bool result = true; TEST_LOG_SS(Info, "Test " << f1.description << " & " << f2.description << " for size [" << width << "," << height << "]."); View src(width, height, srcType, NULL, TEST_ALIGN(width)); FillRandom(src); View dst1(width, height, dstType, NULL, TEST_ALIGN(width)); View dst2(width, height, dstType, NULL, TEST_ALIGN(width)); TEST_EXECUTE_AT_LEAST_MIN_TIME(f1.Call(src, dst1)); TEST_EXECUTE_AT_LEAST_MIN_TIME(f2.Call(src, dst2)); result = result && Compare(dst1, dst2, 0, true, 64); return result; }
bool DifferenceSum32fAutoTest(int size, const FuncF & f1, const FuncF & f2) { bool result = true; std::cout << "Test " << f1.description << " & " << f2.description << " [" << size << "]." << std::endl; View a(size, 1, View::Float, NULL, TEST_ALIGN(size)); FillRandom32f(a); View b(size, 1, View::Float, NULL, TEST_ALIGN(size)); FillRandom32f(b); float s1, s2; TEST_EXECUTE_AT_LEAST_MIN_TIME(f1.Call(a, b, &s1)); TEST_EXECUTE_AT_LEAST_MIN_TIME(f2.Call(a, b, &s2)); result = Compare(s1, s2, EPS*10, true); return result; }
bool ContourAnchorsAutoTest(int width, int height, const FuncA & f1, const FuncA & f2) { bool result = true; TEST_LOG_SS(Info, "Test " << f1.description << " & " << f2.description << " [" << width << ", " << height << "]."); View s(width, height, View::Int16, NULL, TEST_ALIGN(width)); FillRandom(s); View d1(width, height, View::Gray8, NULL, TEST_ALIGN(width)); View d2(width, height, View::Gray8, NULL, TEST_ALIGN(width)); Simd::Fill(d1, 0); Simd::Fill(d2, 0); TEST_EXECUTE_AT_LEAST_MIN_TIME(f1.Call(s, 3, 0, d1)); TEST_EXECUTE_AT_LEAST_MIN_TIME(f2.Call(s, 3, 0, d2)); result = result && Compare(d1, d2, 0, true, 64); return result; }
bool StretchGrayAutoTest(int width, int height, const Func & f1, const Func & f2, int stretch) { bool result = true; std::cout << "Test " << f1.description << " & " << f2.description << " [" << width << ", " << height << "]." << std::endl; const int stretchedWidth = width*stretch; const int stretchedHeight = height*stretch; View s(width, height, View::Gray8, NULL, TEST_ALIGN(width)); FillRandom(s); View d1(stretchedWidth, stretchedHeight, View::Gray8, NULL, TEST_ALIGN(stretchedWidth)); View d2(stretchedWidth, stretchedHeight, View::Gray8, NULL, TEST_ALIGN(stretchedWidth)); TEST_EXECUTE_AT_LEAST_MIN_TIME(f1.Call(s, d1)); TEST_EXECUTE_AT_LEAST_MIN_TIME(f2.Call(s, d2)); result = result && Compare(d1, d2, 0, true, 64); return result; }
bool HistogramConditionalAutoTest(int width, int height, SimdCompareType type, const FuncHC & f1, const FuncHC & 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)); View m(int(width), int(height), View::Gray8, NULL, TEST_ALIGN(width)); uint8_t value = 127; FillRandom(s); FillRandom(m); Histogram h1 = { 0 }, h2 = { 0 }; TEST_EXECUTE_AT_LEAST_MIN_TIME(f1.Call(s, m, value, type, h1)); TEST_EXECUTE_AT_LEAST_MIN_TIME(f2.Call(s, m, value, type, h2)); result = result && Compare(h1, h2, 0, true, 32); return result; }
bool TextureBoostedSaturatedGradientAutoTest(int width, int height, int saturation, int boost, const Func1 & f1, const Func1 & f2) { bool result = true; TEST_LOG_SS(Info, "Test " << f1.description << " & " << f2.description << " [" << width << ", " << height << "] <" << saturation << ", " << boost << ">."); View src(width, height, View::Gray8, NULL, TEST_ALIGN(width)); FillRandom(src); 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)); TEST_EXECUTE_AT_LEAST_MIN_TIME(f1.Call(src, saturation, boost, dx1, dy1)); TEST_EXECUTE_AT_LEAST_MIN_TIME(f2.Call(src, saturation, boost, dx2, dy2)); result = result && Compare(dx1, dx2, 0, true, 32, 0, "dx"); result = result && Compare(dy1, dy2, 0, true, 32, 0, "dy"); return result; }
bool TextureGetDifferenceSumAutoTest(int width, int height, const Func3 & f1, const Func3 & 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 lo(width, height, View::Gray8, NULL, TEST_ALIGN(width)); FillRandom(lo); View hi(width, height, View::Gray8, NULL, TEST_ALIGN(width)); FillRandom(hi); int64_t s1, s2; TEST_EXECUTE_AT_LEAST_MIN_TIME(f1.Call(src, lo, hi, &s1)); TEST_EXECUTE_AT_LEAST_MIN_TIME(f2.Call(src, lo, hi, &s2)); TEST_CHECK_VALUE(s); return result; }
bool HistogramMaskedAutoTest(int width, int height, const FuncHM & f1, const FuncHM & 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)); View m(int(width), int(height), View::Gray8, NULL, TEST_ALIGN(width)); const uint8_t index = 77; FillRandom(s); FillRandomMask(m, index); Histogram h1 = {0}, h2 = {0}; TEST_EXECUTE_AT_LEAST_MIN_TIME(f1.Call(s, m, index, h1)); TEST_EXECUTE_AT_LEAST_MIN_TIME(f2.Call(s, m, index, h2)); result = result && Compare(h1, h2, 0, true, 32); return result; }
bool ShiftAutoTest(View::Format format, int width, int height, double dx, double dy, int crop, const Func & f1, const Func & f2) { bool result = true; TEST_LOG_SS(Info, std::setprecision(1) << std::fixed << "Test " << f1.description << " & " << f2.description << " [" << width << ", " << height << "]," << " (" << dx << ", " << dy << ", " << crop << ")."); View s(width, height, format, NULL, TEST_ALIGN(width)); FillRandom(s); View b(width, height, format, NULL, TEST_ALIGN(width)); FillRandom(b); View d1(width, height, format, NULL, TEST_ALIGN(width)); View d2(width, height, format, NULL, TEST_ALIGN(width)); TEST_EXECUTE_AT_LEAST_MIN_TIME(f1.Call(s, b, dx, dy, crop, crop, width - crop, height - crop, d1)); TEST_EXECUTE_AT_LEAST_MIN_TIME(f2.Call(s, b, dx, dy, crop, crop, width - crop, height - crop, d2)); result = result && Compare(d1, d2, 0, true, 32); return result; }
bool DeinterleaveUvAutoTest(int width, int height, const Func & f1, const Func & f2) { bool result = true; TEST_LOG_SS(Info, "Test " << f1.description << " & " << f2.description << " [" << width << ", " << height << "]."); View uv(width, height, View::Uv16, NULL, TEST_ALIGN(width)); FillRandom(uv); 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)); TEST_EXECUTE_AT_LEAST_MIN_TIME(f1.Call(uv, u1, v1)); TEST_EXECUTE_AT_LEAST_MIN_TIME(f2.Call(uv, u2, v2)); result = result && Compare(u1, u2, 0, true, 32); result = result && Compare(v1, v2, 0, true, 32); return result; }
bool BinarizationAutoTest(int width, int height, SimdCompareType type, const Func1 & f1, const Func1 & 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 = Random(256); uint8_t positive = Random(256); uint8_t negative = Random(256); 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, positive, negative, d1, type)); TEST_EXECUTE_AT_LEAST_MIN_TIME(f2.Call(src, value, positive, negative, d2, type)); result = result && Compare(d1, d2, 0, true, 32); return result; }
bool SegmentationPropagate2x2AutoTest(int width, int height, const FuncP & f1, const FuncP & f2) { bool result = true; TEST_LOG_SS(Info, "Test " << f1.description << " & " << f2.description << " for size [" << 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)); FillRandomMask(parent, currentIndex); FillRandom(childSrc, 0, currentIndex - 1); FillRandom(difference); TEST_EXECUTE_AT_LEAST_MIN_TIME(f1.Call(parent, childSrc, childDst1, difference, currentIndex, invalidIndex, emptyIndex, differenceThreshold)); TEST_EXECUTE_AT_LEAST_MIN_TIME(f2.Call(parent, childSrc, childDst2, difference, currentIndex, invalidIndex, emptyIndex, differenceThreshold)); result = result && Compare(childDst1, childDst2, 0, true, 64); return result; }
bool AlphaBlendingAutoTest(View::Format format, int width, int height, const FuncAB & f1, const FuncAB & f2) { bool result = true; TEST_LOG_SS(Info, "Test " << f1.description << " & " << f2.description << " for size [" << width << "," << height << "]."); View s(width, height, format, NULL, TEST_ALIGN(width)); FillRandom(s); View a(width, height, View::Gray8, NULL, TEST_ALIGN(width)); FillRandom(a); View b(width, height, format, NULL, TEST_ALIGN(width)); FillRandom(b); View d1(width, height, format, NULL, TEST_ALIGN(width)); View d2(width, height, format, NULL, TEST_ALIGN(width)); TEST_EXECUTE_AT_LEAST_MIN_TIME(f1.Call(s, a, b, d1)); TEST_EXECUTE_AT_LEAST_MIN_TIME(f2.Call(s, a, b, d2)); result = result && Compare(d1, d2, 0, true, 64); return result; }