forked from amkovkov/GranuSightSoftware2
feat: testing and fixes
This commit is contained in:
@@ -172,6 +172,7 @@ public partial class AnalyzerService
|
||||
}
|
||||
|
||||
var sampleDataSet = sampleRecords
|
||||
.AsEnumerable()
|
||||
.Where(r => r.Features.Count() > 0 && r.Features.Count() % FEATURES_LENGTH == 0)
|
||||
.SelectMany(r => r.Features.Chunk(FEATURES_LENGTH))
|
||||
.Select(f => new ClusterizationData
|
||||
@@ -231,6 +232,7 @@ public partial class AnalyzerService
|
||||
|
||||
_logger.LogInformation("Подготовка данных");
|
||||
var trainDataSet = sampleRecords
|
||||
.AsEnumerable()
|
||||
.Where(r => r.Features.Count() > 0 && r.Features.Count() % FEATURES_LENGTH == 0)
|
||||
.Where(r => r.MeasuredContent >= 0 || r.MixtureActualRate >= 0)
|
||||
.SelectMany(r =>
|
||||
@@ -290,7 +292,7 @@ public partial class AnalyzerService
|
||||
model.Dispose();
|
||||
}
|
||||
|
||||
public async Task<(Mat avgImage, Rect roi, Mat mask, IEnumerable<Point[]> contours, Mat result, string separatorType, string sampleBrand)?> Analyze(IEnumerable<ImageData> imagesData)
|
||||
public async Task<(Mat avgImage, Rect roi, Mat mask, IEnumerable<Point[]> contours, Mat result)?> Analyze(IEnumerable<ImageData> imagesData)
|
||||
{
|
||||
if (!Initialized)
|
||||
return null;
|
||||
@@ -304,7 +306,7 @@ public partial class AnalyzerService
|
||||
if (segmentationResult is null)
|
||||
return null;
|
||||
|
||||
var (avgImage, roi, mask, contours, separatorType, sampleBrand) = segmentationResult.Value;
|
||||
var (avgImage, roi, mask, contours) = segmentationResult.Value;
|
||||
|
||||
var images = new List<(Mat mat, double visible, double uv365, double uv254)>();
|
||||
foreach (var imageData in imagesData
|
||||
@@ -410,7 +412,7 @@ public partial class AnalyzerService
|
||||
Cv2.Erode(mask, mask, Cv2.GetStructuringElement(MorphShapes.Ellipse, new Size(3, 3)));
|
||||
Cv2.FindContours(mask, out var newContours, out _, RetrievalModes.List, ContourApproximationModes.ApproxSimple);
|
||||
|
||||
return (avgImage, roi, mask, contours, result, separatorType, sampleBrand);
|
||||
return (avgImage, roi, mask, contours, result);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -418,10 +420,10 @@ public partial class AnalyzerService
|
||||
return null;
|
||||
}
|
||||
}
|
||||
private async Task<(Mat avgImage, Rect roi, Mat mask, IEnumerable<Point[]> contours, string separatorType, string sampleBrand)?> Segment(IEnumerable<ImageData> imagesData)
|
||||
private async Task<(Mat avgImage, Rect roi, Mat mask, IEnumerable<Point[]> contours)?> Segment(IEnumerable<ImageData> imagesData)
|
||||
{
|
||||
var separatorPrefix = "SEPARATOR";
|
||||
var samplePrefix = "SAMPLE";
|
||||
var separatorPrefix = "separator";
|
||||
var samplePrefix = "sample";
|
||||
|
||||
if (imagesData.Count() != IMAGES_COUNT)
|
||||
return null;
|
||||
@@ -522,24 +524,14 @@ public partial class AnalyzerService
|
||||
result = new Mat(new Size(ANALYSIS_IMAGE_SIZE, ANALYSIS_IMAGE_SIZE), MatType.CV_8UC1, new Scalar(0));
|
||||
Cv2.DrawContours(result, contours.Where(ContourIsValid), -1, new Scalar(255), -1);
|
||||
|
||||
_logger.LogInformation("Найдено гранул: {}", contours.Where(ContourIsValid).Count());
|
||||
_logger.LogInformation("Найдено гранул: {}", contours.Count(ContourIsValid));
|
||||
_logger.LogInformation("Детекторованные обекты:\n\t{}", string.Join("\n\t", frequency.Select(f => $"{f.Key}: {f.Value}")));
|
||||
|
||||
return (
|
||||
avgImage,
|
||||
roi.Value,
|
||||
result,
|
||||
contours.Where(ContourIsValid),
|
||||
frequency
|
||||
.Where(kv => kv.Key.StartsWith(separatorPrefix))
|
||||
.MaxBy(kv => kv.Value)
|
||||
.Key
|
||||
.Substring(separatorPrefix.Count() + 1),
|
||||
frequency
|
||||
.Where(kv => kv.Key.StartsWith(samplePrefix))
|
||||
.MaxBy(kv => kv.Value)
|
||||
.Key
|
||||
.Substring(samplePrefix.Count() + 1)
|
||||
contours.Where(ContourIsValid)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -82,7 +82,6 @@ public class CameraService : IDisposable
|
||||
private FrameBufferAllocator? _imageCaptureFrameBufferAllocator;
|
||||
private Stream? _imageCaptureStream;
|
||||
private List<MappedBuffer>? _imageCaptureMappedBuffers;
|
||||
private System.Timers.ElapsedEventHandler? _viewFinderTimerElapsed = null;
|
||||
private readonly CancellationTokenSource _disposeCts = new CancellationTokenSource();
|
||||
private readonly Dictionary<string, object> _cameraHardSettings = new Dictionary<string, object>();
|
||||
|
||||
@@ -238,7 +237,7 @@ public class CameraService : IDisposable
|
||||
_cameraConfiguration = _camera.GenerateConfiguration(StreamRoleEnum.Raw);
|
||||
|
||||
|
||||
_imageCaptureStreamConfiguration = _cameraConfiguration.Skip(1).First();
|
||||
_imageCaptureStreamConfiguration = _cameraConfiguration.First();
|
||||
_imageCaptureStreamConfiguration.BufferCount = checked((uint)_configuration.ImageCaptureFrameBufferCount);
|
||||
_imageCaptureStreamConfiguration.Size = new Size(
|
||||
checked((uint)_configuration.ImageCaptureWidth),
|
||||
|
||||
Reference in New Issue
Block a user