public VideoCaptureSettings GetCaptureSettings() { VideoCaptureSettings videoCaptureSettings = new VideoCaptureSettings(); videoCaptureSettings.Fps = 1; return(videoCaptureSettings); }
public VideoCaptureSettings GetCaptureSettings() { VideoCaptureSettings settings = new VideoCaptureSettings(); settings.Width = width; settings.Height = height; settings.Fps = FPS; settings.MirrorOnLocalRender = false; settings.PixelFormat = PixelFormat.FormatYuv420p; return(settings); }
private void Initialize() { foreach (var device in WebCamTexture.devices) { print(device.name); } Close(); videoCaptureSettings = LoadSetting(); if (videoCaptureSettings == null) { Debug.LogError("Missing Setting File : " + IOHandler.IntoStreamingAssets(settingsFileName)); return; } BGRMat = new Mat(); RGBMat = new Mat(); capture = new VideoCapture(); if (!string.IsNullOrEmpty(videoCaptureSettings.DeviceName)) { var devices = WebCamTexture.devices; for (var i = 0; i < devices.Length; i++) { if (devices[i].name == videoCaptureSettings.DeviceName) { capture.open(i, Videoio.CAP_DSHOW); break; } } } if (!capture.isOpened()) { var id = videoCaptureSettings.DeviceId; capture.open(id, Videoio.CAP_DSHOW); //if (!capture.isOpened()) //{ // for (var i = videoCaptureSettings.DeviceId - 1; i >= 0; i--) // { // capture.open(i, Videoio.CAP_DSHOW); // if (capture.isOpened()) break; // } //} } if (!capture.isOpened()) { Debug.LogError("Missing Webcam"); return; } Setup(); //print("backend : " + capture.getBackendName()); //capture.set(Videoio.CAP_PROP_FORMAT, ); //Debug.Log("CAP_PROP_FORMAT: " + capture.get(Videoio.CAP_PROP_FORMAT)); //Debug.Log("CAP_PROP_POS_MSEC: " + capture.get(Videoio.CAP_PROP_POS_MSEC)); //Debug.Log("CAP_PROP_POS_FRAMES: " + capture.get(Videoio.CAP_PROP_POS_FRAMES)); //Debug.Log("CAP_PROP_POS_AVI_RATIO: " + capture.get(Videoio.CAP_PROP_POS_AVI_RATIO)); //Debug.Log("CAP_PROP_FRAME_COUNT: " + capture.get(Videoio.CAP_PROP_FRAME_COUNT)); //Debug.Log("CAP_PROP_FPS: " + capture.get(Videoio.CAP_PROP_FPS)); Debug.Log("CAP_PROP_FRAME_WIDTH: " + capture.get(Videoio.CAP_PROP_FRAME_WIDTH)); Debug.Log("CAP_PROP_FRAME_HEIGHT: " + capture.get(Videoio.CAP_PROP_FRAME_HEIGHT)); //double ext = capture.get(Videoio.CAP_PROP_FOURCC); //Debug.Log("CAP_PROP_FOURCC: " + (char)((int)ext & 0XFF) + (char)(((int)ext & 0XFF00) >> 8) + (char)(((int)ext & 0XFF0000) >> 16) + (char)(((int)ext & 0XFF000000) >> 24)); capture.grab(); capture.retrieve(BGRMat, 0); int frameWidth = BGRMat.cols(); int frameHeight = BGRMat.rows(); Imgproc.cvtColor(BGRMat, RGBMat, Imgproc.COLOR_BGR2RGB); //print(BGRMat.width()); //print(frameWidth); //print(frameHeight); texture = new Texture2D(frameWidth, frameHeight, TextureFormat.RGB24, false); Refresh(); this.OnTextureInitialized(texture); waitFrameCoroutine = WaitFrameRoutine(); StartCoroutine(waitFrameCoroutine); }