public void ReturnsFalseOngameplay() { // All the of the test frames in ./1080 should be from game stills so never black string[] filePaths = Directory.GetFiles("./Test/testdata/frames/1080/gameplay", "*.png", SearchOption.TopDirectoryOnly); byte[] data = new byte[1080 * 1920 * 3]; GCHandle dataHandle = GCHandle.Alloc(data, GCHandleType.Pinned); foreach (string fn in filePaths) { if (fn.Contains("clear_")) { continue; } var testFrame = new Image <Bgr, byte>(fn); // Test frame MUST be 1920x1080 otherwise a black frame will be returned with no errors or warnings Assert.IsTrue(testFrame.Size.Width == 1920); Assert.IsTrue(testFrame.Size.Height == 1080); Mat currentFrame = new Mat(testFrame.Size, DepthType.Cv8U, 3, dataHandle.AddrOfPinnedObject(), testFrame.Width * 3); testFrame.Mat.CopyTo(currentFrame); var hues = VideoProcessor.getHues(data, testFrame.Size); Assert.IsFalse(VideoProcessor.isClearFrame(hues)); } }
private Point getLocation(Image <Bgr, byte> frame, Rectangle roi) { frame.ROI = roi; // Get hues of frame Dictionary <int, int> hues = VideoProcessor.getHues(frame.Mat.GetRawData(), frame.ROI.Size, 3); try { int colorCoverage; // Check for nearby hues from this.color for (int hue = this.color + 2; hue > 0 && hue >= this.color - 2; hue--) { if (hues.TryGetValue(hue, out colorCoverage)) { if (colorCoverage > (threshold * 100)) { _size = new Size(roi.Size.Width, roi.Size.Height); return(roi.Location); } } } return(Point.Empty); } finally { frame.ROI = Rectangle.Empty; } }
public void ReturnsTrueOnBlackFrame() { var testFrame = new Image <Bgr, byte>("./Test/testdata/frames/480/black.png"); byte[] data = new byte[testFrame.Width * testFrame.Height * 3]; GCHandle dataHandle = GCHandle.Alloc(data, GCHandleType.Pinned); Mat currentFrame = new Mat(testFrame.Size, DepthType.Cv8U, 3, dataHandle.AddrOfPinnedObject(), testFrame.Width * 3); testFrame.Mat.CopyTo(currentFrame); var hues = VideoProcessor.getHues(data, testFrame.Size); Assert.IsTrue(VideoProcessor.isBlackFrame(hues)); }
public void ReturnsTrueOnClearFrames() { string[] filePaths = Directory.GetFiles("./Test/testdata/frames/1080/", "clear_*.png", SearchOption.TopDirectoryOnly); byte[] data = new byte[1080 * 1920 * 3]; GCHandle dataHandle = GCHandle.Alloc(data, GCHandleType.Pinned); foreach (string fn in filePaths) { var testFrame = new Image <Bgr, byte>(fn); // Test frame MUST be 1920x1080 otherwise a black frame will be returned with no errors or warnings Assert.IsTrue(testFrame.Size.Width == 1920); Assert.IsTrue(testFrame.Size.Height == 1080); Mat currentFrame = new Mat(testFrame.Size, DepthType.Cv8U, 3, dataHandle.AddrOfPinnedObject(), testFrame.Width * 3); testFrame.Mat.CopyTo(currentFrame); var hues = VideoProcessor.getHues(data, testFrame.Size); Assert.IsTrue(VideoProcessor.isClearFrame(hues)); } dataHandle.Free(); }