public override void SetWeight(float w) { W = _w.Add(w, 1.0f); base.SetWeight(W); _features.FillImage(1); _features.ConvertToTexture(_tmpTexture, true); _alpha += (w * _manager.LayersParameters.MaxAlpha - _alpha) * _manager.LayersParameters.AlphaScaler * Time.deltaTime; _alpha = Mathf.Clamp(_alpha, _manager.LayersParameters.MinAlpha, _manager.LayersParameters.MaxAlpha); //_mr.material.SetVector ("_Color", new Vector4(1,1,1,W+MinAlpha)); _renderProcessor.ProcessingMaterial.SetFloat("_MinAlpha", _manager.LayersParameters.MinAlpha); _renderProcessor.ProcessingMaterial.SetFloat("_MaxAlpha", _alpha); _renderProcessor.ProcessingMaterial.SetTexture("_TargetMask", _tmpTexture); _renderProcessor.ProcessingMaterial.SetFloat("_Strength", W); _blurProcessorH.ProcessingMaterial.SetFloat("_Size", _manager.LayersParameters.ImageBlurSize * (1 - W)); _blurProcessorV.ProcessingMaterial.SetFloat("_Size", _manager.LayersParameters.ImageBlurSize * (1 - W)); }
void Start() { Gaze = GameObject.FindObjectOfType <GazeFollowComponent> (); _processor = new OffscreenProcessor(); _processor.ShaderName = "GazeBased/Blend"; Image <Gray, byte> cache = null; EmguImageUtil.UnityTextureToOpenCVImageGray(TargetTexture, ref cache); //new Mat(pictureStr, LoadImageType.Color); //Read the files as an 8-bit Bgr image long detectionTime; List <Rectangle> faces = new List <Rectangle>(); List <Rectangle> eyes = new List <Rectangle>(); //The cuda cascade classifier doesn't seem to be able to load "haarcascade_frontalface_default.xml" file in this release //disabling CUDA module for now bool tryUseCuda = true; bool tryUseOpenCL = false; DetectObjectCL.DetectFace( cache.Mat, false, faces, eyes, tryUseCuda, tryUseOpenCL, out detectionTime); foreach (Rectangle face in faces) { CvInvoke.Rectangle(cache.Mat, face, new Bgr(0, 0, 1).MCvScalar, 2); } foreach (Rectangle eye in eyes) { CvInvoke.Rectangle(cache.Mat, eye, new Bgr(1, 0, 0).MCvScalar, 2); } Debug.Log("detected faces:" + faces.Count); Debug.Log("face detection time:" + detectionTime.ToString() + "ms"); //display the image /* ImageViewer.Show(image, String.Format( * "Completed face and eye detection using {0} in {1} milliseconds", * (tryUseCuda && CudaInvoke.HasCuda) ? "GPU" * : (tryUseOpenCL && CvInvoke.HaveOpenCLCompatibleGpuDevice) ? "OpenCL" * : "CPU", * detectionTime)); */ _map = new ImageFeatureMap(128, 128); foreach (Rectangle face in faces) { Rectangle r = new Rectangle(); r.X = face.X - 50; r.Y = face.Y - 5; r.Width = face.Width + 50; r.Height = face.Height + 520; _map.FillRectangle((float)r.X / (float)cache.Mat.Width, (float)r.Y / (float)cache.Mat.Height, (float)r.Width / (float)cache.Mat.Width, (float)r.Height / (float)cache.Mat.Height, 1); } _map.Blur(); _map.Blur(); _map.Blur(); _map.Blur(); Texture2D tex = new Texture2D(1, 1); tex.filterMode = FilterMode.Point; _map.ConvertToTexture(tex, true); _processor.ProcessingMaterial.SetTexture("_TargetMask", tex); _processor.ProcessingMaterial.SetTexture("_MainTex", TargetTexture); GetComponent <UITexture> ().mainTexture = tex; //_processor.ProcessTexture (TargetTexture); }