using OpenCVForUnity.CoreModule;
using OpenCVForUnity.ImgcodecsModule;
using OpenCVForUnity.ImgprocModule;
using OpenCVForUnity.UnityUtils;
using UnityEngine;
using UnityEngine.UI;
public class OpencvBlur : MonoBehaviour
{
public int threadValue = 5;
// Start is called before the first frame update
void Start()
{
//把图片读进三通道的容器
var src = Imgcodecs.imread(Application.dataPath + "/Test.png");
把尺寸设置为大小
Imgproc.resize(src, src, new Size(701, 353));
//建立一个四通道的容器
var dst = new Mat(src.cols(), src.rows(), CvType.CV_8UC4);
转换色彩空间
//Imgproc.cvtColor(src, dst, Imgproc.COLOR_BGR2RGBA);
Size ksize = new Size(5, 5);
//Imgproc.blur(src, dst, ksize);
//Imgproc.medianBlur(src, dst, threadValue);
//Imgproc.GaussianBlur(src, dst, ksize,750);
//Imgproc.boxFilter(src, dst, -1, ksize);
Imgproc.bilateralFilter(src, dst,5, 75,75);
// 定义一个 Texture2D 对象
var tex = new Texture2D(dst.cols(), dst.rows());
// 将 dst 转换成这个 Texture2D 对象
Utils.matToTexture2D(dst, tex);
// 将处理后的图片现实在 RawImage 组件上
RawImage raw = GetComponent<RawImage>();
raw.texture = tex;
raw.SetNativeSize();
}
}