public void TestColorEqual() { Bgr c1 = new Bgr(0.0, 0.0, 0.0); Bgr c2 = new Bgr(0.0, 0.0, 0.0); Assert.IsTrue(c1.Equals(c2)); }
void capture_ImageGrabbed(object sender, EventArgs e) { if (Mode.ResultView == _mode) { return; } Interlocked.Increment(ref _frameCount); Mat mat = new Mat(); _capture.Read(mat); if (Mode.Preview == _mode) { RenderImage(mat); return; } if (_resultReset.WaitOne(0)) { _resultImage = null; } if (_modelChanged.WaitOne(0)) { lock (_modelSync) { activeMethod = _method; activeThreshold = _threshold; activeAlpha = _alpha; activeColorAlpha = _colorAlpha; if (colorIndex < colors.Count) { activeColor = new Bgr(colors[colorIndex]); } else { activeColorAlpha = 0; } } thresholdColor = new Hls(0, 255 * activeThreshold, 0); } Image <Bgr, Byte> frame = mat.ToImage <Bgr, Byte>(); if (null == _resultImage) { _previousImage = frame.Clone(); _resultImage = frame.Clone(); } else { Image <Gray, byte> mask = null; if (0 == activeMethod) { mask = frame.Sub(_previousImage).Convert <Hls, byte>().ThresholdBinary(thresholdColor, hlsWhiteColor).Convert <Gray, byte>(); } else { mask = _previousImage.Sub(frame).Convert <Hls, byte>().ThresholdBinary(thresholdColor, hlsWhiteColor).Convert <Gray, byte>(); } Image <Bgr, Byte> basis = _previousImage.And(bgrWhiteColor, mask.Not()); Image <Bgr, Byte> applied = _previousImage.And(bgrWhiteColor, mask).AddWeighted(frame.And(bgrWhiteColor, mask), 1.0 - activeAlpha, activeAlpha, 0.0); _previousImage = basis.Add(applied); if (activeColorAlpha > 0) { if (null == _colorImage || !activeColor.Equals(_previousActiveColor)) { _colorImage = new Image <Bgr, Byte>(applied.Width, applied.Height, activeColor); _previousActiveColor = activeColor; } _resultImage = _resultImage.And(bgrWhiteColor, mask.Not()) .Add(applied.AddWeighted(_colorImage.And(bgrWhiteColor, mask), 1.0 - activeColorAlpha, activeColorAlpha, 0.0)); } else { _resultImage = _previousImage; } } RenderImage(_resultImage); }