コード例 #1
0
        private static void Warn(
            string watcherName,
            decimal currentState,
            decimal limit,
            ThresholdType limitType,
            string scriptPath,
            bool isWarning)
        {
            ConsoleColor defaultColor = Console.ForegroundColor;

            if (isWarning)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.Write("WARNING! ");
                Console.ForegroundColor = ConsoleColor.Cyan;
                Console.Write($"{watcherName} ");
                Console.ForegroundColor = defaultColor;
                Console.WriteLine(
                    $"space {currentState:####.#} GB beyond limit of {limit:####.#} GB!"
                    );
            }
            else
            {
                Console.ForegroundColor = ConsoleColor.Green;
                Console.Write("INFO! ");
                Console.ForegroundColor = defaultColor;
                Console.WriteLine(
                    $"{watcherName} space {currentState:####.#} GB is back within the limit of {limit:####.#} GB!"
                    );
            }

            RunScriptAndEmail(currentState, limit, limitType, scriptPath, watcherName, isWarning);
        }
コード例 #2
0
        public void SetValues(
            GUI_AcuThresholdsPage thresholdsPage, int index, ThresholdType type,
            string thresholdName, float[] values, GasSO gas = default)
        {
            this.thresholdsPage = thresholdsPage;
            Index  = index;
            Type   = type;
            Name   = thresholdName;
            Values = values;
            Gas    = gas;

            if (type == ThresholdType.Linebreak)
            {
                label.SetValueServer(string.Empty);
                return;
            }

            StringBuilder sb = new StringBuilder($"{thresholdName, -14} | ", 55);

            foreach (float value in values)
            {
                // Use a '?' to represent a gas for which the ACU thresholds does not have values for.
                // Allows a technician to set appropriate values for this discovered gas.
                sb.Append($"{(float.IsNaN(value) ? "?" : value.ToString()), -7} | ");
            }
            label.SetValueServer(sb.Remove(sb.Length - 3, 3).ToString());
        }
コード例 #3
0
 // copy constructor
 public Threshold(HermesMiddleware.DataAcquisitionServiceServer.Threshold sourceThreshold)
 {
     this.oValue    = sourceThreshold.value;
     this.bStrict   = sourceThreshold.strict;
     this.type      = sourceThreshold.type;
     this.sVariable = sourceThreshold.variable;
 }
コード例 #4
0
ファイル: common.cs プロジェクト: llotan/beans
        public static Image <Gray, Byte> Binaraze(Image <Gray, Byte> g, ThresholdType tht = ThresholdType.BinaryInv, Double th = 170, Double max = 255)
        {
            var bin = new Image <Gray, Byte>(g.Width, g.Height, new Gray(0));

            CvInvoke.Threshold(g, bin, th, max, tht);
            return(bin);
        }
コード例 #5
0
ファイル: Zuma.cs プロジェクト: DrReiz/DrReiz.Robo-Gamer
        public static Mat Threshold(this Mat src, double thresh, double maxval, ThresholdType type)
        {
            var dst = new Mat();

            Cv2.Threshold(src, dst, thresh, maxval, type);
            return(dst);
        }
コード例 #6
0
ファイル: Program.cs プロジェクト: LarryLegend33/PullPara
        static ContourProperties FishContour(Mat image_raw, Mat background)
        {
            bool fishcont_found = false;
            Size frsize = new Size(image_raw.Width, image_raw.Height);
            Mat image = new Mat(frsize, Emgu.CV.CvEnum.DepthType.Cv8U, 1);
            ContourProperties contprops = new ContourProperties();
            ThresholdType ttype = 0;
            VectorOfVectorOfPoint contours = new VectorOfVectorOfPoint();
            Mat hierarchy = new Mat();
            CvInvoke.AbsDiff(image_raw, background, image);
// This should be 30 as the LB. Switched to 20 to see if i could pick up paramecia. 
            CvInvoke.Threshold(image, image, 10, 255, ttype);
// UNCOMMENT IF YOU WANT TO SHOW THRESHOLDED IMAGE
            String camerawindow = "Camera Window";
            CvInvoke.NamedWindow(camerawindow);
            CvInvoke.Imshow(camerawindow, image);
            CvInvoke.WaitKey(1);
            CvInvoke.FindContours(image, contours, hierarchy, RetrType.External, ChainApproxMethod.ChainApproxNone);
            int fish_contour_index = 0;
            Rectangle bounding_rect = new Rectangle();
            for (int ind = 0; ind < contours.Size; ind++)
            {
                bounding_rect = CvInvoke.BoundingRectangle(contours[ind]);
                if (bounding_rect.Width > bounding_rect.Height)
                {
                    contprops.height = bounding_rect.Width;
                }
                else
                {
                    contprops.height = bounding_rect.Height;
                }
                if (contprops.height < 50 && contprops.height > 25)
                {
                    fish_contour_index = ind;
                    fishcont_found = true;
                    break;
                }
            }
            if (fishcont_found)
            {
                var contourCenter = new Point();
                var contourCOM = new Point();
                MCvMoments com = new MCvMoments();
                com = CvInvoke.Moments(contours[fish_contour_index]);
                contourCOM.X = (int)(com.M10 / com.M00);
                contourCOM.Y = (int) (com.M01 / com.M00);
                contourCenter.X = (int)(bounding_rect.X + (float)bounding_rect.Width / (float)2);
                contourCenter.Y = (int)(bounding_rect.Y + (float)bounding_rect.Height / (float)2);
                contprops.center = contourCenter;                
                contprops.com = contourCOM;
            }
            else
            {
                Console.WriteLine(contprops.com);
                Console.WriteLine(contprops.height);
                Console.WriteLine("no contours");
            }
            return contprops;
        }
コード例 #7
0
ファイル: Terminate.cs プロジェクト: zookae/Microgames
 /// <summary>
 /// Test whether given value has above or below relation to threshold value.
 /// </summary>
 /// <param name="value"></param>
 /// <param name="thresh"></param>
 /// <param name="threshType"></param>
 /// <returns></returns>
 public bool PassedThresh(float value, float thresh, ThresholdType threshType)
 {
     if (threshType == ThresholdType.Above && value >= thresh)
     {
         return(true);
     }
     else if (threshType == ThresholdType.Below && value <= thresh)
     {
         return(true);
     }
     return(false);
 }
コード例 #8
0
        private static void CheckHdd()
        {
            foreach (KeyValuePair <string, long> drive in GetDriveStatuses(_watchedDisksThresholdTypes))
            {
                bool    wasWarning         = false;
                decimal spaceLeftOnDriveGb =
                    (decimal)(drive.Value) / 1024L / 1024L / 1024L;                     //free or used - depends on config
                ThresholdType tt = _watchedDisksThresholdTypes[drive.Key];
                //notify hard drive
                if (!_watchedDisksWarnings[drive.Key])
                {
                    if ((tt == ThresholdType.Free && spaceLeftOnDriveGb < _watchedDisksThresholds[drive.Key]) ||
                        (tt == ThresholdType.Used && spaceLeftOnDriveGb > _watchedDisksThresholds[drive.Key])
                        )
                    {
                        _watchedDisksWarnings[drive.Key] = true;
                        wasWarning = true;
                        Warn(
                            $"Drive {drive.Key} {_watchedDisksThresholdTypes[drive.Key].ToString().ToLower()}",
                            spaceLeftOnDriveGb,
                            _watchedDisksThresholds[drive.Key],
                            tt,
                            _watchedDisksScripts[drive.Key],
                            _watchedDisksWarnings[drive.Key]);
                    }
                }
                else
                {
                    if ((tt == ThresholdType.Free && spaceLeftOnDriveGb > _watchedDisksThresholds[drive.Key]) ||
                        (tt == ThresholdType.Used && spaceLeftOnDriveGb < _watchedDisksThresholds[drive.Key])
                        )
                    {
                        _watchedDisksWarnings[drive.Key] = false;
                        wasWarning = true;
                        Warn(
                            $"Drive {drive.Key} {_watchedDisksThresholdTypes[drive.Key].ToString().ToLower()}",
                            spaceLeftOnDriveGb,
                            _watchedDisksThresholds[drive.Key],
                            tt,
                            _watchedDisksScripts[drive.Key],
                            _watchedDisksWarnings[drive.Key]);
                    }
                }

                if (!wasWarning)
                {
                    Console.WriteLine(
                        _watchedDisksThresholdTypes[drive.Key] == ThresholdType.Free
                                                        ? $"Drive {drive.Key} free space left: {spaceLeftOnDriveGb:####.#} GB"
                                                        : $"Drive {drive.Key} used space: {spaceLeftOnDriveGb:####.#} GB");
                }
            }
        }
コード例 #9
0
        private void ChangeDamageState(ThresholdType threshold)
        {
            if (threshold == currentstate)
            {
                return;
            }

            CurrentDamageState.ExitState(Owner);
            CurrentDamageState = DamageTemplates.StateThresholdMap[threshold];
            CurrentDamageState.EnterState(Owner);

            currentstate = threshold;
        }
コード例 #10
0
ファイル: Program.cs プロジェクト: LarryLegend33/EscapeCode
        static ContourProperties LargestContour(Mat image_raw, Mat background, bool draw)
        {
            Size frsize = new Size(image_raw.Width, image_raw.Height);
            Mat  image  = new Mat(frsize, Emgu.CV.CvEnum.DepthType.Cv8U, 1);
            ContourProperties     contprops = new ContourProperties();
            ThresholdType         ttype     = 0;
            VectorOfVectorOfPoint contours  = new VectorOfVectorOfPoint();
            Mat hierarchy = new Mat();

            CvInvoke.AbsDiff(image_raw, background, image);
            CvInvoke.Threshold(image, image, 35, 255, ttype);
            CvInvoke.FindContours(image, contours, hierarchy, RetrType.External, ChainApproxMethod.ChainApproxNone);
            double largest_area       = 0;
            int    largest_area_index = 0;

            for (int ind = 0; ind < contours.Size; ind++)
            {
                double area = CvInvoke.ContourArea(contours[ind]);
                if (area > largest_area)
                {
                    if (image_raw.Width > 1000 && contours[ind][0].Y < 100) // prevents stim LED from being caught as a contour
                    {
                        continue;
                    }
                    largest_area       = area;
                    largest_area_index = ind;
                }
            }
            var contourCenter = new Point();

            if (contours.Size > 0)
            {
                Rectangle bounding_rect = CvInvoke.BoundingRectangle(contours[largest_area_index]);
                contourCenter.X  = (int)(bounding_rect.X + (float)bounding_rect.Width / (float)2);
                contourCenter.Y  = (int)(bounding_rect.Y + (float)bounding_rect.Height / (float)2);
                contprops.center = contourCenter;
                contprops.height = bounding_rect.Height;
                if (draw)
                {
                    CvInvoke.DrawContours(image_raw, contours, largest_area_index, new MCvScalar(255, 0, 0), 2); // these are correct.
                    CvInvoke.Rectangle(image_raw, bounding_rect, new MCvScalar(255, 0, 0));
                    CvInvoke.Circle(image_raw, contourCenter, 50, new MCvScalar(255, 0, 0));                     // THIS IS ABOUT 50 PIXELS TOO HIGH
                }
            }
            else
            {
                //    Console.WriteLine("no contours");
            }
            return(contprops);
        }
コード例 #11
0
        private void ChangeDamageState(ThresholdType threshold)
        {
            if (threshold == currentstate)
            {
                return;
            }

            CurrentDamageState.ExitState(Owner);
            CurrentDamageState = DamageTemplates.StateThresholdMap[threshold];
            CurrentDamageState.EnterState(Owner);

            currentstate = threshold;

            Owner.RaiseEvent(new MobDamageStateChangedMessage(this));
        }
コード例 #12
0
        public static Image <Gray, byte> AdaptiveThreshold
        (
            this Image <Gray, byte> inImage
            , double maxVal = 250
            , AdaptiveThresholdType adaptiveThresholdType = AdaptiveThresholdType.MeanC
            , ThresholdType thresholdType = ThresholdType.BinaryInv
            , int blockSize = 39
            , double param1 = 4)
        {
            var outImage = inImage.Copy();

            CvInvoke.AdaptiveThreshold
                (GaussBlur(inImage), outImage, maxVal, adaptiveThresholdType, thresholdType, blockSize, param1);
            return(outImage);
        }
コード例 #13
0
        public detect_blobs()
        {
            MinHeightBeaninFrame = 3;
            isMaster             = true;

            cfg = SettingsManager.Instance.GetCurrent(System.Windows.Forms.Application.StartupPath);

            ThresholdType_METHOD = (ThresholdType)cfg.BinMethod;
            ThresholdType_VAL    = (byte)cfg.BinVal;
            ThresholdType_MAX    = 255;

            colorRange = new ColorRange("Red");

            listOfFilter   = (new filters.manager()).get();
            lineColorEmpty = (new filters.manager()).getColorEmpty();
        }
コード例 #14
0
        private static void RunScriptAndEmail(
            decimal currentState,
            decimal limit,
            ThresholdType limitType,
            string scriptPath,
            string watcherName,
            bool isWarning)
        {
            //NOTE: isWarning == false means that notification is about watcher back within limits
            string[] scriptParts = scriptPath.Split(new[] { ' ' }, 2);

            ProcessStartInfo scriptInfo = new ProcessStartInfo(
                scriptParts[0],
                scriptParts[1]
                .Replace("%value%", currentState.ToString("####.#").Replace(",", "."))
                .Replace("%limit%", limit.ToString("####.#").Replace(",", "."))
                .Replace("%type%", limitType.ToString().ToLower())
                );

            try
            {
                Process.Start(scriptInfo);
            }
            catch (Exception ex)
            {
                Console.WriteLine($"Script start failed. Message: {ex.Message}");
            }

            if (_emailNotifier.IsConfigured)
            {
                try
                {
                    _emailNotifier.SendMail(
                        watcherName,
                        currentState,
                        limit,
                        isWarning
                                                        ? EventType.Warning
                                                        : EventType.Ok);
                }
                catch (Exception ex)
                {
                    Console.WriteLine($"Email send failed. Message: {ex.Message}");
                }
            }
        }
コード例 #15
0
ファイル: ChecksumOption.cs プロジェクト: rollend/LevelUp
 private void btnOK_Click( object sender, EventArgs e )
 {
     if( !cbIsUseSizeThreshold.Checked ) {
         ThresholdType = ThresholdType.None;
     } else {
         ThresholdType =
             comboThresholdType.Text == "Least" ?
                 ThresholdType.Least :
                 comboThresholdType.Text == "Most" ?
                     ThresholdType.Most :
                     ThresholdType.None;
         Bound = (long)nudThreshold.Value * 1024;
     }
     IsUpdateExistChecksum = cbIsRecomputeAll.Checked;
     IsOK = true;
     Close();
 }
コード例 #16
0
        internal TimeSpan GetTimeSpanToUse(int threshold, ThresholdType thresholdType)
        {
            if (thresholdType == ThresholdType.Seconds)
            {
                return(TimeSpan.FromSeconds(threshold));
            }
            if (thresholdType == ThresholdType.Hours)
            {
                return(TimeSpan.FromHours(threshold));
            }
            if (thresholdType == ThresholdType.Minutes)
            {
                return(TimeSpan.FromMinutes(threshold));
            }

            throw new InvalidThresholdTypeException(thresholdType.ToString());
        }
コード例 #17
0
        public detect_blobs(ColorRange cr, ThresholdType tm = ThresholdType.BinaryInv, byte tv = 170, byte tmx = 255,
                            int minHeightBeaninFrame        = 2, bool ismaster = true)
        {
            MinHeightBeaninFrame = minHeightBeaninFrame;
            isMaster             = ismaster;

            cfg = SettingsManager.Instance.GetCurrent(System.Windows.Forms.Application.StartupPath);

            ThresholdType_METHOD = (ThresholdType)cfg.BinMethod;
            ThresholdType_VAL    = (byte)cfg.BinVal;
            ThresholdType_MAX    = tmx;

            colorRange = cr;

            listOfFilter   = (new filters.manager()).get();
            lineColorEmpty = (new filters.manager()).getColorEmpty();
        }
コード例 #18
0
        private void ChangeDamageState(ThresholdType threshold)
        {
            if (threshold == currentstate)
            {
                return;
            }

            CurrentDamageState.ExitState(Owner);
            CurrentDamageState = DamageTemplates.StateThresholdMap[threshold];
            CurrentDamageState.EnterState(Owner);

            currentstate = threshold;

            EntityEventArgs toRaise = new MobDamageStateChangedMessage(this);

            Owner.EntityManager.EventBus.RaiseEvent(EventSource.Local, toRaise);
        }
コード例 #19
0
ファイル: ChecksumOption.cs プロジェクト: rollend/LevelUp
 private void btnOK_Click(object sender, EventArgs e)
 {
     if (!cbIsUseSizeThreshold.Checked)
     {
         ThresholdType = ThresholdType.None;
     }
     else
     {
         ThresholdType =
             comboThresholdType.Text == "Least" ?
             ThresholdType.Least :
             comboThresholdType.Text == "Most" ?
             ThresholdType.Most :
             ThresholdType.None;
         Bound = (long)nudThreshold.Value * 1024;
     }
     IsUpdateExistChecksum = cbIsRecomputeAll.Checked;
     IsOK = true;
     Close();
 }
コード例 #20
0
        private void comboThresholdType_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (useAdaptive)
            {
                switch (comboThresholdType.SelectedIndex)
                {
                case (int)ThresholdType.Binary:
                    _thresholdType = ThresholdType.Binary;
                    break;

                case (int)AdaptiveThresholdType.GaussianC:
                    _thresholdType = ThresholdType.BinaryInv;
                    break;

                default:
                    break;
                }
                buttonBinarisation_Click(sender, e);
            }
        }
コード例 #21
0
        private void radThresh_CheckedChanged(object sender, EventArgs e)
        {
            if (radBin.Checked)
            {
                _thresholdType = ThresholdType.Binary;
            }
            else if (radBinInv.Checked)
            {
                _thresholdType = ThresholdType.BinaryInv;
            }
            else if (radOTSU.Checked)
            {
                _thresholdType = ThresholdType.Otsu;
            }

            if (_original != null)
            {
                CvInvoke.Threshold(_original, _img, trackBarThresh.Value, _maxIntensity, _thresholdType);
                pbxPreview.BackgroundImage = _img.Bitmap;
            }
        }
コード例 #22
0
ファイル: Program.cs プロジェクト: LarryLegend33/EscapeCode
        static List <ContourProperties> BarrierLocations(Mat image_raw, Mat background)
        {
            int  minArea = 1000;
            int  maxArea = 600000;
            Size frsize  = new Size(image_raw.Width, image_raw.Height);
            Mat  image   = new Mat(frsize, Emgu.CV.CvEnum.DepthType.Cv8U, 1);

            ThresholdType            ttype    = 0;
            VectorOfVectorOfPoint    contours = new VectorOfVectorOfPoint();
            List <VectorOfPoint>     contlist = new List <VectorOfPoint>();
            List <ContourProperties> cp_list  = new List <ContourProperties>();
            Mat hierarchy = new Mat();

            CvInvoke.AbsDiff(image_raw, background, image);
            CvInvoke.Threshold(image, image, 50, 255, ttype);
            CvInvoke.FindContours(image, contours, hierarchy, RetrType.External, ChainApproxMethod.ChainApproxNone);
            Point contourCenter = new Point();

            for (int ind = 0; ind < contours.Size; ind++)
            {
                double area = CvInvoke.ContourArea(contours[ind]);
                if (area > minArea && area < maxArea)
                {
                    contlist.Add(contours[ind]);
                }
            }
            for (int contind = 0; contind < contlist.Count; contind++)
            {
                ContourProperties contprops     = new ContourProperties();
                Rectangle         bounding_rect = CvInvoke.BoundingRectangle(contlist[contind]);
                contourCenter.X  = (int)(bounding_rect.X + (float)bounding_rect.Width / (float)2);
                contourCenter.Y  = (int)(bounding_rect.Y + (float)bounding_rect.Height / (float)2);
                contprops.center = contourCenter;
                contprops.height = bounding_rect.Height;
                cp_list.Add(contprops);
            }

            return(cp_list);
        }
コード例 #23
0
 /// <summary>
 /// Applies a fixed-level threshold to each array element.
 /// </summary>
 /// <param name="src">input array (single-channel, 8-bit or 32-bit floating point).</param>
 /// <param name="dst">output array of the same size and type as src.</param>
 /// <param name="thresh">threshold value.</param>
 /// <param name="maxval">maximum value to use with the THRESH_BINARY and THRESH_BINARY_INV thresholding types.</param>
 /// <param name="type">thresholding type (see the details below).</param>
 /// <returns>the computed threshold value when type == OTSU</returns>
 public static double Threshold(InputArray src, OutputArray dst, double thresh, double maxval, ThresholdType type)
 {
     if (src == null)
         throw new ArgumentNullException("src");
     if (dst == null)
         throw new ArgumentNullException("dst");
     src.ThrowIfDisposed();
     dst.ThrowIfNotReady();
     double ret = NativeMethods.imgproc_threshold(src.CvPtr, dst.CvPtr, thresh, maxval, (int)type);
     dst.Fix();
     return ret;
 }
コード例 #24
0
ファイル: CvInvoke.cs プロジェクト: sanglin307/UnityOpenCV
 public static extern void cvAdaptiveThreshold(IntPtr src, IntPtr dst, double max_value, AdaptiveThresholdType adaptiveType,
     ThresholdType threshold_type, int block_size, double param1);
コード例 #25
0
ファイル: Program.cs プロジェクト: LarryLegend33/EscapeCode
        static ContourProperties FishContour(Mat image_raw, Mat background, Point tc, List <ContourProperties> blist, bool control)
        {
// BUG IN HERE IS THAT CONTPROPS HEIGHT GETS SET EVEN WHEN THERE IS NO CONTOUR FOUND. THIS OCCURS BEFORE ENTERING THE LOOP
// BASED ON CONTRPOPS.HEIGHT SIZE. YOU RETURN SOMETHING WITH A HEIGHT BUT NO COORDINATE (0,0) AND THE MAIN LINE THINKS YOU HAVE A CONTOUR AT 0,0.
            bool fishcont_found             = false;
            Size frsize                     = new Size(image_raw.Width, image_raw.Height);
            Mat  image                      = new Mat(frsize, Emgu.CV.CvEnum.DepthType.Cv8U, 1);
            ContourProperties     contprops = new ContourProperties();
            ThresholdType         ttype     = 0;
            VectorOfVectorOfPoint contours  = new VectorOfVectorOfPoint();
            Mat hierarchy                   = new Mat();

            CvInvoke.AbsDiff(image_raw, background, image);
            // This should be 30 as the LB. Switched to 20 to see if i could pick up paramecia.
            CvInvoke.Threshold(image, image, 25, 255, ttype);
            // IF YOU NEED TO SHOW THE THRESHOLDED IMAGE, UNCOMMENT THESE LINES
//            String camerawindow2 = "Camera Window 2";
//          CvInvoke.NamedWindow(camerawindow2);
//        CvInvoke.Imshow(camerawindow2, image);
//      CvInvoke.WaitKey(1);
            CvInvoke.FindContours(image, contours, hierarchy, RetrType.External, ChainApproxMethod.ChainApproxNone);
            int       fish_contour_index = 0;
            int       height             = 0;
            Point     contourCOM         = new Point();
            Point     contour_center     = new Point();
            Rectangle bounding_rect      = new Rectangle();

            for (int ind = 0; ind < contours.Size; ind++)
            {
                MCvMoments com = new MCvMoments();
                com              = CvInvoke.Moments(contours[ind]);
                contourCOM.X     = (int)(com.M10 / com.M00);
                contourCOM.Y     = (int)(com.M01 / com.M00);
                bounding_rect    = CvInvoke.BoundingRectangle(contours[ind]);
                contour_center.X = (int)(bounding_rect.X + (float)bounding_rect.Width / (float)2);
                contour_center.Y = (int)(bounding_rect.Y + (float)bounding_rect.Height / (float)2);
                if (bounding_rect.Width > bounding_rect.Height)
                {
                    height = bounding_rect.Width;
                }
                else
                {
                    height = bounding_rect.Height;
                }
                if (height < 60 && height > 8)
                {
                    if (image_raw.Width > 1000)
                    {
                        if (!control)
                        {
                            bool tooclose = false;
                            for (int i = 0; i < blist.Count; i++)
                            {
// This allows 3, 4, or 5 to be recorded as a COM center, but would be rejected by Tap
                                if (VectorMag(blist[i].center, contourCOM) - (blist[i].height / 2) < 3)
                                {
                                    tooclose = true;
                                    break;
                                }
                            }
                            if (tooclose)
                            {
                                continue;
                            }
                        }
                        if (VectorMag(contourCOM, tc) > 460)
                        //this tells the algorithm not to look for fish outside the tank.
                        {
                            continue;
                        }
                        if (contourCOM.X < 0 || contourCOM.Y < 0)
                        {
                            continue;
                        }
                    }
                    fish_contour_index = ind;
                    fishcont_found     = true;
                    break;
                }
            }
            if (fishcont_found)
            {
// could also choose the contour center below using the bounding rect
                contprops.com    = contourCOM;
                contprops.height = height;
                contprops.center = contour_center;
            }
            return(contprops);
        }
コード例 #26
0
ファイル: Cv_A.cs プロジェクト: sanglin307/UnityOpenCV
        /// <summary>
        /// 適応的な閾値処理を行い、グレースケール画像を2値画像に変換する
        /// </summary>
        /// <param name="src">入力画像</param>
        /// <param name="dst">出力画像</param>
        /// <param name="max_value">threshold_type がBinaryあるいはBinaryInvのときに用いる最大値</param>
        /// <param name="adaptive_method">適応的閾値処理で使用するアルゴリズム</param>
        /// <param name="threshold_type">閾値処理の種類. BinaryかBinaryInvのどちらか</param>
        /// <param name="block_size">ピクセルの閾値を計算するために用いる隣接領域のサイズ: 3, 5, 7, ... </param>
        /// <param name="param1">各適応手法に応じたパラメータ. 適応手法がMeanCおよびGaussianCの場合は,平均値または重み付き平均値から引く定数. 負の値の場合もある.</param>
#else
        /// <summary>
        /// Applies adaptive threshold to array.
        /// </summary>
        /// <param name="src">Source image.</param>
        /// <param name="dst">Destination image. </param>
        /// <param name="max_value">Maximum value that is used with CV_THRESH_BINARY and CV_THRESH_BINARY_INV. </param>
        /// <param name="adaptive_method">Adaptive thresholding algorithm to use: CV_ADAPTIVE_THRESH_MEAN_C or CV_ADAPTIVE_THRESH_GAUSSIAN_C.</param>
        /// <param name="threshold_type">Thresholding type.</param>
        /// <param name="block_size">The size of a pixel neighborhood that is used to calculate a threshold value for the pixel: 3, 5, 7, ... </param>
        /// <param name="param1">The method-dependent parameter. For the methods CV_ADAPTIVE_THRESH_MEAN_C and CV_ADAPTIVE_THRESH_GAUSSIAN_C it is a constant subtracted from mean or weighted mean (see the discussion), though it may be negative. </param>
#endif
        public static void AdaptiveThreshold(CvArr src, CvArr dst, double max_value, AdaptiveThresholdType adaptive_method, ThresholdType threshold_type, int block_size, double param1)
        {
            if (src == null)
                throw new ArgumentNullException("src");
            if (dst == null)
                throw new ArgumentNullException("dst");

            if (threshold_type != ThresholdType.Binary && threshold_type != ThresholdType.BinaryInv)
            {
                throw new ArgumentOutOfRangeException("閾値処理の種類は、BinaryかBinaryInvのどちらかである必要があります。");
            }
            CvInvoke.cvAdaptiveThreshold(src.CvPtr, dst.CvPtr, max_value, adaptive_method, threshold_type, block_size, param1);
        }
コード例 #27
0
ファイル: ThresholdFilter.cs プロジェクト: asiryan/UMapx
 /// <summary>
 /// Initializes the threshold filter.
 /// </summary>
 /// <param name="threshold">Threshold value</param>
 /// <param name="type">Compress type</param>
 public ThresholdFilter(float threshold, ThresholdType type = ThresholdType.Abs)
 {
     this.threshold = threshold;
     this.type      = type;
 }
コード例 #28
0
        /// <summary>
        /// シングルチャンネルの配列に対して,固定閾値での閾値処理を行う
        /// </summary>
        /// <param name="src">入力配列 (シングルチャンネル,8ビット,あるいは32ビット浮動小数点型)</param>
        /// <param name="dst">出力配列.src と同じデータタイプ,または8ビット. </param>
        /// <param name="threshold">閾値</param>
        /// <param name="maxValue">threshold_type が Binary と BinaryInv のときに使用する最大値</param>
        /// <param name="thresholdType">閾値処理の種類</param>
#else
        /// <summary>
        /// Applies fixed-level threshold to array elements.
        /// </summary>
        /// <param name="src">Source array (single-channel, 8-bit of 32-bit floating point). </param>
        /// <param name="dst">Destination array; must be either the same type as src or 8-bit. </param>
        /// <param name="threshold">Threshold value. </param>
        /// <param name="maxValue">Maximum value to use with CV_THRESH_BINARY and CV_THRESH_BINARY_INV thresholding types. </param>
        /// <param name="thresholdType">Thresholding type.</param>
#endif
        public static double Threshold(CvArr src, CvArr dst, double threshold, double maxValue, ThresholdType thresholdType)
        {
            if (src == null)
            {
                throw new ArgumentNullException("src");
            }
            if (dst == null)
            {
                throw new ArgumentNullException("dst");
            }
            double ret = NativeMethods.cvThreshold(src.CvPtr, dst.CvPtr, threshold, maxValue, thresholdType);

            GC.KeepAlive(src);
            GC.KeepAlive(dst);
            return(ret);
        }
コード例 #29
0
ファイル: Cv_A.cs プロジェクト: jorik041/opencvsharp
        /// <summary>
        /// 適応的な閾値処理を行い、グレースケール画像を2値画像に変換する
        /// </summary>
        /// <param name="src">入力画像</param>
        /// <param name="dst">出力画像</param>
        /// <param name="maxValue">threshold_type がBinaryあるいはBinaryInvのときに用いる最大値</param>
        /// <param name="adaptiveMethod">適応的閾値処理で使用するアルゴリズム</param>
        /// <param name="thresholdType">閾値処理の種類. BinaryかBinaryInvのどちらか</param>
        /// <param name="blockSize">ピクセルの閾値を計算するために用いる隣接領域のサイズ: 3, 5, 7, ... </param>
        /// <param name="param1">各適応手法に応じたパラメータ. 適応手法がMeanCおよびGaussianCの場合は,平均値または重み付き平均値から引く定数. 負の値の場合もある.</param>
#else
        /// <summary>
        /// Applies adaptive threshold to array.
        /// </summary>
        /// <param name="src">Source image.</param>
        /// <param name="dst">Destination image. </param>
        /// <param name="maxValue">Maximum value that is used with Binary and BinaryInv. </param>
        /// <param name="adaptiveMethod">Adaptive thresholding algorithm to use: MeanC or GaussianC.</param>
        /// <param name="thresholdType">Thresholding type.</param>
        /// <param name="blockSize">The size of a pixel neighborhood that is used to calculate a threshold value for the pixel: 3, 5, 7, ... </param>
        /// <param name="param1">The method-dependent parameter. For the methods MeanC and GaussianC it is a constant subtracted from mean or weighted mean (see the discussion), though it may be negative. </param>
#endif
        public static void AdaptiveThreshold(CvArr src, CvArr dst, double maxValue, AdaptiveThresholdType adaptiveMethod, ThresholdType thresholdType, int blockSize, double param1)
        {
            if (src == null)
                throw new ArgumentNullException("src");
            if (dst == null)
                throw new ArgumentNullException("dst");

            if (thresholdType != ThresholdType.Binary && thresholdType != ThresholdType.BinaryInv)
            {
                throw new ArgumentException("thresholdType == Binary || thresholdType == BinaryInv");
            }
            NativeMethods.cvAdaptiveThreshold(src.CvPtr, dst.CvPtr, maxValue, adaptiveMethod, thresholdType, blockSize, param1);
        }
コード例 #30
0
ファイル: XImgprocInvoke.cs プロジェクト: neutmute/emgucv
 /// <summary>
 /// Niblack threshold
 /// </summary>
 /// <param name="src">The source image</param>
 /// <param name="dst">The output result</param>
 /// <param name="type">Threshold type</param>
 /// <param name="blockSize">Block size</param>
 /// <param name="delta">delta</param>
 /// <param name="maxValue">Maximum value to use with CV_THRESH_BINARY and CV_THRESH_BINARY_INV thresholding types</param>
 public static void NiBlackThreshold(IInputArray src, IOutputArray dst, double maxValue, ThresholdType type, int blockSize,
    double delta)
 {
    using (InputArray iaSrc = src.GetInputArray())
    using (OutputArray oaDst = dst.GetOutputArray())
    {
       cveNiBlackThreshold(iaSrc, oaDst, maxValue, type, blockSize, delta);
    }
 }
コード例 #31
0
ファイル: XImgprocInvoke.cs プロジェクト: neutmute/emgucv
 private static extern void cveNiBlackThreshold(IntPtr src, IntPtr dst, double maxValue, ThresholdType type, int blockSize, double delta);
コード例 #32
0
ファイル: Mat_CvMethods.cs プロジェクト: MJunak/opencvsharp
 /// <summary>
 /// Applies an adaptive threshold to an array.
 /// Source matrix must be 8-bit single-channel image.
 /// </summary>
 /// <param name="maxValue">Non-zero value assigned to the pixels for which the condition is satisfied. See the details below.</param>
 /// <param name="adaptiveMethod">Adaptive thresholding algorithm to use, ADAPTIVE_THRESH_MEAN_C or ADAPTIVE_THRESH_GAUSSIAN_C .</param>
 /// <param name="thresholdType">Thresholding type that must be either THRESH_BINARY or THRESH_BINARY_INV .</param>
 /// <param name="blockSize">Size of a pixel neighborhood that is used to calculate a threshold value for the pixel: 3, 5, 7, and so on.</param>
 /// <param name="c">Constant subtracted from the mean or weighted mean (see the details below). 
 /// Normally, it is positive but may be zero or negative as well.</param>
 /// <returns>Destination image of the same size and the same type as src.</returns>
 public Mat AdaptiveThreshold(double maxValue, AdaptiveThresholdType adaptiveMethod, 
     ThresholdType thresholdType, int blockSize, double c)
 {
     var dst = new Mat();
     Cv2.AdaptiveThreshold(this, dst, maxValue, adaptiveMethod, 
         thresholdType, blockSize, c);
     return dst;
 }
コード例 #33
0
ファイル: ChecksumOption.cs プロジェクト: rollend/LevelUp
 private void btnCancel_Click( object sender, EventArgs e )
 {
     ThresholdType = ThresholdType.None;
     IsOK = false;
     Close();
 }
コード例 #34
0
ファイル: Cv_A.cs プロジェクト: sanglin307/UnityOpenCV
        /// <summary>
        /// 適応的な閾値処理を行い、グレースケール画像を2値画像に変換する
        /// </summary>
        /// <param name="src">入力画像</param>
        /// <param name="dst">出力画像</param>
        /// <param name="max_value">threshold_type がBinaryあるいはBinaryInvのときに用いる最大値</param>
        /// <param name="adaptive_method">適応的閾値処理で使用するアルゴリズム</param>
        /// <param name="threshold_type">閾値処理の種類. BinaryかBinaryInvのどちらか</param>
        /// <param name="block_size">ピクセルの閾値を計算するために用いる隣接領域のサイズ: 3, 5, 7, ... </param>
#else
        /// <summary>
        /// Applies adaptive threshold to array.
        /// </summary>
        /// <param name="src">Source image.</param>
        /// <param name="dst">Destination image. </param>
        /// <param name="max_value">Maximum value that is used with CV_THRESH_BINARY and CV_THRESH_BINARY_INV. </param>
        /// <param name="adaptive_method">Adaptive thresholding algorithm to use: CV_ADAPTIVE_THRESH_MEAN_C or CV_ADAPTIVE_THRESH_GAUSSIAN_C.</param>
        /// <param name="threshold_type">Thresholding type.</param>
        /// <param name="block_size">The size of a pixel neighborhood that is used to calculate a threshold value for the pixel: 3, 5, 7, ... </param>
#endif
        public static void AdaptiveThreshold(CvArr src, CvArr dst, double max_value, AdaptiveThresholdType adaptive_method, ThresholdType threshold_type, Int32 block_size)
        {
            AdaptiveThreshold(src, dst, max_value, adaptive_method, threshold_type, block_size, 5);
        }
コード例 #35
0
        /// <summary>
        /// 適応的な閾値処理を行い、グレースケール画像を2値画像に変換する
        /// </summary>
        /// <param name="src">入力画像</param>
        /// <param name="dst">出力画像</param>
        /// <param name="maxValue">threshold_type がBinaryあるいはBinaryInvのときに用いる最大値</param>
        /// <param name="adaptiveMethod">適応的閾値処理で使用するアルゴリズム</param>
        /// <param name="thresholdType">閾値処理の種類. BinaryかBinaryInvのどちらか</param>
        /// <param name="blockSize">ピクセルの閾値を計算するために用いる隣接領域のサイズ: 3, 5, 7, ... </param>
#else
        /// <summary>
        /// Applies adaptive threshold to array.
        /// </summary>
        /// <param name="src">Source image.</param>
        /// <param name="dst">Destination image. </param>
        /// <param name="maxValue">Maximum value that is used with Binary and BinaryInv. </param>
        /// <param name="adaptiveMethod">Adaptive thresholding algorithm to use: MeanC or GaussianC.</param>
        /// <param name="thresholdType">Thresholding type.</param>
        /// <param name="blockSize">The size of a pixel neighborhood that is used to calculate a threshold value for the pixel: 3, 5, 7, ... </param>
#endif
        public static void AdaptiveThreshold(CvArr src, CvArr dst, double maxValue, AdaptiveThresholdType adaptiveMethod, ThresholdType thresholdType, int blockSize)
        {
            AdaptiveThreshold(src, dst, maxValue, adaptiveMethod, thresholdType, blockSize, 5);
        }
コード例 #36
0
 public void AdaptiveThreshold(AdaptiveThresholdType adaptiveType = AdaptiveThresholdType.MeanC, ThresholdType thresholdType = ThresholdType.Binary, double maxValue = 255)
 {
     CvInvoke.AdaptiveThreshold(this.Data, this.Data, maxValue, adaptiveType, thresholdType, 201, -2);
 }
コード例 #37
0
 public void Threshold(ThresholdType type = ThresholdType.Binary, double threshold = 30, double maxValue = 255)
 {
     CvInvoke.Threshold(this.Data, this.Data, threshold, maxValue, type);
 }
コード例 #38
0
ファイル: Cv_A.cs プロジェクト: jorik041/opencvsharp
        /// <summary>
        /// 適応的な閾値処理を行い、グレースケール画像を2値画像に変換する
        /// </summary>
        /// <param name="src">入力画像</param>
        /// <param name="dst">出力画像</param>
        /// <param name="maxValue">threshold_type がBinaryあるいはBinaryInvのときに用いる最大値</param>
        /// <param name="adaptiveMethod">適応的閾値処理で使用するアルゴリズム</param>
        /// <param name="thresholdType">閾値処理の種類. BinaryかBinaryInvのどちらか</param>
        /// <param name="blockSize">ピクセルの閾値を計算するために用いる隣接領域のサイズ: 3, 5, 7, ... </param>
#else
        /// <summary>
        /// Applies adaptive threshold to array.
        /// </summary>
        /// <param name="src">Source image.</param>
        /// <param name="dst">Destination image. </param>
        /// <param name="maxValue">Maximum value that is used with Binary and BinaryInv. </param>
        /// <param name="adaptiveMethod">Adaptive thresholding algorithm to use: MeanC or GaussianC.</param>
        /// <param name="thresholdType">Thresholding type.</param>
        /// <param name="blockSize">The size of a pixel neighborhood that is used to calculate a threshold value for the pixel: 3, 5, 7, ... </param>
#endif
        public static void AdaptiveThreshold(CvArr src, CvArr dst, double maxValue, AdaptiveThresholdType adaptiveMethod, ThresholdType thresholdType, int blockSize)
        {
            AdaptiveThreshold(src, dst, maxValue, adaptiveMethod, thresholdType, blockSize, 5);
        }
コード例 #39
0
ファイル: Mat_CvMethods.cs プロジェクト: MJunak/opencvsharp
 /// <summary>
 /// Applies a fixed-level threshold to each array element.
 /// The input matrix must be single-channel, 8-bit or 32-bit floating point.
 /// </summary>
 /// <param name="thresh">threshold value.</param>
 /// <param name="maxval">maximum value to use with the THRESH_BINARY and THRESH_BINARY_INV thresholding types.</param>
 /// <param name="type">thresholding type (see the details below).</param>
 /// <returns>output array of the same size and type as src.</returns>
 public Mat Threshold(double thresh, double maxval, ThresholdType type)
 {
     var dst = new Mat();
     Cv2.Threshold(this, dst, thresh, maxval, type);
     return dst;
 }
コード例 #40
0
 /// <summary>
 /// Applies an adaptive threshold to an array.
 /// </summary>
 /// <param name="src">Source 8-bit single-channel image.</param>
 /// <param name="dst">Destination image of the same size and the same type as src .</param>
 /// <param name="maxValue">Non-zero value assigned to the pixels for which the condition is satisfied. See the details below.</param>
 /// <param name="adaptiveMethod">Adaptive thresholding algorithm to use, ADAPTIVE_THRESH_MEAN_C or ADAPTIVE_THRESH_GAUSSIAN_C .</param>
 /// <param name="thresholdType">Thresholding type that must be either THRESH_BINARY or THRESH_BINARY_INV .</param>
 /// <param name="blockSize">Size of a pixel neighborhood that is used to calculate a threshold value for the pixel: 3, 5, 7, and so on.</param>
 /// <param name="c">Constant subtracted from the mean or weighted mean (see the details below). 
 /// Normally, it is positive but may be zero or negative as well.</param>
 public static void AdaptiveThreshold(InputArray src, OutputArray dst,
     double maxValue, AdaptiveThresholdType adaptiveMethod, ThresholdType thresholdType, int blockSize, double c)
 {
     if (src == null)
         throw new ArgumentNullException("src");
     if (dst == null)
         throw new ArgumentNullException("dst");
     src.ThrowIfDisposed();
     dst.ThrowIfNotReady();
     NativeMethods.imgproc_adaptiveThreshold(src.CvPtr, dst.CvPtr, maxValue, (int)adaptiveMethod, (int)thresholdType, blockSize, c);
     dst.Fix();
 }
コード例 #41
0
 public DamageThreshold(DamageType damageType, int value, ThresholdType thresholdType)
 {
     DamageType    = damageType;
     Value         = value;
     ThresholdType = thresholdType;
 }
コード例 #42
0
 /// <summary>
 /// Add a type of threshold to combine with the existing
 /// </summary>
 /// <param name="type">The type of threshold to add</param>
 /// <returns></returns>
 public CoverletSettings WithThresholdType(ThresholdType type)
 {
     ThresholdType |= type;
     return(this);
 }
コード例 #43
0
        /// <summary>
        /// 適応的な閾値処理を行い、グレースケール画像を2値画像に変換する
        /// </summary>
        /// <param name="src">入力画像</param>
        /// <param name="dst">出力画像</param>
        /// <param name="maxValue">threshold_type がBinaryあるいはBinaryInvのときに用いる最大値</param>
        /// <param name="adaptiveMethod">適応的閾値処理で使用するアルゴリズム</param>
        /// <param name="thresholdType">閾値処理の種類. BinaryかBinaryInvのどちらか</param>
        /// <param name="blockSize">ピクセルの閾値を計算するために用いる隣接領域のサイズ: 3, 5, 7, ... </param>
        /// <param name="param1">各適応手法に応じたパラメータ. 適応手法がMeanCおよびGaussianCの場合は,平均値または重み付き平均値から引く定数. 負の値の場合もある.</param>
#else
        /// <summary>
        /// Applies adaptive threshold to array.
        /// </summary>
        /// <param name="src">Source image.</param>
        /// <param name="dst">Destination image. </param>
        /// <param name="maxValue">Maximum value that is used with Binary and BinaryInv. </param>
        /// <param name="adaptiveMethod">Adaptive thresholding algorithm to use: MeanC or GaussianC.</param>
        /// <param name="thresholdType">Thresholding type.</param>
        /// <param name="blockSize">The size of a pixel neighborhood that is used to calculate a threshold value for the pixel: 3, 5, 7, ... </param>
        /// <param name="param1">The method-dependent parameter. For the methods MeanC and GaussianC it is a constant subtracted from mean or weighted mean (see the discussion), though it may be negative. </param>
#endif
        public static void AdaptiveThreshold(CvArr src, CvArr dst, double maxValue, AdaptiveThresholdType adaptiveMethod, ThresholdType thresholdType, int blockSize, double param1)
        {
            if (src == null)
            {
                throw new ArgumentNullException(nameof(src));
            }
            if (dst == null)
            {
                throw new ArgumentNullException(nameof(dst));
            }

            if (thresholdType != ThresholdType.Binary && thresholdType != ThresholdType.BinaryInv)
            {
                throw new ArgumentException("thresholdType == Binary || thresholdType == BinaryInv");
            }
            NativeMethods.cvAdaptiveThreshold(src.CvPtr, dst.CvPtr, maxValue, adaptiveMethod, thresholdType, blockSize, param1);

            GC.KeepAlive(src);
            GC.KeepAlive(dst);
        }
コード例 #44
0
ファイル: Threshold.cs プロジェクト: tealole/practice
 public Threshold(int downLimit = 50, int upLimit = 60, ThresholdType type = ThresholdType.Binary)
 {
     this.downLimit = downLimit;
     this.upLimit = upLimit;
     this.type = type;
 }