//Initialize in the Start function

    void OnNewFrame(VideoPlayer source, long frameIdx)
    {
        videoPlayer.Pause();
        seekBar.value = videoPlayer.frame;

        RenderTexture renderTexture = source.texture as RenderTexture;

        if (videoFrame.width != renderTexture.width || videoFrame.height != renderTexture.height)
        {
            videoFrame.Resize(renderTexture.width, renderTexture.height);
        }
        RenderTexture.active = renderTexture;
        videoFrame.ReadPixels(new Rect(0, 0, renderTexture.width, renderTexture.height), 0, 0);
        videoFrame.Apply();
        RenderTexture.active = null;

        VideoResolution.text = "W:" + renderTexture.width.ToString() + " x " + "H:" + renderTexture.height.ToString();
        VideoName.text       = videoPlayer.url;


        if (bCallMatCreationOnce == false)
        {
            openCVMat.CreateMats(videoFrame);
            openCVUpdateLoop.initOpenCV(videoFrame);
            openCVUpdateLoop.StartTracking = true;
            bCallMatCreationOnce           = true;
        }

        openCVUpdateLoop.RunOpenCV(videoFrame, frameIdx.ToString());
        FrameRateText.text = "Video frame: " + frameIdx.ToString() + " of " + videoPlayer.frameCount.ToString();

        //targetColor = CalculateAverageColorFromTexture(videoFrame);
        //lSource.color = targetColor;
    }
示例#2
0
    void OnNewFrame(VideoPlayer source, long frameIdx)
    {
        RenderTexture renderTexture = source.texture as RenderTexture;


        if (videoFrame.width != renderTexture.width || videoFrame.height != renderTexture.height)
        {
            videoFrame.Resize(renderTexture.width, renderTexture.height);
        }
        RenderTexture.active = renderTexture;
        videoFrame.ReadPixels(new Rect(0, 0, renderTexture.width, renderTexture.height), 0, 0);
        videoFrame.Apply();
        RenderTexture.active = null;


        openCVMat.CreateMats(videoPlayer.texture);
        openCVUpdateLoop.StartTracking = true;


        //targetColor = CalculateAverageColorFromTexture(videoFrame);
        //lSource.color = targetColor;
    }