E4: l'analisi regge dissolvenze su nero, colori pieni e foto scure, e filmati ripetuti
Una scritta o un marchio sul nero, un cartello blu e una foto scura che si dissolvono risultavano «In movimento»: il guadagno si stima pesando i blocchi sulla luce, sul canale più forte non bruciato. Lo stesso per un'immagine scura quanto la soglia, che la grana porta sopra e sotto: un fotogramma scuro fra due si confronta, non si condanna. Gli istanti nuovi abbracciano almeno il 48 % del giro di un filmato ripetuto da 2 a 40 volte; prima, a quasi sette ripetizioni, cadevano tutti insieme e il video risultava «Fermo». Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
90fa8aefcc
commit
cf52e0ea6a
2 files changed
+236
-91
No files matched your search
@@ -34,7 +34,7 @@ public sealed class StillVideoAnalyzerTests
|
||||
Assert.AreEqual(StillVideoAnalyzer.Samples, result.Sampled);
|
||||
Assert.AreEqual(1, result.Algorithm);
|
||||
|
||||
// Seven equal parts of one second: the first one looked at is picture 2 (the nearest to 72 ms), never the very
|
||||
// Seven equal parts of one second: the first one looked at is picture 2 (the nearest to 77 ms), never the very
|
||||
// first.
|
||||
Assert.AreEqual(Ms(2), result.FrameAtMs, "a parità di nitidezza il primo mostrato fra quelli guardati");
|
||||
Assert.AreEqual(new VideoAnalysis("abc", 1, VideoAnalysisOutcome.Still, Make.T0, result.FrameAt, null), result.ToAnalysis("abc", Make.T0));
|
||||
@@ -52,13 +52,13 @@ public sealed class StillVideoAnalyzerTests
|
||||
[TestMethod]
|
||||
public void AFadeFromBlackIsStillAndTheFrameComesAfterIt()
|
||||
{
|
||||
// The first nine pictures fade in from black (picture 2, the first one looked at, at 22 %; picture 6 at 67 %);
|
||||
// the third one looked at is picture 11, the one nearest to 358 ms.
|
||||
// The first nine pictures fade in from black (picture 2, the first one looked at, at 22 %; picture 7 at 78 %);
|
||||
// the third one looked at is picture 10, the one nearest to 345 ms.
|
||||
var photo = PcmVideos.Photo(3);
|
||||
var result = Analyse(PcmVideos.Mp4(30, i => i < 9 ? PcmVideos.Fade(photo, i / 9.0) : photo));
|
||||
|
||||
Assert.AreEqual(VideoAnalysisOutcome.Still, result.Outcome, Describe(result));
|
||||
Assert.AreEqual(Ms(11), result.FrameAtMs, "il più nitido: il primo a piena luce, non uno della dissolvenza");
|
||||
Assert.AreEqual(Ms(10), result.FrameAtMs, "il più nitido: il primo a piena luce, non uno della dissolvenza");
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
@@ -217,12 +217,12 @@ public sealed class StillVideoAnalyzerTests
|
||||
[TestMethod]
|
||||
public void TheSharpestFrameIsChosen()
|
||||
{
|
||||
// Every picture softened but picture 15 (the fourth looked at): the cells are the same, the detail is not.
|
||||
// Every picture softened but picture 13 (the fourth looked at): the cells are the same, the detail is not.
|
||||
var photo = PcmVideos.Photo(14);
|
||||
var soft = PcmVideos.Blur(photo);
|
||||
var result = Analyse(PcmVideos.Mp4(30, i => i == 15 ? photo : soft));
|
||||
var result = Analyse(PcmVideos.Mp4(30, i => i == 13 ? photo : soft));
|
||||
Assert.AreEqual(VideoAnalysisOutcome.Still, result.Outcome, Describe(result));
|
||||
Assert.AreEqual(Ms(15), result.FrameAtMs);
|
||||
Assert.AreEqual(Ms(13), result.FrameAtMs);
|
||||
Assert.IsGreaterThan(0, result.Sharpness);
|
||||
}
|
||||
|
||||
@@ -509,14 +509,17 @@ public sealed class StillVideoAnalyzerTests
|
||||
(StillVideoAnalyzer.Algorithm, StillVideoAnalyzer.Samples, StillVideoAnalyzer.GridSize, StillVideoAnalyzer.DarkLevel,
|
||||
StillVideoAnalyzer.UniformSpread, StillVideoAnalyzer.BlockThreshold, StillVideoAnalyzer.MeanThreshold, StillVideoAnalyzer.AreaThreshold));
|
||||
Assert.AreEqual(
|
||||
(128, 4, 3.0, 16.0, 0.1, 8.0, 0.1),
|
||||
(StillVideoAnalyzer.FineGridSize, StillVideoAnalyzer.FineCell, StillVideoAnalyzer.EarlyAreaFactor, StillVideoAnalyzer.GainFloor,
|
||||
StillVideoAnalyzer.GainAgreement, StillVideoAnalyzer.GainRange, StillVideoAnalyzer.ClippedShare));
|
||||
(128, 4, 3.0, 0.1),
|
||||
(StillVideoAnalyzer.FineGridSize, StillVideoAnalyzer.FineCell, StillVideoAnalyzer.EarlyAreaFactor, StillVideoAnalyzer.ClippedShare));
|
||||
Assert.AreEqual(
|
||||
(8.0, 10, 1.5, 0.1, 16.0),
|
||||
(StillVideoAnalyzer.GainFloor, StillVideoAnalyzer.GainBlocks, StillVideoAnalyzer.GainNoise, StillVideoAnalyzer.GainAgreement,
|
||||
StillVideoAnalyzer.GainRange));
|
||||
Assert.AreEqual(
|
||||
(250, 0.25, 96, 64.0, 32.0, 0.0002, TimeSpan.FromSeconds(1e9)),
|
||||
(StillVideoAnalyzer.White, StillVideoAnalyzer.ChromaWeight, StillVideoAnalyzer.BrightDetail, StillVideoAnalyzer.UniformVariance,
|
||||
StillVideoAnalyzer.UniformDetail, StillVideoAnalyzer.DetailShare, StillVideoAnalyzer.LatestInstant));
|
||||
CollectionAssert.AreEqual(new[] { 0.4173, 0.3611, 0.6237, 0.5, 0.6619, 0.3307, 0.5521 }, StillVideoAnalyzer.Offsets);
|
||||
CollectionAssert.AreEqual(new[] { 0.54, 0.865, 0.417, 0.253, 0.432, 0.45, 0.46 }, StillVideoAnalyzer.Offsets);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
@@ -551,6 +554,40 @@ public sealed class StillVideoAnalyzerTests
|
||||
Assert.AreEqual(VideoAnalysisOutcome.Moving, boomerang.Outcome, Describe(boomerang));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[DataRow(210, 30, 9, 21)]
|
||||
[DataRow(300, 45, 0, 23)]
|
||||
[DataRow(450, 68, 0, 34)]
|
||||
[DataRow(60, 9, 0, 5)]
|
||||
[DataRow(20, 3, 0, 2)]
|
||||
public void TwoPicturesOfARepeatedClipAreMotion(int pictures, int period, int from, int to)
|
||||
{
|
||||
// Two pictures, each for a good part of the clip, with whole and broken numbers of repetitions: the frames looked
|
||||
// at must not all fall on the same one.
|
||||
var a = PcmVideos.Photo(1);
|
||||
var b = PcmVideos.Photo(2);
|
||||
var result = Analyse(PcmVideos.Mp4(pictures, i => i % period >= from && i % period < to ? b : a));
|
||||
Assert.AreEqual(VideoAnalysisOutcome.Moving, result.Outcome, Describe(result));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void TheInstantsNeverFallOnMuchLessThanHalfOfARepeatedClip()
|
||||
{
|
||||
var at = StillVideoAnalyzer.Offsets.Select((o, i) => (i + o) / StillVideoAnalyzer.Samples).ToArray();
|
||||
for (var repetitions = 2.0; repetitions <= 40; repetitions += 0.01)
|
||||
{
|
||||
// The positions inside the clip, around it: the largest stretch with none of them.
|
||||
var phases = at.Select(t => t * repetitions % 1).Order().ToArray();
|
||||
var empty = phases.Select((p, i) => (i + 1 < phases.Length ? phases[i + 1] : phases[0] + 1) - p).Max();
|
||||
Assert.IsGreaterThanOrEqualTo(0.48, 1 - empty, $"{repetitions:0.00} ripetizioni");
|
||||
}
|
||||
|
||||
// Far from the ends, and no long stretch of the video not looked at.
|
||||
Assert.IsGreaterThan(0.3, StillVideoAnalyzer.Offsets[0]);
|
||||
Assert.IsLessThan(0.7, StillVideoAnalyzer.Offsets[^1]);
|
||||
Assert.IsLessThan(1.4 / StillVideoAnalyzer.Samples, at.Skip(1).Zip(at, (next, t) => next - t).Max());
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[DataRow(0.0)]
|
||||
[DataRow(0.015)]
|
||||
@@ -600,6 +637,79 @@ public sealed class StillVideoAnalyzerTests
|
||||
Assert.AreEqual(VideoAnalysisOutcome.Still, text.Outcome, Describe(text));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void ACardOnBlackABlueOneOrADarkPhotoWithAFadeIsStill()
|
||||
{
|
||||
// Few blocks with light, or little luma in all of them: the fade is told by those there are.
|
||||
var text = PcmVideos.Grey(PcmVideos.Width, PcmVideos.Height, (x, y) =>
|
||||
y is > 80 and < 170 && y / 6 % 2 == 0 && x is > 20 and < 124 && x / 5 % 2 == 0 ? 235 : 16);
|
||||
var logo = PcmVideos.Grey(PcmVideos.Width, PcmVideos.Height, (x, y) => x is >= 48 and < 96 && y is >= 100 and < 156 ? 200 : 16);
|
||||
var night = PcmVideos.Fade(PcmVideos.Photo(5), 0.1);
|
||||
foreach (var at in new[] { 20, 70, 110 })
|
||||
{
|
||||
night = PcmVideos.Sticker(night, at, 2 * at, 4, 4);
|
||||
}
|
||||
|
||||
foreach (var (name, picture) in new[]
|
||||
{
|
||||
("scritta su nero", text), ("marchio su nero", logo), ("foto scura", night), ("cartello blu", PcmVideos.Poster(41, 240, 110, 0.15)),
|
||||
("foto in basso su nero, 5 %", PcmVideos.Poster(16, 128, 128, 0.05)), ("10 %", PcmVideos.Poster(16, 128, 128, 0.1)),
|
||||
})
|
||||
{
|
||||
foreach (var (pictures, fade) in new[] { (30, 4.0), (30, 22), (90, 30), (150, 15) })
|
||||
{
|
||||
var result = Analyse(PcmVideos.Mp4(pictures, i => PcmVideos.Noise(PcmVideos.Fade(picture, Math.Min(1, i / fade)), 1, i)));
|
||||
Assert.AreEqual((VideoAnalysisOutcome.Still, null), (result.Outcome, result.Note), $"{name}, {pictures}, {fade}: {Describe(result)}");
|
||||
}
|
||||
|
||||
// At the end too.
|
||||
var last = Analyse(PcmVideos.Mp4(30, i => PcmVideos.Fade(picture, Math.Min(1, (29 - i) / 12.0))));
|
||||
Assert.AreEqual(VideoAnalysisOutcome.Still, last.Outcome, $"{name}: {Describe(last)}");
|
||||
}
|
||||
|
||||
// What moves on black, or a card that moves, is still motion while it fades.
|
||||
H264PcmPicture Scroll(int i) => PcmVideos.Grey(PcmVideos.Width, PcmVideos.Height, (x, y) =>
|
||||
y is > 60 and < 190 && (y + (2 * i)) / 6 % 2 == 0 && x is > 20 and < 124 && x / 5 % 2 == 0 ? 235 : 16);
|
||||
H264PcmPicture Pass(int i) => PcmVideos.Grey(PcmVideos.Width, PcmVideos.Height, (x, y) =>
|
||||
x >= 10 + (2 * i) && x < 58 + (2 * i) && y is >= 100 and < 156 ? 200 : 16);
|
||||
foreach (var (name, picture) in new (string, Func<int, H264PcmPicture>)[]
|
||||
{
|
||||
("scritta che scorre", Scroll), ("marchio che passa", Pass),
|
||||
("cartello blu", i => PcmVideos.Sticker(PcmVideos.Flat(41, 240, 110), 5 + i, 60, 90, 120)),
|
||||
})
|
||||
{
|
||||
var moving = Analyse(PcmVideos.Mp4(30, i => PcmVideos.Fade(picture(i), Math.Min(1, i / 9.0))));
|
||||
Assert.AreEqual(VideoAnalysisOutcome.Moving, moving.Outcome, $"{name}: {Describe(moving)}");
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void ADimPictureAroundTheDarkThresholdIsNotMotion()
|
||||
{
|
||||
// The same dim picture in every frame: the grain takes some over the threshold and leaves others under it.
|
||||
H264PcmPicture Gradient(double light) => PcmVideos.Grey(PcmVideos.Width, PcmVideos.Height, (x, y) => 16 + ((x + y) * light / 400 * 219 / 255));
|
||||
H264PcmPicture Text(double light) => PcmVideos.Grey(PcmVideos.Width, PcmVideos.Height, (x, y) =>
|
||||
y is >= 120 and < 126 && x is >= 60 and < 66 && (x + y) % 2 == 0 ? 16 + (light * 219 / 255) : 20);
|
||||
foreach (var (name, picture, grain) in new[]
|
||||
{
|
||||
("sfumatura 31,5", Gradient(31.5), 8), ("sfumatura 32", Gradient(32), 4), ("sfumatura 32", Gradient(32), 8),
|
||||
("sfumatura 32,5", Gradient(32.5), 2), ("sfumatura 32,5", Gradient(32.5), 4), ("scritta 92", Text(92), 10),
|
||||
("scritta 94", Text(94), 4), ("scritta 94", Text(94), 6), ("scritta 94", Text(94), 10), ("scritta 96", Text(96), 2), ("scritta 96", Text(96), 4),
|
||||
})
|
||||
{
|
||||
var result = Analyse(PcmVideos.Mp4(60, i => PcmVideos.Noise(picture, grain, i)));
|
||||
Assert.AreNotEqual(VideoAnalysisOutcome.Moving, result.Outcome, $"{name} ±{grain}: {Describe(result)}");
|
||||
}
|
||||
|
||||
// Black between two pictures is, dark as they are.
|
||||
var night = PcmVideos.Fade(PcmVideos.Photo(5), 0.25);
|
||||
foreach (var (name, picture) in new[] { ("foto scura", night), ("grigio", PcmVideos.Flat(60)), ("bianco", PcmVideos.Flat(235)) })
|
||||
{
|
||||
var between = Analyse(PcmVideos.Mp4(30, i => i is >= 12 and < 18 ? PcmVideos.Black() : picture));
|
||||
Assert.AreEqual(VideoAnalysisOutcome.Moving, between.Outcome, $"{name}: {Describe(between)}");
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void OnePictureAmongDarkFramesSaysNothingOfTheVideo()
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user