Esempio n. 1
0
    void Start()
    {
        _of = GetComponent<OpticalFlowWorker>();
        _tex = new Texture2D(0, 0, TextureFormat.RGB24, false);
        var mf = flow.GetComponent<MeshFilter>();
        _mesh = mf.mesh = new Mesh();
        background.renderer.sharedMaterial.mainTexture = _tex;

        _corners0 = FlowUtil.GenGridCorners(_of.width, _of.height, 50f);
        _result = _of.CalculateOpticalFlow(_corners0);
    }
Esempio n. 2
0
    // Use this for initialization
    void Start()
    {
        _of = GetComponent<OpticalFlowWorker>();
        _videoTex = new Texture2D(0, 0, TextureFormat.RGB24, false, false);
        _flowMesh = new Mesh();

        var mf = flow.GetComponent<MeshFilter>();
        mf.sharedMesh = _flowMesh;
        video.renderer.sharedMaterial.mainTexture = _videoTex;

        _corners0 = FlowUtil.GenGridCorners(_of.width, _of.height, 50f);
        _cornerBirthTimes = new float[_corners0.Length];
        var t = Time.timeSinceLevelLoad;
        for (var i = 0; i < _cornerBirthTimes.Length; i++)
            _cornerBirthTimes[i] = t;
        _ofResult = _of.CalculateOpticalFlow(_corners0);
    }
Esempio n. 3
0
    void Update()
    {
        if (!_result.completed)
            return;

        if (_firstTimeUpdate) {
            _firstTimeUpdate = false;
            UpdateAspectRatio(_result.imageWidth, _result.imageHeight);
            _velocities = new CvPoint2D32f[_mesh.vertexCount / 2];
        }

        ShowImage(_result);
        FlowUtil.CalculateFlowVelocities(_result, ref _velocities);
        FlowUtil.UpdateLineMesh(_result, _mesh, _velocities, limitVelocity);

        _result = _of.CalculateOpticalFlow(_corners0);
    }
Esempio n. 4
0
    // Update is called once per frame
    void Update()
    {
        if (!_ofResult.completed)
            return;

        //Debug.Log(string.Format("Optical Flow elapsed time {0:f}(ms)", _ofResult.elapsedMs));
        if (_ofResult.imageWidth != _videoTex.width || _ofResult.imageHeight != _videoTex.height) {
            _videoTex.Resize(_ofResult.imageWidth, _ofResult.imageHeight);
            var s = video.transform.localScale;
            s.x = s.y * _ofResult.imageWidth / _ofResult.imageHeight;
            video.transform.localScale = s;

        }
        _videoTex.LoadRawTextureData(_ofResult.imageData);
        _videoTex.Apply();

        FlowUtil.CalculateFlowVelocities(_ofResult, ref _velocities);
        FlowUtil.UpdateLineMesh(_ofResult, _flowMesh, _velocities, limitVelocity);

        _ofResult = _of.CalculateOpticalFlow(_ofResult.corners1);
    }
Esempio n. 5
0
    void Update()
    {
        if (!_result.completed)
            return;

        if (_firstTimeUpdate) {
            _firstTimeUpdate = false;
            UpdateAspectRatio(_result.imageWidth, _result.imageHeight);
        }

        ShowImage(_result);
        ShowParticles(_result);

        _prevResult = _result;
        _result = _of.CalculateOpticalFlow(_corners0);
    }
Esempio n. 6
0
    void Start()
    {
        _of = GetComponent<OpticalFlowWorker>();
        _tex = new Texture2D(0, 0, TextureFormat.RGB24, false);
        target.renderer.sharedMaterial.mainTexture = _tex;

        _corners0 = FlowUtil.GenGridCorners(_of.width, _of.height, 50f);
        _prevResult = _result = _of.CalculateOpticalFlow(_corners0);
    }