Squirrowse/Squirrowse.Client/Service/CameraService.cs

36 lines
852 B
C#
Raw Normal View History

2019-11-05 10:30:31 +01:00
using System.Collections.Generic;
2019-11-01 19:04:24 +01:00
using System.Threading.Tasks;
using OpenCvSharp;
2019-11-04 14:28:45 +01:00
using Squirrowse.Core.Services;
2019-11-01 19:04:24 +01:00
namespace Squirrowse.Client.Service
{
public class CameraService : ICameraService
{
2019-11-04 14:28:45 +01:00
private readonly VideoCapture _videoCapture;
2019-11-05 10:30:31 +01:00
2019-11-04 14:28:45 +01:00
public CameraService(CameraFactory cam)
2019-11-01 19:04:24 +01:00
{
2019-11-04 14:28:45 +01:00
_videoCapture = cam.GetCamera();
}
2019-11-04 09:29:37 +01:00
2019-11-04 14:28:45 +01:00
public async Task<Mat> GetFrame()
2019-11-05 10:30:31 +01:00
{
2019-11-04 14:28:45 +01:00
var video = _videoCapture.RetrieveMat();
return video;
2019-11-01 19:04:24 +01:00
}
2019-11-04 14:28:45 +01:00
public async IAsyncEnumerable<byte[]> GetFramesAsyncEnumerator()
2019-11-01 19:04:24 +01:00
{
2019-11-08 16:36:20 +01:00
while (true)
{
using var fr = await GetFrame();
yield return fr.ConvertToJpgByte();
await Task.Delay(1000 / 30);
}
2019-11-05 10:30:31 +01:00
//fr.Dispose();
2019-11-01 19:04:24 +01:00
}
}
2019-11-04 09:29:37 +01:00
}