arskrald/AR-2b/Assets/StylizedScript.cs

45 lines
1.3 KiB
C#
Raw Permalink Normal View History

2019-02-28 10:52:10 +00:00
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));
}
}
}