public byte[] TakePicture(PictureSize pictureSize, Percent jpegCompressionRate = default(Percent)) { if (IsVideoStreamOpenned) { return(new byte[0]); } Console.WriteLine("TakePicture"); if (picturesCache.HasPicture(devicePath, pictureSize, jpegCompressionRate)) { Console.WriteLine("Read picture from cache"); return(picturesCache.GetPicture(devicePath, pictureSize, jpegCompressionRate)); } var pictureBuffer = RaspberryCamInterop.TakePicture(devicePath, (uint)pictureSize.Width, (uint)pictureSize.Height, (uint)(100 - jpegCompressionRate.Value)); var data = new byte[pictureBuffer.Size]; Marshal.Copy(pictureBuffer.Data, data, 0, pictureBuffer.Size); picturesCache.AddPicture(devicePath, pictureSize, jpegCompressionRate, data); return(data); }
public void StopVideoStreaming() { if (!IsVideoStreamOpenned) { return; } RaspberryCamInterop.CloseCameraStream(videoStreamHandle); videoStreamHandle = IntPtr.Zero; }
public void StartVideoStreaming(PictureSize pictureSize, int fps = 20) { if (IsVideoStreamOpenned) { return; } videoStreamFps = fps; videoFramesInterval = 1000 / videoStreamFps; videoStreamHandle = RaspberryCamInterop.OpenCameraStream(devicePath, (uint)pictureSize.Width, (uint)pictureSize.Height, (uint)fps); }
private static void Main(string[] args) { Console.WriteLine("Starting..."); var handle = RaspberryCamInterop.OpenCameraStream("/dev/video0", 640, 480, 20); var previousSize = 0; var data = new byte [0]; for (int i = 0; i < 100; i++) { var watch = Stopwatch.StartNew(); var pictureBuffer = RaspberryCamInterop.GrabVideoFrame(handle); watch.Stop(); Console.WriteLine("GrabVideoFrame take: {0} ms", watch.ElapsedMilliseconds); /* * if we allocate a new buffer for each frame, the garbadge collector pause the app while collecting. */ if (pictureBuffer.Size > previousSize) { data = new byte[pictureBuffer.Size]; } Marshal.Copy(pictureBuffer.Data, data, 0, pictureBuffer.Size); /* * if you uncomment this, you will solicit garbage collection and decrease performances */ //MemoryStream s = new MemoryStream(data); //using (var fs = File.Open(string.Format("capture_{0}.raw", i), FileMode.Create)) //{ // s.CopyTo(fs); // s.Flush(); // fs.Flush(); //} } RaspberryCamInterop.CloseCameraStream(handle); }
public byte[] GetVideoFrame(Percent compressionRate = default(Percent)) { if (!IsVideoStreamOpenned) { return(new byte[0]); } if (!CanReadVideoFrame) { Thread.Sleep(RemainingWaitingMilliseconds); } var pictureBuffer = RaspberryCamInterop.ReadVideoFrame(videoStreamHandle, (uint)(100 - compressionRate.Value)); var data = new byte[pictureBuffer.Size]; Marshal.Copy(pictureBuffer.Data, data, 0, pictureBuffer.Size); return(data); }