Squirrowse/Squirrowse.Client/Service/CameraService.cs
danielgrabowski 6f1cc96c16 Rework stream
2019-11-08 16:36:20 +01:00

36 lines
852 B
C#

using System.Collections.Generic;
using System.Threading.Tasks;
using OpenCvSharp;
using Squirrowse.Core.Services;
namespace Squirrowse.Client.Service
{
public class CameraService : ICameraService
{
private readonly VideoCapture _videoCapture;
public CameraService(CameraFactory cam)
{
_videoCapture = cam.GetCamera();
}
public async Task<Mat> GetFrame()
{
var video = _videoCapture.RetrieveMat();
return video;
}
public async IAsyncEnumerable<byte[]> GetFramesAsyncEnumerator()
{
while (true)
{
using var fr = await GetFrame();
yield return fr.ConvertToJpgByte();
await Task.Delay(1000 / 30);
}
//fr.Dispose();
}
}
}