36 lines
852 B
C#
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();
|
|
}
|
|
}
|
|
} |