Exemplo n.º 1
0
        /// <summary>
        /// Event Callback for the Black Screen event generated by the VideoProcessor
        /// </summary>
        private void VideoProcessor_BlackScreen(object sender, VideoProcessor.VideoEventArgs e)
        {
            log.Debug("Detected a black screen");
            BeginInvoke((MethodInvoker)(() => processingLabel.Text = "Processing black screen..."));

            // Is this a new level?
            Image <Bgr, byte> frame             = e.frameBuffer[e.frameBuffer.Length - 5];
            double            imageMatchPercent = ImageLibrary.CompareImages(frame, levelSelectScreen);

            if (imageMatchPercent > 0.94)
            {
                log.Info("Detected new level.");
                previewer.SetLastMatch(frame, new Rectangle[] { levelCodeArea, creatorNameArea, levelTitleArea });
                BeginInvoke((MethodInvoker)(() => processingLabel.Text = "Processing level screen..."));

                Level level = getLevelFromCurrentFrame(frame);
                writeLevelToFile(level);
                SMMServer.BroadcastLevel(level);

                BeginInvoke((MethodInvoker)(() => ocrTextBox.Text = level.code + "  |  " + level.author + "  |  " + level.name));
                BeginInvoke((MethodInvoker)(() => processingLabel.Text = ""));
            }
            else
            {
                // Not a new level, see if we can detect a template.
                Dictionary <String, bool> events = new Dictionary <String, bool>
                {
                    { "death", false },
                    { "restart", false },
                    { "exit", false },
                };


                BeginInvoke((MethodInvoker)(() => processingLabel.Text = "Processing events..."));
                foreach (Image <Bgr, byte> f in e.frameBuffer)
                {
                    Image <Gray, byte> grayscaleFrame = f.Mat.ToImage <Gray, byte>().Resize(640, 480, Inter.Cubic);
                    //grayscaleFrame.Save("frame_" + DateTime.Now.ToString("yyyyMMddHHmmssffff") + ".png"); // XXX: Useful for debugging template false-negatives, and for getting templates

                    List <Rectangle> boundaries = new List <Rectangle>();
                    foreach (EventTemplate tmpl in templates)
                    {
                        if (events[tmpl.eventType])
                        {
                            continue;
                        }
                        Point loc = tmpl.getLocation(grayscaleFrame);
                        if (!loc.IsEmpty)
                        {
                            events[tmpl.eventType] = true;
                            boundaries.Add(ImageLibrary.ChangeSize(new Rectangle(loc.X, loc.Y, tmpl.template.Width, tmpl.template.Height), grayscaleFrame.Size, f.Size));
                            previewer.SetLastMatch(f, boundaries.ToArray());
                        }
                    }
                }
                BeginInvoke((MethodInvoker)(() => processingLabel.Text = ""));

                foreach (var evt in events)
                {
                    if (evt.Value)
                    {
                        log.Info(String.Format("Detected {0}.", evt.Key));
                        SMMServer.BroadcastEvent(evt.Key);
                    }
                }
            }
        }
Exemplo n.º 2
0
 private void VideoProcessor_NewFrame(object sender, VideoProcessor.VideoEventArgs e)
 {
     previewer.SetLiveFrame(e.currentFrame);
 }
Exemplo n.º 3
0
 /// <summary>
 /// Event callback for the Clear Screen event generatead by the VideoProcessor
 /// </summary>
 private void VideoProcessor_ClearScreen(object sender, VideoProcessor.VideoEventArgs e)
 {
     log.Debug("Detected Level Clear");
     SMMServer.BroadcastEvent("clear");
 }