Skip to content

Commit

Permalink
Move black time into event argument, and fire event after the blacksc…
Browse files Browse the repository at this point in the history
…reen has ended. This is to determine if processing time impacted the time calculation.
  • Loading branch information
underscore-zi committed Aug 5, 2019
1 parent a3cfeb7 commit 7e2bcad
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
8 changes: 4 additions & 4 deletions MarioMaker2OCR/Form1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -290,17 +290,17 @@ private void VideoProcessor_ClearScreen(object sender, VideoProcessor.VideoEvent
/// <summary>
/// Event Callback for the Black Screen event generated by the VideoProcessor
/// </summary>
private void VideoProcessor_BlackScreen(object sender, VideoProcessor.VideoEventArgs e)
private void VideoProcessor_BlackScreen(object sender, VideoProcessor.BlackScreenEventArgs e)
{
log.Debug("Detected a black screen");
log.Debug(String.Format("Detected a black screen [{0}]", e.seconds));
BeginInvoke((MethodInvoker)(() => processingLabel.Text = "Processing black screen..."));

double imageMatchPercent = ImageLibrary.CompareImages(e.currentFrame, levelDetailScreen);

// Is this frame a 93% match to a level screen?
if(imageMatchPercent > 0.93)
{
log.Info("Detected new level.");
log.Info(String.Format("Detected new level. [{0}]", e.seconds));

BeginInvoke((MethodInvoker)(() => processingLabel.Text = "Processing level screen..."));

Expand Down Expand Up @@ -354,7 +354,7 @@ private void VideoProcessor_BlackScreen(object sender, VideoProcessor.VideoEvent
{
if (evt.Value)
{
log.Info(String.Format("Detected {0}.", evt.Key));
log.Info(String.Format("Detected {0} [{1}].", evt.Key, e.seconds));
SMMServer.BroadcastEvent(evt.Key);
}
}
Expand Down
19 changes: 12 additions & 7 deletions MarioMaker2OCR/VideoProcessing.cs
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,11 @@ public void processingLoop()
WasBlack = isBlackFrame(hues);
if(!WasBlack)
{
log.Debug(String.Format("Black Screen Length: {0}", DateTime.Now.Subtract(blackStart).TotalMilliseconds / 1000));
BlackScreenEventArgs args = new BlackScreenEventArgs();
args.frameBuffer = copyFrameBuffer();
args.currentFrame = getLevelScreenImageFromBuffer(args.frameBuffer);
args.seconds = DateTime.Now.Subtract(blackStart).TotalMilliseconds/1000;
onBlackScreen(args);
}
}
else if (WasClear)
Expand All @@ -230,10 +234,6 @@ public void processingLoop()
WasBlack = true;
WaitForClearStats = false; // XXX: If we get a black screen and this is true, something weird is going on
blackStart = DateTime.Now;
VideoEventArgs args = new VideoEventArgs();
args.frameBuffer = copyFrameBuffer();
args.currentFrame = getLevelScreenImageFromBuffer(args.frameBuffer);
onBlackScreen(args);
}
else if (isClearFrame(hues))
{
Expand Down Expand Up @@ -372,8 +372,8 @@ public static bool isClearWithStatsScreen(Dictionary<int, int> hues)
/// <summary>
/// Event that fires off whenever a black screen is detected
/// </summary>
public event EventHandler<VideoEventArgs> BlackScreen;
protected virtual void onBlackScreen(VideoEventArgs e)
public event EventHandler<BlackScreenEventArgs> BlackScreen;
protected virtual void onBlackScreen(BlackScreenEventArgs e)
{
if (frameBuffer[0] == null) return;
BlackScreen?.Invoke(this, e);
Expand Down Expand Up @@ -414,6 +414,11 @@ public class VideoEventArgs : EventArgs
public Image<Bgr, byte> currentFrame;
}

public class BlackScreenEventArgs: VideoEventArgs
{
public double seconds;
}

/// <summary>
/// Inspects passed in buffer and returns the best guess of level screen.
///
Expand Down

0 comments on commit 7e2bcad

Please sign in to comment.