示例#1
0
        /// <summary>
        /// Create a combined Hue/Saturation/Value image from an existing 
        /// image using supplied thresholds for hue, saturation and value.
        /// </summary>
        /// <param name="image">Image to convert to HSV.</param>
        /// <param name="thresholds">Thresholds for hue, saturation and value</param>
        /// <returns>HSV image along with the component images for hue, 
        /// saturation and value.</returns>
        public HsvFilter generateCombinedHSV(Image<Bgr, byte> image, BinaryThresholds thresholds)
        {
            Image<Hsv, Byte> hsvFrame = image.Convert<Hsv, Byte>();
            Image<Gray, Byte>[] channels = hsvFrame.Split();

            Image<Gray, byte> hueImage = channels[0];
            Image<Gray, byte> satImage = channels[1];
            Image<Gray, byte> valImage = channels[2];

            Image<Gray, byte> hueFilter = hueImage.InRange(new Gray(thresholds.HueMin), new Gray(thresholds.HueMax));
            Image<Gray, byte> satFilter = satImage.InRange(new Gray(thresholds.SatMin), new Gray(thresholds.SatMax));
            Image<Gray, byte> valFilter = valImage.InRange(new Gray(thresholds.ValMin), new Gray(thresholds.ValMax));
            Image<Gray, byte> combinedFilter = hueFilter.And(satFilter).And(valFilter).SmoothMedian(5);

            HsvFilter hsvFilter = new HsvFilter();
            hsvFilter.HueFilter = hueFilter;
            hsvFilter.SatFilter = satFilter;
            hsvFilter.ValFilter = valFilter;
            hsvFilter.CombinedFilter = combinedFilter;

            return hsvFilter;
        }
示例#2
0
        /// <summary>
        /// Display all HSV filters.
        /// </summary>
        /// <param name="yellowFilter">Yellow HSV Filters to display.</param>
        /// <param name="greenFilter">Green HSV Filters to display.</param>
        private void displayFilters(HsvFilter yellowFilter, HsvFilter greenFilter)
        {
            this.YellowHueImgBox.Image = yellowFilter.HueFilter.Resize(this.YellowHueImgBox.Width, this.YellowHueImgBox.Height, Emgu.CV.CvEnum.INTER.CV_INTER_LINEAR);
            this.YellowSatImgBox.Image = yellowFilter.SatFilter.Resize(this.YellowSatImgBox.Width, this.YellowSatImgBox.Height, Emgu.CV.CvEnum.INTER.CV_INTER_LINEAR);
            this.YellowValImgBox.Image = yellowFilter.ValFilter.Resize(this.YellowValImgBox.Width, this.YellowValImgBox.Height, Emgu.CV.CvEnum.INTER.CV_INTER_LINEAR);

            this.YellowComImgBox.Image = yellowFilter.CombinedFilter.Resize(this.YellowComImgBox.Width, this.YellowComImgBox.Height, Emgu.CV.CvEnum.INTER.CV_INTER_LINEAR);

            this.GreenHueImgBox.Image = greenFilter.HueFilter.Resize(this.GreenHueImgBox.Width, this.GreenHueImgBox.Height, Emgu.CV.CvEnum.INTER.CV_INTER_LINEAR);
            this.GreenSatImgBox.Image = greenFilter.SatFilter.Resize(this.GreenSatImgBox.Width, this.GreenSatImgBox.Height, Emgu.CV.CvEnum.INTER.CV_INTER_LINEAR);
            this.GreenValImgBox.Image = greenFilter.ValFilter.Resize(this.GreenValImgBox.Width, this.GreenValImgBox.Height, Emgu.CV.CvEnum.INTER.CV_INTER_LINEAR);

            this.GreenComImgBox.Image = greenFilter.CombinedFilter.Resize(this.GreenComImgBox.Width, this.GreenComImgBox.Height, Emgu.CV.CvEnum.INTER.CV_INTER_LINEAR);
        }