public void ExtractFHogFeatures2() { var path = this.GetDataFile($"{LoadTarget}.bmp"); var tests = new[] { new { Type = MatrixElementTypes.Float, ExpectResult = true }, new { Type = MatrixElementTypes.Double, ExpectResult = true } }; foreach (var output in tests) { Array2DBase imageObj = null; Array2DMatrixBase outputObj = null; try { imageObj = DlibTest.LoadImageHelp(ImageTypes.RgbPixel, path); switch (output.Type) { case MatrixElementTypes.Float: outputObj = Dlib.ExtractFHogFeatures <float>(imageObj); break; case MatrixElementTypes.Double: outputObj = Dlib.ExtractFHogFeatures <double>(imageObj); break; default: throw new ArgumentOutOfRangeException(); } MatrixBase matrix = Dlib.DrawFHog(outputObj); if (this.CanGuiDebug) { var window = new ImageWindow(matrix); window.WaitUntilClosed(); } } catch (Exception e) { Console.WriteLine(e); throw; } finally { if (imageObj != null) { this.DisposeAndCheckDisposedState(imageObj); } if (outputObj != null) { this.DisposeAndCheckDisposedState(outputObj); } } } }
public void ExtractFHogFeatures() { const string testName = nameof(this.ExtractFHogFeatures); var path = this.GetDataFile($"{LoadTarget}.bmp"); var tests = new[] { new { Type = MatrixElementTypes.Float, ExpectResult = true }, new { Type = MatrixElementTypes.Double, ExpectResult = true }, new { Type = MatrixElementTypes.RgbPixel, ExpectResult = false }, new { Type = MatrixElementTypes.RgbAlphaPixel, ExpectResult = false }, new { Type = MatrixElementTypes.HsiPixel, ExpectResult = false }, new { Type = MatrixElementTypes.LabPixel, ExpectResult = false }, new { Type = MatrixElementTypes.UInt32, ExpectResult = false }, new { Type = MatrixElementTypes.UInt8, ExpectResult = false }, new { Type = MatrixElementTypes.UInt16, ExpectResult = false }, new { Type = MatrixElementTypes.Int8, ExpectResult = false }, new { Type = MatrixElementTypes.Int16, ExpectResult = false }, new { Type = MatrixElementTypes.Int32, ExpectResult = false } }; foreach (ImageTypes inputType in Enum.GetValues(typeof(ImageTypes))) { foreach (var output in tests) { if (inputType == ImageTypes.Matrix) { continue; } var expectResult = output.ExpectResult; var imageObj = DlibTest.LoadImageHelp(inputType, path); Array2DMatrixBase outputObj = null; var outputImageAction = new Func <bool, Array2DMatrixBase>(expect => { switch (output.Type) { case MatrixElementTypes.UInt8: outputObj = Dlib.ExtractFHogFeatures <byte>(imageObj); break; case MatrixElementTypes.UInt16: outputObj = Dlib.ExtractFHogFeatures <ushort>(imageObj); break; case MatrixElementTypes.UInt32: outputObj = Dlib.ExtractFHogFeatures <uint>(imageObj); break; case MatrixElementTypes.Int8: outputObj = Dlib.ExtractFHogFeatures <sbyte>(imageObj); break; case MatrixElementTypes.Int16: outputObj = Dlib.ExtractFHogFeatures <short>(imageObj); break; case MatrixElementTypes.Int32: outputObj = Dlib.ExtractFHogFeatures <int>(imageObj); break; case MatrixElementTypes.Float: outputObj = Dlib.ExtractFHogFeatures <float>(imageObj); break; case MatrixElementTypes.Double: outputObj = Dlib.ExtractFHogFeatures <double>(imageObj); break; case MatrixElementTypes.RgbPixel: outputObj = Dlib.ExtractFHogFeatures <RgbPixel>(imageObj); break; case MatrixElementTypes.RgbAlphaPixel: outputObj = Dlib.ExtractFHogFeatures <RgbAlphaPixel>(imageObj); break; case MatrixElementTypes.HsiPixel: outputObj = Dlib.ExtractFHogFeatures <HsiPixel>(imageObj); break; case MatrixElementTypes.LabPixel: outputObj = Dlib.ExtractFHogFeatures <LabPixel>(imageObj); break; default: throw new ArgumentOutOfRangeException(); } return(outputObj); }); var successAction = new Action <Array2DMatrixBase>(image => { MatrixBase ret = null; try { ret = Dlib.DrawFHog(image); } catch (Exception e) { Console.WriteLine(e); throw; } finally { if (ret != null) { this.DisposeAndCheckDisposedState(ret); } } }); var failAction = new Action(() => { Assert.True(false, $"{testName} should throw exception for InputType: {inputType}, OutputType: {output.Type}."); }); var finallyAction = new Action(() => { if (imageObj != null) { this.DisposeAndCheckDisposedState(imageObj); } if (outputObj != null) { this.DisposeAndCheckDisposedState(outputObj); } }); var exceptionAction = new Action(() => { Console.WriteLine($"Failed to execute {testName} to InputType: {inputType}, OutputType: {output.Type}."); }); DoTest(outputImageAction, expectResult, successAction, finallyAction, failAction, exceptionAction); } } }