Squirrowse/Squirrowse.Client/Service/CameraService.cs
2019-11-04 14:28:45 +01:00

34 lines
823 B
C#

using System;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
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)
{
var fr = await GetFrame();
yield return fr.ConvertToJpgByte();
}
}
}
}