mirror of
https://github.com/azaion/annotations.git
synced 2026-04-22 17:46:36 +00:00
add ai recognition: stage 1, works, but doesn't show
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using Azaion.Annotator.DTO;
|
||||
using Azaion.Annotator.Extensions;
|
||||
using Compunet.YoloV8;
|
||||
using LibVLCSharp.Shared;
|
||||
using MediatR;
|
||||
|
||||
namespace Azaion.Annotator;
|
||||
|
||||
public class AIDetector(Config config, MediaPlayer mediaPlayer, VLCFrameExtractor frameExtractor)
|
||||
: IRequestHandler<AIDetectEvent, List<YoloLabel>>
|
||||
{
|
||||
public async Task<List<YoloLabel>> Handle(AIDetectEvent request, CancellationToken cancellationToken)
|
||||
{
|
||||
using var predictor = new YoloPredictor(config.AIModelPath);
|
||||
await frameExtractor.Start(async stream =>
|
||||
{
|
||||
stream.Seek(0, SeekOrigin.Begin);
|
||||
var sw = Stopwatch.StartNew();
|
||||
var result = await predictor.DetectAsync(stream);
|
||||
sw.Stop();
|
||||
var log = string.Join("|", result.Select(det =>
|
||||
$"{det.Name.Id}.{det.Name.Name}: xy=({det.Bounds.X},{det.Bounds.Y}), size=({det.Bounds.Width}, {det.Bounds.Height}), Prob: {det.Confidence*100:F1}%"));
|
||||
log += $". Inf time: {sw.ElapsedMilliseconds} ms";
|
||||
Console.WriteLine(log);
|
||||
});
|
||||
|
||||
while (mediaPlayer.IsPlaying)
|
||||
{
|
||||
|
||||
try
|
||||
{
|
||||
// using var thumbnail = await mediaPlayer.Media.GenerateThumbnail(time: 200,
|
||||
// speed: ThumbnailerSeekSpeed.Fast,
|
||||
// width: 1280,
|
||||
// height: resultHeight,
|
||||
// crop: false,
|
||||
// pictureType: PictureType.Argb)
|
||||
//
|
||||
// mediaPlayer.TakeSnapshot(0, TEMP_IMG, 1280, resultHeight);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Console.WriteLine(e);
|
||||
throw;
|
||||
}
|
||||
//var result = predictor.Detect();
|
||||
}
|
||||
|
||||
return new List<YoloLabel>();
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user