/// <summary> /// Initiate the camera /// </summary> public Camera() { // You can select other size and other format, this is a very basic one supported by all types of webcams including old ones VideoConnectionSettings settings = new VideoConnectionSettings(0, (640, 480), Iot.Device.Media.PixelFormat.JPEG); _device = VideoDevice.Create(settings); // if the device has sufficent ram, enabling pooling significantly improves frames per second by preventing GC. _device.ImageBufferPoolingEnabled = true; }
private Camera() { // You can select other size and other format, this is a very basic one supported by all types of webcams including old ones VideoConnectionSettings settings = new VideoConnectionSettings(0, (640, 480), Iot.Device.Media.PixelFormat.JPEG); Device = VideoDevice.Create(settings); IsRunning = true; new Thread(() => { TakePictures(); }).Start(); }
public static void Main(string[] args) { VideoConnectionSettings settings = new VideoConnectionSettings(0, (2560, 1920), PixelFormat.JPEG); using VideoDevice device = VideoDevice.Create(settings); // Get the supported formats of the device foreach (PixelFormat item in device.GetSupportedPixelFormats()) { Console.Write($"{item} "); } Console.WriteLine(); // Get the resolutions of the format foreach (var resolution in device.GetPixelFormatResolutions(PixelFormat.YUYV)) { Console.Write($"{resolution.Width}x{resolution.Height} "); } Console.WriteLine(); // Query v4l2 controls default and current value VideoDeviceValue value = device.GetVideoDeviceValue(VideoDeviceValueType.Rotate); Console.WriteLine($"{value.Name} Min: {value.Minimum} Max: {value.Maximum} Step: {value.Step} Default: {value.DefaultValue} Current: {value.CurrentValue}"); string path = Directory.GetCurrentDirectory(); // Take photos device.Capture($"{path}/jpg_direct_output.jpg"); // Change capture setting device.Settings.PixelFormat = PixelFormat.YUV420; // Convert pixel format Color[] colors = VideoDevice.Yv12ToRgb(device.Capture(), settings.CaptureSize); Bitmap bitmap = VideoDevice.RgbToBitmap(settings.CaptureSize, colors); bitmap.Save($"{path}/yuyv_to_jpg.jpg", System.Drawing.Imaging.ImageFormat.Jpeg); }