45 lines
1.3 KiB
C#
45 lines
1.3 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using OpenCVForUnity.CoreModule;
|
|
using OpenCVForUnity.ImgprocModule;
|
|
using Vuforia;
|
|
|
|
public class StylizedScript : MonoBehaviour
|
|
{
|
|
Mat cameraImageMat;
|
|
Mat stylizedMat = new Mat();
|
|
Mat greyMat = new Mat();
|
|
// Start is called before the first frame update
|
|
void Start()
|
|
{
|
|
|
|
}
|
|
|
|
// Update is called once per frame
|
|
void Update()
|
|
{
|
|
MatDisplay.SetCameraFoV(41.5f);
|
|
|
|
Image cameraImage = CameraDevice.Instance.GetCameraImage(Image.PIXEL_FORMAT.RGBA8888);
|
|
|
|
if (cameraImage != null)
|
|
{
|
|
if (cameraImageMat == null)
|
|
{
|
|
cameraImageMat = new Mat(cameraImage.Height, cameraImage.Width, CvType.CV_8UC4);
|
|
}
|
|
cameraImageMat.put(0, 0, cameraImage.Pixels);
|
|
|
|
Imgproc.cvtColor(cameraImageMat, greyMat, Imgproc.COLOR_RGB2GRAY);
|
|
|
|
Imgproc.adaptiveThreshold(greyMat, stylizedMat, 255, Imgproc.ADAPTIVE_THRESH_MEAN_C, Imgproc.THRESH_BINARY, 11, 5);
|
|
|
|
MatDisplay.DisplayMat(stylizedMat, MatDisplaySettings.FULL_BACKGROUND);
|
|
|
|
Shader.SetGlobalVector("_NoiseVector", new Vector2(Random.value, Random.value));
|
|
|
|
}
|
|
}
|
|
}
|