示例#1
0
        void Update()
        {
            // Check if the webcam is ready (needed for macOS support)
            if (_webcamRaw.width <= 16)
            {
                return;
            }

            // Input buffer update
            var vflip  = _webcamRaw.videoVerticallyMirrored;
            var scale  = new Vector2(1, vflip ? -1 : 1);
            var offset = new Vector2(0, vflip ? 1 : 0);

            Graphics.Blit(_webcamRaw, _webcamBuffer, scale, offset);

            // Run the object detector with the webcam input.
            _detector.ProcessImage
                (_webcamBuffer, _scoreThreshold, _overlapThreshold);

            // Draw bouding boxes into the alpha channel of _webcamBuffer.
            RenderTexture.active = _webcamBuffer;
            _detector.SetIndirectDrawCount(_drawArgs);
            _material.SetBuffer("_Boxes", _detector.BoundingBoxBuffer);
            _material.SetPass(0);
            Graphics.DrawProceduralIndirectNow(MeshTopology.Triangles, _drawArgs, 0);
        }
        void Update()
        {
            // Check if the webcam is ready (needed for macOS support)
            if (_webcamRaw.width <= 16)
            {
                return;
            }

            // Input buffer update with aspect ratio correction
            var vflip  = _webcamRaw.videoVerticallyMirrored;
            var aspect = (float)_webcamRaw.height / _webcamRaw.width;
            var scale  = new Vector2(aspect, vflip ? -1 : 1);
            var offset = new Vector2((1 - aspect) / 2, vflip ? 1 : 0);

            Graphics.Blit(_webcamRaw, _webcamBuffer, scale, offset);

            // Run the object detector with the webcam input.
            _detector.ProcessImage
                (_webcamBuffer, _scoreThreshold, _overlapThreshold);
        }