opnecv canny 边缘检测

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using OpenCVForUnity;
using UnityEngine.UI;

public class test : MonoBehaviour {

    public Texture2D src2d;
    public RawImage srcimg;


	
	void Start () {
		
	}
	
	
	void Update () {

        if (Input.GetKeyDown(KeyCode.K))
        {

               Mat src = new Mat(src2d.height,src2d.width,CvType.CV_8UC3);       
               Utils.texture2DToMat(src2d, src);

               Mat edge=new Mat();
               Mat grayImage = new Mat();

               Imgproc.cvtColor(src, grayImage, Imgproc.COLOR_BGR2GRAY);

               Imgproc.blur(grayImage, edge, new Size(5,5));

               Imgproc.Canny(edge,edge,2,50);

               Texture2D texture2D = new Texture2D(src.cols(), src.rows(),TextureFormat.RGBA32, false);
               Utils.matToTexture2D(edge, texture2D);
     
                srcimg.texture = texture2D;

        }


	}
}

猜你喜欢

转载自blog.csdn.net/weixin_37744986/article/details/80638746