コード例 #1
0
ファイル: virtualCVRig.cs プロジェクト: fnwinter/virtualCV
        // Start is called before the first frame update
        void Start()
        {
            socket = new VirtualCVWebSocket();
            socket.Initialize();

            left       = this.gameObject.transform.GetChild(0).gameObject;
            leftCamera = left.GetComponent <Camera>();

            if (VirtualCVSettings.GetParam().useStereoCamera)
            {
                right       = this.gameObject.transform.GetChild(1).gameObject;
                rightCamera = right.GetComponent <Camera>();

                float ipd = VirtualCVSettings.GetParam().ipd;
                left.transform.localPosition.Set(0, -ipd / 2, 0);
                right.transform.localPosition.Set(0, ipd / 2, 0);
            }
            else
            {
                left.transform.localPosition.Set(0, 0, 0);
            }

            string pythonScript = VirtualCVSettings.GetParam().python_script;

            PythonExecutor.getInstance().ExecutePython(pythonScript);
        }
コード例 #2
0
        static void Init()
        {
            param = VirtualCVSettings.LoadSettings();

            VirtualCVDialog window = (VirtualCVDialog)EditorWindow.GetWindow(typeof(VirtualCVDialog));

            window.titleContent.text = "virtualCV";
            window.Show();
        }
コード例 #3
0
        void SetCamera()
        {
            cam = GetComponent <Camera>();

            cam.fieldOfView           = VirtualCVSettings.GetParam().fov;
            cam.usePhysicalProperties = VirtualCVSettings.GetParam().usePhysicalCamera;
            cam.focalLength           = VirtualCVSettings.GetParam().focal_length;

            VirtualCVLog.Log($"Camera info : {name} - {cam.fieldOfView} - {cam.usePhysicalProperties} - {cam.focalLength}");
        }
コード例 #4
0
 void SetTexture()
 {
     // 640x480
     textureWidth  = VirtualCVSettings.GetParam().textureWidth;
     textureHeight = VirtualCVSettings.GetParam().textureHeight;
     if (textureWidth > 0 && textureHeight > 0)
     {
         cam.targetTexture.texelSize.Set(textureWidth, textureHeight);
         cameraImage = new Texture2D(textureWidth, textureHeight, TextureFormat.RGB24, false);
     }
 }
コード例 #5
0
        void OnGUI()
        {
            GUILayout.Label("Camera settings", EditorStyles.boldLabel);

            param.usePhysicalCamera = EditorGUILayout.Toggle("Use physical camera", param.usePhysicalCamera);
            param.useDepthCameara   = EditorGUILayout.Toggle("Use depth camera", param.useDepthCameara);

            EditorGUILayout.Space();

            param.textureWidth  = EditorGUILayout.IntField("Texture width", param.textureWidth);
            param.textureHeight = EditorGUILayout.IntField("Texture height", param.textureHeight);

            EditorGUILayout.Space();

            param.fov          = EditorGUILayout.FloatField("Field of view", param.fov);
            param.fps          = EditorGUILayout.IntField("FPS", param.fps);
            param.focal_length = EditorGUILayout.FloatField("Focal length", param.focal_length);

            EditorGUILayout.Space();

            param.useStereoCamera = EditorGUILayout.Toggle("Use stereo camera", param.useStereoCamera);
            param.ipd             = EditorGUILayout.FloatField("Interpupillary distance", param.ipd);

            EditorGUILayout.Space();

            if (GUILayout.Button("Save settings"))
            {
                VirtualCVLog.Log("Settings saved");
                VirtualCVSettings.SaveSettings(param);
            }
            if (GUILayout.Button("Apply to camera"))
            {
                ApplyCamera();
            }

            EditorGUILayout.Space();

            int selectedPythonScript = GetPythonScriptIndex(param.python_script);

            selectedPythonScript = EditorGUILayout.Popup("Python script", selectedPythonScript, pythonFiles);
            param.python_script  = pythonFiles[selectedPythonScript];
            if (GUILayout.Button("Launch the script"))
            {
                if (Application.isPlaying)
                {
                    PythonExecutor.getInstance().ExecutePython(param.python_script);
                }
                else
                {
                    VirtualCVLog.LogE("It's able to run only when Unity is playing.");
                }
            }
        }
コード例 #6
0
ファイル: PythonExecutor.cs プロジェクト: fnwinter/virtualCV
        /// <summary>
        /// Execute python script
        /// </summary>
        /// <param name="scriptFile">python script file name, default is opencv.py</param>
        public void ExecutePython(string pythonScriptFile)
        {
            VirtualCVLog.Log("Execute python script : " + pythonScriptFile);

            string useStereo = VirtualCVSettings.GetParam().useStereoCamera ? "stereo" : "";

            pythonProcess.StartInfo.FileName               = pythonExe;
            pythonProcess.StartInfo.WorkingDirectory       = pythonScriptPath;
            pythonProcess.StartInfo.Arguments              = $"{pythonScriptFile} {useStereo}";
            pythonProcess.StartInfo.UseShellExecute        = false;
            pythonProcess.StartInfo.RedirectStandardOutput = true;
            pythonProcess.StartInfo.CreateNoWindow         = true;

            pythonProcess.Start();
        }
コード例 #7
0
        void Start()
        {
            VirtualCVLog.Log("VirtualCVCamera starts");

            bool useStereo = VirtualCVSettings.GetParam().useStereoCamera;

            isRightCamera = (name == "VirtualCVCameraRight");
            if (isRightCamera && !useStereo)
            {
                return;
            }

            SetCamera();
            SetTexture();

            screenshotPath = Path.Combine(Application.dataPath, "..", "Screenshot");
            Directory.CreateDirectory(screenshotPath);

            int port = isRightCamera ? rightCameraPort : leftCameraPort;

            ffmpegExecutor = new FFMPEGExecutor(port);
            ffmpegExecutor.Initialze();
            ffmpegExecutor.ExecuteFFMPEG();
        }