Exemplo n.º 1
0
        void Start()
        {
            // Texture allocation
            _webcamRaw    = new WebCamTexture();
            _webcamBuffer = new RenderTexture(1920, 1080, 0);

            _webcamRaw.Play();
            _previewUI.texture = _webcamBuffer;

            // Face detector initialization
            _detector = new FaceDetector(_resources);

            // Visualizer initialization
            _material = new Material(_visualizer);
            _drawArgs = new ComputeBuffer
                            (4, sizeof(uint), ComputeBufferType.IndirectArguments);
            _drawArgs.SetData(new [] { 6, 0, 0, 0 });
        }
        void Start()
        {
            using var detector = new FaceDetector(_resources);

            detector.ProcessImage(_image, _scoreThreshold, _overlapThreshold);

            var w = _markerParent.rect.width;
            var h = _markerParent.rect.height;

            foreach (var box in detector.DetectedFaces)
            {
                var x1 = box.x1 * w;
                var y1 = box.y1 * h;
                var x2 = box.x2 * w;
                var y2 = box.y2 * h;

                var marker = Instantiate(_markerPrefab, _markerParent);
                marker.anchoredPosition = new Vector2(x1, h - y2);
                marker.SetSizeWithCurrentAnchors(Axis.Horizontal, x2 - x1);
                marker.SetSizeWithCurrentAnchors(Axis.Vertical, y2 - y1);
            }
        }