GaussianBlur() public static method

Blurs an image using a Gaussian filter.
public static GaussianBlur ( InputArray src, OutputArray dst, Size ksize, double sigmaX, double sigmaY, BorderTypes borderType = BorderTypes.Default ) : void
src InputArray input image; the image can have any number of channels, which are processed independently, /// but the depth should be CV_8U, CV_16U, CV_16S, CV_32F or CV_64F.
dst OutputArray output image of the same size and type as src.
ksize Size Gaussian kernel size. ksize.width and ksize.height can differ but they both must be positive and odd. /// Or, they can be zero’s and then they are computed from sigma* .
sigmaX double Gaussian kernel standard deviation in X direction.
sigmaY double Gaussian kernel standard deviation in Y direction; if sigmaY is zero, it is set to be equal to sigmaX, /// if both sigmas are zeros, they are computed from ksize.width and ksize.height, /// respectively (see getGaussianKernel() for details); to fully control the result /// regardless of possible future modifications of all this semantics, it is recommended to specify all of ksize, sigmaX, and sigmaY.
borderType BorderTypes pixel extrapolation method
return void
コード例 #1
0
        // Use this for initialization
        void Start()
        {
            Mat mat        = Unity.TextureToMat(this.texture);
            Mat changedMat = new Mat();

            Cv2.GaussianBlur(mat, changedMat, new Size(3, 3), 1.3, 1.3);
            Texture2D changedTex = Unity.MatToTexture(changedMat);

            GetComponent <RawImage>().texture = changedTex;
        }
コード例 #2
0
        //OpenCVを使用して、座標を求める。
        void OpenCVTexture(Texture2D texture)
        {
            Mat newMat = Unity.TextureToMat(texture);

            //画像をCv2.Equalsで変化があるかグローバルのoldMatと比較して検知しようとしたが、できなかった。

            //Convert image to grayscale
            Mat imgGray = new Mat();

            Cv2.CvtColor(newMat, imgGray, ColorConversionCodes.BGR2GRAY);

            //Debug.Log(Cv2.Equals(imgGray, imgGray));


            // Clean up image using Gaussian Blur
            Mat imgGrayBlur = new Mat();

            Cv2.GaussianBlur(imgGray, imgGrayBlur, new Size(5, 5), 0);

            //Extract edges
            Mat cannyEdges = new Mat();

            Cv2.Canny(imgGrayBlur, cannyEdges, 10.0, 70.0);

            //Do an invert binarize the image
            Mat mask = new Mat();

            Cv2.Threshold(cannyEdges, mask, 70.0, 255.0, ThresholdTypes.BinaryInv);

            // Extract Contours
            Point[][]        contours;                                                                                                    //特徴点が格納される変数。
            HierarchyIndex[] hierarchy;                                                                                                   //特徴点の階層が格納される。
            Cv2.FindContours(cannyEdges, out contours, out hierarchy, RetrievalModes.Tree, ContourApproximationModes.ApproxSimple, null); //特徴点を検出する。


            PointChangeNumSendUDP(contours);  //Pointが変化しなければ送信を実装しようとしている途中。
            //StartCoroutine(udpSendCoroutine(contours));


            //輪郭描画
            int width    = (int)transform.GetComponent <RectTransform>().sizeDelta.x;
            int height   = (int)transform.GetComponent <RectTransform>().sizeDelta.y;
            Mat Contours = new Mat(width, height, MatType.CV_8UC3, new Scalar(0, 0, 0)); //初期値として黒い画面を作成する。

            Cv2.DrawContours(Contours, contours, -1, new Scalar(0, 255, 0, 255), 1);     //MatにCountours(特徴点)を描画する。
            Texture2D changedTex = Unity.MatToTexture(Contours);                         //MatをTexture2Dへ変更

            GetComponent <RawImage>().texture = changedTex;                              //RaxImageにTexture2Dを書き込み。

            //MatをDisposeする。
            newMat.Dispose();
            imgGray.Dispose();
            imgGrayBlur.Dispose();
            cannyEdges.Dispose();
            mask.Dispose();
            Contours.Dispose();

            //TextureをDestryしないとメモリーリークを送りました。
            MonoBehaviour.Destroy(texture);
            if (changedTex != oldChangedTex)
            {
                MonoBehaviour.Destroy(oldChangedTex);
                oldChangedTex = changedTex;
            }
        }