public void cannot_use_factory_if_is_not_initialised() { using var module = new PiTopModule(new DummyGpioController()); var action = new Action(() => module.GetOrCreateCamera<FileSystemCamera>(new DirectoryInfo(Path.GetTempPath())) ); action.Should().Throw<InvalidOperationException>() .Which .Message .Should() .Match("Cannot find a factory if type PiTop.Abstractions.IConnectedDeviceFactory<PiTop.Camera.FileSystemCameraSettings, PiTop.Camera.FileSystemCamera>, make sure to configure the module calling UseCamera first."); }
static void Main(string[] args) { using var module = new PiTopModule() .UseCamera(); var count = OpenCvCamera.GetCameraCount(); Console.WriteLine($"Found {count} cameras available"); var camera = module.GetOrCreateCamera <OpenCvCamera>(0); var file = new FileInfo("./test.png"); var frame = camera.GetFrameAsMat(); frame.SaveImage(file.FullName); module.DisposeDevice(camera); Console.WriteLine($"Dumping frame at {file.FullName}"); }
public static T GetOrCreateCamera <T>(this PiTopModule module, DirectoryInfo directory, string imageFileSearchPattern = "*.png") where T : FileSystemCamera { return(module.GetOrCreateCamera <T>( new FileSystemCameraSettings(directory, imageFileSearchPattern))); }