コード例 #1
0
ファイル: Form1.cs プロジェクト: fishbot/fishbot
        private IplImage FeatureDetector(Bitmap bitmapIn)
        {
            double minVal, maxVal;
            IplImage i1 = BitmapConverter.ToIplImage(bitmapIn);

            IplImage gray = new IplImage(new OpenCvSharp.CvSize(i1.Size.Width, i1.Size.Height), BitDepth.U8, 1);
            IplImage blur = new IplImage(new OpenCvSharp.CvSize(i1.Size.Width, i1.Size.Height), BitDepth.U8, 1);
            IplImage gaussian = new IplImage(new OpenCvSharp.CvSize(i1.Size.Width, i1.Size.Height), BitDepth.U8, 1);
            IplImage laplace = new IplImage(new OpenCvSharp.CvSize(i1.Size.Width, i1.Size.Height), BitDepth.F32, gaussian.NChannels);
            IplImage converted = new IplImage(new OpenCvSharp.CvSize(i1.Size.Width, i1.Size.Height), BitDepth.U8, 1);
            IplImage normalized = new IplImage(new OpenCvSharp.CvSize(i1.Size.Width, i1.Size.Height), BitDepth.U8, 1);
            IplImage tresh = new IplImage(new OpenCvSharp.CvSize(i1.Size.Width, i1.Size.Height), BitDepth.U8, 1);

            OpenCvSharp.Cv.CvtColor(i1, gray, ColorConversion.RgbToGray);
            OpenCvSharp.Cv.Normalize(gray, normalized, 0.0, 255.0, NormType.MinMax);
            OpenCvSharp.Cv.Smooth(normalized, blur, SmoothType.Median, 5, 5);
            OpenCvSharp.Cv.Smooth(blur, gaussian, SmoothType.Gaussian, 5, 5);
            OpenCvSharp.Cv.Laplace(gaussian, laplace, ApertureSize.Size5);

            laplace.MinMaxLoc(out minVal, out maxVal);
            laplace.ConvertScale(converted, 255.0 / (2.0 * maxVal), 128);

            OpenCvSharp.Cv.Threshold(converted, tresh, 150.0, 255.0, ThresholdType.Binary);

            return tresh;
        }