Exemple #1
0
 /// <summary>
 /// Raises the change camera button click event.
 /// </summary>
 public void OnChangeCameraButtonClick()
 {
     #if UNITY_ANDROID && !UNITY_EDITOR
     if (!webCamTextureToMatHelper.IsFrontFacing())
     {
         rearCameraRequestedFPS = webCamTextureToMatHelper.requestedFPS;
         webCamTextureToMatHelper.Initialize(!webCamTextureToMatHelper.IsFrontFacing(), 15, webCamTextureToMatHelper.rotate90Degree);
     }
     else
     {
         webCamTextureToMatHelper.Initialize(!webCamTextureToMatHelper.IsFrontFacing(), rearCameraRequestedFPS, webCamTextureToMatHelper.rotate90Degree);
     }
     #else
     webCamTextureToMatHelper.requestedIsFrontFacing = !webCamTextureToMatHelper.IsFrontFacing();
     #endif
 }
        // Use this for initialization
        void Start()
        {
            exampleTitle      = "[NatCorderWithOpenCVForUnity Example] (" + NatCorderWithOpenCVForUnityExample.GetNatCorderVersion() + ")";
            exampleSceneTitle = "- Video Recording Example";

            fpsMonitor = GetComponent <FpsMonitor>();

            webCamTextureToMatHelper = gameObject.GetComponent <WebCamTextureToMatHelper>();
            int width, height;

            Dimensions(requestedResolution, out width, out height);
            webCamTextureToMatHelper.requestedWidth  = width;
            webCamTextureToMatHelper.requestedHeight = height;

#if UNITY_ANDROID && !UNITY_EDITOR
            // Avoids the front camera low light issue that occurs in only some Android devices (e.g. Google Pixel, Pixel2).
            webCamTextureToMatHelper.avoidAndroidFrontCameraLowLightIssue = true;
#endif
            webCamTextureToMatHelper.Initialize();


            microphoneSource = gameObject.AddComponent <AudioSource>();
            videoPlayer      = gameObject.AddComponent <VideoPlayer>();


            comicFilter = new ComicFilter();

            // Update GUI state
            requestedResolutionDropdown.value = (int)requestedResolution;
            containerDropdown.value           = (int)container;
            videoBitRateDropdown.value        = Array.IndexOf(System.Enum.GetNames(typeof(VideoBitRatePreset)), videoBitRate.ToString());
            audioBitRateDropdown.value        = Array.IndexOf(System.Enum.GetNames(typeof(AudioBitRatePreset)), audioBitRate.ToString());
            applyComicFilterToggle.isOn       = applyComicFilter;
            recordMicrophoneAudioToggle.isOn  = recordMicrophoneAudio;
        }
Exemple #3
0
        // Use this for initialization
        void Start()
        {
            fpsMonitor = GetComponent <FpsMonitor> ();

            webCamTextureToMatHelper = gameObject.GetComponent <WebCamTextureToMatHelper> ();
            int width, height;

            Dimensions(requestedResolution, out width, out height);
            webCamTextureToMatHelper.requestedWidth  = width;
            webCamTextureToMatHelper.requestedHeight = height;

            #if UNITY_ANDROID && !UNITY_EDITOR
            // Set the requestedFPS parameter to avoid the problem of the WebCamTexture image becoming low light on some Android devices. (Pixel, pixel 2)
            // https://forum.unity.com/threads/android-webcamtexture-in-low-light-only-some-models.520656/
            // https://forum.unity.com/threads/released-opencv-for-unity.277080/page-33#post-3445178
            rearCameraRequestedFPS = webCamTextureToMatHelper.requestedFPS;
            if (webCamTextureToMatHelper.requestedIsFrontFacing)
            {
                webCamTextureToMatHelper.requestedFPS = 15;
                webCamTextureToMatHelper.Initialize();
            }
            else
            {
                webCamTextureToMatHelper.Initialize();
            }
            #else
            webCamTextureToMatHelper.Initialize();
            #endif

            microphoneSource = gameObject.GetComponent <AudioSource> ();

            videoPlayer = gameObject.GetComponent <VideoPlayer> ();

            comicFilter = new ComicFilter();

            // Update GUI state
            requestedResolutionDropdown.value = (int)requestedResolution;
            containerDropdown.value           = (int)container - 1;
            applyComicFilterToggle.isOn       = applyComicFilter;
            recordMicrophoneAudioToggle.isOn  = recordMicrophoneAudio;
        }
        /// <summary>
        /// Raises the requested resolution dropdown value changed event.
        /// </summary>
        public void OnRequestedResolutionDropdownValueChanged(int result)
        {
            if ((int)requestedResolution != result)
            {
                requestedResolution = (ResolutionPreset)result;

                int width, height;
                Dimensions(requestedResolution, out width, out height);

                webCamTextureToMatHelper.Initialize(width, height);
            }
        }